feat: mes交互工具
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
package org.nl.wms.ext_manage.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.config.SpringContextHolder;
|
||||||
|
import org.nl.wms.ext_manage.service.util.AcsResponse;
|
||||||
|
import org.nl.wms.system_manage.enums.SysParamConstant;
|
||||||
|
import org.nl.wms.system_manage.service.param.dao.Param;
|
||||||
|
import org.nl.wms.system_manage.service.param.impl.SysParamServiceImpl;
|
||||||
|
import org.nl.wms.warehouse_manage.enums.IOSConstant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Date: 2025/7/30
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class MesUtil {
|
||||||
|
/**
|
||||||
|
* 下发任务
|
||||||
|
* @param api mes地址
|
||||||
|
* @param param 下发参数
|
||||||
|
* @return AcsResponse
|
||||||
|
*/
|
||||||
|
public static <T> AcsResponse notifyMes(String api, T param) {
|
||||||
|
log.info("下发MES的参数为:-------------------" + param.toString());
|
||||||
|
// 返回参数
|
||||||
|
AcsResponse resultAcs;
|
||||||
|
// 系统参数类
|
||||||
|
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class);
|
||||||
|
//判断是否连接MES系统
|
||||||
|
Param isConnectMes = sysParamService.findByCode(SysParamConstant.IS_CONNECT_MES);
|
||||||
|
if (ObjectUtil.isEmpty(isConnectMes)) {
|
||||||
|
return AcsResponse.requestError("系统参数表中:" + SysParamConstant.IS_CONNECT_MES + "不存在");
|
||||||
|
}
|
||||||
|
if (isConnectMes.getValue().equals(IOSConstant.IS_DELETE_NO)) {
|
||||||
|
return AcsResponse.requestOkMessage("下发成功,未连接MES系统!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//MES地址
|
||||||
|
Param acsUrlParam = sysParamService.findByCode(SysParamConstant.MES_URL);
|
||||||
|
if (ObjectUtil.isEmpty(acsUrlParam)) {
|
||||||
|
return AcsResponse.requestError("系统参数表中:" + SysParamConstant.MES_URL + "不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = acsUrlParam.getValue() + api;
|
||||||
|
try {
|
||||||
|
String resultMsg = HttpRequest.post(url)
|
||||||
|
.body(String.valueOf(param))
|
||||||
|
.execute().body();
|
||||||
|
// 格式转换
|
||||||
|
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||||
|
resultAcs = JSONObject.toJavaObject(result, AcsResponse.class);
|
||||||
|
|
||||||
|
log.info("下发MES任务的输出参数为:-------------------" + resultMsg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//网络不通
|
||||||
|
String msg = e.getMessage();
|
||||||
|
log.error("连接失败:{}", msg);
|
||||||
|
return AcsResponse.requestError("网络不通,操作失败!");
|
||||||
|
}
|
||||||
|
return resultAcs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,10 +12,16 @@ public class SysParamConstant {
|
|||||||
*/
|
*/
|
||||||
public final static String IS_CONNECT_ACS = "is_connect_acs";
|
public final static String IS_CONNECT_ACS = "is_connect_acs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否连接MES
|
||||||
|
*/
|
||||||
|
public final static String IS_CONNECT_MES = "is_connect_mes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ACS系统IP
|
* ACS系统IP
|
||||||
*/
|
*/
|
||||||
public final static String ACS_URL = "acs_url";
|
public final static String ACS_URL = "acs_url";
|
||||||
|
public final static String MES_URL = "mes_url";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP系统IP
|
* ERP系统IP
|
||||||
|
|||||||
Reference in New Issue
Block a user