refactor(sync): 高压IMS-流程生产订单和备料计划同步-调整数据源获取方式

This commit is contained in:
mzr 2025-11-21 18:28:04 +08:00
parent 68cee38aab
commit 7de733be00
5 changed files with 164 additions and 382 deletions

View File

@ -1,5 +1,6 @@
package nc.bs.mmpac.pickm.bp; package nc.bs.mmpac.pickm.bp;
import nc.bs.mmpac.pickm.bp.rule.AfterApproveRuleHighpressureIms;
import nc.bs.mmpac.pickm.bp.rule.AfterQtyUpdRuleHighpressureMes; import nc.bs.mmpac.pickm.bp.rule.AfterQtyUpdRuleHighpressureMes;
import nc.bs.mmpac.pickm.bp.rule.AfterupdateSyncEpicMesRule; import nc.bs.mmpac.pickm.bp.rule.AfterupdateSyncEpicMesRule;
import nc.bs.mmpac.pickm.bp.rule.PickItemsSetVbdef36Rule; import nc.bs.mmpac.pickm.bp.rule.PickItemsSetVbdef36Rule;
@ -184,7 +185,7 @@ public class PickmUpdateBP {
processer.addAfterRule(subMoAdjustSuggestRule); processer.addAfterRule(subMoAdjustSuggestRule);
processer.addAfterRule(new AfterupdateSyncEpicMesRule()); processer.addAfterRule(new AfterupdateSyncEpicMesRule());
// 备料计划变更后推送高压IMS // 备料计划变更后推送高压IMS
// processer.addAfterRule(new AfterApproveRuleHighpressureIms()); processer.addAfterRule(new AfterApproveRuleHighpressureIms());
// 备料计划预留推送高压MES // 备料计划预留推送高压MES
processer.addAfterRule(new AfterQtyUpdRuleHighpressureMes()); processer.addAfterRule(new AfterQtyUpdRuleHighpressureMes());
} }

View File

@ -1,22 +1,9 @@
package nc.bs.mmpac.pickm.bp; package nc.bs.mmpac.pickm.bp;
import java.util.Map;
import nc.bs.mmpac.pickm.bp.rule.AfterApproveRuleHighpressureIms; import nc.bs.mmpac.pickm.bp.rule.AfterApproveRuleHighpressureIms;
import nc.bs.mmpac.pickm.bp.rule.AfterQtyUpdRuleHighpressureMes;
import nc.bs.mmpac.pickm.bp.rule.AfterupdateSyncEpicMesRule; import nc.bs.mmpac.pickm.bp.rule.AfterupdateSyncEpicMesRule;
import nc.bs.mmpac.pickm.plugin.PickmPluginPoint; import nc.bs.mmpac.pickm.plugin.PickmPluginPoint;
import nc.bs.mmpac.pickm.rule.PickmCheckItemMaterialPermissionRule; import nc.bs.mmpac.pickm.rule.*;
import nc.bs.mmpac.pickm.rule.PickmCheckMaterialPermissionRule;
import nc.bs.mmpac.pickm.rule.PickmCreateSubMoRule;
import nc.bs.mmpac.pickm.rule.PickmHeadEditRule;
import nc.bs.mmpac.pickm.rule.PickmItemAdjustRule;
import nc.bs.mmpac.pickm.rule.PickmItemReCreateRule;
import nc.bs.mmpac.pickm.rule.PickmNeedDeliverBackCheckRule;
import nc.bs.mmpac.pickm.rule.PickmReserveCheckForMoUpdateRule;
import nc.bs.mmpac.pickm.rule.PickmSubMoAdjustSuggestRule;
import nc.bs.mmpac.pickm.rule.PickmSynBrepairFlagRule;
import nc.bs.mmpac.pickm.rule.SNMaterialNotBackFlushRule;
import nc.bs.mmpac.pickm.rule.ic.PickmATPCheckRule; import nc.bs.mmpac.pickm.rule.ic.PickmATPCheckRule;
import nc.bs.mmpac.pickm.rule.ic.PickmAutoChangeStateRule; import nc.bs.mmpac.pickm.rule.ic.PickmAutoChangeStateRule;
import nc.bs.mmpac.pickm.rule.ic.PickmAutoReserveRule; import nc.bs.mmpac.pickm.rule.ic.PickmAutoReserveRule;
@ -24,11 +11,7 @@ import nc.bs.mmpac.pickm.rule.ic.PickmRewriteOtherNumRule;
import nc.bs.mmpac.pickm.rule.realsub.PickmRewritePLOWhenUpdateRule; import nc.bs.mmpac.pickm.rule.realsub.PickmRewritePLOWhenUpdateRule;
import nc.bs.mmpub.rule.MMAutoMaterialAssignRule; import nc.bs.mmpub.rule.MMAutoMaterialAssignRule;
import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule; import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule;
import nc.bs.pubapp.pub.rule.BillCodeCheckRule; import nc.bs.pubapp.pub.rule.*;
import nc.bs.pubapp.pub.rule.FieldLengthCheckRule;
import nc.bs.pubapp.pub.rule.FillUpdateDataRule;
import nc.bs.pubapp.pub.rule.OrgDisabledCheckRule;
import nc.bs.pubapp.pub.rule.UpdateBillCodeRule;
import nc.bs.uif2.validation.ValidationFailure; import nc.bs.uif2.validation.ValidationFailure;
import nc.bsutil.mmpac.pickm.PickmSagasUtil; import nc.bsutil.mmpac.pickm.PickmSagasUtil;
import nc.impl.pubapp.bd.material.assistant.MarAssistantSaveRule; import nc.impl.pubapp.bd.material.assistant.MarAssistantSaveRule;
@ -46,6 +29,8 @@ import nc.vo.mmpac.pickm.entity.PickmHeadVO;
import nc.vo.mmpac.pickm.entity.PickmItemVO; import nc.vo.mmpac.pickm.entity.PickmItemVO;
import nc.vo.mmpac.pickm.param.MoChangeParam; import nc.vo.mmpac.pickm.param.MoChangeParam;
import java.util.Map;
/** /**
* 生产订单修改后同步变更备料计划操作 * 生产订单修改后同步变更备料计划操作
* *
@ -225,13 +210,10 @@ public class PickmUpdateForMOBP {
// 配套变更建议 // 配套变更建议
ICompareRule<AggPickmVO> subMoAdjustSuggestRule = new PickmSubMoAdjustSuggestRule(this.checkInfo); ICompareRule<AggPickmVO> subMoAdjustSuggestRule = new PickmSubMoAdjustSuggestRule(this.checkInfo);
aroundProcesser.addAfterRule(subMoAdjustSuggestRule); aroundProcesser.addAfterRule(subMoAdjustSuggestRule);
aroundProcesser.addAfterRule(new AfterupdateSyncEpicMesRule()); aroundProcesser.addAfterRule(new AfterupdateSyncEpicMesRule());
//备料计划修改后推送高压IMS // 备料计划修改后推送高压IMS
aroundProcesser.addAfterRule(new AfterApproveRuleHighpressureIms()); aroundProcesser.addAfterRule(new AfterApproveRuleHighpressureIms());
} }
} }

View File

@ -5,12 +5,9 @@ import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException; import nc.bs.dao.DAOException;
import nc.bs.logging.Log; import nc.bs.logging.Log;
import nc.bs.trade.business.HYPubBO; import nc.bs.trade.business.HYPubBO;
import nc.bs.uapbd.util.GyImsDbUtil;
import nc.bs.uapbd.util.MyHelper; import nc.bs.uapbd.util.MyHelper;
import nc.impl.pubapp.pattern.rule.IRule; import nc.impl.pubapp.pattern.rule.IRule;
import nc.jdbc.framework.JdbcSession;
import nc.jdbc.framework.PersistenceManager;
import nc.jdbc.framework.exception.DbException;
import nc.jdbc.framework.processor.MapProcessor;
import nc.uif.pub.exception.UifException; import nc.uif.pub.exception.UifException;
import nc.vo.mmpac.pickm.entity.AggPickmVO; import nc.vo.mmpac.pickm.entity.AggPickmVO;
import nc.vo.mmpac.pickm.entity.PickmHeadVO; import nc.vo.mmpac.pickm.entity.PickmHeadVO;
@ -22,8 +19,6 @@ import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.scmpub.util.ArrayUtil; import nc.vo.scmpub.util.ArrayUtil;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@ -112,8 +107,8 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
// 2. 组织过滤仅同步目标组织原逻辑保留并优化日志 // 2. 组织过滤仅同步目标组织原逻辑保留并优化日志
String pkOrg = headVO.getPk_org(); String pkOrg = headVO.getPk_org();
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
if (checkIfSkipOrg(orgCode,configParams)) { if (checkIfSkipOrg(orgCode, configParams)) {
logger.info("备料计划组织编码"+ orgCode +"非目标同步组织,跳过同步,备料单号:"+headVO.getVbillcode()+""); logger.info("备料计划组织编码" + orgCode + "非目标同步组织,跳过同步,备料单号:" + headVO.getVbillcode() + "");
continue; continue;
} }
if (!checkIfVtrantypecode(headVO.getVsourcebilltype(), configParams)) { if (!checkIfVtrantypecode(headVO.getVsourcebilltype(), configParams)) {
@ -158,6 +153,7 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
} }
return true; return true;
} }
private void pushIms(List<Map<String, Object>> mainDataList, List<Map<String, Object>> detailDataList, String targetCpickmid) throws BusinessException { private void pushIms(List<Map<String, Object>> mainDataList, List<Map<String, Object>> detailDataList, String targetCpickmid) throws BusinessException {
// 1. 关键参数校验 // 1. 关键参数校验
if (targetCpickmid == null || targetCpickmid.trim().isEmpty()) { if (targetCpickmid == null || targetCpickmid.trim().isEmpty()) {
@ -165,94 +161,37 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
return; return;
} }
if (mainDataList.isEmpty()) { if (mainDataList.isEmpty()) {
logger.warn("备料计划主表数据为空终止同步cpickmid" + targetCpickmid + ""); logger.warn("备料计划主表数据为空终止同步cpickmid" + targetCpickmid);
return; return;
} }
// 2. 直接通过静态工厂方法获取 PersistenceManager
PersistenceManager pm = null;
JdbcSession jdbcSession = null;
Connection conn = null;
boolean isSuccess = false;
try { // 3. 判断新增/更新 (checkMainExists 方法逻辑不变)
// 直接调用 PersistenceManager 的静态方法 getInstance() boolean isUpdate = checkMainExists(targetCpickmid);
pm = PersistenceManager.getInstance("gyims");
pm.setAddTimeStamp(false);
// 2.1 获取 JdbcSession Connection // 4. 执行主表+子表操作 (传入共享的 pm)
jdbcSession = pm.getJdbcSession(); if (isUpdate) {
jdbcSession.setSQLTranslator(true); // 保持 SQL 转换 updatePlanMain(mainDataList, targetCpickmid);
conn = jdbcSession.getConnection(); if (!detailDataList.isEmpty()) {
conn.setAutoCommit(false); updatePlanDetail(detailDataList, targetCpickmid);
logger.info("直接获取PersistenceManager手动事务开启cpickmid" + targetCpickmid + "");
// 3. 判断新增/更新 (checkMainExists 方法逻辑不变)
boolean isUpdate = checkMainExists(pm, targetCpickmid);
// 4. 执行主表+子表操作 (传入共享的 pm)
if (isUpdate) {
logger.info("事务内执行更新cpickmid" + targetCpickmid + "");
updatePlanMain(mainDataList, pm, targetCpickmid);
if (!detailDataList.isEmpty()) {
updatePlanDetail(detailDataList, pm, targetCpickmid);
}
} else {
logger.info("事务内执行新增cpickmid" + targetCpickmid + "");
insertPlanMain(mainDataList, pm, targetCpickmid);
if (!detailDataList.isEmpty()) {
insertPlanDetail(detailDataList, pm, targetCpickmid);
}
} }
} else {
isSuccess = true; insertPlanMain(mainDataList, targetCpickmid);
logger.info("事务内操作全部成功准备提交cpickmid" + targetCpickmid + ""); if (!detailDataList.isEmpty()) {
insertPlanDetail(detailDataList, targetCpickmid);
} catch (DbException | SQLException e) { // 捕获 DbException SQLException
logger.error("事务执行失败触发回滚cpickmid" + targetCpickmid + "");
if (conn != null) {
try {
conn.rollback();
logger.info("事务回滚完成cpickmid" + targetCpickmid + "");
} catch (SQLException rollbackE) {
logger.error("事务回滚异常cpickmid" + targetCpickmid + "");
}
}
throw new BusinessException("备料计划同步事务失败:" + e.getMessage(), e);
} finally {
if (conn != null) {
try {
if (isSuccess) {
conn.commit();
logger.info("事务提交成功cpickmid" + targetCpickmid + "");
}
conn.setAutoCommit(true);
} catch (SQLException commitE) {
logger.error("事务提交异常cpickmid" + targetCpickmid + "");
}
}
// 5. 释放 PersistenceManager (至关重要)
if (pm != null) {
try {
pm.release(); // 必须调用 release() 将连接归还给连接池
logger.info("PersistenceManager 释放完成cpickmid" + targetCpickmid + "");
} catch (Exception releaseE) {
logger.error("PersistenceManager 释放异常", releaseE);
}
} }
} }
} }
/** /**
* 校验主表是否存在使用共享的 PersistenceManager * 校验主表是否存在
*/ */
private boolean checkMainExists(PersistenceManager pm, String cpickmid) throws DAOException, DbException { private boolean checkMainExists(String cpickmid) throws BusinessException {
String safeCpickmid = cpickmid.replace("'", "''"); String safeCpickmid = cpickmid.replace("'", "''");
String sql = "SELECT cpickmid FROM BIPPlanMainTab WHERE cpickmid = '" + safeCpickmid + "'"; String sql = "SELECT cpickmid FROM BIPPlanMainTab WHERE cpickmid = '" + safeCpickmid + "'";
// 使用共享 pm JdbcSession 执行查询避免新建连接 Map<String, Object> existMain = GyImsDbUtil.queryOne(sql);
Map<String, Object> existMain = (Map<String, Object>) pm.getJdbcSession().executeQuery(sql, new MapProcessor());
return existMain != null && !existMain.isEmpty(); return existMain != null && !existMain.isEmpty();
} }
@ -266,47 +205,47 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
JSONObject mainJson = new JSONObject(); JSONObject mainJson = new JSONObject();
mainJson.put("cpickmid", headVO.getCpickmid());// 主键ID mainJson.put("cpickmid", headVO.getCpickmid());// 主键ID
Object pk_org = new HYPubBO().findColValue("org_factory", "code", "nvl(dr,0) = 0 and pk_factory='" + headVO.getPk_org() + "' "); Object pk_org = new HYPubBO().findColValue("org_factory", "code", "nvl(dr,0) = 0 and pk_factory='" + headVO.getPk_org() + "' ");
mainJson.put("pk_org", pk_org);//组织_业务单元_工厂 mainJson.put("pk_org", pk_org);// 组织_业务单元_工厂
mainJson.put("vbillcode", headVO.getVbillcode());// 备料计划单号 mainJson.put("vbillcode", headVO.getVbillcode());// 备料计划单号
mainJson.put("fbillstatus", headVO.getFbillstatus());//备料状态 mainJson.put("fbillstatus", headVO.getFbillstatus());// 备料状态
mainJson.put("vbusitypeid", headVO.getVbusitypeid());//备料类型 mainJson.put("vbusitypeid", headVO.getVbusitypeid());// 备料类型
mainJson.put("vbusitype", headVO.getVbusitype());//备料类型编码 mainJson.put("vbusitype", headVO.getVbusitype());// 备料类型编码
Object cmaterialvid = new HYPubBO().findColValue("bd_material", "code", "nvl(dr,0) = 0 and pk_material='" + headVO.getCmaterialvid() + "' "); Object cmaterialvid = new HYPubBO().findColValue("bd_material", "code", "nvl(dr,0) = 0 and pk_material='" + headVO.getCmaterialvid() + "' ");
mainJson.put("cmaterialvid", cmaterialvid.toString());//产品编码 mainJson.put("cmaterialvid", cmaterialvid.toString());// 产品编码
mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);//计划数量; mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);// 计划数量;
mainJson.put("cdeptid", headVO.getCdeptid());//用料部门最新版本 mainJson.put("cdeptid", headVO.getCdeptid());// 用料部门最新版本
mainJson.put("cdeptvid", headVO.getCdeptid());//用料部门 mainJson.put("cdeptvid", headVO.getCdeptid());// 用料部门
mainJson.put("vsalebillcode", headVO.getVsalebillcode());//销售订单号 mainJson.put("vsalebillcode", headVO.getVsalebillcode());// 销售订单号
mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());//客户物料码 mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());// 客户物料码
mainJson.put("cemployeeid", headVO.getCemployeeid());//业务员 mainJson.put("cemployeeid", headVO.getCemployeeid());// 业务员
mainJson.put("vfirstmoid", headVO.getVfirstmoid());//源头生产订单 mainJson.put("vfirstmoid", headVO.getVfirstmoid());// 源头生产订单
mainJson.put("vfirstmocode", headVO.getVfirstmocode());//源头生产订单号 mainJson.put("vfirstmocode", headVO.getVfirstmocode());// 源头生产订单号
mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());//源头生产订单明细 mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());// 源头生产订单明细
mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());//源头生产订单行号 mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());// 源头生产订单行号
mainJson.put("vsourcemoid", headVO.getVsourcemoid());//来源生产订单 mainJson.put("vsourcemoid", headVO.getVsourcemoid());// 来源生产订单
mainJson.put("vsourcemocode", headVO.getVsourcemocode());//来源生产订单号 mainJson.put("vsourcemocode", headVO.getVsourcemocode());// 来源生产订单号
mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());//来源生产订单明细 mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());// 来源生产订单明细
mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());//来源生产订单行号 mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());// 来源生产订单行号
mainJson.put("cfirstbillid", headVO.getCfirstbillid());//源头单据 mainJson.put("cfirstbillid", headVO.getCfirstbillid());// 源头单据
mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());//源头单据号 mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());// 源头单据号
mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());//源头单据类型 mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());// 源头单据类型
mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());//源头交易类型 mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());// 源头交易类型
mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());//源头交易类型编码 mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());// 源头交易类型编码
mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());//源头单据明细 mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());// 源头单据明细
mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());//源头单据行号 mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());// 源头单据行号
mainJson.put("csourcebillid", headVO.getCsourcebillid());//来源单据 mainJson.put("csourcebillid", headVO.getCsourcebillid());// 来源单据
mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());//来源单据号 mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());// 来源单据号
mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());//来源单据类型 mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());// 来源单据类型
mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());//来源交易类型 mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());// 来源交易类型
mainJson.put("vsrctrantype", headVO.getVsrctrantype());//来源交易类型编码 mainJson.put("vsrctrantype", headVO.getVsrctrantype());// 来源交易类型编码
mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());//来源单据明细 mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());// 来源单据明细
mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());//来源单据行号 mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());// 来源单据行号
mainJson.put("vnote", headVO.getVnote());//备注 mainJson.put("vnote", headVO.getVnote());// 备注
mainJson.put("status", headVO.getStatus());//同步状态 mainJson.put("status", headVO.getStatus());// 同步状态
mainJson.put("billmaker", headVO.getBillmaker()); mainJson.put("billmaker", headVO.getBillmaker());
;//制单人 ;// 制单人
mainJson.put("dmakedate", headVO.getDmakedate()); // UFDate制单时间 mainJson.put("dmakedate", headVO.getDmakedate()); // UFDate制单时间
mainJson.put("creator", headVO.getCreator());//创建人 mainJson.put("creator", headVO.getCreator());// 创建人
mainJson.put("creationtime", headVO.getCreationtime()); // UFDateTime创建时间 mainJson.put("creationtime", headVO.getCreationtime()); // UFDateTime创建时间
return mainJson; return mainJson;
} }
@ -335,7 +274,7 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
detailJson.put("nplanoutastnum", itemVO.getNplanoutastnum() != null ? itemVO.getNplanoutastnum().doubleValue() : null); // 计划出库数量 detailJson.put("nplanoutastnum", itemVO.getNplanoutastnum() != null ? itemVO.getNplanoutastnum().doubleValue() : null); // 计划出库数量
detailJson.put("nplanoutnum", itemVO.getNplanoutnum() != null ? itemVO.getNplanoutnum().doubleValue() : null);// 计划出库主数量 detailJson.put("nplanoutnum", itemVO.getNplanoutnum() != null ? itemVO.getNplanoutnum().doubleValue() : null);// 计划出库主数量
detailJson.put("vbdef22", itemVO.getVbdef20()); // 是否备件 detailJson.put("vbdef22", itemVO.getVbdef20()); // 是否备件
detailJson.put("nunituseastnum",itemVO.getNunituseastnum() != null ? itemVO.getNunituseastnum().toString() : null); detailJson.put("nunituseastnum", itemVO.getNunituseastnum() != null ? itemVO.getNunituseastnum().toString() : null);
return detailJson; return detailJson;
} }
@ -343,13 +282,12 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
// -------------------------- 新增/更新逻辑提取通用SQL值处理减少冗余 -------------------------- // -------------------------- 新增/更新逻辑提取通用SQL值处理减少冗余 --------------------------
/** /**
* 主表新增使用共享的 PersistenceManager * 主表新增
* *
* @param mainDataList 主表数据列表 * @param mainDataList 主表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 主表业务主键 * @param cpickmid 主表业务主键
*/ */
private void insertPlanMain(List<Map<String, Object>> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException, DbException { private void insertPlanMain(List<Map<String, Object>> mainDataList, String cpickmid) throws BusinessException {
// 1. 构建 SQL逻辑与原代码一致仅执行方式改变 // 1. 构建 SQL逻辑与原代码一致仅执行方式改变
String[] mainFields = { String[] mainFields = {
"cpickmid", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", "cpickmid", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype",
@ -377,29 +315,26 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
valuesSb.append("), "); valuesSb.append("), ");
} }
// 2. 执行 SQL使用共享 pm JdbcSession避免新建连接 if (!valuesSb.isEmpty()) {
if (valuesSb.length() > 0) {
String valuesStr = valuesSb.substring(0, valuesSb.length() - 2); String valuesStr = valuesSb.substring(0, valuesSb.length() - 2);
String insertSql = "INSERT INTO BIPPlanMainTab (" + fieldStr + ") VALUES " + valuesStr; String insertSql = "INSERT INTO BIPPlanMainTab (" + fieldStr + ") VALUES " + valuesStr;
// 关键用共享 pm JdbcSession 执行而非 BaseDAO executeUpdate int rows = GyImsDbUtil.update(insertSql);
int rows = pm.getJdbcSession().executeUpdate(insertSql); logger.error("主表新增成功cpickmid" + cpickmid + ",影响行数:" + rows + "");
logger.info("主表新增成功cpickmid" + cpickmid + ",影响行数:" + rows + "");
} }
} }
/** /**
* 子表新增使用共享的 PersistenceManager * 子表新增
* *
* @param detailDataList 子表数据列表 * @param detailDataList 子表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 子表业务主键 * @param cpickmid 子表业务主键
*/ */
private void insertPlanDetail(List<Map<String, Object>> detailDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { private void insertPlanDetail(List<Map<String, Object>> detailDataList, String cpickmid) throws BusinessException {
String[] detailFields = { String[] detailFields = {
"cpickm_bid", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "cpickm_bid", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype",
"fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum",
"nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum"
}; };
String fieldStr = String.join(", ", detailFields); String fieldStr = String.join(", ", detailFields);
StringBuilder valuesSb = new StringBuilder(); StringBuilder valuesSb = new StringBuilder();
@ -416,24 +351,22 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
valuesSb.append("), "); valuesSb.append("), ");
} }
if (valuesSb.length() > 0) { if (!valuesSb.isEmpty()) {
String valuesStr = valuesSb.substring(0, valuesSb.length() - 2); String valuesStr = valuesSb.substring(0, valuesSb.length() - 2);
String insertSql = "INSERT INTO BIPPlanDetailTab (" + fieldStr + ") VALUES " + valuesStr; String insertSql = "INSERT INTO BIPPlanDetailTab (" + fieldStr + ") VALUES " + valuesStr;
// 关键用共享 pm JdbcSession 执行 int rows = GyImsDbUtil.update(insertSql);
int rows = pm.getJdbcSession().executeUpdate(insertSql); logger.error("子表新增成功子表cpickmid" + cpickmid + ",影响行数:" + rows);
logger.info("子表新增成功子表cpickmid" + cpickmid + ",影响行数:" + rows + "");
} }
} }
/** /**
* 主表更新使用共享的 PersistenceManager * 主表更新
* *
* @param mainDataList 主表数据列表 * @param mainDataList 主表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 主表业务主键 * @param cpickmid 主表业务主键
*/ */
private void updatePlanMain(List<Map<String, Object>> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { private void updatePlanMain(List<Map<String, Object>> mainDataList, String cpickmid) throws BusinessException {
String[] mainFields = { String[] mainFields = {
"pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype",
"cmaterialvid", "nastnum", "cdeptid", "cdeptvid", "vsalebillcode", "ccustmaterialid", "cmaterialvid", "nastnum", "cdeptid", "cdeptvid", "vsalebillcode", "ccustmaterialid",
@ -453,41 +386,40 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
setSb.append(field).append(" = ").append(SqlValueUtil.processSqlValue(value)).append(", "); setSb.append(field).append(" = ").append(SqlValueUtil.processSqlValue(value)).append(", ");
} }
if (setSb.length() > 0) { if (!setSb.isEmpty()) {
String setStr = setSb.substring(0, setSb.length() - 2); String setStr = setSb.substring(0, setSb.length() - 2);
String safeCpickmid = cpickmid.replace("'", "''"); String safeCpickmid = cpickmid.replace("'", "''");
String updateSql = "UPDATE BIPPlanMainTab SET " + setStr + " WHERE cpickmid = '" + safeCpickmid + "'"; String updateSql = "UPDATE BIPPlanMainTab SET " + setStr + " WHERE cpickmid = '" + safeCpickmid + "'";
// 关键用共享 pm JdbcSession 执行 // 关键用共享 pm JdbcSession 执行
int rows = pm.getJdbcSession().executeUpdate(updateSql); int rows = GyImsDbUtil.update(updateSql);
logger.info("主表更新成功cpickmid" + cpickmid + ",影响行数:" + rows + ""); logger.error("主表更新成功cpickmid" + cpickmid + ",影响行数:" + rows);
} }
} }
/** /**
* 子表更新使用共享的 PersistenceManager * 子表更新
* *
* @param detailDataList 子表数据列表 * @param detailDataList 子表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 子表业务主键 * @param cpickmid 子表业务主键
*/ */
private void updatePlanDetail(List<Map<String, Object>> detailDataList, PersistenceManager pm, String cpickmid) throws BusinessException { private void updatePlanDetail(List<Map<String, Object>> detailDataList, String cpickmid) throws BusinessException {
if (detailDataList.isEmpty()) { if (detailDataList.isEmpty()) {
logger.warn("备料计划" + cpickmid + "子表同步数据为空,跳过更新"); logger.error("备料计划" + cpickmid + "子表同步数据为空,跳过更新");
return; return;
} }
String[] detailFields = { String[] detailFields = {
"cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype",
"fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum",
"nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum"
}; };
// 循环更新每条子表数据 // 循环更新每条子表数据
for (Map<String, Object> detailData : detailDataList) { for (Map<String, Object> detailData : detailDataList) {
String cpickmBid = (String) detailData.get("cpickm_bid"); String cpickmBid = (String) detailData.get("cpickm_bid");
if (cpickmBid == null || cpickmBid.trim().isEmpty()) { if (cpickmBid == null || cpickmBid.trim().isEmpty()) {
logger.warn("备料计划" + cpickmid + "子表主键cpickm_bid为空跳过该子表更新"); logger.error("备料计划" + cpickmid + "子表主键cpickm_bid为空跳过该子表更新");
continue; continue;
} }
@ -499,18 +431,13 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
} }
// 执行SQL // 执行SQL
if (setSb.length() > 0) { if (!setSb.isEmpty()) {
String setStr = setSb.substring(0, setSb.length() - 2); String setStr = setSb.substring(0, setSb.length() - 2);
String safeBid = cpickmBid.replace("'", "''"); String safeBid = cpickmBid.replace("'", "''");
String updateSql = "UPDATE BIPPlanDetailTab SET " + setStr + " WHERE cpickm_bid = '" + safeBid + "'"; String updateSql = "UPDATE BIPPlanDetailTab SET " + setStr + " WHERE cpickm_bid = '" + safeBid + "'";
// 关键使用共享的 PersistenceManager 执行 SQL int rows = GyImsDbUtil.update(updateSql);
try { logger.error("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows);
int rows = pm.getJdbcSession().executeUpdate(updateSql);
logger.info("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows + "");
} catch (DbException e) {
throw new BusinessException("子表更新失败SQL: " + updateSql, e);
}
} }
} }
} }
@ -518,30 +445,10 @@ public class AfterApproveRuleHighpressureIms implements IRule<AggPickmVO> {
// -------------------------- 通用工具方法提取后复用减少冗余 -------------------------- // -------------------------- 通用工具方法提取后复用减少冗余 --------------------------
/**
* 执行SQL并处理DAO异常
*
* @param sql SQL语句
* @param dao BaseDAO实例
* @param operType 操作类型"主表新增"
* @param bizKey 业务标识如cpickmid
*/
private void executeSql(String sql, BaseDAO dao, String operType, String bizKey) throws BusinessException {
try {
logger.debug("执行" + operType + "SQL业务标识" + bizKey + "SQL" + sql + "");
int rows = dao.executeUpdate(sql);
logger.info("" + operType + "成功,业务标识:" + bizKey + ",影响行数:" + rows + "");
} catch (DAOException e) {
String errorMsg = operType + "失败,业务标识:" + bizKey + "SQL" + sql;
logger.error(errorMsg, e);
throw new BusinessException(errorMsg, e);
}
}
/** /**
* 判断是否跳过该组织 * 判断是否跳过该组织
*/ */
private boolean checkIfSkipOrg(String code, Map<String, String> configParams) throws BusinessException{ private boolean checkIfSkipOrg(String code, Map<String, String> configParams) throws BusinessException {
String targetCode = configParams.get("imsOrg"); String targetCode = configParams.get("imsOrg");
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
throw new BusinessException("未配置组织参数"); throw new BusinessException("未配置组织参数");

View File

@ -32,25 +32,11 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
private Map<String, String> configParams; private Map<String, String> configParams;
// BIP数据源 // BIP数据源
public static final BaseDAO baseDAO = new BaseDAO(); public static final BaseDAO baseDAO = new BaseDAO();
// IMS数据源
public BaseDAO imsDao;
public AfterApproveSyncImsRule(String auditFlag) { public AfterApproveSyncImsRule(String auditFlag) {
this.auditFlag = auditFlag; this.auditFlag = auditFlag;
} }
/**
* 获取IMS数据源
*/
public BaseDAO getImsDao() {
if (imsDao == null) {
imsDao = new BaseDAO("gyims");
// 禁用时间戳ts
imsDao.setAddTimeStamp(false);
}
return imsDao;
}
// 表头-表名 // 表头-表名
private static final String HEAD_TABLE = "BIPOrderMainTab"; private static final String HEAD_TABLE = "BIPOrderMainTab";
// 表体-表名 // 表体-表名

View File

@ -1,17 +1,12 @@
package nc.bs.mmpac.pmo.pac0002.bp.rule; package nc.bs.mmpac.pmo.pac0002.bp.rule;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.NCLocator; import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log; import nc.bs.logging.Log;
import nc.bs.trade.business.HYPubBO; import nc.bs.trade.business.HYPubBO;
import nc.bs.uapbd.util.GyImsDbUtil;
import nc.bs.uapbd.util.MyHelper; import nc.bs.uapbd.util.MyHelper;
import nc.impl.pubapp.pattern.rule.IRule; import nc.impl.pubapp.pattern.rule.IRule;
import nc.jdbc.framework.JdbcSession;
import nc.jdbc.framework.PersistenceManager;
import nc.jdbc.framework.exception.DbException;
import nc.jdbc.framework.processor.MapProcessor;
import nc.md.model.MetaDataException; import nc.md.model.MetaDataException;
import nc.md.persist.framework.IMDPersistenceQueryService; import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.uif.pub.exception.UifException; import nc.uif.pub.exception.UifException;
@ -26,8 +21,6 @@ import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime; import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@ -181,91 +174,34 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
logger.warn("备料计划主表数据为空终止同步cpickmid" + targetCpickmid + ""); logger.warn("备料计划主表数据为空终止同步cpickmid" + targetCpickmid + "");
return; return;
} }
// 3. 判断新增/更新 (checkMainExists 方法逻辑不变)
boolean isUpdate = checkMainExists(targetCpickmid);
// 2. 直接通过静态工厂方法获取 PersistenceManager // 4. 执行主表+子表操作 (传入共享的 pm)
PersistenceManager pm = null; if (isUpdate) {
JdbcSession jdbcSession = null; logger.info("事务内执行更新cpickmid" + targetCpickmid + "");
Connection conn = null; updatePlanMain(mainDataList, targetCpickmid);
boolean isSuccess = false; if (!detailDataList.isEmpty()) {
updatePlanDetail(detailDataList, targetCpickmid);
try {
// 直接调用 PersistenceManager 的静态方法 getInstance()
pm = PersistenceManager.getInstance("gyims");
pm.setAddTimeStamp(false);
// 2.1 获取 JdbcSession Connection
jdbcSession = pm.getJdbcSession();
jdbcSession.setSQLTranslator(true); // 保持 SQL 转换
conn = jdbcSession.getConnection();
conn.setAutoCommit(false);
logger.info("直接获取PersistenceManager手动事务开启cpickmid" + targetCpickmid + "");
// 3. 判断新增/更新 (checkMainExists 方法逻辑不变)
boolean isUpdate = checkMainExists(pm, targetCpickmid);
// 4. 执行主表+子表操作 (传入共享的 pm)
if (isUpdate) {
logger.info("事务内执行更新cpickmid" + targetCpickmid + "");
updatePlanMain(mainDataList, pm, targetCpickmid);
if (!detailDataList.isEmpty()) {
updatePlanDetail(detailDataList, pm, targetCpickmid);
}
} else {
logger.info("事务内执行新增cpickmid" + targetCpickmid + "");
insertPlanMain(mainDataList, pm, targetCpickmid);
if (!detailDataList.isEmpty()) {
insertPlanDetail(detailDataList, pm, targetCpickmid);
}
} }
} else {
isSuccess = true; logger.info("事务内执行新增cpickmid" + targetCpickmid);
logger.info("事务内操作全部成功准备提交cpickmid" + targetCpickmid + ""); insertPlanMain(mainDataList, targetCpickmid);
if (!detailDataList.isEmpty()) {
} catch (DbException | SQLException e) { // 捕获 DbException SQLException insertPlanDetail(detailDataList, targetCpickmid);
logger.error("事务执行失败触发回滚cpickmid" + targetCpickmid + "");
if (conn != null) {
try {
conn.rollback();
logger.info("事务回滚完成cpickmid" + targetCpickmid + "");
} catch (SQLException rollbackE) {
logger.error("事务回滚异常cpickmid" + targetCpickmid + "");
}
}
throw new BusinessException("备料计划同步事务失败:" + e.getMessage(), e);
} finally {
if (conn != null) {
try {
if (isSuccess) {
conn.commit();
logger.info("事务提交成功cpickmid" + targetCpickmid + "");
}
conn.setAutoCommit(true);
} catch (SQLException commitE) {
logger.error("事务提交异常cpickmid" + targetCpickmid + "");
}
}
// 5. 释放 PersistenceManager (至关重要)
if (pm != null) {
try {
pm.release(); // 必须调用 release() 将连接归还给连接池
logger.info("PersistenceManager 释放完成cpickmid" + targetCpickmid + "");
} catch (Exception releaseE) {
logger.error("PersistenceManager 释放异常", releaseE);
}
} }
} }
} }
/** /**
* 校验主表是否存在使用共享的 PersistenceManager * 校验主表是否存在
*/ */
private boolean checkMainExists(PersistenceManager pm, String cpickmid) throws DAOException, DbException { private boolean checkMainExists(String cpickmid) throws BusinessException {
String safeCpickmid = cpickmid.replace("'", "''"); String safeCpickmid = cpickmid.replace("'", "''");
String sql = "SELECT cpickmid FROM BIPPlanMainTab WHERE cpickmid = '" + safeCpickmid + "'"; String sql = "SELECT cpickmid FROM BIPPlanMainTab WHERE cpickmid = '" + safeCpickmid + "'";
// 使用共享 pm JdbcSession 执行查询避免新建连接 // 使用共享 pm JdbcSession 执行查询避免新建连接
Map<String, Object> existMain = (Map<String, Object>) pm.getJdbcSession().executeQuery(sql, new MapProcessor()); Map<String, Object> existMain = GyImsDbUtil.queryOne(sql);
return existMain != null && !existMain.isEmpty(); return existMain != null && !existMain.isEmpty();
} }
@ -279,47 +215,47 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
JSONObject mainJson = new JSONObject(); JSONObject mainJson = new JSONObject();
mainJson.put("cpickmid", headVO.getCpickmid());// 主键ID mainJson.put("cpickmid", headVO.getCpickmid());// 主键ID
Object pk_org = new HYPubBO().findColValue("org_factory", "code", "nvl(dr,0) = 0 and pk_factory='" + headVO.getPk_org() + "' "); Object pk_org = new HYPubBO().findColValue("org_factory", "code", "nvl(dr,0) = 0 and pk_factory='" + headVO.getPk_org() + "' ");
mainJson.put("pk_org", pk_org);//组织_业务单元_工厂 mainJson.put("pk_org", pk_org);// 组织_业务单元_工厂
mainJson.put("vbillcode", headVO.getVbillcode());// 备料计划单号 mainJson.put("vbillcode", headVO.getVbillcode());// 备料计划单号
mainJson.put("fbillstatus", headVO.getFbillstatus());//备料状态 mainJson.put("fbillstatus", headVO.getFbillstatus());// 备料状态
mainJson.put("vbusitypeid", headVO.getVbusitypeid());//备料类型 mainJson.put("vbusitypeid", headVO.getVbusitypeid());// 备料类型
mainJson.put("vbusitype", headVO.getVbusitype());//备料类型编码 mainJson.put("vbusitype", headVO.getVbusitype());// 备料类型编码
Object cmaterialvid = new HYPubBO().findColValue("bd_material", "code", "nvl(dr,0) = 0 and pk_material='" + headVO.getCmaterialvid() + "' "); Object cmaterialvid = new HYPubBO().findColValue("bd_material", "code", "nvl(dr,0) = 0 and pk_material='" + headVO.getCmaterialvid() + "' ");
mainJson.put("cmaterialvid", cmaterialvid.toString());//产品编码 mainJson.put("cmaterialvid", cmaterialvid.toString());// 产品编码
mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);//计划数量; mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);// 计划数量;
mainJson.put("cdeptid", headVO.getCdeptid());//用料部门最新版本 mainJson.put("cdeptid", headVO.getCdeptid());// 用料部门最新版本
mainJson.put("cdeptvid", headVO.getCdeptid());//用料部门 mainJson.put("cdeptvid", headVO.getCdeptid());// 用料部门
mainJson.put("vsalebillcode", headVO.getVsalebillcode());//销售订单号 mainJson.put("vsalebillcode", headVO.getVsalebillcode());// 销售订单号
mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());//客户物料码 mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());// 客户物料码
mainJson.put("cemployeeid", headVO.getCemployeeid());//业务员 mainJson.put("cemployeeid", headVO.getCemployeeid());// 业务员
mainJson.put("vfirstmoid", headVO.getVfirstmoid());//源头生产订单 mainJson.put("vfirstmoid", headVO.getVfirstmoid());// 源头生产订单
mainJson.put("vfirstmocode", headVO.getVfirstmocode());//源头生产订单号 mainJson.put("vfirstmocode", headVO.getVfirstmocode());// 源头生产订单号
mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());//源头生产订单明细 mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());// 源头生产订单明细
mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());//源头生产订单行号 mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());// 源头生产订单行号
mainJson.put("vsourcemoid", headVO.getVsourcemoid());//来源生产订单 mainJson.put("vsourcemoid", headVO.getVsourcemoid());// 来源生产订单
mainJson.put("vsourcemocode", headVO.getVsourcemocode());//来源生产订单号 mainJson.put("vsourcemocode", headVO.getVsourcemocode());// 来源生产订单号
mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());//来源生产订单明细 mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());// 来源生产订单明细
mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());//来源生产订单行号 mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());// 来源生产订单行号
mainJson.put("cfirstbillid", headVO.getCfirstbillid());//源头单据 mainJson.put("cfirstbillid", headVO.getCfirstbillid());// 源头单据
mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());//源头单据号 mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());// 源头单据号
mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());//源头单据类型 mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());// 源头单据类型
mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());//源头交易类型 mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());// 源头交易类型
mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());//源头交易类型编码 mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());// 源头交易类型编码
mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());//源头单据明细 mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());// 源头单据明细
mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());//源头单据行号 mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());// 源头单据行号
mainJson.put("csourcebillid", headVO.getCsourcebillid());//来源单据 mainJson.put("csourcebillid", headVO.getCsourcebillid());// 来源单据
mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());//来源单据号 mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());// 来源单据号
mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());//来源单据类型 mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());// 来源单据类型
mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());//来源交易类型 mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());// 来源交易类型
mainJson.put("vsrctrantype", headVO.getVsrctrantype());//来源交易类型编码 mainJson.put("vsrctrantype", headVO.getVsrctrantype());// 来源交易类型编码
mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());//来源单据明细 mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());// 来源单据明细
mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());//来源单据行号 mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());// 来源单据行号
mainJson.put("vnote", headVO.getVnote());//备注 mainJson.put("vnote", headVO.getVnote());// 备注
mainJson.put("status", headVO.getStatus());//同步状态 mainJson.put("status", headVO.getStatus());// 同步状态
mainJson.put("billmaker", headVO.getBillmaker()); mainJson.put("billmaker", headVO.getBillmaker());
;//制单人 ;// 制单人
mainJson.put("dmakedate", headVO.getDmakedate()); // UFDate制单时间 mainJson.put("dmakedate", headVO.getDmakedate()); // UFDate制单时间
mainJson.put("creator", headVO.getCreator());//创建人 mainJson.put("creator", headVO.getCreator());// 创建人
mainJson.put("creationtime", headVO.getCreationtime()); // UFDateTime创建时间 mainJson.put("creationtime", headVO.getCreationtime()); // UFDateTime创建时间
return mainJson; return mainJson;
} }
@ -348,7 +284,7 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
detailJson.put("nplanoutastnum", itemVO.getNplanoutastnum() != null ? itemVO.getNplanoutastnum().doubleValue() : null); // 计划出库数量 detailJson.put("nplanoutastnum", itemVO.getNplanoutastnum() != null ? itemVO.getNplanoutastnum().doubleValue() : null); // 计划出库数量
detailJson.put("nplanoutnum", itemVO.getNplanoutnum() != null ? itemVO.getNplanoutnum().doubleValue() : null);// 计划出库主数量 detailJson.put("nplanoutnum", itemVO.getNplanoutnum() != null ? itemVO.getNplanoutnum().doubleValue() : null);// 计划出库主数量
detailJson.put("vbdef22", itemVO.getVbdef20()); // 是否备件 detailJson.put("vbdef22", itemVO.getVbdef20()); // 是否备件
detailJson.put("nunituseastnum",itemVO.getNunituseastnum() != null ? itemVO.getNunituseastnum().toString() : null); detailJson.put("nunituseastnum", itemVO.getNunituseastnum() != null ? itemVO.getNunituseastnum().toString() : null);
return detailJson; return detailJson;
} }
@ -356,13 +292,12 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
// -------------------------- 新增/更新逻辑提取通用SQL值处理减少冗余 -------------------------- // -------------------------- 新增/更新逻辑提取通用SQL值处理减少冗余 --------------------------
/** /**
* 主表新增使用共享的 PersistenceManager * 主表新增
* *
* @param mainDataList 主表数据列表 * @param mainDataList 主表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 主表业务主键 * @param cpickmid 主表业务主键
*/ */
private void insertPlanMain(List<Map<String, Object>> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException, DbException { private void insertPlanMain(List<Map<String, Object>> mainDataList, String cpickmid) throws BusinessException {
// 1. 构建 SQL逻辑与原代码一致仅执行方式改变 // 1. 构建 SQL逻辑与原代码一致仅执行方式改变
String[] mainFields = { String[] mainFields = {
"cpickmid", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", "cpickmid", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype",
@ -395,24 +330,22 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
String valuesStr = valuesSb.substring(0, valuesSb.length() - 2); String valuesStr = valuesSb.substring(0, valuesSb.length() - 2);
String insertSql = "INSERT INTO BIPPlanMainTab (" + fieldStr + ") VALUES " + valuesStr; String insertSql = "INSERT INTO BIPPlanMainTab (" + fieldStr + ") VALUES " + valuesStr;
// 关键用共享 pm JdbcSession 执行而非 BaseDAO executeUpdate int rows = GyImsDbUtil.update(insertSql);
int rows = pm.getJdbcSession().executeUpdate(insertSql); logger.error("主表新增成功cpickmid" + cpickmid + ",影响行数:" + rows);
logger.info("主表新增成功cpickmid" + cpickmid + ",影响行数:" + rows + "");
} }
} }
/** /**
* 子表新增使用共享的 PersistenceManager * 子表新增
* *
* @param detailDataList 子表数据列表 * @param detailDataList 子表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 子表业务主键 * @param cpickmid 子表业务主键
*/ */
private void insertPlanDetail(List<Map<String, Object>> detailDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { private void insertPlanDetail(List<Map<String, Object>> detailDataList, String cpickmid) throws BusinessException {
String[] detailFields = { String[] detailFields = {
"cpickm_bid", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "cpickm_bid", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype",
"fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum",
"nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum"
}; };
String fieldStr = String.join(", ", detailFields); String fieldStr = String.join(", ", detailFields);
StringBuilder valuesSb = new StringBuilder(); StringBuilder valuesSb = new StringBuilder();
@ -434,19 +367,18 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
String insertSql = "INSERT INTO BIPPlanDetailTab (" + fieldStr + ") VALUES " + valuesStr; String insertSql = "INSERT INTO BIPPlanDetailTab (" + fieldStr + ") VALUES " + valuesStr;
// 关键用共享 pm JdbcSession 执行 // 关键用共享 pm JdbcSession 执行
int rows = pm.getJdbcSession().executeUpdate(insertSql); int rows = GyImsDbUtil.update(insertSql);
logger.info("子表新增成功子表cpickmid" + cpickmid + ",影响行数:" + rows + ""); logger.info("子表新增成功子表cpickmid" + cpickmid + ",影响行数:" + rows + "");
} }
} }
/** /**
* 主表更新使用共享的 PersistenceManager * 主表更新
* *
* @param mainDataList 主表数据列表 * @param mainDataList 主表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 主表业务主键 * @param cpickmid 主表业务主键
*/ */
private void updatePlanMain(List<Map<String, Object>> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { private void updatePlanMain(List<Map<String, Object>> mainDataList, String cpickmid) throws BusinessException {
String[] mainFields = { String[] mainFields = {
"pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype",
"cmaterialvid", "nastnum", "cdeptid", "cdeptvid", "vsalebillcode", "ccustmaterialid", "cmaterialvid", "nastnum", "cdeptid", "cdeptvid", "vsalebillcode", "ccustmaterialid",
@ -466,25 +398,24 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
setSb.append(field).append(" = ").append(SqlValueUtil.processSqlValue(value)).append(", "); setSb.append(field).append(" = ").append(SqlValueUtil.processSqlValue(value)).append(", ");
} }
if (setSb.length() > 0) { if (!setSb.isEmpty()) {
String setStr = setSb.substring(0, setSb.length() - 2); String setStr = setSb.substring(0, setSb.length() - 2);
String safeCpickmid = cpickmid.replace("'", "''"); String safeCpickmid = cpickmid.replace("'", "''");
String updateSql = "UPDATE BIPPlanMainTab SET " + setStr + " WHERE cpickmid = '" + safeCpickmid + "'"; String updateSql = "UPDATE BIPPlanMainTab SET " + setStr + " WHERE cpickmid = '" + safeCpickmid + "'";
// 关键用共享 pm JdbcSession 执行 // 关键用共享 pm JdbcSession 执行
int rows = pm.getJdbcSession().executeUpdate(updateSql); int rows = GyImsDbUtil.update(updateSql);
logger.info("主表更新成功cpickmid" + cpickmid + ",影响行数:" + rows + ""); logger.error("主表更新成功cpickmid" + cpickmid + ",影响行数:" + rows);
} }
} }
/** /**
* 子表更新使用共享的 PersistenceManager * 子表更新
* *
* @param detailDataList 子表数据列表 * @param detailDataList 子表数据列表
* @param pm 共享的 PersistenceManager 实例
* @param cpickmid 子表业务主键 * @param cpickmid 子表业务主键
*/ */
private void updatePlanDetail(List<Map<String, Object>> detailDataList, PersistenceManager pm, String cpickmid) throws BusinessException { private void updatePlanDetail(List<Map<String, Object>> detailDataList, String cpickmid) throws BusinessException {
if (detailDataList.isEmpty()) { if (detailDataList.isEmpty()) {
logger.warn("备料计划" + cpickmid + "子表同步数据为空,跳过更新"); logger.warn("备料计划" + cpickmid + "子表同步数据为空,跳过更新");
return; return;
@ -493,7 +424,7 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
String[] detailFields = { String[] detailFields = {
"cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype",
"fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum",
"nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum"
}; };
// 循环更新每条子表数据 // 循环更新每条子表数据
@ -512,18 +443,13 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
} }
// 执行SQL // 执行SQL
if (setSb.length() > 0) { if (!setSb.isEmpty()) {
String setStr = setSb.substring(0, setSb.length() - 2); String setStr = setSb.substring(0, setSb.length() - 2);
String safeBid = cpickmBid.replace("'", "''"); String safeBid = cpickmBid.replace("'", "''");
String updateSql = "UPDATE BIPPlanDetailTab SET " + setStr + " WHERE cpickm_bid = '" + safeBid + "'"; String updateSql = "UPDATE BIPPlanDetailTab SET " + setStr + " WHERE cpickm_bid = '" + safeBid + "'";
// 关键使用共享的 PersistenceManager 执行 SQL int rows = GyImsDbUtil.update(updateSql);
try { logger.error("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows);
int rows = pm.getJdbcSession().executeUpdate(updateSql);
logger.info("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows + "");
} catch (DbException e) {
throw new BusinessException("子表更新失败SQL: " + updateSql, e);
}
} }
} }
} }
@ -531,26 +457,6 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule<PMOAggVO> {
// -------------------------- 通用工具方法提取后复用减少冗余 -------------------------- // -------------------------- 通用工具方法提取后复用减少冗余 --------------------------
/**
* 执行SQL并处理DAO异常
*
* @param sql SQL语句
* @param dao BaseDAO实例
* @param operType 操作类型"主表新增"
* @param bizKey 业务标识如cpickmid
*/
private void executeSql(String sql, BaseDAO dao, String operType, String bizKey) throws BusinessException {
try {
logger.debug("执行" + operType + "SQL业务标识" + bizKey + "SQL" + sql + "");
int rows = dao.executeUpdate(sql);
logger.info("" + operType + "成功,业务标识:" + bizKey + ",影响行数:" + rows + "");
} catch (DAOException e) {
String errorMsg = operType + "失败,业务标识:" + bizKey + "SQL" + sql;
logger.error(errorMsg, e);
throw new BusinessException(errorMsg, e);
}
}
/** /**
* 判断是否跳过该组织 * 判断是否跳过该组织
*/ */