真空-流程生产订单推真空MES-V1
This commit is contained in:
parent
6959f0e1cb
commit
0a79ead6a6
|
|
@ -0,0 +1,182 @@
|
||||||
|
package nc.bs.mmpac.pmo.pac0002.bp.rule;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import nc.bs.dao.BaseDAO;
|
||||||
|
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.material.MaterialVO;
|
||||||
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
||||||
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
|
||||||
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
||||||
|
import nc.vo.org.OrgVO;
|
||||||
|
import nc.vo.pub.BusinessException;
|
||||||
|
import nc.vo.pub.lang.UFDate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 真空-流程生产订单推真空MES
|
||||||
|
*
|
||||||
|
* @author mzr
|
||||||
|
* @date 2025/11/15
|
||||||
|
*/
|
||||||
|
public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
|
||||||
|
|
||||||
|
private static final String LOG_INFO_NAME = "zkmeslog";
|
||||||
|
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
|
||||||
|
private static final String addUrl = "/webApi/WorkPlan/AddWorkOrder";
|
||||||
|
private static final String delUrl = "/webApi/WorkPlan/DelPartCodes";
|
||||||
|
private Map<String, String> configParams;
|
||||||
|
public static final BaseDAO baseDAO = new BaseDAO();
|
||||||
|
private String flag = "";
|
||||||
|
|
||||||
|
public AfterPmoSyncZkMesRule() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AfterPmoSyncZkMesRule(String flag) {
|
||||||
|
this.flag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(PMOAggVO[] pmoAggVOS) {
|
||||||
|
try {
|
||||||
|
configParams = MyHelper.getConfigParams("zk-config", null);
|
||||||
|
if (configParams.isEmpty()) {
|
||||||
|
throw new BusinessException("真空MES接口缺少配置");
|
||||||
|
}
|
||||||
|
if ("cancel".equals(flag)) {
|
||||||
|
buildSyncDelData(pmoAggVOS);
|
||||||
|
} else {
|
||||||
|
buildSyncData(pmoAggVOS);
|
||||||
|
}
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建同步数据
|
||||||
|
*/
|
||||||
|
private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException {
|
||||||
|
for (PMOAggVO vo : useVOs) {
|
||||||
|
// 判断物料的业务单元是否是配置的公司,不是则跳过
|
||||||
|
String pkOrg = vo.getParentVO().getPk_org();
|
||||||
|
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||||
|
if (checkIfOrg(orgCode, configParams)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PMOHeadVO pmoHeadVO = vo.getParentVO();
|
||||||
|
PMOItemVO[] itemVOS = vo.getChildrenVO();
|
||||||
|
UFDate dbilldate = pmoHeadVO.getDbilldate();
|
||||||
|
// 组装数据
|
||||||
|
JSONObject singleObj = new JSONObject();
|
||||||
|
singleObj.put("WorkOrderNo", "2025111001");// 产品类型-对应PLM产品编码
|
||||||
|
if (dbilldate != null) {
|
||||||
|
singleObj.put("SendDate", dbilldate.toString().substring(0, 10));// 接收日期
|
||||||
|
}
|
||||||
|
// 处理子表数组
|
||||||
|
JSONArray contentArray = new JSONArray();
|
||||||
|
for (PMOItemVO item : itemVOS) {
|
||||||
|
String projectName = MyHelper.getStrValByCondition("bd_project", "project_name",
|
||||||
|
"pk_project = '" + item.getCprojectid() + "' ");
|
||||||
|
// 物料
|
||||||
|
String cmaterialid = item.getCmaterialid();
|
||||||
|
String materialCode = MyHelper.getStrValByCondition(MaterialVO.getDefaultTableName(), MaterialVO.CODE,
|
||||||
|
MaterialVO.PK_MATERIAL + " = '" + cmaterialid + "'");
|
||||||
|
JSONObject itemObj = new JSONObject();
|
||||||
|
// itemObj.put("WorkOrderId", 0);//
|
||||||
|
// itemObj.put("IsAddPlan", "");//
|
||||||
|
itemObj.put("PartCode", materialCode);// 产品编码
|
||||||
|
itemObj.put("ProductTypeId", 8);
|
||||||
|
// itemObj.put("XMPZ", "");// 项目配置-暂时不传
|
||||||
|
itemObj.put("HTBM", item.getVdef1());// 合同编码
|
||||||
|
itemObj.put("ProjectName", projectName);// 项目名称
|
||||||
|
itemObj.put("Field1", item.getAttributeValue("vdef44"));//
|
||||||
|
itemObj.put("Field2", item.getAttributeValue("vdef45"));//
|
||||||
|
itemObj.put("Field3", item.getAttributeValue("vdef46"));//
|
||||||
|
itemObj.put("Field4", item.getAttributeValue("vdef47"));//
|
||||||
|
itemObj.put("Field5", item.getAttributeValue("vdef48"));//
|
||||||
|
itemObj.put("Field6", item.getAttributeValue("vdef49"));//
|
||||||
|
itemObj.put("Field7", item.getAttributeValue("vdef50"));//
|
||||||
|
itemObj.put("Field8", item.getAttributeValue("vdef51"));//
|
||||||
|
itemObj.put("Field9", item.getAttributeValue("vdef52"));//
|
||||||
|
itemObj.put("Field10", item.getAttributeValue("vdef53"));//
|
||||||
|
itemObj.put("Field11", item.getAttributeValue("vdef54"));//
|
||||||
|
itemObj.put("Field12", item.getAttributeValue("vdef55"));//
|
||||||
|
itemObj.put("Field13", item.getAttributeValue("vdef56"));//
|
||||||
|
// itemObj.put("Id", 0);//
|
||||||
|
contentArray.add(itemObj);
|
||||||
|
}
|
||||||
|
singleObj.put("partListAddEntity", contentArray);
|
||||||
|
String param = JSON.toJSONString(singleObj);
|
||||||
|
pushData(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildSyncDelData(PMOAggVO[] useVOs) throws BusinessException {
|
||||||
|
for (PMOAggVO vo : useVOs) {
|
||||||
|
// 判断物料的业务单元是否是配置的公司,不是则跳过
|
||||||
|
String pkOrg = vo.getParentVO().getPk_org();
|
||||||
|
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||||
|
if (checkIfOrg(orgCode, configParams)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PMOItemVO[] itemVOS = vo.getChildrenVO();
|
||||||
|
|
||||||
|
// 组装数据
|
||||||
|
JSONArray contentArray = new JSONArray();
|
||||||
|
for (PMOItemVO item : itemVOS) {
|
||||||
|
// 物料
|
||||||
|
String cmaterialid = item.getCmaterialid();
|
||||||
|
String materialCode = MyHelper.getStrValByCondition(MaterialVO.getDefaultTableName(), MaterialVO.CODE,
|
||||||
|
MaterialVO.PK_MATERIAL + " = '" + cmaterialid + "'");
|
||||||
|
contentArray.add(materialCode);
|
||||||
|
}
|
||||||
|
String param = JSON.toJSONString(contentArray);
|
||||||
|
pushData(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送同步数据
|
||||||
|
*/
|
||||||
|
private void pushData(String param) throws BusinessException {
|
||||||
|
// 转json字符串的时候保留null值
|
||||||
|
logger.error("zkmes-PMO-param = " + param);
|
||||||
|
String baseUrl = configParams.get("baseUrl");
|
||||||
|
String requestUrl = baseUrl + addUrl;
|
||||||
|
if ("cancel".equals(flag)) {
|
||||||
|
requestUrl = baseUrl + delUrl;
|
||||||
|
}
|
||||||
|
logger.error("zkmes-PMO-url = " + requestUrl);
|
||||||
|
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param);
|
||||||
|
logger.error("zkmes-PMO-res = " + result);
|
||||||
|
JSONObject resultObj = JSONObject.parseObject(result);
|
||||||
|
|
||||||
|
if (!"true".equals(resultObj.getString("result"))) {
|
||||||
|
logger.error("zkmes-PMO-error,result[" + resultObj.toJSONString() + "]");
|
||||||
|
throw new BusinessException("真空MES错误信息:" + resultObj.getString("msg"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
||||||
|
String targetCode = configParams.get("zkOrg");
|
||||||
|
if (targetCode == null || MMValueCheck.isEmpty(targetCode)) {
|
||||||
|
throw new BusinessException("未配置组织参数");
|
||||||
|
}
|
||||||
|
String[] orgItem = targetCode.split(",");
|
||||||
|
for (String orgCode : orgItem) {
|
||||||
|
if (!orgCode.isEmpty() && orgCode.equals(code)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue