真空mes-流程生产订单同步

This commit is contained in:
mzr 2025-11-20 13:47:39 +08:00
parent b46333b113
commit d5fdad79f2
2 changed files with 154 additions and 46 deletions

View File

@ -66,6 +66,7 @@ public class PMOApproveBP {
processer.addAfterRule(new AfterApproveSyncImsRule("Y")); processer.addAfterRule(new AfterApproveSyncImsRule("Y"));
// 流程生产订单审批后推送高压IMS-流程备料计划 // 流程生产订单审批后推送高压IMS-流程备料计划
processer.addAfterRule(new PMOAfterApproveRuleHighpressureIms()); processer.addAfterRule(new PMOAfterApproveRuleHighpressureIms());
processer.addAfterRule(new AfterPmoSyncZkMesRule("audit"));
} }
public PMOAggVO[] approveCancel(PMOAggVO[] fullBills, PMOAggVO[] originBills) { public PMOAggVO[] approveCancel(PMOAggVO[] fullBills, PMOAggVO[] originBills) {
@ -96,5 +97,6 @@ public class PMOApproveBP {
// 生产订单取消审批后推送高压MES // 生产订单取消审批后推送高压MES
processer.addAfterRule(new AfterApproveSyncImsRule("N")); processer.addAfterRule(new AfterApproveSyncImsRule("N"));
processer.addAfterRule(new AfterApproveCancelSyncHighpressureMesRule()); processer.addAfterRule(new AfterApproveCancelSyncHighpressureMesRule());
processer.addAfterRule(new AfterPmoSyncZkMesRule("cancel"));
} }
} }

View File

@ -4,21 +4,32 @@ package nc.bs.mmpac.pmo.pac0002.bp.rule;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import nc.bs.uapbd.util.IgnoreSslUtil;
import nc.bs.dao.BaseDAO; import nc.bs.dao.BaseDAO;
import nc.bs.logging.Log; import nc.bs.logging.Log;
import nc.bs.trade.business.HYPubBO;
import nc.bs.uapbd.util.MyHelper; import nc.bs.uapbd.util.MyHelper;
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
import nc.impl.pubapp.pattern.rule.IRule; import nc.impl.pubapp.pattern.rule.IRule;
import nc.util.mmf.framework.base.MMValueCheck; import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.bd.material.MaterialVO; import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.cmp.util.StringUtils;
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO; import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO; import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO; import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
import nc.vo.org.DeptVO;
import nc.vo.org.OrgVO; import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDate;
import org.eclipse.swt.internal.win32.MSG;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.zip.GZIPInputStream;
/** /**
* 真空-流程生产订单推真空MES * 真空-流程生产订单推真空MES
@ -30,8 +41,8 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
private static final String LOG_INFO_NAME = "zkmeslog"; private static final String LOG_INFO_NAME = "zkmeslog";
private static final Log logger = Log.getInstance(LOG_INFO_NAME); private static final Log logger = Log.getInstance(LOG_INFO_NAME);
private static final String addUrl = "/webApi/WorkPlan/AddWorkOrder"; private static final String addUrl = "/api/WorkPlan/AddWorkOrder";
private static final String delUrl = "/webApi/WorkPlan/DelPartCodes"; private static final String delUrl = "/api/WorkPlan/DelPartCodes";
private Map<String, String> configParams; private Map<String, String> configParams;
public static final BaseDAO baseDAO = new BaseDAO(); public static final BaseDAO baseDAO = new BaseDAO();
private String flag = ""; private String flag = "";
@ -56,6 +67,7 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
buildSyncData(pmoAggVOS); buildSyncData(pmoAggVOS);
} }
} catch (BusinessException e) { } catch (BusinessException e) {
logger.error("AfterPmoSyncZkMesRule-exp: " + e.getMessage(), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -64,8 +76,9 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
* 构建同步数据 * 构建同步数据
*/ */
private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException { private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException {
HYPubBO hyPub = new HYPubBO();
for (PMOAggVO vo : useVOs) { for (PMOAggVO vo : useVOs) {
// 判断物料的业务单元是否是配置的公司不是则跳过 // 判断是否是真空公司不是则跳过
String pkOrg = vo.getParentVO().getPk_org(); String pkOrg = vo.getParentVO().getPk_org();
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
if (checkIfOrg(orgCode, configParams)) { if (checkIfOrg(orgCode, configParams)) {
@ -73,55 +86,42 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
} }
PMOHeadVO pmoHeadVO = vo.getParentVO(); PMOHeadVO pmoHeadVO = vo.getParentVO();
PMOItemVO[] itemVOS = vo.getChildrenVO(); PMOItemVO[] itemVOS = vo.getChildrenVO();
String vbillcode = pmoHeadVO.getVbillcode();
UFDate dbilldate = pmoHeadVO.getDbilldate(); UFDate dbilldate = pmoHeadVO.getDbilldate();
// 组装数据 // 组装数据
JSONObject singleObj = new JSONObject(); String SendDate = "";
singleObj.put("WorkOrderNo", "2025111001");// 产品类型-对应PLM产品编码
if (dbilldate != null) { if (dbilldate != null) {
singleObj.put("SendDate", dbilldate.toString().substring(0, 10));// 接收日期 SendDate = dbilldate.toString().substring(0, 10);
} }
// 处理子表数组
JSONArray contentArray = new JSONArray();
for (PMOItemVO item : itemVOS) { for (PMOItemVO item : itemVOS) {
String projectName = MyHelper.getStrValByCondition("bd_project", "project_name",
"pk_project = '" + item.getCprojectid() + "' ");
// 物料 // 物料
String cmaterialid = item.getCmaterialid(); String cmaterialid = item.getCmaterialid();
String materialCode = MyHelper.getStrValByCondition(MaterialVO.getDefaultTableName(), MaterialVO.CODE, String materialCode = MyHelper.getStrValByCondition(MaterialVO.getDefaultTableName(), MaterialVO.CODE,
MaterialVO.PK_MATERIAL + " = '" + cmaterialid + "'"); MaterialVO.PK_MATERIAL + " = '" + cmaterialid + "'");
String cdeptid = item.getCdeptid();
Object deptCode = hyPub.findColValue(DeptVO.getDefaultTableName(), DeptVO.CODE,
"pk_dept = '" + cdeptid + "'");
String castunitid = item.getCastunitid();
Object unitCode = hyPub.findColValue(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE,
"pk_measdoc = '" + castunitid + "'");
JSONObject itemObj = new JSONObject(); JSONObject itemObj = new JSONObject();
// itemObj.put("WorkOrderId", 0);// itemObj.put("WorkOrderNo", vbillcode);// 工单号
// itemObj.put("IsAddPlan", "");// itemObj.put("SendDate", SendDate);// 接收日期
itemObj.put("PartCode", materialCode);// 产品编码 itemObj.put("ERPOrderCode", item.getCmoid());// ERP的工单ID
itemObj.put("ProductTypeId", 8); itemObj.put("OrderNum", item.getNastnum().toString());// 工单数量
// itemObj.put("XMPZ", "");// 项目配置-暂时不传 itemObj.put("materialvid", materialCode);// 物料编码
itemObj.put("HTBM", item.getVdef1());// 合同编码 itemObj.put("unitid", unitCode);// 计量单位编码
itemObj.put("ProjectName", projectName);// 项目名称 itemObj.put("deptid", deptCode);// 部门编码
itemObj.put("Field1", item.getAttributeValue("vdef44"));// String param = JSON.toJSONString(itemObj);
itemObj.put("Field2", item.getAttributeValue("vdef45"));// pushData(param);
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 { private void buildSyncDelData(PMOAggVO[] useVOs) throws BusinessException {
for (PMOAggVO vo : useVOs) { for (PMOAggVO vo : useVOs) {
// 判断物料的业务单元是否是配置的公司不是则跳过 // 判断是否是真空公司不是则跳过
String pkOrg = vo.getParentVO().getPk_org(); String pkOrg = vo.getParentVO().getPk_org();
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
if (checkIfOrg(orgCode, configParams)) { if (checkIfOrg(orgCode, configParams)) {
@ -132,11 +132,8 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
// 组装数据 // 组装数据
JSONArray contentArray = new JSONArray(); JSONArray contentArray = new JSONArray();
for (PMOItemVO item : itemVOS) { for (PMOItemVO item : itemVOS) {
// 物料 String cmoid = item.getCmoid();
String cmaterialid = item.getCmaterialid(); contentArray.add(cmoid);
String materialCode = MyHelper.getStrValByCondition(MaterialVO.getDefaultTableName(), MaterialVO.CODE,
MaterialVO.PK_MATERIAL + " = '" + cmaterialid + "'");
contentArray.add(materialCode);
} }
String param = JSON.toJSONString(contentArray); String param = JSON.toJSONString(contentArray);
pushData(param); pushData(param);
@ -155,13 +152,22 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
requestUrl = baseUrl + delUrl; requestUrl = baseUrl + delUrl;
} }
logger.error("zkmes-PMO-url = " + requestUrl); logger.error("zkmes-PMO-url = " + requestUrl);
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param); Map<String, String> headers = new HashMap<>();
headers.put("token", configParams.get("zkMesToken"));
headers.put("Content-Type", "application/json;charset=UTF-8");
String result = doSendHttp(requestUrl, "POST", null, "", headers, param);
logger.error("zkmes-PMO-res = " + result); logger.error("zkmes-PMO-res = " + result);
JSONObject resultObj = JSONObject.parseObject(result); JSONObject resultObj = JSONObject.parseObject(result);
if (MMValueCheck.isEmpty(resultObj)) {
throw new BusinessException("真空MES返回信息:" + result);
}
if (!"true".equals(resultObj.getString("result"))) { if (!"true".equals(resultObj.getString("result"))) {
logger.error("zkmes-PMO-error,result[" + resultObj.toJSONString() + "]"); logger.error("zkmes-PMO-error,result[" + result + "]");
throw new BusinessException("真空MES错误信息:" + resultObj.getString("msg")); String msg = resultObj.getString("msg");
if (MMValueCheck.isEmpty(msg)) {
msg = resultObj.getString("message");
}
throw new BusinessException("真空MES错误信息:" + msg);
} }
} }
@ -179,4 +185,104 @@ public class AfterPmoSyncZkMesRule implements IRule<PMOAggVO> {
return true; return true;
} }
/**
* 业务请求方法
*/
public String doSendHttp(String baseUrl, String method, Map<String, String> paramMap, String mediaType,
Map<String, String> headers, String json) {
HttpURLConnection urlConnection = null;
InputStream in = null;
OutputStream out = null;
BufferedReader bufferedReader = null;
String result = null;
try {
StringBuffer sb = new StringBuffer();
sb.append(baseUrl);
if (paramMap != null) {
sb.append("?");
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
sb.append(key + "=" + value).append("&");
baseUrl = sb.toString().substring(0, sb.toString().length() - 1);
}
}
URL urlobj = new URL(baseUrl);
if ("https".equalsIgnoreCase(urlobj.getProtocol())) {// 判定网址是否信任不信任则调用忽略信任工具类SslUtil
IgnoreSslUtil.ignoreSsl();
}
urlConnection = (HttpURLConnection) urlobj.openConnection();
urlConnection.setConnectTimeout(50000);
urlConnection.setRequestMethod(method);
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
// 如果设置了自定义头则打印它们
if (headers != null && !headers.isEmpty()) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
urlConnection.addRequestProperty(entry.getKey(), entry.getValue());
}
}
if (json != null && json.length() > 0) {
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
out = urlConnection.getOutputStream();
out.write(json.getBytes(StandardCharsets.UTF_8));
out.flush();
}
int resCode = urlConnection.getResponseCode();
String ecod = urlConnection.getContentEncoding();
if (resCode == HttpURLConnection.HTTP_OK || resCode == HttpURLConnection.HTTP_CREATED
|| resCode == HttpURLConnection.HTTP_ACCEPTED) {
if (!StringUtils.isEmpty(ecod) && ecod.equals("gzip")) {
in = new GZIPInputStream(urlConnection.getInputStream());
} else {
in = urlConnection.getInputStream();
}
} else {
in = urlConnection.getErrorStream();
}
bufferedReader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
StringBuffer temp = new StringBuffer();
String line = bufferedReader.readLine();
while (line != null) {
temp.append(line).append("\r\n");
line = bufferedReader.readLine();
}
if (ecod == null || ecod.equals("gzip")) {
ecod = StandardCharsets.UTF_8.name();
}
result = new String(temp.toString().getBytes(StandardCharsets.UTF_8), ecod);
} catch (Exception e) {
JSONObject js = new JSONObject();
js.put("", -1);
js.put("message", "调用外系统接口失败:" + e.getMessage());
result = js.toString();
e.printStackTrace();
} finally {
if (null != bufferedReader) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != out) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
urlConnection.disconnect();
}
return result;
}
} }