物料动作监听插件v0

This commit is contained in:
mzr 2025-07-15 10:15:42 +08:00
parent 41c262029e
commit 4c505d6b7e
1 changed files with 30 additions and 18 deletions

View File

@ -1,12 +1,14 @@
package nccloud.api.uapbd.material.listener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import nc.bs.bd.baseservice.ArrayClassConvertUtil;
import nc.bs.businessevent.IBusinessEvent;
import nc.bs.businessevent.IBusinessListener;
import nc.bs.businessevent.bd.BDCommonEvent;
import nc.bs.dao.BaseDAO;
import nc.bs.logging.Logger;
import nc.bs.logging.Log;
import nc.bs.uapbd.util.MyHelper;
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
import nc.itf.arap.goldentax.SysParaInitQuery;
@ -26,7 +28,8 @@ import java.util.Map;
* @date 2025/06/27
*/
public class MaterialToEpicMesListener implements IBusinessListener {
private static final String LOG_INFO_NAME = "dldzlog";
private static final Log logDl = Log.getInstance(LOG_INFO_NAME);
private static final String reqUrl = "/prj-v5-web/ext/api/mrl";
@Override
@ -35,13 +38,11 @@ public class MaterialToEpicMesListener implements IBusinessListener {
String eventType = event.getEventType();
Object[] objs = e.getObjs();
MaterialVO[] useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class);
// EventType是事件编码
if ("1002".equals(eventType)) {
// 新增后
buildSyncData(useVOs, eventType);
} else if ("1004".equals(eventType)) {
// 修改后
// EventType是事件编码 1002-新增后 1004-修改后 1071-状态由停用变为启用后 1069-状态由启用变为停用后
if ("1002".equals(eventType) || "1004".equals(eventType)) {
buildSyncData(useVOs, eventType);
} else if ("1071".equals(eventType) || "1069".equals(eventType)) {
}
}
@ -69,14 +70,14 @@ public class MaterialToEpicMesListener implements IBusinessListener {
// 组装数据
JSONObject singleObj = new JSONObject();
singleObj.put("id", null);// 唯一标识主键
singleObj.put("siteCode", orgCode);// 工厂编码 todo
singleObj.put("siteCode", orgCode);// 工厂编码
singleObj.put("mrlCode", vo.getCode());// 物料编码
singleObj.put("mrlName", vo.getName());// 物料名称
singleObj.put("unit", unitMap.get("unitName"));// 单位
singleObj.put("unit", unitMap.get("unitname"));// 单位
singleObj.put("model", vo.getMaterialtype());// 型号
singleObj.put("specification", vo.getMaterialspec());// 规格
singleObj.put("type", getType(eventType));// 类型I:新增 U:修改 D:删除
singleObj.put("deputyUnit", unitMap.get("deputyUnitName"));// 副单位
singleObj.put("deputyUnit", unitMap.get("deputy_unitname"));// 副单位
singleObj.put("auditCode", "1");// 审核码
singleObj.put("statusCode", statusCode);// 状态码Y表示启用N表示停用
singleObj.put("mrlTypeErp", "3");// 物料类型ERP1:专用件3:通用件todo
@ -91,16 +92,24 @@ public class MaterialToEpicMesListener implements IBusinessListener {
* 推送同步数据
*/
private void pushData(JSONObject param) throws BusinessException {
// String jsonString = param.toJSONString();
// 转json字符串的时候保留null值
String jsonStr = JSON.toJSONString(param,
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty
);
logDl.error("EpicMes-Material-param = " + jsonStr);
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
baseUrl = "http://192.168.55.39:8080";
String requestUrl = baseUrl + reqUrl;
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
logDl.error("EpicMes-Material-url = " + requestUrl);
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
JSONObject resultObj = JSONObject.parseObject(result);
Logger.error("EpicMes-Material-req = " + result);
logDl.error("EpicMes-Material-res = " + result);
if ("false".equals(resultObj.getString("success"))) {
throw new BusinessException("EpicMes-Material-failerror:" + resultObj.getString("msg"));
} else {
Logger.error("EpicMes-Material-suc,result[" + resultObj.toJSONString() + "]");
if (!"1".equals(resultObj.getString("flag"))) {
// throw new BusinessException("EpicMes-Material-error:" + resultObj.getString("msg"));
logDl.error("EpicMes-Material-error,result[" + resultObj.toJSONString() + "]");
}
}
@ -109,16 +118,19 @@ public class MaterialToEpicMesListener implements IBusinessListener {
Map<String, String> map = new HashMap<>();
map.put("1002", "I");
map.put("1004", "U");
map.put("1069", "U");
map.put("1071", "U");
return map.getOrDefault(eventType, "I");
}
private Map getUnitInfo(String pkMaterial) throws BusinessException {
String sql = " select a.pk_measdoc, c.name unitName, b.pk_measdoc deputyUnit, d.name deputyUnitName, nvl(b.measrate, '1/1') measrate " +
String sql = " select a.pk_measdoc, c.name unitname, b.pk_measdoc deputyUnit, d.name deputy_unitname, nvl(b.measrate, '1/1') measrate " +
"from bd_material a " +
"left join bd_materialconvert b on a.pk_material = b.pk_material " +
"left join bd_measdoc c on a.pk_measdoc = c.pk_measdoc " +
"left join bd_measdoc d on b.pk_measdoc = d.pk_measdoc " +
"where a.pk_material = '" + pkMaterial + "' ";
// logDl.error("EpicMes-Material-getUnitInfo-sql = " + sql);
Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor());
map.put("convertRate", MyHelper.transferSpecialField(map.get("measrate") + ""));
return map;