From 841b2103518110a741050195dae5441c98cdab8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E?= Date: Thu, 15 May 2025 14:12:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(ic):=20=E5=AE=9E=E7=8E=B0=E7=9B=98?= =?UTF-8?q?=E7=82=B9=E5=92=8C=E9=94=80=E5=94=AE=E5=87=BA=E5=BA=93=E7=9A=84?= =?UTF-8?q?=20MES=20=E5=90=8C=E6=AD=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 AfterApprovingSynchronizeRule 类用于盘点单审批后同步到 MES - 新增 AfterSigningSynchronizeRule 类用于销售出库单签字后同步到 MES- 在 ApproveBP 和 SignBP 中集成同步规则 - 优化数据构建和响应处理逻辑,提高同步效率和可靠性 --- ic/src/private/nc/bs/ic/m4c/sign/SignBP.java | 61 ++++++ .../rule/AfterSigningSynchronizeRule.java | 190 ++++++++++++++++++ .../nc/bs/ic/m4r/approve/ApproveBP.java | 32 +++ .../rule/AfterApprovingSynchronizeRule.java | 176 ++++++++++++++++ 4 files changed, 459 insertions(+) create mode 100644 ic/src/private/nc/bs/ic/m4c/sign/SignBP.java create mode 100644 ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRule.java create mode 100644 ic/src/private/nc/bs/ic/m4r/approve/ApproveBP.java create mode 100644 ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRule.java diff --git a/ic/src/private/nc/bs/ic/m4c/sign/SignBP.java b/ic/src/private/nc/bs/ic/m4c/sign/SignBP.java new file mode 100644 index 0000000..96970de --- /dev/null +++ b/ic/src/private/nc/bs/ic/m4c/sign/SignBP.java @@ -0,0 +1,61 @@ +package nc.bs.ic.m4c.sign; + +import com.yonyou.cloud.ncc.plugin.entity.OperationInfo; +import nc.bs.ic.general.sign.ISignBP; +import nc.bs.ic.general.sign.ISignRuleProvider; +import nc.bs.ic.general.sign.SignBPTemplate; +import nc.bs.ic.m4c.base.BPPlugInPoint; +import nc.bs.ic.m4c.base.rule.SaleOutFillInvoiceNumRule; +import nc.bs.ic.m4c.sign.rule.*; +import nc.bs.ic.pub.util.SagasUtils; +import nc.bs.scmpub.rule.VOSagaFrozenValidateRule; +import nc.impl.pubapp.pattern.rule.processer.AroundProcesser; +import nc.itf.ic.m4c.compensate.ISaleOutSagasCompensate; +import nc.vo.ic.m4c.entity.SaleOutVO; +import nc.vo.ic.pub.util.VOEntityUtil; +import nc.vo.scmpub.res.billtype.ICBillType; +import nccloud.bs.ic.mobile.component.operation.rule.MobAfterSignMessageRule; +import nccloud.bs.ic.tms.kj.KJTMSConfirmAction; +import nccloud.vo.scmpub.tms.enumeration.BusiScene; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class SignBP implements ISignBP, ISignRuleProvider { + public SignBP() { + } + + public SaleOutVO[] sign(SaleOutVO[] bills) { + SignBPTemplate signBP = new SignBPTemplate(BPPlugInPoint.SignBP, this); + SagasUtils.frozenAndAddSaga(bills, ICBillType.SaleOut.getCode(), "1", (OperationInfo) null); + Map paramMap = new HashMap(); + paramMap.put("actionname", "sign_4C"); + paramMap.put("hid", VOEntityUtil.getPksFromAggVO(bills)); + SagasUtils.compensate(paramMap, ISaleOutSagasCompensate.class); + SaleOutVO[] resultVOs = (SaleOutVO[]) signBP.sign(bills); + KJTMSConfirmAction action = new KJTMSConfirmAction(BusiScene.SODelivery); + action.confirm(resultVOs); + return resultVOs; + } + + public void addAfterRule(SaleOutVO[] vos, AroundProcesser processor) { + processor.addAfterRule(new PushSquareSignRule()); + processor.addAfterRule(new AfterSignRuleForSquareiaProcess()); + processor.addAfterRule(new AfterSignRuleForFinanceProcess()); + processor.addAfterRule(new SaleOutFillInvoiceNumRule()); + processor.addAfterRule(new AfterSignRuleForLiabilityProcess()); + processor.addAfterRule(new SaleOutProceedsRule()); + processor.addAfterRule(new AfterRedSignRuleTOArsubProcess()); + processor.addAfterRule(new ArsubToVoucherRule()); + processor.addAfterRule(new SaleOutProceedsRuleCG()); + processor.addAfterRule(new MobAfterSignMessageRule()); + // ۳ ǩֺ ͬMES˼άϵͳ + processor.addAfterRule(new AfterSigningSynchronizeRule()); + // ̵㣨MES + } + + public void addBeforeRule(SaleOutVO[] vos, AroundProcesser processor) { + processor.addBeforeRule(new VOSagaFrozenValidateRule(true)); + } +} \ No newline at end of file diff --git a/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRule.java b/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRule.java new file mode 100644 index 0000000..1ecd1f0 --- /dev/null +++ b/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRule.java @@ -0,0 +1,190 @@ +package nc.bs.ic.m4c.sign.rule; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.yonyou.cloud.utils.StringUtils; +import nc.IHttpPostOtherSys; +import nc.bs.framework.common.NCLocator; +import nc.bs.logging.Log; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.vo.ic.m4c.entity.SaleOutBodyVO; +import nc.vo.ic.m4c.entity.SaleOutHeadVO; +import nc.vo.ic.m4c.entity.SaleOutVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDate; + +import java.text.SimpleDateFormat; + + +//۳⣨ǩֺMES˼άϵͳ +public class AfterSigningSynchronizeRule implements IRule { + private static final String SALE_OUT_URL = "/GTHINKING/AjaxService/N_MISPRO/SaleOrderOutbound.ashx/SaveData"; // ۳Ǽǽӿ + private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final String logginfo = "OALOG"; + private static final Log obmlog = Log.getInstance(logginfo); + + public AfterSigningSynchronizeRule() { + } + + @Override + public void process(SaleOutVO[] saleOutVOS) { + try { + if (saleOutVOS == null || saleOutVOS.length == 0) { + return; + } + // ʼHTTP󹤾 + IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); + // ÿ۳ⵥ + for (SaleOutVO saleOutVO : saleOutVOS) { + SaleOutHeadVO hvo = (SaleOutHeadVO) saleOutVO.getParentVO(); + SaleOutBodyVO[] bvos = (SaleOutBodyVO[]) saleOutVO.getChildrenVO(); + // Ҫ͵ + JSONObject syncData = buildSyncData(hvo, bvos); + // ݵ˼άϵͳʹHttpPostOtherSysImpl + String mesResponse = httpPostOtherSys.callLE(SALE_OUT_URL, syncData); + obmlog.debug("AfterSigningSynchronizeRule-˼άϵͳӦ: " + mesResponse); + // Ӧ + processResponse(hvo.getVbillcode(), mesResponse); + } + } catch (Exception e) { + obmlog.error("AfterSigningSynchronizeRule-쳣:" + e.getMessage(), e); + } + } + + /** + * Ͻ˼άϵͳӿڹ淶 + * NCC/YonBIPֶӳ䵽˼άϵͳֶ + */ + private JSONObject buildSyncData(SaleOutHeadVO hvo, SaleOutBodyVO[] bvos) { + JSONObject requestData = new JSONObject(); + requestData.put("operation_type", "I"); + + JSONObject info = new JSONObject(); + // - ֵֶӳ + info.put("orderNo", hvo.getVbillcode()); // ID - ݺ(vbillcode) + // ڸʽת + UFDate dbilldate = hvo.getDbilldate(); + String billDateStr = dateTimeFormat.format(dbilldate.toDate()); + info.put("orderDate", billDateStr); // ᵥ - (dbilldate) + info.put("planDate", billDateStr); // ƻ - ʹͬĵ + info.put("actureDate", billDateStr); + // ɷʽܴ洢Զֶ + String genType = getStringValue(hvo.getVdef1()); + info.put("genType", null); // ɷʽ - ĬN + info.put("type", "XSCK"); // ĬXSCK + info.put("departmentId", hvo.getCdptvid()); // ID - (cdptvid) + info.put("storeId", hvo.getCwarehouseid()); // ֿID - ֿ(cwarehouseid) + // ĬΪ1 + info.put("exRate", null); + info.put("sType", "N"); // Ĭֵ + info.put("billing", "Y"); // ߷ƱĬֵ + info.put("billingBasis", "S"); // ƱĬֵ + + // ЧڿΪգܴ洢ֶλԶֶ + String effDateStr = getStringValue(hvo.getVdef2()); + if (StringUtils.isNotEmpty(effDateStr)) { + try { + UFDate effDate = new UFDate(effDateStr); + info.put("effDate", dateTimeFormat.format(effDate.toDate())); + } catch (Exception e) { + obmlog.error("Чڳ: " + e.getMessage()); + } + } + + info.put("consignStoreId", null); // ۲ֿID + info.put("consignType", null); // + info.put("operatorNo", null); // ˹ - Ƶ(billmaker) + info.put("operatorName", null); // - Զֶ + info.put("storeKeeper", hvo.getCwhsmanagerid()); // Ա - Ա(cwhsmanagerid) + info.put("cwhsmanagerid", hvo.getCwhsmanagerid()); // ԱID - Ա(cwhsmanagerid) + info.put("customId", hvo.getCcustomerid()); // ͻID - ͻ(ccustomerid) + info.put("mark", "Y"); // ɱ־Ĭֵ + info.put("remark", hvo.getVnote()); // ע - ע(vnote) + + // detailsϸ + JSONArray details = new JSONArray(); + if (bvos != null) { + for (SaleOutBodyVO bvo : bvos) { + JSONObject detail = new JSONObject(); + detail.put("orderNo", hvo.getVbillcode()); // ID - ݺ(vbillcode) + detail.put("sequenceNum", bvo.getCrowno()); + + // ԴϢ - ֵȷӳ + detail.put("saleOrderNo", null); // SOID - Դݺ(vsourcebillcode) + detail.put("saleSequenceNum", null); // SO - Դк(vsourcerowno) + detail.put("allocationNum", null); // + + // - ʹȷֶ + detail.put("materialId", bvo.getCmaterialoid()); // ID - (cmaterialoid) + detail.put("unit", bvo.getCunitid()); // λ - λ(cunitid) + detail.put("productNum", null); // - Զֶ + + detail.put("storageId", bvo.getClocationid()); // λ - λ(clocationid) + detail.put("batchNum", bvo.getVbatchcode()); // - κ(vbatchcode) + detail.put("scaleFactor", bvo.getVchangerate()); + + // Ӧʵ + detail.put("issuedQty", bvo.getNshouldassistnum()); // Ӧ(nshouldassistnum) + detail.put("mIssuedQty", bvo.getNshouldnum()); // Ӧ(nshouldnum) + detail.put("actQry", bvo.getNassistnum()); // ʵ(nassistnum) + detail.put("mActQry", bvo.getNnum()); // ʵ(nnum) + detail.put("assistActQry", null); // ʵ(nassistnum) + + // ͻϢ + detail.put("customId", getStringValue(bvo.getCasscustid())); // ͻID - ͻ(casscustid) + // ӦϢ + detail.put("supplierId", getStringValue(bvo.getCvendorid())); // ӦID - Ӧ(cvendorid) + detail.put("color", null); + // + detail.put("manufactureDate", null); // (dproducedate) + detail.put("properties", null); + detail.put("remark", bvo.getVnotebody()); // ע - бע(vnotebody) + + details.add(detail); + } + } + info.put("details", details); + + // infoӵ + requestData.put("info", info); + + return requestData; + } + + /** + * ȫȡֵַָֹ쳣 + */ + private String getStringValue(Object value) { + return value == null ? "" : value.toString(); + } + + /** + * ˼άϵͳӦ + */ + private void processResponse(String vbillcode, String response) { + if (StringUtils.isEmpty(response)) { + obmlog.error("AfterSigningSynchronizeRule-ӦΪգݺ: " + vbillcode); + return; + } + + try { + JSONObject respObj = JSONObject.parseObject(response); + JSONObject result = respObj.getJSONObject("result"); + if (result != null) { + boolean success = result.getBooleanValue("success"); + String message = result.getString("message"); + String errorMessage = result.getString("errorMessage"); + String orderNo = result.getString("orderNo"); + + if (success) { + obmlog.info("AfterSigningSynchronizeRule-ͬɹݺ: " + vbillcode + ", ص: " + orderNo + ", Ϣ: " + message); + } else { + obmlog.error("AfterSigningSynchronizeRule-ͬʧܣݺ: " + vbillcode + ", : " + errorMessage); + throw new BusinessException("ͬ˼άϵͳʧ: " + errorMessage); + } + } + } catch (Exception e) { + obmlog.error("AfterSigningSynchronizeRule-Ӧ쳣: " + e.getMessage(), e); + } + } +} diff --git a/ic/src/private/nc/bs/ic/m4r/approve/ApproveBP.java b/ic/src/private/nc/bs/ic/m4r/approve/ApproveBP.java new file mode 100644 index 0000000..edd4eda --- /dev/null +++ b/ic/src/private/nc/bs/ic/m4r/approve/ApproveBP.java @@ -0,0 +1,32 @@ +package nc.bs.ic.m4r.approve; + +import nc.bs.ic.m4r.approve.rule.AfterApprovingSynchronizeRule; +import nc.bs.ic.m4r.approve.rule.PushInOutBills; +import nc.bs.ic.m4r.base.BPPluginPoint; +import nc.bs.ic.m4r.insert.rule.InvcountDataCheck; +import nc.bs.ic.pub.base.ICAroundProcesser; +import nc.bs.ic.special.approve.ApproveBPTemplate; +import nc.bs.ic.special.approve.IApproveBP; +import nc.bs.ic.special.approve.rule.SpecialAuditDataCheck; +import nc.bs.ic.special.base.IApproveRuleProvider; +import nc.bs.pub.compiler.AbstractCompiler2; +import nc.vo.ic.m4r.entity.InvCountBillVO; + +public class ApproveBP implements IApproveBP, IApproveRuleProvider { + public ApproveBP() { + } + + public InvCountBillVO[] approve(InvCountBillVO[] bills, AbstractCompiler2 script) { + return (InvCountBillVO[]) (new ApproveBPTemplate(BPPluginPoint.ApproveBP, this)).approve(bills, script); + } + + public void addApproveAfterRule(ICAroundProcesser processor) { + processor.addAfterRule(new PushInOutBills()); + // ̵㣨MES + processor.addAfterRule(new AfterApprovingSynchronizeRule()); + } + + public void addApproveBeforeRule(ICAroundProcesser processor) { + processor.replaceBeforeRuleAt(new InvcountDataCheck(), SpecialAuditDataCheck.class); + } +} \ No newline at end of file diff --git a/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRule.java b/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRule.java new file mode 100644 index 0000000..40cf1d2 --- /dev/null +++ b/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRule.java @@ -0,0 +1,176 @@ +package nc.bs.ic.m4r.approve.rule; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.yonyou.cloud.utils.StringUtils; +import nc.IHttpPostOtherSys; +import nc.bs.framework.common.NCLocator; +import nc.bs.logging.Log; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.vo.ic.m4r.entity.InvCountBillVO; +import nc.vo.ic.m4r.entity.InvCountHeaderVO; +import nc.vo.ic.m4r.entity.InvCountBodyVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; + +import java.text.SimpleDateFormat; + + +// ̵㣨MES +public class AfterApprovingSynchronizeRule implements IRule { + private static final String INV_COUNT_URL = "/GTHINKING/AjaxService/N_MISPRO/InvCount.ashx/SaveData"; // ̵㵥ͬӿ + private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final String logginfo = "OALOG"; + private static final Log obmlog = Log.getInstance(logginfo); + + public AfterApprovingSynchronizeRule() { + } + + @Override + public void process(InvCountBillVO[] invCountBillVOs) { + try { + if (invCountBillVOs == null || invCountBillVOs.length == 0) { + return; + } + + // ʼHTTP󹤾 + IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); + + // ÿ̵㵥 + for (InvCountBillVO invCountBillVO : invCountBillVOs) { + InvCountHeaderVO hvo = invCountBillVO.getParentVO(); + InvCountBodyVO[] bvos = invCountBillVO.getChildrenVO(); + + // Ҫ͵ + JSONObject syncData = buildSyncData(hvo, bvos); + + // ݵ˼άϵͳʹHttpPostOtherSysImpl + String mesResponse = httpPostOtherSys.callLE(INV_COUNT_URL, syncData); + obmlog.debug("AfterApprovingSynchronizeRule-˼άϵͳӦ: " + mesResponse); + + // Ӧ + processResponse(hvo.getVbillcode(), mesResponse); + } + } catch (Exception e) { + obmlog.error("AfterApprovingSynchronizeRule-쳣:" + e.getMessage(), e); + } + } + + /** + * Ͻ˼άϵͳӿڹ淶 + * սӿĵҪ󹹽JSONṹ + */ + private JSONObject buildSyncData(InvCountHeaderVO hvo, InvCountBodyVO[] bvos) throws BusinessException { + JSONObject requestData = new JSONObject(); + // Ϊ + requestData.put("operation_type", "I"); + + // info - սӿҪñֶ + JSONObject info = new JSONObject(); + + // ֶ + info.put("storeId", hvo.getCwarehouseid()); // ֿID(cwarehouseid) - + info.put("departmentId", hvo.getCdptvid()); // ID(cdptvid) - + + // ڴ - ̵ + UFDate dcountdate = hvo.getDcountdate(); + if (dcountdate != null) { + info.put("date", dateTimeFormat.format(dcountdate.toDate())); // ̵(dcountdate) - + } else { + // ̵Ϊգʹõ + UFDate dbilldate = hvo.getDbilldate(); + if (dbilldate != null) { + info.put("date", dateTimeFormat.format(dbilldate.toDate())); + } else { + // ӿҪֶαûʹõǰ + info.put("date", dateTimeFormat.format(new java.util.Date())); + } + } + + // ֶ + info.put("worker", getStringValue(hvo.getCountoperator())); // ̵(countoperator) + info.put("mark", "N"); // ɱ־ĬΪN + info.put("remark", getStringValue(hvo.getVnote())); // ע(vnote) + + // detailsϸ + JSONArray details = new JSONArray(); + if (bvos != null) { + for (InvCountBodyVO bvo : bvos) { + JSONObject detail = new JSONObject(); + + // ֶ + // - תΪ + detail.put("sequenceNum", bvo.getCrowno()); // (crowno) - + detail.put("materialId", getStringValue(bvo.getCmaterialvid())); // ID(cmaterialvid) - + detail.put("storageId", getStringValue(bvo.getClocationid())); // λ(clocationid) - + detail.put("batchNum", getStringValue(bvo.getVbatchcode())); // (vbatchcode) - + + // ̴ - ʹʵ + UFDouble countNum = bvo.getNcountnum(); + if (countNum != null) { + detail.put("panQty", countNum.doubleValue()); // ̴(ncountnum) - + } else { + throw new BusinessException("̴Ϊ"); + } + + detail.put("customId", getStringValue(bvo.getCasscustid())); // ͻID + detail.put("supplierId", getStringValue(bvo.getCvendorid())); // ӦID + + // ڴ + detail.put("manufactureDate", null); // ûУnull + detail.put("color", null); + + // װϢԶԣ + detail.put("packLen", null); + detail.put("packSize", null); + // ע + detail.put("remark", getStringValue(bvo.getVnotebody())); // ע(vnotebody) + details.add(detail); + } + } + info.put("details", details); + + // infoӵ + requestData.put("info", info); + + return requestData; + } + + /** + * ȫȡֵַָֹ쳣 + */ + private String getStringValue(Object value) { + return value == null ? "" : value.toString(); + } + + /** + * ˼άϵͳӦ + */ + private void processResponse(String vbillcode, String response) { + if (StringUtils.isEmpty(response)) { + obmlog.error("AfterApprovingSynchronizeRule-ӦΪգݺ: " + vbillcode); + return; + } + + try { + JSONObject respObj = JSONObject.parseObject(response); + JSONObject result = respObj.getJSONObject("result"); + if (result != null) { + boolean success = result.getBooleanValue("success"); + String message = result.getString("message"); + String errorMessage = result.getString("errorMessage"); + String orderNo = result.getString("orderNo"); + + if (success) { + obmlog.info("AfterApprovingSynchronizeRule-ͬɹݺ: " + vbillcode + ", ص: " + orderNo + ", Ϣ: " + message); + } else { + obmlog.error("AfterApprovingSynchronizeRule-ͬʧܣݺ: " + vbillcode + ", : " + errorMessage); + throw new BusinessException("ͬ˼άϵͳʧ: " + errorMessage); + } + } + } catch (Exception e) { + obmlog.error("AfterApprovingSynchronizeRule-Ӧ쳣: " + e.getMessage(), e); + } + } +}