From 2f5997b069ee42fbd54f8dd40672fce50ba34dc6 Mon Sep 17 00:00:00 2001 From: houyi <1398559711@qq.com> Date: Fri, 26 Sep 2025 18:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E5=8E=8B-=E5=A4=87=E6=96=99=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E5=AE=A1=E6=89=B9=E5=90=8E=E6=8E=A8=E9=80=81=E9=AB=98?= =?UTF-8?q?=E5=8E=8BMES=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/AfterApproveRuleHighpressureMes.java | 37 +++- ...rApproveSyncUpdateHighpressureMesRule.java | 188 ++++++++++++++++++ .../approve/AfterSoSyncRuleUpdateGyMes.java | 188 ++++++++++++++++++ 3 files changed, 410 insertions(+), 3 deletions(-) create mode 100644 mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncUpdateHighpressureMesRule.java create mode 100644 so/src/private/nc/bs/so/m30/rule/approve/AfterSoSyncRuleUpdateGyMes.java diff --git a/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureMes.java b/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureMes.java index a5e90a3a..6492c0e1 100644 --- a/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureMes.java +++ b/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureMes.java @@ -6,17 +6,21 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import nc.bs.dao.BaseDAO; +import nc.bs.dao.DAOException; import nc.bs.logging.Log; import nc.bs.trade.business.HYPubBO; +import nc.bs.trade.business.HYSuperDMO; import nc.bs.uapbd.util.MyHelper; import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; import nc.impl.pubapp.pattern.rule.IRule; import nc.jdbc.framework.processor.ColumnProcessor; import nc.jdbc.framework.processor.MapProcessor; +import nc.vo.bd.defdoc.DefdocVO; import nc.vo.mmpac.pickm.entity.AggPickmVO; import nc.vo.mmpac.pickm.entity.PickmHeadVO; import nc.vo.mmpac.pickm.entity.PickmItemVO; import nc.vo.org.OrgVO; +import nc.vo.pmpub.project.ProjectHeadVO; import nc.vo.pub.BusinessException; import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.scmpub.util.ArrayUtil; @@ -78,9 +82,9 @@ public class AfterApproveRuleHighpressureMes implements IRule { singleObj.put("bipProcessProductionOrderId", pickmHeadVO.getVsourcemocode()); // 流程生产订单号 singleObj.put("bipProcessProductionOrderRowNum", pickmHeadVO.getVsourcemorowcode()); // 来源单据号行号 - singleObj.put("bipParentProcessProductionOrderId", pickmHeadVO.getVsourcebillcode()); // 上级来源单据号 - singleObj.put("bipParentProcessProductionOrderRowNum", pickmHeadVO.getVsourcebillrowno()); // 上级来源单据行号 - singleObj.put("bipOriginProcessProductionOrderId", pickmHeadVO.getVfirstbillcode()); // 顶级来源单据号 + singleObj.put("bipParentProcessProductionOrderId", pickmHeadVO.getVfirstbillcode()); // 上级来源单据号 + singleObj.put("bipParentProcessProductionOrderRowNum", pickmHeadVO.getVfirstbillrowno()); // 上级来源单据行号 + singleObj.put("bipOriginProcessProductionOrderId", pickmHeadVO.getVsalebillcode()); // 顶级来源单据号 singleObj.put("bipOriginProcessProductionOrderRowNum", pickmHeadVO.getVfirstbillrowno()); // 顶级来源单据行号 singleObj.put("orderQuantity", pickmHeadVO.getNastnum() != null ? pickmHeadVO.getNastnum().doubleValue() : null); // 订单数量(计划数量) singleObj.put("bomVersion", pickmHeadVO.getVbomversionnumber()); // bom版本 @@ -123,6 +127,15 @@ public class AfterApproveRuleHighpressureMes implements IRule { // 生产信息 itemObj.put("intervalModel", material.get("materialspec")); // 产品类型 itemObj.put("lineNumber", String.valueOf(item.getVrowno())); // 行号 + // 项目编码 + String cprojectid = pickmHeadVO.getCprojectid();// 项目id + String projectCode = MyHelper.getStrValByCondition(ProjectHeadVO.getDefaultTableName(), ProjectHeadVO.PROJECT_CODE, + ProjectHeadVO.PK_PROJECT + " = '" + cprojectid + "'"); + singleObj.put("cbprojectid", projectCode); + // 生产厂商 + String productor = item.getCbproductorid();// 生产厂商id + String productorCode = getDefCode("Defdoc-BD006_0xx", item.getCbproductorid()); + singleObj.put("cbproductorid", productorCode); contentArray.add(itemObj); // 将子项添加到数组 } @@ -134,6 +147,24 @@ public class AfterApproveRuleHighpressureMes implements IRule { pushData(list); } + /** + * 获取自定义项信息 + */ + private String getDefCode(String code, String pk_defdoc) { + String res = ""; + String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr = 0 and pk_defdoc = '" + pk_defdoc + "'"; + try { + DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); + if (defdocVOs != null && defdocVOs.length > 0) { + res = defdocVOs[0].getCode().trim(); + } + } catch (DAOException e) { + logger.error("gyMes-SaleOrder-error,getDefCode[" + e.getMessage() + "]"); + } + return res; + + } + /** * 推送同步数据 */ diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncUpdateHighpressureMesRule.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncUpdateHighpressureMesRule.java new file mode 100644 index 00000000..7e11e082 --- /dev/null +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncUpdateHighpressureMesRule.java @@ -0,0 +1,188 @@ +package nc.bs.mmpac.pmo.pac0002.bp.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.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.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapProcessor; +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.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.scmpub.util.ArrayUtil; + +import java.util.Map; + +/** + * 流程生产订单审批后推送高压MES修改 + * + * @author lihao + * @date 2025/9/1 + */ +public class AfterApproveSyncUpdateHighpressureMesRule implements IRule { + + private static final String LOG_INFO_NAME = "gymeslog"; + private static final Log logger = Log.getInstance(LOG_INFO_NAME); + private Map configParams; + + @Override + public void process(PMOAggVO[] pmoAggVOS) { + if (ArrayUtil.isEmpty(pmoAggVOS)) { + return; + } + configParams = MyHelper.getConfigParams("gy-config", null); + try { + buildSyncData(pmoAggVOS); + } catch (Exception e) { + logger.error("同步生产订单到高压MES系统失败: " + e.getMessage(), e); + ExceptionUtils.wrappException(e); + } + } + + /** + * 构建同步数据 + */ + private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + + HYPubBO hybo = new HYPubBO(); + JSONObject list = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + for (PMOAggVO vo : useVOs) { + PMOHeadVO pmoHeadVO = vo.getParentVO(); + PMOItemVO[] itemVOS = vo.getChildrenVO(); + // 判断物料的业务单元是否是箱变公司,不是则跳过 + String pkOrg = pmoHeadVO.getPk_org(); + String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); + if (checkIfOrg(orgCode, configParams)) { + continue; + } + JSONObject singleObj = new JSONObject(); + singleObj.put("bipProcessProductionOrderId", pmoHeadVO.getVbillcode()); + singleObj.put("bipId", pmoHeadVO.getCpmohid());// 主键ID +// singleObj.put("orderQuantity", pmoHeadVO.getPlanQuantity()); // 订单数量(计划数量) + singleObj.put("billDate", pmoHeadVO.getDbilldate().toString()); // 单据日期 + singleObj.put("orderVersion", pmoHeadVO.getVersion()); // 版本号 + singleObj.put("orderTranType", pmoHeadVO.getVtrantypecode()); // 订单交易类型 + String sql1 = " select user_name from sm_user where cuserid = '" + pmoHeadVO.getModifier() + "' "; + String bipCreateBy = (String) baseDAO.executeQuery(sql1, new ColumnProcessor()); + + singleObj.put("bipUpdateBy", bipCreateBy); // 修改人ID + + // 创建子项数组 + JSONArray contentArray = new JSONArray(); + for (PMOItemVO item : itemVOS) { + JSONObject itemObj = new JSONObject(); + + // 填充子项基础信息 + + String sql = " select pk_defdoclist from bd_defdoclist where code='zdy-001' and dr=0 "; + String o = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + + Object contractNum = hybo.findColValue("bd_defdoc", "code", " (pk_defdoclist = '" + o + "' and pk_defdoc='" + item.getVdef1() + "') "); + + itemObj.put("contractNum", contractNum); // 合同编号 +// itemObj.put("cwarehouseid", item.getAttributeValue("vbdef35")); // 仓库编号 + Object pk_project = hybo.findColValue("bd_project", "project_name", " pk_project = '" + item.getCprojectid() + "' "); + + itemObj.put("entryName", pk_project); // 项目名称 + + // 部门信息 + String deptsql = " select code,name from org_dept where pk_dept='" + item.getCdeptid() + "' and dr=0 "; + Map tr = (Map) baseDAO.executeQuery(deptsql, new MapProcessor()); + itemObj.put("bipDeptName", tr.get("name")); // 生产部门名称 + itemObj.put("bipDeptId", tr.get("code")); // 生产部门编码 + + // 日期信息 + itemObj.put("requiredDate", item.getTrequiredate().toString()); // 需用日期 + + itemObj.put("bipParentProcessProductionOrderId", item.getVparentbillcode()); + itemObj.put("bipParentProcessProductionOrderRowNum", item.getVparentmorowno()); + itemObj.put("bipOriginProcessProductionOrderId", item.getVsrccode()); + itemObj.put("bipOriginProcessProductionOrderRowNum", item.getVsrcrowno()); + + // 物料信息 + String mrlsql = "select code,name,graphid,pk_measdoc,materialspec from bd_material where pk_material = '" + item.getCmaterialvid() + "' "; + Map mrl = (Map) baseDAO.executeQuery(mrlsql, new MapProcessor()); + itemObj.put("materialCode", mrl.get("code")); // 物料编码 + itemObj.put("materialName", mrl.get("name")); // 物料名称 +// itemObj.put("drawingNumber", mrl.get("graphid")); // 图号编码 graphid + itemObj.put("drawingNumber",mrl.get("graphid")); + Object unit = hybo.findColValue("bd_measdoc", "code", " pk_measdoc = '" + mrl.get("pk_measdoc") + "' "); + + itemObj.put("unit", unit); // 单位 pk_measdoc + + // 生产信息 + itemObj.put("intervalModel", mrl.get("materialspec")); // 产品类型 +// itemObj.put("processCode", item.getProcedures()); // 工序编码 + itemObj.put("lineNumber", String.valueOf(item.getVrowno())); // 行号 + + // 库存信息 + itemObj.put("demandInventoryOrganization", item.getCrequireorg()); // 需求库存组织 + itemObj.put("plannedInputQuantity",(int) item.getNplanputastnum().doubleValue()); // 计划投入量 + itemObj.put("plannedOutputQuantity",(int)item.getNmmastnum().doubleValue()); // 计划产出量 + itemObj.put("plannedStartTime", item.getTplanstarttime().toString()); // 计划开工时间 + itemObj.put("plannedCompletionTime", item.getTplanendtime().toString()); // 计划完工时间 + itemObj.put("customerMaterialCode", item.getCcustmaterialid()); // 客户物料编码 + itemObj.put("productionBatch", item.getCbatchid()); // 生产批次(按BIP格式) + itemObj.put("productionBatchNumber", item.getVbatchcode()); // 生产批次号(按BIP格式) + + contentArray.add(itemObj); // 将子项添加到数组 + } + + singleObj.put("itemList", contentArray); // 将子项数组添加到主对象 + jsonArray.add(singleObj); + list.put("list", jsonArray); + } + pushData(list); + } + + /** + * 推送同步数据 + */ + private void pushData(JSONObject param) throws BusinessException { + // 转json字符串的时候保留null值 + String jsonStr = JSON.toJSONString(param, + SerializerFeature.WriteMapNullValue, + SerializerFeature.WriteNullStringAsEmpty + ); + logger.error("gyMes-PMO-param = " + jsonStr); + String baseUrl = configParams.get("mesBaseUrl"); + String requestUrl = baseUrl + configParams.get("productionOrderUpdate"); + logger.error("gyMes-PMO-url = " + requestUrl); + String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); + JSONObject resultObj = JSONObject.parseObject(result); + logger.error("gyMes-PMO-res = " + result); + + if (!"200".equals(resultObj.getString("code"))) { + logger.error("gyMes-PMO-error,result[" + resultObj.toJSONString() + "]"); + throw new BusinessException("流程生产订单推送高压MES错误:" + resultObj.getString("msg")); + } + } + + private boolean checkIfOrg(String code, Map configParams) throws BusinessException { + String targetCode = configParams.get("gyOrg"); + if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { + throw new BusinessException("未配置组织参数"); + } + String[] orgItem = targetCode.split(","); + for (String orgCode : orgItem) { + if (!orgCode.isEmpty() && orgCode.equals(code)) { + return false; + } + } + return true; + } + + +} diff --git a/so/src/private/nc/bs/so/m30/rule/approve/AfterSoSyncRuleUpdateGyMes.java b/so/src/private/nc/bs/so/m30/rule/approve/AfterSoSyncRuleUpdateGyMes.java new file mode 100644 index 00000000..1cff53d0 --- /dev/null +++ b/so/src/private/nc/bs/so/m30/rule/approve/AfterSoSyncRuleUpdateGyMes.java @@ -0,0 +1,188 @@ +package nc.bs.so.m30.rule.approve; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import nc.bs.dao.BaseDAO; +import nc.bs.dao.DAOException; +import nc.bs.logging.Log; +import nc.bs.trade.business.HYPubBO; +import nc.bs.trade.business.HYSuperDMO; +import nc.bs.uapbd.util.MyHelper; +import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapProcessor; +import nc.vo.bd.defdoc.DefdocVO; +import nc.vo.org.OrgVO; +import nc.vo.pub.BusinessException; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.so.m30.entity.SaleOrderBVO; +import nc.vo.so.m30.entity.SaleOrderHVO; +import nc.vo.so.m30.entity.SaleOrderVO; +import nccloud.baseapp.core.log.NCCForUAPLogger; + +import java.util.Map; + +/** + * 销售订单推送高压mes修改 + * + * @author houyi + */ +public class AfterSoSyncRuleUpdateGyMes implements IRule { + private static final String LOG_INFO_NAME = "gymeslog"; + private static final Log logger = Log.getInstance(LOG_INFO_NAME); + private static final String reqUrl = "/bip/order/saleOrderUpdate"; + private Map configParams; + + @Override + public void process(SaleOrderVO[] saleOrderVOs) { + try { + if (saleOrderVOs == null || saleOrderVOs.length == 0) { + return; + } + configParams = MyHelper.getConfigParams("gy-config", null); + if (configParams.isEmpty()) { + throw new BusinessException("高压的接口缺少配置"); + } + buildSyncData(saleOrderVOs); + } catch (Exception e) { + ExceptionUtils.wrappException(e); + } + } + + /** + * 构建同步数据 + */ + private void buildSyncData(SaleOrderVO[] useVOs) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + HYPubBO hybo = new HYPubBO(); + for (SaleOrderVO 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; + } + + SaleOrderHVO hvo = vo.getParentVO(); + SaleOrderBVO[] itemVOS = vo.getChildrenVO(); + // 客户 + String customerSql = " select name from bd_customer where dr = 0 and pk_customer = '" + hvo.getCcustomerid() + "' "; + String customerName = (String) baseDAO.executeQuery(customerSql, new ColumnProcessor()); + // 创建人 + String userSql = " select user_name from sm_user where dr = 0 and cuserid = '" + hvo.getCreviserid() + "' "; + String createName = (String) baseDAO.executeQuery(userSql, new ColumnProcessor()); + // 合同编号 + String vdef6 = hvo.getVdef6(); + String contractNum = getDefCode("zdy-001", vdef6); + for (SaleOrderBVO item : itemVOS) { + Object projectName =getDefName("zdy-001", vdef6); +// Object projectName = hybo.findColValue(ProjectHeadVO.getDefaultTableName(), ProjectHeadVO.PROJECT_NAME, ProjectHeadVO.PK_PROJECT + " = '" + item.getCprojectid() + "' "); + String wlsql = " select code,name,graphid from bd_material where dr = 0 and pk_material = '" + item.getCmaterialvid() + "' "; + Map mrlMap = (Map) baseDAO.executeQuery(wlsql, new MapProcessor()); + + JSONObject itemObj = new JSONObject(); + itemObj.put("contractNum", contractNum);// 合同编码 + itemObj.put("bipOrderId", hvo.getVbillcode());// 销售订单号 + itemObj.put("entryName", projectName);// 项目名称 + itemObj.put("productQuantity", item.getNastnum().doubleValue());// 数量 + itemObj.put("materialCode", mrlMap.get("code"));// 物料编码 + itemObj.put("materialName", mrlMap.get("name"));// 物料名称 + itemObj.put("drawingNumber", mrlMap.get("graphid"));// 图号 + itemObj.put("supplyDate", item.getDreceivedate().toString());// 供货日期-要求收货日期 + itemObj.put("remark", item.getVrownote());// 备注 + itemObj.put("bipUpdateBy", createName);// 修改人 + itemObj.put("customers", customerName);// 客户 + pushData(itemObj); + } + /*{ + "contractNum": "TZF2520201225 合同编码", + "bipOrderId": "TZF2520201225 销售的订单号", + "entryName": "大唐河北故城50MW风电项目", + "productQuantity": "数量个数 例如 1", + "materialCode": "物料编码", + "materialName": "物料名称", + "drawingNumber": "图号编码 计划信息组织是高压的图号", //计划信息组织是高压的图号 + "supplyDate": "2025-01-03 11:09:22", + "remark": "备注", + "bipUpdateBy": "修改人ID", + "customers": "客户 例如贵州电网xxx" + }*/ + } + } + + /** + * 推送同步数据 + */ + private void pushData(JSONObject param) throws BusinessException { + // String jsonString = param.toJSONString(); + // 转json字符串的时候保留null值 + String jsonStr = JSON.toJSONString(param, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty); + logger.error("gyMes-SaleOrder-param = " + jsonStr); + NCCForUAPLogger.debug("gyMes-SaleOrder-param = " + jsonStr); + String baseUrl = configParams.get("mesBaseUrl"); + String requestUrl = baseUrl + reqUrl; + logger.error("gyMes-SaleOrder-url = " + requestUrl); + String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); + JSONObject resultObj = JSONObject.parseObject(result); + logger.error("gyMes-SaleOrder-res = " + result); + + if (!"200".equals(resultObj.getString("code"))) { + logger.error("gyMes-SaleOrder-error,result[" + resultObj.toJSONString() + "]"); + throw new BusinessException("销售订单推送高压MES错误:" + resultObj.getString("msg")); + } + } + + private boolean checkIfOrg(String code, Map configParams) throws BusinessException { + String targetCode = configParams.get("gyOrg"); + if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { + throw new BusinessException("未配置组织参数"); + } + String[] orgItem = targetCode.split(","); + for (String orgCode : orgItem) { + if (!orgCode.isEmpty() && orgCode.equals(code)) { + return false; + } + } + return true; + } + + /** + * 获取自定义项信息 + */ + private String getDefCode(String code, String pk_defdoc) { + String res = ""; + String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr = 0 and pk_defdoc = '" + pk_defdoc + "'"; + try { + DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); + if (defdocVOs != null && defdocVOs.length > 0) { + res = defdocVOs[0].getCode().trim(); + } + } catch (DAOException e) { + logger.error("gyMes-SaleOrder-error,getDefCode[" + e.getMessage() + "]"); + } + return res; + + } + /** + * 获取自定义项信息 + */ + private String getDefName(String code, String pk_defdoc) { + String res = ""; + String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr = 0 and pk_defdoc = '" + pk_defdoc + "'"; + try { + DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); + if (defdocVOs != null && defdocVOs.length > 0) { + res = defdocVOs[0].getName().trim(); + } + } catch (DAOException e) { + logger.error("gyMes-SaleOrder-error,getDefCode[" + e.getMessage() + "]"); + } + return res; + + } + + +} +