From 0bdb98af27293daa52a967741bf602144905c375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E?= <125556714+Topfunplus@users.noreply.github.com> Date: Wed, 21 May 2025 16:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=87=87=E8=B4=AD=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E5=90=8C=E6=AD=A5=20MES=20=E6=8E=A5=E5=8F=A3=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 AfterSigningSynchronizeRuleMES 类的逻辑,增加了判断是否需要同步到 MES 的方法 -重构了 buildSyncData 方法,优化了请求数据的构建过程 - 新增了 PurchaseReceiptRuleMES 类,用于处理采购收货单推送 MES 系统的逻辑 - 优化了代码结构,提高了可读性和可维护性 --- ic/src/private/nc/bs/ic/m45/sign/SignBP.java | 3 +- .../rule/AfterSigningSynchronizeRuleMES.java | 305 +++++++---------- .../m45/sign/rule/PurchaseReceiptRuleMES.java | 312 ++++++++++++++++++ .../rule/AfterSigningSynchronizeRuleMES.java | 28 +- .../sign/rule/SalesDeliveryOrderRuleMES.java | 42 ++- 5 files changed, 453 insertions(+), 237 deletions(-) create mode 100644 ic/src/private/nc/bs/ic/m45/sign/rule/PurchaseReceiptRuleMES.java diff --git a/ic/src/private/nc/bs/ic/m45/sign/SignBP.java b/ic/src/private/nc/bs/ic/m45/sign/SignBP.java index a52e3dd..3951916 100644 --- a/ic/src/private/nc/bs/ic/m45/sign/SignBP.java +++ b/ic/src/private/nc/bs/ic/m45/sign/SignBP.java @@ -4,7 +4,7 @@ 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.m45.sign.rule.AfterSigningSynchronizeRuleMES; +import nc.bs.ic.m45.sign.rule.PurchaseReceiptRuleMES; import nc.bs.ic.m45.base.BPPlugInPoint; import nc.bs.ic.m45.insert.rule.InsertOrSignRewritePayPlanInvoiceRule; import nc.bs.ic.m45.sign.rule.*; @@ -51,6 +51,7 @@ public class SignBP implements ISignBP, ISignRuleProvider { - private static final String PURCHASE_IN_URL = "/GTHINKING/AjaxService/N_CGSJJSA/102223002.ashx/CGSH_INSERT"; // ɹջͬӿ + + // MESӿURL + private static final String ADD_URL = "/GTHINKING/AjaxService/N_KCSJJS/101527010.ashx/gt_rec_api_cgrkdj"; + private static final String DELETE_URL = "/GTHINKING/AjaxService/N_KCSJJS/101527010.ashx/gt_rec_api_qxcgrkdj"; + private static final String logginfo = "OALOG"; private static final Log obmlog = Log.getInstance(logginfo); private static final BaseDAO dao = new BaseDAO(); @Override - public void process(PurchaseInVO[] purchaseInVOS) { + public void process(PurchaseInVO[] purchaseInVOs) { try { - if (purchaseInVOS == null || purchaseInVOS.length == 0) { - return; - } - - // 鲢ɸѡɹջ - List filteredPurchaseInVOS = checkAndFilterBills(purchaseInVOS); - if (filteredPurchaseInVOS.isEmpty()) { + if (purchaseInVOs == null || purchaseInVOs.length == 0) { return; } // ʼHTTP󹤾 IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); - // ÿɹջ - for (PurchaseInVO purchaseInVO : filteredPurchaseInVOS) { - PurchaseInHeadVO head = purchaseInVO.getHead(); - PurchaseInBodyVO[] bodys = purchaseInVO.getBodys(); - // Ҫ͵ - JSONObject syncData = buildSyncData(head, bodys); - // ݵMESϵͳ - httpPostOtherSys.sendToExternalSystem(PURCHASE_IN_URL, syncData); + for (PurchaseInVO purchaseInVO : purchaseInVOs) { + // жǷҪͬMES + if (!isSyncToMES(purchaseInVO)) { + continue; + } + + PurchaseInHeadVO hvo = (PurchaseInHeadVO) purchaseInVO.getParentVO(); + PurchaseInBodyVO[] bvos = (PurchaseInBodyVO[]) purchaseInVO.getChildrenVO(); + // + JSONObject requestParam = buildSyncData(hvo, bvos); + + if (requestParam != null) { + // ȡ + String operationType = (String) requestParam.get("operation_type"); + // ݲѡURL + String url = "I".equals(operationType) ? ADD_URL : DELETE_URL; + obmlog.debug("ɹͬMES-ʼ: " + hvo.getVbillcode()); + obmlog.debug("ɹͬMES-: " + requestParam.toJSONString()); + // MESӿ + httpPostOtherSys.sendToExternalSystem(url, requestParam); + } } } catch (Exception e) { - obmlog.error("AfterSigningSynchronizeRuleMES-쳣:" + e.getMessage(), e); + obmlog.error("ɹͬMES-쳣:" + e.getMessage(), e); ExceptionUtils.wrappException(e); } } /** - * 鲢ɸѡҪͬĵ + * жǷҪͬMES */ - private List checkAndFilterBills(PurchaseInVO[] purchaseInVOS) throws BusinessException { - List result = new ArrayList<>(); - - for (PurchaseInVO vo : purchaseInVOS) { - // ֯ǷΪ֯ - if (vo.getHead() != null && "0001A110000000000677".equals(vo.getHead().getPk_org())) { - result.add(vo); - } - } - - return result; - } - - /** - * ϸ - */ - private JSONArray buildDetailsData(PurchaseInBodyVO[] bodys) throws BusinessException { - JSONArray details = new JSONArray(); - if (bodys != null) { - for (PurchaseInBodyVO body : bodys) { - JSONObject detailItem = new JSONObject(); - // ջţ - detailItem.put("orderNo", null); - // ջţ- ʹȷıֶcrowno - detailItem.put("orderSn", body.getCrowno()); - // ͣ- ʹñֶcbodytranstypecode - detailItem.put("type", null); - // ࣨ- H:, F:, L: - detailItem.put("costOrder", null); - // ɹ - Դݺvsourcebillcode - detailItem.put("poNo", body.getVsourcebillcode()); - // ɹ - Դкvsourcerowno - detailItem.put("poSn", body.getVsourcerowno()); - // ϱ루 - String materialCode = transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, - MaterialVO.PK_MATERIAL, body.getCmaterialvid()); - detailItem.put("materialId", materialCode); - // λ- ʹõλcastunitidλcunitid - detailItem.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, body.getCastunitid())); - // - detailItem.put("batchNum", null); - // - PurchaseInBodyVOûֱӶӦֶΣԴvdefֶλȡ - detailItem.put("productNum", null); // vdef1洢 - // ϵ - String scaleFactor = body.getVchangerate(); - detailItem.put("scaleFactor", transferSpecialField(scaleFactor)); - // TODO ĵûжӦϵ - UFDouble taxRate = body.getNtaxrate(); - detailItem.put("taxRate", taxRate != null ? taxRate.getDouble() : null); - // Ӧ- ʹnshouldassistnum - UFDouble recQty = body.getNshouldassistnum(); - detailItem.put("recQty", recQty != null ? recQty.getDouble() : null); - // Ӧ- ʹnshouldnum - UFDouble mainRecQty = body.getNshouldnum(); - detailItem.put("mainRecQty", mainRecQty != null ? mainRecQty.getDouble() : null); - // Ӧ - Զֶ - detailItem.put("assitRecQty", null); - // ԭҺ˰۸ - - UFDouble priceIncludeTax = body.getNpickupnum(); - detailItem.put("priceIncludeTax", priceIncludeTax != null ? priceIncludeTax.getDouble() : null); - // ԭҺ˰ - ʹnorigtaxmny - UFDouble amountIncludeTax = body.getNorigtaxmny(); - detailItem.put("amountIncludeTax", amountIncludeTax != null ? amountIncludeTax.getDouble() : null); - // ԭ˰۸ - - UFDouble priceNoTax = body.getNorigprice(); - detailItem.put("priceNoTax", priceNoTax != null ? priceNoTax.getDouble() : null); - // ԭ˰ - ʹnorigmny - UFDouble amountNoTax = body.getNqtnetprice(); - detailItem.put("amountNoTax", amountNoTax != null ? amountNoTax.getDouble() : null); - // ˰ - ʹntax - UFDouble taxAmount = body.getNtax(); - detailItem.put("taxAmount", taxAmount != null ? taxAmount.getDouble() : null); - // ע - ʹvnotebody - detailItem.put("remark", body.getVnotebody()); - // ԭջϢ - detailItem.put("oldOrderNo", null); - detailItem.put("oldOrderSn", null); - details.add(detailItem); - } - } - return details; + private boolean isSyncToMES(PurchaseInVO purchaseInVO) { + // ˴ҵжǷҪͬ + return true; } /** * MESϵͳӿڹ淶 */ - private JSONObject buildSyncData(PurchaseInHeadVO head, PurchaseInBodyVO[] bodys) throws BusinessException { - // + private JSONObject buildSyncData(PurchaseInHeadVO hvo, PurchaseInBodyVO[] bvos) throws BusinessException { + obmlog.debug("ɹͬMES-ʼ: " + hvo.getVbillcode()); + JSONObject requestData = new JSONObject(); - JSONObject data = new JSONObject(); + // ò + requestData.put("operation_type", "I"); // ǩΪ - // ջϢ - // ջţ - data.put("orderNo", head.getVbillcode()); - // ջ - UFDate dbilldate = head.getDbilldate(); - data.put("orderDate", dbilldate != null ? dbilldate.toString().substring(0, 10) : null); - // ջ - data.put("orderType", "P"); - // - data.put("type", null); - // ֿ - String storeId = transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE, - StordocVO.PK_STORDOC, head.getCwarehouseid()); - data.put("storeId", storeId); + // data + List dataList = new ArrayList<>(); - // ɹID- ע⣺ֵֶ䣬ɹֶΪcdptidcdeptid - String departmentId = transferCodeByPk(DeptVersionVO.getDefaultTableName(), DeptVersionVO.CODE, - DeptVersionVO.PK_VID, head.getCdptvid()); - data.put("departmentId", departmentId); - // ɹԱ - ɹԱֶΪcbizid - String purchaser = transferCodeByPk(PsndocVO.getDefaultTableName(), PsndocVO.CODE, - PsndocVO.PK_PSNDOC, head.getCbizid()); - data.put("purchaser", purchaser); - // Ӧ̱루 - String supplyId = transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, - SupplierVO.PK_SUPPLIER, head.getCvendorid()); - data.put("supplyId", supplyId); - // ID - data.put("currency", null); - // ʣ - data.put("rate", null); - // 㷽ʽ - data.put("settleType", null); - // Ʊ - data.put("billBasis", null); - // ɷʽ- P:ɹ, Z:ֱ - data.put("genType", "P"); - // ࣨ- N:, Y: - data.put("costOrder", "N"); - // Ƿ˻- N:, Y: - data.put("returned", head.getFreplenishflag()); - // ע - data.put("remark", head.getVnote()); - // άϢ - data.put("creatorNo", null); // - data.put("creator", head.getBillmaker()); // Ƶ - data.put("creatTime", head.getDmakedate() != null ? head.getCreationtime().toString() : null); // ʱ + JSONObject dataObj = new JSONObject(); - // ϸ - JSONArray details = buildDetailsData(bodys); - data.put("Details", details); - requestData.put("Data", data); + // ⵥϢ + UFDate billDate = hvo.getDbilldate(); + dataObj.put("orderDate", billDate != null ? billDate.toString().substring(0, 10) : ""); // - ʽyyyy-MM-dd + dataObj.put("originalOrderNo", hvo.getVbillcode()); // ɹջ + // ֿ - ʹȷIJֶֿ(cwarehouseid) + dataObj.put("warehouseId", transferCodeByPk(StordocVO.getDefaultTableName(), + StordocVO.CODE, StordocVO.PK_STORDOC, hvo.getCwarehouseid())); // ֿ - obmlog.debug("AfterSigningSynchronizeRuleMES-ɹջ: " + requestData.toJSONString()); + // ID - ɹ°汾(cdptid)cdptvidcdptvidDzŰ汾Ϣ + dataObj.put("departmentId", transferCodeByPk(DeptVersionVO.getDefaultTableName(), + DeptVersionVO.CODE, DeptVersionVO.PK_VID, hvo.getCdptvid())); // ű + // Ա + dataObj.put("creator", transferCodeByPk(PsndocVO.getDefaultTableName(), + PsndocVO.NAME, PsndocVO.PK_PSNDOC, hvo.getCwhsmanagerid())); // Ա + dataObj.put("remark", hvo.getVnote()); // ע + // ӲɹԱϢ - cbizidֶ + String purchaser = transferCodeByPk(PsndocVO.getDefaultTableName(), + PsndocVO.NAME, PsndocVO.PK_PSNDOC, hvo.getCbizid()); + if (purchaser != null && !purchaser.isEmpty()) { + dataObj.put("purchaser", purchaser); // ɹԱ + } + // ӹӦϢ - cvendoridֶ + String supplier = transferCodeByPk(SupplierVO.getDefaultTableName(), + SupplierVO.CODE, SupplierVO.PK_SUPPLIER, hvo.getCvendorid()); + if (supplier != null && !supplier.isEmpty()) { + dataObj.put("supplierId", supplier); // Ӧ̱ + } + // ϸ + List detailsList = new ArrayList<>(); + if (bvos != null) { + for (PurchaseInBodyVO bvo : bvos) { + JSONObject detailMap = new JSONObject(); + // TODO ûֶ + detailMap.put("originalOrderNo", hvo.getVbillcode()); // ɹջ + detailMap.put("sequenceNum", bvo.getCrowno()); // ɹջ + // ϱ - + detailMap.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(), + MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialoid())); // ϱ + // λ - ֶαʹclocationidcspaceid + detailMap.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(), + RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); // λ + detailMap.put("batchNum", bvo.getVbatchcode()); // + // Ϣ - ֶα + UFDouble assistNum = bvo.getNassistnum(); // ʵ + detailMap.put("quantity", assistNum != null ? assistNum.doubleValue() : null); // + UFDouble mainNum = bvo.getNnum(); // ʵ + detailMap.put("mQuantity", mainNum != null ? mainNum.doubleValue() : null); // + // Ӧ̱ - ֶαʹcvendoridcsupplierid + detailMap.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(), + SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); // Ӧ̱ + // - ֶαȷΪdproducedate + UFDate produceDate = bvo.getDproducedate(); + if (produceDate != null) { + detailMap.put("manufactureDate", produceDate.toString().substring(0, 10)); + } + detailsList.add(detailMap); + } + } + + dataObj.put("details", detailsList); + dataList.add(dataObj); + + requestData.put("data", dataList); return requestData; } /** - * תֶ 1/1 תΪС 1.0 + * ѯӦı */ - - private String transferSpecialField(String field) { - if (field == null || field.trim().isEmpty()) { - return null; - } - String[] split = field.split("/"); - if (split.length == 2) { - String numStr = split[0].trim(); - String denStr = split[1].trim(); - - if (denStr.equals("0")) { - return "0.00"; // ĸΪ - } - - try { - BigDecimal numerator = new BigDecimal(numStr); - BigDecimal denominator = new BigDecimal(denStr); - return numerator.divide(denominator, 2, RoundingMode.HALF_UP).toString(); - } catch (NumberFormatException e) { - return field; // Ƿ֣ԭֶ - } - } - return field; - } - - /** - * ѯ - */ - private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException { - if (StringUtils.isEmpty(pk)) { + private String transferCodeByPk(String tableName, String selectField, String pkField, Object pk) throws BusinessException { + if (pk == null || "".equals(pk.toString().trim())) { return null; } SqlBuilder sqlBuilder = new SqlBuilder(); sqlBuilder.append(" select " + selectField); sqlBuilder.append(" from " + tableName); sqlBuilder.append(" where "); - sqlBuilder.append(pkField, pk); + sqlBuilder.append(pkField, pk.toString()); Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor()); if (o == null) { - throw new BusinessException("δѯϢsql" + sqlBuilder + ""); + obmlog.warn("δѯϢsql" + sqlBuilder + ""); + return null; } return o.toString(); } diff --git a/ic/src/private/nc/bs/ic/m45/sign/rule/PurchaseReceiptRuleMES.java b/ic/src/private/nc/bs/ic/m45/sign/rule/PurchaseReceiptRuleMES.java new file mode 100644 index 0000000..b4d364b --- /dev/null +++ b/ic/src/private/nc/bs/ic/m45/sign/rule/PurchaseReceiptRuleMES.java @@ -0,0 +1,312 @@ +package nc.bs.ic.m45.sign.rule; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.NCLocator; +import nc.bs.logging.Log; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.vo.bd.material.MaterialVO; +import nc.vo.bd.material.measdoc.MeasdocVO; +import nc.vo.bd.psn.PsndocVO; +import nc.vo.bd.stordoc.StordocVO; +import nc.vo.bd.supplier.SupplierVO; +import nc.vo.cmp.util.StringUtils; +import nc.vo.ic.m45.entity.PurchaseInVO; +import nc.vo.ic.m45.entity.PurchaseInBodyVO; +import nc.vo.ic.m45.entity.PurchaseInHeadVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.pub.SqlBuilder; +import nc.vo.vorg.DeptVersionVO; +import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; + +/** + * (ǰ)ɹջMESϵͳ,òɹ + */ +public class PurchaseReceiptRuleMES implements IRule { + private static final String PURCHASE_IN_URL = "/GTHINKING/AjaxService/N_CGSJJSA/102223002.ashx/CGSH_INSERT"; // ɹջͬӿ + private static final String PURCHASE_DELETE_URL = "/GTHINKING/AjaxService/N_CGSJJSA/102223002.ashx/CGSH_DELETE"; // ɹջɾӿ + private static final String logginfo = "OALOG"; + private static final Log obmlog = Log.getInstance(logginfo); + private static final BaseDAO dao = new BaseDAO(); + + @Override + public void process(PurchaseInVO[] purchaseInVOS) { + try { + if (purchaseInVOS == null || purchaseInVOS.length == 0) { + return; + } + + // 鲢ɸѡɹջ + List filteredPurchaseInVOS = checkAndFilterBills(purchaseInVOS); + if (filteredPurchaseInVOS.isEmpty()) { + return; + } + + // ʼHTTP󹤾 + IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); + + // ÿɹջ + for (PurchaseInVO purchaseInVO : filteredPurchaseInVOS) { + PurchaseInHeadVO head = purchaseInVO.getHead(); + PurchaseInBodyVO[] bodys = purchaseInVO.getBodys(); + + // ÿɹջǰɾϵͳеݣٽ + String orderNo = head.getVbillcode(); + boolean deleteSuccess = deletePurchaseReceipt(orderNo); + if (deleteSuccess) { + // Ҫ͵ + JSONObject syncData = buildSyncData(head, bodys); + // ݵMESϵͳ + obmlog.debug("PurchaseReceiptRuleMES-׼Ͳɹջ: " + orderNo); + httpPostOtherSys.sendToExternalSystem(PURCHASE_IN_URL, syncData); + } + } + } catch (Exception e) { + obmlog.error("AfterSigningSynchronizeRuleMES-쳣:" + e.getMessage(), e); + ExceptionUtils.wrappException(e); + } + } + + /** + * ɾϵͳеIJɹջ + * + * @param orderNo ҪɾIJɹջ + * @return ɾǷɹ + * @throws BusinessException ҵ쳣 + */ + public boolean deletePurchaseReceipt(String orderNo) throws BusinessException { + try { + if (orderNo == null || orderNo.trim().isEmpty()) { + throw new BusinessException("ɹջŲΪ"); + } + + obmlog.debug("PurchaseReceiptRuleMES-׼ɾϵͳɹջ: " + orderNo); + + // + JSONObject requestData = new JSONObject(); + JSONObject dataObj = new JSONObject(); + dataObj.put("orderNo", orderNo); + requestData.put("Data", dataObj); + + // ʼHTTP󹤾 + IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); + + // ɾ + String response = httpPostOtherSys.callMes(PURCHASE_DELETE_URL, requestData); + obmlog.debug("PurchaseReceiptRuleMES-ɾ󷵻ؽ: " + response); + + // ؽ + JSONObject jsonResponse = JSONObject.parseObject(response); + boolean isSuccess = jsonResponse.getBooleanValue("Success"); + String errorMessage = jsonResponse.getString("ErrorMessage"); + + if (!isSuccess) { + obmlog.error("PurchaseReceiptRuleMES-ɾɹջʧ: " + orderNo + ", Ϣ: " + errorMessage); + throw new BusinessException("ɾɹջʧ: " + (errorMessage != null ? errorMessage : "δ֪")); + } + + obmlog.debug("PurchaseReceiptRuleMES-ɹɾɹջ: " + orderNo); + return true; + } catch (Exception e) { + obmlog.error("PurchaseReceiptRuleMES-ɾɹջ쳣:" + e.getMessage(), e); + throw new BusinessException("ɾɹջʱ쳣: " + e.getMessage(), e); + } + } + + /** + * 鲢ɸѡҪͬĵ + */ + private List checkAndFilterBills(PurchaseInVO[] purchaseInVOS) throws BusinessException { + List result = new ArrayList<>(); + + for (PurchaseInVO vo : purchaseInVOS) { + // ֯ǷΪ֯ + if (vo.getHead() != null && "0001A110000000000677".equals(vo.getHead().getPk_org())) { + result.add(vo); + } + } + + return result; + } + + + /** + * MESϵͳӿڹ淶 + */ + private JSONObject buildSyncData(PurchaseInHeadVO head, PurchaseInBodyVO[] bodys) throws BusinessException { + // + JSONObject requestData = new JSONObject(); + JSONObject data = new JSONObject(); + // ջϢ + // ջţ- ӳΪvbillcode + data.put("orderNo", head.getVbillcode()); + // ջ - ӳΪdbilldate (ʽyyyy-MM-dd) + UFDate dbilldate = head.getDbilldate(); + data.put("orderDate", dbilldate != null ? dbilldate.toString().substring(0, 10) : null); + // ջ - ĬΪ"P"(⹺) + data.put("orderType", "P"); + // + data.put("type", "WGRK"); + // ֿ - ӳΪcwarehouseid + data.put("storeId", transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE, + StordocVO.PK_STORDOC, head.getCwarehouseid())); + // ɹID- ӳΪcdptvid + data.put("departmentId", transferCodeByPk(DeptVersionVO.getDefaultTableName(), DeptVersionVO.CODE, + DeptVersionVO.PK_VID, head.getCdptvid())); + // ɹԱ - ӳΪcbizid + String purchaser = transferCodeByPk(PsndocVO.getDefaultTableName(), PsndocVO.CODE, + PsndocVO.PK_PSNDOC, head.getCbizid()); + data.put("purchaser", purchaser); + // Ӧ̱루- ӳΪcvendorid + String supplyId = transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, + SupplierVO.PK_SUPPLIER, head.getCvendorid()); + data.put("supplyId", supplyId); + // ID - ȷӳ + data.put("currency", null); + //ʣ + data.put("rate", 1); + // 㷽ʽ - ĬΪ"S"(ת) + data.put("settleType", "S"); + // Ʊ - ĬΪ"S"(ʵ) + data.put("billBasis", "S"); + // ɷʽ- ĬΪ"P"(ɹ) + data.put("genType", "P"); + // ࣨ- ĬΪ"N"() + data.put("costOrder", "N"); + // Ƿ˻- ӳΪfreplenishflagΪYΪ˻ + data.put("returned", head.getFreplenishflag()); + // ע - ӳΪvnote + data.put("remark", head.getVnote()); + // άϢ + data.put("creatorNo", null); // ˹ + data.put("creator", head.getBillmaker()); // Ƶ + data.put("creatTime", head.getDmakedate() != null ? head.getDmakedate().toString() : null); // ʱ + // ϸ + JSONArray details = new JSONArray(); + if (bodys != null) { + for (PurchaseInBodyVO body : bodys) { + JSONObject detailItem = new JSONObject(); + // ջţ- buildSyncData + detailItem.put("orderNo", dbilldate != null ? dbilldate.toString().substring(0, 10) : null); + // ջţ- ӳΪк(crowno) + detailItem.put("orderSn", body.getCrowno()); + // ͣ- ʹñֶcbodytranstypecode + detailItem.put("type", "WGRK"); + // ࣨ- ĬΪ"H" - H:, F:, L: + detailItem.put("costOrder", "H"); + // ɹ - Դݺ(vsourcebillcode) + detailItem.put("poNo", body.getVsourcebillcode()); + // ɹ - Դк(vsourcerowno) + detailItem.put("poSn", body.getVsourcerowno()); + // ϱ루- ӳΪcmaterialvid + String materialCode = transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, + MaterialVO.PK_MATERIAL, body.getCmaterialvid()); + detailItem.put("materialId", materialCode); + // λ- ӳΪcastunitidcunitid + detailItem.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE, + MeasdocVO.PK_MEASDOC, body.getCastunitid())); + // - ӳΪvbatchcode + detailItem.put("batchNum", body.getVbatchcode()); + // - BIPϵͳûжӦֶΣԴԶֶλȡ + detailItem.put("productNum", body.getVbdef1()); // 洢Զֶ1 + // ϵ- ӳΪvchangerate + String scaleFactor = body.getVchangerate(); + detailItem.put("scaleFactor", transferSpecialField(scaleFactor)); + // ˰ʣ- ӳΪntaxrate + UFDouble taxRate = body.getNtaxrate(); + detailItem.put("taxRate", taxRate != null ? taxRate.doubleValue() : null); + // Ӧ- ӳΪnshouldassistnum + UFDouble recQty = body.getNshouldassistnum(); + detailItem.put("recQty", recQty != null ? recQty.doubleValue() : null); + // Ӧ- ӳΪnshouldnum + UFDouble mainRecQty = body.getNshouldnum(); + detailItem.put("mainRecQty", mainRecQty != null ? mainRecQty.doubleValue() : null); + // Ӧ - BIPϵͳûȷӦֶ + detailItem.put("assitRecQty", null); + // ԭҺ˰۸ - ӳΪnpickupnum + UFDouble priceIncludeTax = body.getNpickupnum(); + detailItem.put("priceIncludeTax", priceIncludeTax != null ? priceIncludeTax.doubleValue() : null); + // ԭҺ˰ - ӳΪnorigtaxmny + UFDouble amountIncludeTax = body.getNorigtaxmny(); + detailItem.put("amountIncludeTax", amountIncludeTax != null ? amountIncludeTax.doubleValue() : null); + // ԭ˰۸ - ӳΪnorigprice + UFDouble priceNoTax = body.getNorigprice(); + detailItem.put("priceNoTax", priceNoTax != null ? priceNoTax.doubleValue() : null); + // ԭ˰ - ӳΪnqtnetprice + UFDouble amountNoTax = body.getNqtnetprice(); + detailItem.put("amountNoTax", amountNoTax != null ? amountNoTax.doubleValue() : null); + // ˰ - ӳΪntax + UFDouble taxAmount = body.getNtax(); + detailItem.put("taxAmount", taxAmount != null ? taxAmount.doubleValue() : null); + // ע - ӳΪvnotebody + detailItem.put("remark", body.getVnotebody()); + // ԭջϢ - ˻ҪԭϢ + detailItem.put("oldOrderNo", null); + detailItem.put("oldOrderSn", null); + details.add(detailItem); + } + } + data.put("Details", details); + requestData.put("Data", data); + obmlog.debug("PurchaseReceiptRuleMES-ɹջ: " + requestData.toJSONString()); + + return requestData; + } + + /** + * תֶ 1/1 תΪС 1.0 + */ + + private String transferSpecialField(String field) { + if (field == null || field.trim().isEmpty()) { + return null; + } + String[] split = field.split("/"); + if (split.length == 2) { + String numStr = split[0].trim(); + String denStr = split[1].trim(); + + if (denStr.equals("0")) { + return "0.00"; // ĸΪ + } + + try { + BigDecimal numerator = new BigDecimal(numStr); + BigDecimal denominator = new BigDecimal(denStr); + return numerator.divide(denominator, 2, RoundingMode.HALF_UP).toString(); + } catch (NumberFormatException e) { + return field; // Ƿ֣ԭֶ + } + } + return field; + } + + /** + * ѯ + */ + private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException { + if (StringUtils.isEmpty(pk)) { + return null; + } + SqlBuilder sqlBuilder = new SqlBuilder(); + sqlBuilder.append(" select " + selectField); + sqlBuilder.append(" from " + tableName); + sqlBuilder.append(" where "); + sqlBuilder.append(pkField, pk); + Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor()); + if (o == null) { + throw new BusinessException("δѯϢsql" + sqlBuilder + ""); + } + return o.toString(); + } +} diff --git a/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRuleMES.java b/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRuleMES.java index b38d1d0..5aa473b 100644 --- a/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRuleMES.java +++ b/ic/src/private/nc/bs/ic/m4c/sign/rule/AfterSigningSynchronizeRuleMES.java @@ -74,10 +74,10 @@ public class AfterSigningSynchronizeRuleMES implements IRule { */ private JSONObject buildSyncData(SaleOutHeadVO hvo, SaleOutBodyVO[] bvos) throws BusinessException { obmlog.debug("AfterSigningSynchronizeRule-ʼ۳ⵥ: " + hvo.getVbillcode()); - if (!hvo.getPk_org().equals("0001A110000000000677")) { - obmlog.debug("AfterSigningSynchronizeRule-۳ⵥ,Ϊ˵֯ǵ: " + hvo.getVbillcode()); - return null; - } +// if (!hvo.getPk_org().equals("0001A110000000000677")) { +// obmlog.debug("AfterSigningSynchronizeRule-۳ⵥ,Ϊ˵֯ǵ: " + hvo.getVbillcode()); +// return null; +// } JSONObject requestData = new JSONObject(); JSONObject dataObj = new JSONObject(); @@ -90,18 +90,17 @@ public class AfterSigningSynchronizeRuleMES implements IRule { dataObj.put("actureDate", dbilldate.toString().substring(0, 10)); // ʵ - (dbilldate)ʽyyyy-MM-dd dataObj.put("orderType", null); // ջ - ޶Ӧֶ dataObj.put("type", "XSCK"); // - ۳ + // ĬΪ1 + dataObj.put("exRate", 1); // ID - (cdptvid) dataObj.put("departmentId", transferCodeByPk(DeptVO.getDefaultTableName(), DeptVO.CODE, DeptVO.PK_DEPT, hvo.getCdptvid())); // ɹID // ֿ - ֿ(cwarehouseid) dataObj.put("storeId", transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, hvo.getCwarehouseid())); // ֿ - - // ɹԱ - ҵԱ(cbizpersonid) dataObj.put("purchaser", transferCodeByPk(PsndocVO.getDefaultTableName(), PsndocVO.CODE, PsndocVO.PK_PSNDOC, hvo.getCbizid())); - // ͻID - ͻ(ccustomerid)ΪDzɹùӦӳ dataObj.put("supplyId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, hvo.getCcustomerid())); @@ -126,58 +125,45 @@ public class AfterSigningSynchronizeRuleMES implements IRule { //ͻID dataObj.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, hvo.getCcustomerid())); //ɱ־ - dataObj.put("mark", "Y"); + dataObj.put("mark", "W"); //ע dataObj.put("remark", hvo.getVnote()); - - // Detailsϸ JSONArray details = new JSONArray(); if (bvos != null) { for (SaleOutBodyVO bvo : bvos) { - // - dataObj.put("exRate", bvo.getNchangestdrate()); - JSONObject detail = new JSONObject(); detail.put("orderNo", hvo.getVbillcode()); // ID - ݺ(vbillcode) - detail.put("sequenceNum", bvo.getCrowno()); // - к(crowno) - detail.put("type", "XSCK"); // - ĬXSCK - // ԴϢ detail.put("saleOrderNo", bvo.getVsourcebillcode()); // SOID - Դݺ(vsourcebillcode) detail.put("saleSequenceNum", bvo.getVsourcerowno()); // SO - Դк(vsourcerowno) detail.put("allocationNum", null); // - // Ϣ - detail.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialoid())); // ID - detail.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, bvo.getCunitid())); // λ - - detail.put("productNum", null); // - // λ - detail.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); // λ - - detail.put("batchNum", bvo.getVbatchcode()); // - detail.put("scaleFactor", transferSpecialField(bvo.getVchangerate())); // ϵ - - // Ϣ - detail.put("issuedQty", bvo.getNshouldassistnum()); // Ӧ - detail.put("mIssuedQty", bvo.getNshouldnum()); // Ӧ - detail.put("actQry", bvo.getNassistnum()); // ʵ - detail.put("mActQry", bvo.getNnum()); // ʵ - detail.put("assistActQry", bvo.getNassistnum()); // ʵ - - // ͻ͹ӦϢ detail.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, bvo.getCasscustid())); // ͻID detail.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); // ӦID - detail.put("manufactureDate", bvo.getDproducedate()); // detail.put("color", null); // ɫ detail.put("properties", null); diff --git a/ic/src/private/nc/bs/ic/m4c/sign/rule/SalesDeliveryOrderRuleMES.java b/ic/src/private/nc/bs/ic/m4c/sign/rule/SalesDeliveryOrderRuleMES.java index eef5f1c..03b0cce 100644 --- a/ic/src/private/nc/bs/ic/m4c/sign/rule/SalesDeliveryOrderRuleMES.java +++ b/ic/src/private/nc/bs/ic/m4c/sign/rule/SalesDeliveryOrderRuleMES.java @@ -12,12 +12,10 @@ import nc.vo.bd.cust.CustomerVO; import nc.vo.bd.material.MaterialVO; import nc.vo.bd.material.measdoc.MeasdocVO; import nc.vo.bd.psn.PsndocVO; -import nc.vo.bd.rack.RackVO; -import nc.vo.bd.supplier.SupplierVO; +import nc.vo.bd.stordoc.StordocVO; import nc.vo.ic.m4c.entity.SaleOutBodyVO; import nc.vo.ic.m4c.entity.SaleOutHeadVO; import nc.vo.ic.m4c.entity.SaleOutVO; -import nc.vo.org.DeptVO; import nc.vo.pub.BusinessException; import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.pattern.pub.SqlBuilder; @@ -29,12 +27,12 @@ import java.math.RoundingMode; /** - * ۽(BIP) MES + * (ǰ)۽(BIP) MES */ public class SalesDeliveryOrderRuleMES implements IRule { private static final BaseDAO dao = new BaseDAO(); // MESϵͳAPIӿڵַ - private static final String MES_API_URL = "/GTHINKING/AjaxService/N_MISPRO/SalesDeliveryOrder.ashx/SaveData"; + private static final String MES_API_URL = "/GTHINKING/AjaxService/N_XSSJJSA/102397002.ashx/SOTH_INSERT"; // ɾ۽ӿڵַ private static final String MES_DELETE_API_URL = "/GTHINKING/AjaxService/N_XSSJJSA/102397002.ashx/SOTH_DELETE"; private static final Log obmlog = Log.getInstance("OALOG"); @@ -80,10 +78,10 @@ public class SalesDeliveryOrderRuleMES implements IRule { obmlog.debug("SalesDeliveryOrderRuleMES-ʼ۽: " + hvo.getVbillcode()); // ֯Ƿ - if (!hvo.getPk_org().equals("0001A110000000000677")) { - obmlog.debug("SalesDeliveryOrderRuleMES-۽,Ϊ˵֯ǵ: " + hvo.getVbillcode()); - return null; - } +// if (!hvo.getPk_org().equals("0001A110000000000677")) { +// obmlog.debug("SalesDeliveryOrderRuleMES-۽,Ϊ˵֯ǵ: " + hvo.getVbillcode()); +// return null; +// } JSONObject requestData = new JSONObject(); JSONObject info = new JSONObject(); @@ -106,9 +104,10 @@ public class SalesDeliveryOrderRuleMES implements IRule { info.put("invoicingBasis", "S"); // Ʊ info.put("settlementType", "S"); // 㷽ʽ // ֿ - info.put("warehouseId", transferCodeByPk(RackVO.getDefaultTableName(), - RackVO.CODE, RackVO.PK_RACK, hvo.getCwarehouseid())); // ֿ - info.put("type", "XSJH"); // ͣ۽ + info.put("warehouseId", transferCodeByPk(StordocVO.getDefaultTableName(), + StordocVO.CODE, StordocVO.PK_STORDOC, hvo.getCwarehouseid())); // ֿ + //  + info.put("type", "XSCK"); // ɷʽ info.put("genType", "S"); // Ƿ˻ @@ -123,18 +122,16 @@ public class SalesDeliveryOrderRuleMES implements IRule { info.put("creatorNo", null); // ά˹ info.put("creator", null); // ά info.put("creatTime", null); // άʱ - + // ͷֶҪֶ + //  + info.put("exchangeRate", 1); + // ұ + info.put("currency", "CNY"); // ϸ JSONArray details = new JSONArray(); if (bvos != null) { for (SaleOutBodyVO bvo : bvos) { JSONObject detail = new JSONObject(); - // ͷֶҪֶ - //  - info.put("exchangeRate", bvo.getNchangestdrate()); - // ұ - info.put("currency", transferCodeByPk(CurrtypeVO.getDefaultTableName(), - CurrtypeVO.CODE, CurrtypeVO.PK_CURRTYPE, bvo.getCorigcurrencyid())); // ֶ detail.put("orderNo", hvo.getVbillcode()); //  detail.put("orderSn", bvo.getCrowno()); //  @@ -148,10 +145,9 @@ public class SalesDeliveryOrderRuleMES implements IRule { detail.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, bvo.getCunitid())); // λ detail.put("scaleFactor", transferSpecialField(bvo.getVchangerate())); // ϵ - detail.put("taxRate", bvo.getNtaxrate()); // ˰ - detail.put("recQty", bvo.getNshouldassistnum()); // Ӧ - detail.put("mainRecQty", bvo.getNnum()); // Ӧ - + detail.put("taxRate", bvo.getNtaxrate().getDouble()); // ˰ + detail.put("recQty", bvo.getNshouldassistnum().getDouble()); // Ӧ + detail.put("mainRecQty", bvo.getNnum().getDouble()); // Ӧ // DZֶ detail.put("batchNum", null); // detail.put("productNum", null); //