From 9f109aeaaf768730756c58b934dcf6e5ac735206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E?= <125556714+Topfunplus@users.noreply.github.com> Date: Fri, 30 May 2025 10:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=B7=E8=B4=AD=E5=8D=95?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95=E6=89=B9?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整代码结构,提高可读性和维护性- 优化分页查询,降低内存消耗 - 完善错误处理,确保数据一致性 -移除冗余日志,提升日志可读性 --- .../plugin/BatchTransferToPurchaseOrder.java | 95 ++++++++----------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/pu/src/private/nc/bs/pu/m21/plugin/BatchTransferToPurchaseOrder.java b/pu/src/private/nc/bs/pu/m21/plugin/BatchTransferToPurchaseOrder.java index c647a4f..c764af9 100644 --- a/pu/src/private/nc/bs/pu/m21/plugin/BatchTransferToPurchaseOrder.java +++ b/pu/src/private/nc/bs/pu/m21/plugin/BatchTransferToPurchaseOrder.java @@ -1,8 +1,6 @@ package nc.bs.pu.m21.plugin; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import nc.bs.framework.common.NCLocator; import nc.bs.logging.Log; @@ -20,10 +18,10 @@ import nc.util.mmf.framework.db.MMSqlBuilder; import nc.vo.pu.m20.entity.PraybillHeaderVO; import nc.vo.pu.m20.entity.PraybillItemVO; import nc.vo.pu.m20.entity.PraybillVO; +import nc.vo.pu.m21.entity.OrderHeaderVO; import nc.vo.pu.m21.entity.OrderItemVO; import nc.vo.pu.m21.entity.OrderVO; import nc.vo.pub.BusinessException; -import nc.vo.pub.compiler.PfParameterVO; import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill; import nc.vo.scmpub.res.billtype.POBillType; @@ -44,13 +42,13 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { // 1. ѯ빺ۺVO PraybillVO[] purchaseRequestVOs = getQualifiedPurchaseRequests(bgWorkingContext); logger.info("ѯ빺: " + purchaseRequestVOs.length, this.getClass(), "executeTask"); - if (purchaseRequestVOs.length > 0) { - // 2. ת - processBatchTransfer(purchaseRequestVOs, bgWorkingContext); - logger.info("ת빺ɹ", this.getClass(), "executeTask"); - } else { + if (purchaseRequestVOs.length <= 0) { logger.info("δҵ빺", this.getClass(), "executeTask"); + return null; } + // 2. ת + processBatchTransfer(purchaseRequestVOs, bgWorkingContext); + logger.info("ת빺ɹ", this.getClass(), "executeTask"); } catch (Exception e) { logger.error("ִת빺ɹʧ", e, this.getClass(), "executeTask"); ExceptionUtils.marsh(e); @@ -72,9 +70,8 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { return new PraybillVO[0]; } List resultList = new ArrayList<>(); - int pageSize = 2048; + int pageSize = 100; IDDBPage page = new IDDBPage(sql, pageSize); - logger.info("ʼҳѯҳС: " + pageSize, this.getClass(), "getQualifiedPurchaseRequests"); int pageCount = 0; while (page.hasNext()) { pageCount++; @@ -121,9 +118,6 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { * IDȡ빺ۺVO */ private PraybillVO[] getBGWorkInfo(String[] ids) { - if (logger.isDebugEnabled()) { - logger.debug("ʼIDȡ빺ۺVOID: " + ids.length, this.getClass(), "getBGWorkInfo"); - } // ѯ빺 VOQuery itemQuery = new VOQuery<>(PraybillItemVO.class); PraybillItemVO[] itemVOs = itemQuery.query(ids); @@ -144,35 +138,25 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { VOQuery headerQuery = new VOQuery<>(PraybillHeaderVO.class); PraybillHeaderVO[] headerVOs = headerQuery.query(headerIds.toArray(new String[headerIds.size()])); logger.debug("ѯ빺ͷ: " + (headerVOs != null ? headerVOs.length : 0), this.getClass(), "getBGWorkInfo"); - return this.getAggvofromHeaderAndItem(headerVOs, - itemVOs); + return this.getAggvofromHeaderAndItem(headerVOs, itemVOs); } /** * װɹۺVO */ private PraybillVO[] getAggvofromHeaderAndItem(PraybillHeaderVO[] headerVOs, PraybillItemVO[] itemVOs) { - if (logger.isDebugEnabled()) { - logger.debug("ʼװۺVOͷ: " + (headerVOs != null ? headerVOs.length : 0) + - ", : " + (itemVOs != null ? itemVOs.length : 0), this.getClass(), "getAggvofromHeaderAndItem"); - } - if (MMArrayUtil.isEmpty(headerVOs) || MMArrayUtil.isEmpty(itemVOs)) { logger.warn("ͷΪգ޷װۺVO", this.getClass(), "getAggvofromHeaderAndItem"); return new PraybillVO[0]; } - List aggList = new ArrayList<>(); - for (PraybillHeaderVO headerVO : headerVOs) { List itemList = new ArrayList<>(); - for (PraybillItemVO itemVO : itemVOs) { if (headerVO.getPk_praybill().equals(itemVO.getPk_praybill())) { itemList.add(itemVO); } } - if (!itemList.isEmpty()) { PraybillVO aggVO = new PraybillVO(); aggVO.setParentVO(headerVO); @@ -180,7 +164,6 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { aggList.add(aggVO); } } - logger.debug("ۺVOװɣ: " + aggList.size(), this.getClass(), "getAggvofromHeaderAndItem"); return aggList.toArray(new PraybillVO[aggList.size()]); } @@ -193,39 +176,43 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { try { // õתɲɹ20->21 - logger.info("õת򣬴빺(20)תΪɹ(21)", this.getClass(), "processBatchTransfer"); OrderVO[] orderVOs = PfServiceScmUtil.exeVOChangeByBillItfDef("20", "21", vos); - - if (orderVOs != null && orderVOs.length > 0) { - logger.info("תɹɲɹ: " + orderVOs.length, this.getClass(), "processBatchTransfer"); - // ö涯ű - logger.info("ʼɹ", this.getClass(), "processBatchTransfer"); - for (OrderVO orderVO : orderVOs) { - // Բɹֵк - OrderItemVO[] bvo = orderVO.getBVO(); - for (int j = 0; j < bvo.length; j++) { - int rowNum = (j + 1) * 10; - bvo[j].setCrowno(String.valueOf(rowNum)); - } - } - IPfExchangeService service = NCLocator.getInstance().lookup(IPfExchangeService.class); - OrderVO[] transVos = (OrderVO[]) service.runChangeDataAryNeedClassify("20", "21", orderVOs, null, 1); - CloudPFlowContext cloudContext = this.getCloudPFlowContext(transVos); - AppInfoContext.setBtnCode("Save"); - SCMScriptResultDTO scriptResult = ((IBatchRunScriptService) NCLocator.getInstance().lookup(IBatchRunScriptService.class)).runBacth(cloudContext, OrderVO.class); - AbstractBill[] sucessVOs = scriptResult.getSucessVOs(); - if (transVos == null || transVos.length <= 0) { - logger.info("תʱ,VOΪ", this.getClass(), "processBatchTransfer"); - } - logger.info("ɹ", this.getClass(), "processBatchTransfer"); - - } else { + if (orderVOs == null || orderVOs.length == 0) { logger.warn("תδκβɹ", this.getClass(), "processBatchTransfer"); + return; + } + // ö涯ű + logger.info("ʼɹ", this.getClass(), "processBatchTransfer"); + for (OrderVO orderVO : orderVOs) { + // Բɹֵк + OrderHeaderVO hvo = orderVO.getHVO(); + OrderItemVO[] bvo = orderVO.getBVO(); + for (int j = 0; j < bvo.length; j++) { + int rowNum = (j + 1) * 10; + // pk_order + bvo[j].setPk_order(hvo.getPk_order()); + bvo[j].setCrowno(String.valueOf(rowNum)); + } + } + CloudPFlowContext cloudContext = this.getCloudPFlowContext(orderVOs); + AppInfoContext.setBtnCode("Save"); + SCMScriptResultDTO scriptResult = ((IBatchRunScriptService) NCLocator.getInstance().lookup(IBatchRunScriptService.class)).runBacth(cloudContext, OrderVO.class); + AbstractBill[] sucessVOs = scriptResult.getSucessVOs(); + Map errorMessageMap = scriptResult.getErrorMessageMap(); + if (!errorMessageMap.isEmpty()) { + errorMessageMap.keySet().forEach(key -> { + String errMsg = errorMessageMap.get(key); + if (errMsg.isEmpty()) return; + OrderVO orderVO = orderVOs[key]; + // ôϢ + orderVO.getHVO().setVdef30(errMsg); + orderVO.getHVO().setVdef31("N"); + logger.warn("תɲɹʱ: " + scriptResult.getErrorMessage(), this.getClass(), "processBatchTransfer"); + }); } - } catch (Exception e) { logger.error("ת빺ɹʧ", e, this.getClass(), "processBatchTransfer"); - throw new BusinessException("ת빺ɹʧ: " + e.getMessage(), e); + ExceptionUtils.marsh(e); } }