From be45267932b571376872fa0f6d20ae9648e3c104 Mon Sep 17 00:00:00 2001 From: maolei Date: Fri, 23 May 2025 14:56:19 +0800 Subject: [PATCH] =?UTF-8?q?mmpac:=20=E6=B5=81=E7=A8=8B=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8F=AA=E5=90=8C=E6=AD=A5=E6=88=90=E5=93=81?= =?UTF-8?q?and=E5=BF=BD=E7=95=A5=E9=87=8D=E5=A4=8Dkey=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加了对主键冲突错误的处理,避免因重复数据导致的同步失败 -改进了错误处理机制,对不同类型的错误进行区分和记录 - 优化了请求和响应的处理流程,提高了系统稳定性 - 添加了日志记录,便于问题追踪和调试 --- .../bp/rule/AfterApproveRuleSyncMes.java | 102 +++++++++++++++++- 1 file changed, 97 insertions(+), 5 deletions(-) diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveRuleSyncMes.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveRuleSyncMes.java index 974bc82..1f6691f 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveRuleSyncMes.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveRuleSyncMes.java @@ -43,13 +43,14 @@ public class AfterApproveRuleSyncMes implements IRule { private static final String MES_PMO_SYNC_URL = "/GTHINKING/AjaxService/N_SCSJJSA/102525006.ashx/receive_woinfo_insert"; + private static final String PK_VIOLATION_ERROR_SUBSTRING = "Υ PRIMARY KEY ԼPK_WO"; + @Override public void process(PMOAggVO[] pmoAggVOS) { if (ArrayUtil.isEmpty(pmoAggVOS)) { return; } try { - // 鲢ɸѡ List filteredOrders = checkAndFilterBillSrcOrg(pmoAggVOS); if (filteredOrders.isEmpty()) { obmlog.info("ûзҪͬMESϵͳ"); @@ -68,17 +69,99 @@ public class AfterApproveRuleSyncMes implements IRule { } for (PMOItemVO item : bodys) { + if (item.getVparentbillid() == null || item.getVparentbillid().isBlank()) { + continue; + } syncOrderItemToMes(head, item); } } obmlog.info("ͬMESϵͳɡ"); + } catch (Exception e) { obmlog.error("ͬMESϵͳʧ: " + e.getMessage(), e); ExceptionUtils.wrappException(e); } } + /** + * MESӿڲضͻ + * + * @param apiPath MESӿ· + * @param requestPayload + * @param orderNo (־) + * @param itemRow к (־) + * @throws BusinessException ضɺԵĴ + */ + private void callMesWithCustomErrorHandling(String apiPath, JSONObject requestPayload, String orderNo, String itemRow) throws BusinessException { + String responseString = null; + try { + responseString = HTTP_POST_OTHER_SYS.callMes(apiPath, requestPayload); + obmlog.info(" " + orderNo + " " + itemRow + " MESϵͳԭʼ: " + responseString); + + if (responseString == null || responseString.trim().isEmpty()) { + obmlog.warn(" " + orderNo + " " + itemRow + " MESϵͳΪա"); + // ҵ󣬿ӦҲһִ + // throw new BusinessException("MESϵͳΪա"); + return; // ΪӦ󣬼ִ + } + + JSONObject jsonResponse = JSONObject.parseObject(responseString); + + // Ƿ "Data" + if (jsonResponse.containsKey("Data") && jsonResponse.get("Data") instanceof JSONArray) { + JSONArray dataArray = jsonResponse.getJSONArray("Data"); + for (int i = 0; i < dataArray.size(); i++) { + JSONObject dataObject = dataArray.getJSONObject(i); + String successInData = dataObject.getString("Success"); + if ("false".equalsIgnoreCase(successInData)) { + String errorMessage = dataObject.getString("ErrorMessage"); + if (StringUtils.isEmpty(errorMessage)) { + errorMessage = dataObject.getString("Message"); + } + if (StringUtils.isEmpty(errorMessage)) { + errorMessage = "ⲿϵͳDataδṩȷϢSuccessΪfalse"; + } + + if (errorMessage.contains(PK_VIOLATION_ERROR_SUBSTRING)) { + obmlog.warn(" " + orderNo + " " + itemRow + " MESͻItem " + i + "Ϊɺԣ " + errorMessage); + // ض󣬼¼ + } else { + throw new BusinessException("ͬMESϵͳʧ (Item " + i + "), Ϣ" + errorMessage); + } + } + } + } else { + // Successֶ + String success = jsonResponse.getString("Success"); + if ("false".equalsIgnoreCase(success)) { + String errorMessage = jsonResponse.getString("ErrorMessage"); + if (StringUtils.isEmpty(errorMessage)) { + errorMessage = jsonResponse.getString("Message"); + } + if (StringUtils.isEmpty(errorMessage)) { + errorMessage = "ⲿϵͳδṩȷϢSuccessΪfalse"; + } + + if (errorMessage.contains(PK_VIOLATION_ERROR_SUBSTRING)) { + obmlog.warn(" " + orderNo + " " + itemRow + " MESͻΪɺԣ " + errorMessage); + // ض󣬼¼ + } else { + throw new BusinessException("ͬMESϵͳʧ, Ϣ" + errorMessage); + } + } + } + // мͨض󱻺ԣ򷽷 + } catch (BusinessException e) { + // ֱ׳Ѳҵ쳣 + throw e; + } catch (Exception e) { + // callMesJSON쳣 + obmlog.error(" " + orderNo + " " + itemRow + " MESӦʱԭʼӦ: " + responseString + " : " + e.getMessage(), e); + throw new BusinessException("MESӦʱ" + e.getMessage(), e); + } + } + /** * 鲢ɸѡҪͬĵ */ @@ -87,6 +170,14 @@ public class AfterApproveRuleSyncMes implements IRule { for (PMOAggVO aggvo : pmoAggVOS) { String pkOrg = aggvo.getParentVO().getPk_org(); String orgCode = transferCodeByPk(FactoryVO.getDefaultTableName(), FactoryVO.CODE, FactoryVO.PK_FACTORY, pkOrg); +// // ֹmesbipbip͸mes +// String billmaker = aggvo.getParentVO().getBillmaker(); +// String userCode = transferCodeByPk("sm_user", UserVO.USER_CODE, UserVO.CUSERID, billmaker); +// +// if ("C034".equals(orgCode)&&(!"gaoning".equals(userCode))) { +// aggvoList.add(aggvo); +// } + if ("C034".equals(orgCode)) { aggvoList.add(aggvo); } @@ -236,12 +327,13 @@ public class AfterApproveRuleSyncMes implements IRule { obmlog.info(" " + vbillcode + " " + itemRow + " ͬMES: " + requestPayload.toJSONString()); - // Send to MES - // Note: The actual endpoint URL might need to be configured or obtained from a central place. - HTTP_POST_OTHER_SYS.sendToExternalSystem(MES_PMO_SYNC_URL, requestPayload); - obmlog.info(" " + vbillcode + " " + itemRow + " ѳɹ͵MESϵͳ"); + // Send to MES using custom error handling + callMesWithCustomErrorHandling(MES_PMO_SYNC_URL, requestPayload, vbillcode, itemRow); + + obmlog.info(" " + vbillcode + " " + itemRow + " ѳɹ͵MESϵͳضѱ¼"); } + /** * ѯ */