refactor(taikai2312): 优化代码并添加日志记录

- 在 AfterApprovingSynchronizeRuleMES 中添加 DefdocVO 导入,用于产品编号转换
- 在 BatchTransferToPurchaseOrder 中:
  - 优化变量命名,提高代码可读性
  - 添加日志记录功能,记录请购单和采购订单信息
  - 修复 SQL 日志输出,提高调试效率
This commit is contained in:
张明 2025-06-14 13:22:17 +08:00
parent c44c5ddf74
commit 12ff9ca7cb
2 changed files with 21 additions and 4 deletions

View File

@ -2,6 +2,8 @@ package nc.bs.pu.m21.plugin;
import java.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log;
import nc.bs.pub.common.PfServiceScmUtil;
@ -41,7 +43,8 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin {
// 限制数量 每次查询的数量
String limitNum = (String) bgWorkingContext.getKeyMap().get("limitNum");
// 是否过滤失败 配置true的时候 过滤 过滤条件为 vdef31 != N 配置 false时 不过滤 查询全部数据
String filterFailed = (String) bgWorkingContext.getKeyMap().get("filterFail6ed");
String filterFailed = (String) bgWorkingContext.getKeyMap().get("filterFailed");
// 如果配置的是过滤 那么就是Y 并且 过滤条件为 vdef31 != N
String failed = filterFailed.equals("Y") ? "N" : "";
PreAlertObject retObj = new PreAlertObject();
retObj.setReturnType(PreAlertReturnType.RETURNNOTHING);
@ -53,6 +56,11 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin {
logger.info("未找到满足条件的请购单,任务结束", this.getClass(), "executeTask");
return null;
}
// 循环打印请购单VO的信息
for (PraybillVO vo : purchaseRequestVOs) {
logger.info("请购单信息:\n");
logger.info("单据号:" + vo.getHVO().getVbillcode(), this.getClass(), "executeTask");
}
// 2. 批量转换处理
processBatchTransfer(purchaseRequestVOs);
logger.info("批量转换请购单到采购订单完成", this.getClass(), "executeTask");
@ -110,7 +118,7 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin {
sb.append(" AND ROWNUM ", "<", limitNum);
}
String finalSql = sb.toString();
logger.debug("SQL构建完成", this.getClass(), "getSql");
logger.debug("SQL构建完成->" + finalSql, this.getClass(), "getSql");
return finalSql;
}
@ -219,6 +227,14 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin {
}
SCMScriptResultDTO scriptResult = ((IBatchRunScriptService) NCLocator.getInstance().lookup(IBatchRunScriptService.class)).runBacth(cloudContext, OrderVO.class);
AbstractBill[] sucessVOs = scriptResult.getSucessVOs();
// 对生成的采购订单进行日志信息记录
sucessVOs = scriptResult.getSucessVOs();
logger.info("批量处理成功,采购订单信息如下:\n");
for (AbstractBill sucessVO : sucessVOs) {
OrderVO orderVO = (OrderVO) sucessVO;
logger.info("采购订单主键" + orderVO.getHVO().getPk_order(), this.getClass(), "processBatch");
logger.info("采购订单信息:" + JSONObject.toJSONString(orderVO.getHVO()), this.getClass(), "processBatch");
}
// 要进行批量更新的数组
List<PraybillVO> failedHVOList = new ArrayList<>(vos.length - sucessVOs.length);
Map<Integer, String> errorMessageMap = scriptResult.getErrorMessageMap();
@ -246,7 +262,7 @@ public class BatchTransferToPurchaseOrder implements IBackgroundWorkPlugin {
}
for (PraybillVO hvo : hvoList) {
hvoBatchUpdatedList = ArrayUtils.add(hvoBatchUpdatedList, hvo.getHVO());
logger.info("循环更新请购单表头: " + hvo.getHVO().getPk_praybill(), this.getClass(), "processBatchTransfer");
logger.info("更新请购单表头: " + hvo.getHVO().getPk_praybill(), this.getClass(), "processBatchTransfer");
}
if (hvoBatchUpdatedList.length == 0) {
logger.warn("批量更新请购单表头失败,需要更新的数组为0", this.getClass(), "processBatchTransfer");

View File

@ -10,6 +10,7 @@ import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.bd.balatype.BalaTypeVO;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.bd.cust.CustomerVO;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.bd.psn.PsndocVO;
@ -139,7 +140,7 @@ public class AfterApprovingSynchronizeRuleMES implements IRule<SaleOrderVO> {
if (bodys != null) {
for (SaleOrderBVO body : bodys) {
JSONObject detailItem = new JSONObject();
detailItem.put("productNum", body.getVbdef1());
detailItem.put("productNum", transferCodeByPk("bd_defdoc", DefdocVO.CODE, DefdocVO.PK_DEFDOC, body.getVbdef1()));
// 以下字段需要表体的字段
// 需求日期 表体dreceivedate
UFDate dreceivedate = body.getDreceivedate();