From d5fdad79f254378763ae2f33bac8baee0d335d75 Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 20 Nov 2025 13:47:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=9F=E7=A9=BAmes-=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=AE=A2=E5=8D=95=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bs/mmpac/pmo/pac0002/bp/PMOApproveBP.java | 2 + .../bp/rule/AfterPmoSyncZkMesRule.java | 198 ++++++++++++++---- 2 files changed, 154 insertions(+), 46 deletions(-) diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/PMOApproveBP.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/PMOApproveBP.java index ef470887..f13e7f6d 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/PMOApproveBP.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/PMOApproveBP.java @@ -66,6 +66,7 @@ public class PMOApproveBP { processer.addAfterRule(new AfterApproveSyncImsRule("Y")); // 流程生产订单审批后推送高压IMS-流程备料计划 processer.addAfterRule(new PMOAfterApproveRuleHighpressureIms()); + processer.addAfterRule(new AfterPmoSyncZkMesRule("audit")); } public PMOAggVO[] approveCancel(PMOAggVO[] fullBills, PMOAggVO[] originBills) { @@ -96,5 +97,6 @@ public class PMOApproveBP { // 生产订单取消审批后推送高压MES processer.addAfterRule(new AfterApproveSyncImsRule("N")); processer.addAfterRule(new AfterApproveCancelSyncHighpressureMesRule()); + processer.addAfterRule(new AfterPmoSyncZkMesRule("cancel")); } } diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterPmoSyncZkMesRule.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterPmoSyncZkMesRule.java index 1903a8d5..61fdf8a7 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterPmoSyncZkMesRule.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterPmoSyncZkMesRule.java @@ -4,21 +4,32 @@ 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.uapbd.util.IgnoreSslUtil; import nc.bs.dao.BaseDAO; import nc.bs.logging.Log; +import nc.bs.trade.business.HYPubBO; 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.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.PMOHeadVO; import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO; +import nc.vo.org.DeptVO; import nc.vo.org.OrgVO; import nc.vo.pub.BusinessException; 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.zip.GZIPInputStream; /** * 真空-流程生产订单推真空MES @@ -30,8 +41,8 @@ public class AfterPmoSyncZkMesRule implements IRule { 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 static final String addUrl = "/api/WorkPlan/AddWorkOrder"; + private static final String delUrl = "/api/WorkPlan/DelPartCodes"; private Map configParams; public static final BaseDAO baseDAO = new BaseDAO(); private String flag = ""; @@ -56,6 +67,7 @@ public class AfterPmoSyncZkMesRule implements IRule { buildSyncData(pmoAggVOS); } } catch (BusinessException e) { + logger.error("AfterPmoSyncZkMesRule-exp: " + e.getMessage(), e); throw new RuntimeException(e); } } @@ -64,8 +76,9 @@ public class AfterPmoSyncZkMesRule implements IRule { * 构建同步数据 */ private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException { + HYPubBO hyPub = new HYPubBO(); 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)) { @@ -73,55 +86,42 @@ public class AfterPmoSyncZkMesRule implements IRule { } PMOHeadVO pmoHeadVO = vo.getParentVO(); PMOItemVO[] itemVOS = vo.getChildrenVO(); + String vbillcode = pmoHeadVO.getVbillcode(); UFDate dbilldate = pmoHeadVO.getDbilldate(); // 组装数据 - JSONObject singleObj = new JSONObject(); - singleObj.put("WorkOrderNo", "2025111001");// 产品类型-对应PLM产品编码 + String SendDate = ""; 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) { - 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 + "'"); + 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(); - // 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); + itemObj.put("WorkOrderNo", vbillcode);// 工单号 + itemObj.put("SendDate", SendDate);// 接收日期 + itemObj.put("ERPOrderCode", item.getCmoid());// ERP的工单ID + itemObj.put("OrderNum", item.getNastnum().toString());// 工单数量 + itemObj.put("materialvid", materialCode);// 物料编码 + itemObj.put("unitid", unitCode);// 计量单位编码 + itemObj.put("deptid", deptCode);// 部门编码 + String param = JSON.toJSONString(itemObj); + pushData(param); } - 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)) { @@ -132,11 +132,8 @@ public class AfterPmoSyncZkMesRule implements IRule { // 组装数据 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 cmoid = item.getCmoid(); + contentArray.add(cmoid); } String param = JSON.toJSONString(contentArray); pushData(param); @@ -155,13 +152,22 @@ public class AfterPmoSyncZkMesRule implements IRule { requestUrl = baseUrl + delUrl; } logger.error("zkmes-PMO-url = " + requestUrl); - String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param); + Map 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); JSONObject resultObj = JSONObject.parseObject(result); - + if (MMValueCheck.isEmpty(resultObj)) { + throw new BusinessException("真空MES返回信息:" + result); + } if (!"true".equals(resultObj.getString("result"))) { - logger.error("zkmes-PMO-error,result[" + resultObj.toJSONString() + "]"); - throw new BusinessException("真空MES错误信息:" + resultObj.getString("msg")); + logger.error("zkmes-PMO-error,result[" + result + "]"); + 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 { return true; } + /** + * 业务请求方法 + */ + public String doSendHttp(String baseUrl, String method, Map paramMap, String mediaType, + Map 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 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 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; + } + }