优化批量转换请购单到采购订单功能
- 添加阈值设置,限制每次查询的数量 - 增加是否过滤失败的配置选项- 重构 SQL 构建逻辑,提高查询效率 - 移除不必要的参数和异常处理
This commit is contained in:
		
							parent
							
								
									a82291870c
								
							
						
					
					
						commit
						7f4a704b36
					
				|  | @ -37,18 +37,24 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { | |||
|     @Override | ||||
|     public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException { | ||||
|         logger.info("开始执行批量转换请购单到采购订单任务", this.getClass(), "executeTask"); | ||||
|         // 获取阈值 限制数量以及是否过滤失败 | ||||
|         // 限制数量 每次查询的数量 | ||||
|         String limitNum = (String) bgWorkingContext.getKeyMap().get("limitNum"); | ||||
|         // 是否过滤失败 配置true的时候 过滤 过滤条件为 vdef31 != N 配置 false时 不过滤 查询全部数据 | ||||
|         String filterFailed = (String) bgWorkingContext.getKeyMap().get("filterFailed"); | ||||
|         String failed = filterFailed.equals("Y") ? "N" : ""; | ||||
|         PreAlertObject retObj = new PreAlertObject(); | ||||
|         retObj.setReturnType(PreAlertReturnType.RETURNNOTHING); | ||||
|         try { | ||||
|             // 1. 查询满足条件的请购单聚合VO | ||||
|             PraybillVO[] purchaseRequestVOs = getQualifiedPurchaseRequests(bgWorkingContext); | ||||
|             PraybillVO[] purchaseRequestVOs = getQualifiedPurchaseRequests(failed, limitNum); | ||||
|             logger.info("查询到满足条件的请购单数量: " + purchaseRequestVOs.length, this.getClass(), "executeTask"); | ||||
|             if (purchaseRequestVOs.length == 0) { | ||||
|                 logger.info("未找到满足条件的请购单,任务结束", this.getClass(), "executeTask"); | ||||
|                 return null; | ||||
|             } | ||||
|             // 2. 批量转换处理 | ||||
|             processBatchTransfer(purchaseRequestVOs, bgWorkingContext); | ||||
|             processBatchTransfer(purchaseRequestVOs); | ||||
|             logger.info("批量转换请购单到采购订单完成", this.getClass(), "executeTask"); | ||||
|         } catch (Exception e) { | ||||
|             logger.error("执行批量转换请购单到采购订单任务失败", e, this.getClass(), "executeTask"); | ||||
|  | @ -61,10 +67,10 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { | |||
|      * 查询满足条件的请购单 | ||||
|      * 条件:表体请购单主数量-累计订货主数量>0,且没有行关闭 | ||||
|      */ | ||||
|     private PraybillVO[] getQualifiedPurchaseRequests(BgWorkingContext bgWorkingContext) throws BusinessException { | ||||
|     private PraybillVO[] getQualifiedPurchaseRequests(String isFilter, String limitNum) throws BusinessException { | ||||
|         logger.info("开始查询满足条件的请购单", this.getClass(), "getQualifiedPurchaseRequests"); | ||||
|         try { | ||||
|             String sql = getSql(bgWorkingContext); | ||||
|             String sql = getSql(isFilter, limitNum); | ||||
|             if (sql == null) { | ||||
|                 logger.warn("生成的SQL为空,返回空结果", this.getClass(), "getQualifiedPurchaseRequests"); | ||||
|                 return new PraybillVO[0]; | ||||
|  | @ -93,22 +99,16 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { | |||
|     /** | ||||
|      * 构建查询SQL 查询视图 | ||||
|      */ | ||||
|     private String getSql(BgWorkingContext bgwc) throws BusinessException { | ||||
|         logger.debug("开始构建查询SQL", this.getClass(), "getSql"); | ||||
|         String[] pkorgs = bgwc.getPk_orgs(); | ||||
|         String pkGroup = AppBsContext.getInstance().getPkGroup(); | ||||
|         if (pkGroup == null) { | ||||
|             throw new BusinessException("请购单转换到采购订单任务时pkGroup为空"); | ||||
|         } | ||||
|         if (MMArrayUtil.isNotEmpty(pkorgs)) { | ||||
|             throw new BusinessException("请购单转换到采购订单时组织为空"); | ||||
|         } | ||||
|     private String getSql(String isFilter, String limitNum) { | ||||
|         MMSqlBuilder sb = new MMSqlBuilder(); | ||||
|         sb.append(" SELECT PK_PRAYBILL_B"); | ||||
|         sb.append(" FROM TRANS_PRAYBILL_PURCHASE"); | ||||
|         sb.append(" WHERE PK_GROUP ", pkGroup); | ||||
|         sb.append(" AND"); | ||||
|         sb.append(" PK_ORG", pkorgs); | ||||
|         if (!isFilter.isEmpty()) { | ||||
|             sb.appendNotEqual(" WHERE vdef31 ", isFilter); | ||||
|         } | ||||
|         if (!limitNum.equals("0")) { | ||||
|             sb.append(" AND ROWNUM ", "<", limitNum); | ||||
|         } | ||||
|         String finalSql = sb.toString(); | ||||
|         logger.debug("SQL构建完成", this.getClass(), "getSql"); | ||||
|         return finalSql; | ||||
|  | @ -171,7 +171,7 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin { | |||
|     /** | ||||
|      * 批量转换请购单到采购订单 | ||||
|      */ | ||||
|     private void processBatchTransfer(PraybillVO[] vos, BgWorkingContext bgWorkingContext) { | ||||
|     private void processBatchTransfer(PraybillVO[] vos) { | ||||
|         logger.info("开始批量转换请购单到采购订单,请购单数量: " + vos.length, this.getClass(), "processBatchTransfer"); | ||||
|         // 调用单据转换规则生成采购订单(20->21) | ||||
|         OrderVO[] orderVOs = PfServiceScmUtil.exeVOChangeByBillItfDef("20", "21", vos); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue