BOM修改后同步艾普MES的BOM

This commit is contained in:
mzr 2025-08-29 16:59:14 +08:00
parent 3e15bd6457
commit 8d86ad7e43
1 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,120 @@
package nc.bs.bd.bom.bom0202.rule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import nc.bs.logging.Log;
import nc.bs.uapbd.util.MyHelper;
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.bd.bom.bom0202.entity.AggBomVO;
import nc.vo.bd.bom.bom0202.entity.BomItemVO;
import nc.vo.bd.bom.bom0202.entity.BomVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import java.util.Map;
/**
* BOM修改后同步艾普MES的BOM
*
* @author mzr
* @date 2025/08/29
*/
public class BomUpdateAfterEpicMesRule implements IRule<AggBomVO> {
private static final String LOG_INFO_NAME = "dldzlog";
private static final Log logDl = Log.getInstance(LOG_INFO_NAME);
private static final String reqUrl = "";
private Map<String, String> configParams;
@Override
public void process(AggBomVO[] vos) {
if (!MMValueCheck.isEmpty(vos)) {
try {
configParams = MyHelper.getConfigParams("Dldz-config", null);
JSONArray data = buildSyncData(vos);
pushData(data);
} catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
}
}
/**
* 构建同步数据
*/
private JSONArray buildSyncData(AggBomVO[] useVOs) throws BusinessException {
JSONArray data = new JSONArray();
for (AggBomVO vo : useVOs) {
// 判断物料的业务单元是否是电力电子公司不是则跳过
BomVO hvo = (BomVO) vo.getParentVO();
String pkOrg = (String) hvo.getAttributeValue("pk_org");
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
if (MyHelper.checkIfDldzOrg(orgCode, configParams)) {
continue;
}
BomItemVO[] childrenVOs = vo.getChildrenVO();
if (MMValueCheck.isEmpty(childrenVOs)) {
continue;
}
String hfmaterialid = hvo.getHfmaterialid();// 父项物料编码
String hcprojectid = hvo.getHcprojectid();// 项目
String hversion = hvo.getHversion();// BOM版本号
for (BomItemVO childrenVO : childrenVOs) {
String cmaterialid = childrenVO.getCmaterialid();
// 组装数据
JSONObject singleObj = new JSONObject();
singleObj.put("mitm", ""); // 制造物料编码(ERP父项物料编码)
singleObj.put("sitm", ""); // 子物料编码
singleObj.put("orderNum", ""); // 合同号(ERP项目)
singleObj.put("qana", childrenVO.getNassitemnum()); // 数量(ERP子项数量)
singleObj.put("ver", hversion); // BOM版本号
singleObj.put("remark", childrenVO.getVnote()); // 备注
data.add(singleObj);
}
/**
* [
* {
* "mitm": "DSF01-2501230028",
* "sitm": "2305050447",
* "orderNum": "111",
* "qana": 1,
* "ver": "1",
* "remark": ""
* }
* ]
*/
}
return data;
}
/**
* 推送同步数据
*/
private void pushData(JSONArray param) throws BusinessException {
// 转json字符串的时候保留null值
String jsonStr = JSON.toJSONString(param,
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty
);
logDl.error("EpicMes-BOM-param = " + jsonStr);
NCCForUAPLogger.debug("EpicMes-BOM-param = " + jsonStr);
String baseUrl = configParams.get("epicMesUrl");
String requestUrl = baseUrl + reqUrl;
logDl.error("EpicMes-BOM-url = " + requestUrl);
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
JSONObject resultObj = JSONObject.parseObject(result);
logDl.error("EpicMes-BOM-res = " + result);
if (!"1".equals(resultObj.getString("flag"))) {
// throw new BusinessException("EpicMes-BOM-error:" + resultObj.getString("msg"));
logDl.error("EpicMes-BOM-error,result[" + resultObj.toJSONString() + "]");
}
}
}