From 7de733be0028b0577971ed769c3d0ee6a9fc24e3 Mon Sep 17 00:00:00 2001 From: mzr Date: Fri, 21 Nov 2025 18:28:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor(sync):=20=E9=AB=98=E5=8E=8BIMS-?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E7=94=9F=E4=BA=A7=E8=AE=A2=E5=8D=95=E5=92=8C?= =?UTF-8?q?=E5=A4=87=E6=96=99=E8=AE=A1=E5=88=92=E5=90=8C=E6=AD=A5-?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE=E6=BA=90=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nc/bs/mmpac/pickm/bp/PickmUpdateBP.java | 3 +- .../bs/mmpac/pickm/bp/PickmUpdateForMOBP.java | 28 +- .../rule/AfterApproveRuleHighpressureIms.java | 259 ++++++------------ .../bp/rule/AfterApproveSyncImsRule.java | 14 - .../PMOAfterApproveRuleHighpressureIms.java | 242 +++++----------- 5 files changed, 164 insertions(+), 382 deletions(-) diff --git a/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateBP.java b/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateBP.java index dbecc262..cf370a88 100644 --- a/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateBP.java +++ b/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateBP.java @@ -1,5 +1,6 @@ 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.AfterupdateSyncEpicMesRule; import nc.bs.mmpac.pickm.bp.rule.PickItemsSetVbdef36Rule; @@ -184,7 +185,7 @@ public class PickmUpdateBP { processer.addAfterRule(subMoAdjustSuggestRule); processer.addAfterRule(new AfterupdateSyncEpicMesRule()); // 备料计划变更后推送高压IMS - // processer.addAfterRule(new AfterApproveRuleHighpressureIms()); + processer.addAfterRule(new AfterApproveRuleHighpressureIms()); // 备料计划预留推送高压MES processer.addAfterRule(new AfterQtyUpdRuleHighpressureMes()); } diff --git a/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateForMOBP.java b/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateForMOBP.java index dffb0636..3f5f74a5 100644 --- a/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateForMOBP.java +++ b/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmUpdateForMOBP.java @@ -1,22 +1,9 @@ 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.AfterQtyUpdRuleHighpressureMes; import nc.bs.mmpac.pickm.bp.rule.AfterupdateSyncEpicMesRule; import nc.bs.mmpac.pickm.plugin.PickmPluginPoint; -import nc.bs.mmpac.pickm.rule.PickmCheckItemMaterialPermissionRule; -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.*; import nc.bs.mmpac.pickm.rule.ic.PickmATPCheckRule; import nc.bs.mmpac.pickm.rule.ic.PickmAutoChangeStateRule; 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.mmpub.rule.MMAutoMaterialAssignRule; import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule; -import nc.bs.pubapp.pub.rule.BillCodeCheckRule; -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.pubapp.pub.rule.*; import nc.bs.uif2.validation.ValidationFailure; import nc.bsutil.mmpac.pickm.PickmSagasUtil; 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.param.MoChangeParam; +import java.util.Map; + /** * 生产订单修改后同步变更备料计划操作 * @@ -225,13 +210,10 @@ public class PickmUpdateForMOBP { // 配套变更建议 ICompareRule subMoAdjustSuggestRule = new PickmSubMoAdjustSuggestRule(this.checkInfo); aroundProcesser.addAfterRule(subMoAdjustSuggestRule); - - aroundProcesser.addAfterRule(new AfterupdateSyncEpicMesRule()); - //备料计划修改后推送高压IMS + // 备料计划修改后推送高压IMS aroundProcesser.addAfterRule(new AfterApproveRuleHighpressureIms()); - } } diff --git a/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureIms.java b/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureIms.java index acac7cbb..ba101a75 100644 --- a/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureIms.java +++ b/mmpac/src/private/nc/bs/mmpac/pickm/bp/rule/AfterApproveRuleHighpressureIms.java @@ -5,12 +5,9 @@ import nc.bs.dao.BaseDAO; import nc.bs.dao.DAOException; import nc.bs.logging.Log; import nc.bs.trade.business.HYPubBO; +import nc.bs.uapbd.util.GyImsDbUtil; import nc.bs.uapbd.util.MyHelper; 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.vo.mmpac.pickm.entity.AggPickmVO; 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.scmpub.util.ArrayUtil; -import java.sql.Connection; -import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; @@ -112,8 +107,8 @@ public class AfterApproveRuleHighpressureIms implements IRule { // 2. 组织过滤(仅同步目标组织,原逻辑保留并优化日志) String pkOrg = headVO.getPk_org(); String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); - if (checkIfSkipOrg(orgCode,configParams)) { - logger.info("备料计划组织编码"+ orgCode +"非目标同步组织,跳过同步,备料单号:"+headVO.getVbillcode()+""); + if (checkIfSkipOrg(orgCode, configParams)) { + logger.info("备料计划组织编码" + orgCode + "非目标同步组织,跳过同步,备料单号:" + headVO.getVbillcode() + ""); continue; } if (!checkIfVtrantypecode(headVO.getVsourcebilltype(), configParams)) { @@ -158,6 +153,7 @@ public class AfterApproveRuleHighpressureIms implements IRule { } return true; } + private void pushIms(List> mainDataList, List> detailDataList, String targetCpickmid) throws BusinessException { // 1. 关键参数校验 if (targetCpickmid == null || targetCpickmid.trim().isEmpty()) { @@ -165,94 +161,37 @@ public class AfterApproveRuleHighpressureIms implements IRule { return; } if (mainDataList.isEmpty()) { - logger.warn("备料计划主表数据为空,终止同步,cpickmid:" + targetCpickmid + ""); + logger.warn("备料计划主表数据为空,终止同步,cpickmid:" + targetCpickmid); return; } - // 2. 直接通过静态工厂方法获取 PersistenceManager - PersistenceManager pm = null; - JdbcSession jdbcSession = null; - Connection conn = null; - boolean isSuccess = false; - try { - // 直接调用 PersistenceManager 的静态方法 getInstance() - pm = PersistenceManager.getInstance("gyims"); - pm.setAddTimeStamp(false); + // 3. 判断新增/更新 (checkMainExists 方法逻辑不变) + boolean isUpdate = checkMainExists(targetCpickmid); - // 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); - } + // 4. 执行主表+子表操作 (传入共享的 pm) + if (isUpdate) { + updatePlanMain(mainDataList, targetCpickmid); + if (!detailDataList.isEmpty()) { + updatePlanDetail(detailDataList, targetCpickmid); } - - isSuccess = true; - logger.info("事务内操作全部成功,准备提交,cpickmid:" + 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); - } + } else { + insertPlanMain(mainDataList, targetCpickmid); + if (!detailDataList.isEmpty()) { + insertPlanDetail(detailDataList, targetCpickmid); } } + } /** - * 校验主表是否存在(使用共享的 PersistenceManager) + * 校验主表是否存在 */ - private boolean checkMainExists(PersistenceManager pm, String cpickmid) throws DAOException, DbException { + private boolean checkMainExists(String cpickmid) throws BusinessException { String safeCpickmid = cpickmid.replace("'", "''"); String sql = "SELECT cpickmid FROM BIPPlanMainTab WHERE cpickmid = '" + safeCpickmid + "'"; - // 使用共享 pm 的 JdbcSession 执行查询,避免新建连接 - Map existMain = (Map) pm.getJdbcSession().executeQuery(sql, new MapProcessor()); + Map existMain = GyImsDbUtil.queryOne(sql); return existMain != null && !existMain.isEmpty(); } @@ -266,47 +205,47 @@ public class AfterApproveRuleHighpressureIms implements IRule { JSONObject mainJson = new JSONObject(); 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() + "' "); - mainJson.put("pk_org", pk_org);//组织_业务单元_工厂 + mainJson.put("pk_org", pk_org);// 组织_业务单元_工厂 mainJson.put("vbillcode", headVO.getVbillcode());// 备料计划单号 - mainJson.put("fbillstatus", headVO.getFbillstatus());//备料状态 - mainJson.put("vbusitypeid", headVO.getVbusitypeid());//备料类型 - mainJson.put("vbusitype", headVO.getVbusitype());//备料类型编码 + mainJson.put("fbillstatus", headVO.getFbillstatus());// 备料状态 + mainJson.put("vbusitypeid", headVO.getVbusitypeid());// 备料类型 + mainJson.put("vbusitype", headVO.getVbusitype());// 备料类型编码 Object cmaterialvid = new HYPubBO().findColValue("bd_material", "code", "nvl(dr,0) = 0 and pk_material='" + headVO.getCmaterialvid() + "' "); - mainJson.put("cmaterialvid", cmaterialvid.toString());//产品编码 - mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);//计划数量; - mainJson.put("cdeptid", headVO.getCdeptid());//用料部门最新版本 - mainJson.put("cdeptvid", headVO.getCdeptid());//用料部门 - mainJson.put("vsalebillcode", headVO.getVsalebillcode());//销售订单号 - mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());//客户物料码 - mainJson.put("cemployeeid", headVO.getCemployeeid());//业务员 - mainJson.put("vfirstmoid", headVO.getVfirstmoid());//源头生产订单 - mainJson.put("vfirstmocode", headVO.getVfirstmocode());//源头生产订单号 - mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());//源头生产订单明细 - mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());//源头生产订单行号 - mainJson.put("vsourcemoid", headVO.getVsourcemoid());//来源生产订单 - mainJson.put("vsourcemocode", headVO.getVsourcemocode());//来源生产订单号 - mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());//来源生产订单明细 - mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());//来源生产订单行号 - mainJson.put("cfirstbillid", headVO.getCfirstbillid());//源头单据 - mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());//源头单据号 - mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());//源头单据类型 - mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());//源头交易类型 - mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());//源头交易类型编码 - mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());//源头单据明细 - mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());//源头单据行号 - mainJson.put("csourcebillid", headVO.getCsourcebillid());//来源单据 - mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());//来源单据号 - mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());//来源单据类型 - mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());//来源交易类型 - mainJson.put("vsrctrantype", headVO.getVsrctrantype());//来源交易类型编码 - mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());//来源单据明细 - mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());//来源单据行号 - mainJson.put("vnote", headVO.getVnote());//备注 - mainJson.put("status", headVO.getStatus());//同步状态 + mainJson.put("cmaterialvid", cmaterialvid.toString());// 产品编码 + mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);// 计划数量; + mainJson.put("cdeptid", headVO.getCdeptid());// 用料部门最新版本 + mainJson.put("cdeptvid", headVO.getCdeptid());// 用料部门 + mainJson.put("vsalebillcode", headVO.getVsalebillcode());// 销售订单号 + mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());// 客户物料码 + mainJson.put("cemployeeid", headVO.getCemployeeid());// 业务员 + mainJson.put("vfirstmoid", headVO.getVfirstmoid());// 源头生产订单 + mainJson.put("vfirstmocode", headVO.getVfirstmocode());// 源头生产订单号 + mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());// 源头生产订单明细 + mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());// 源头生产订单行号 + mainJson.put("vsourcemoid", headVO.getVsourcemoid());// 来源生产订单 + mainJson.put("vsourcemocode", headVO.getVsourcemocode());// 来源生产订单号 + mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());// 来源生产订单明细 + mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());// 来源生产订单行号 + mainJson.put("cfirstbillid", headVO.getCfirstbillid());// 源头单据 + mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());// 源头单据号 + mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());// 源头单据类型 + mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());// 源头交易类型 + mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());// 源头交易类型编码 + mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());// 源头单据明细 + mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());// 源头单据行号 + mainJson.put("csourcebillid", headVO.getCsourcebillid());// 来源单据 + mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());// 来源单据号 + mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());// 来源单据类型 + mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());// 来源交易类型 + mainJson.put("vsrctrantype", headVO.getVsrctrantype());// 来源交易类型编码 + mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());// 来源单据明细 + mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());// 来源单据行号 + mainJson.put("vnote", headVO.getVnote());// 备注 + mainJson.put("status", headVO.getStatus());// 同步状态 mainJson.put("billmaker", headVO.getBillmaker()); - ;//制单人 + ;// 制单人 mainJson.put("dmakedate", headVO.getDmakedate()); // UFDate制单时间 - mainJson.put("creator", headVO.getCreator());//创建人 + mainJson.put("creator", headVO.getCreator());// 创建人 mainJson.put("creationtime", headVO.getCreationtime()); // UFDateTime创建时间 return mainJson; } @@ -335,7 +274,7 @@ public class AfterApproveRuleHighpressureIms implements IRule { detailJson.put("nplanoutastnum", itemVO.getNplanoutastnum() != null ? itemVO.getNplanoutastnum().doubleValue() : null); // 计划出库数量 detailJson.put("nplanoutnum", itemVO.getNplanoutnum() != null ? itemVO.getNplanoutnum().doubleValue() : null);// 计划出库主数量 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; } @@ -343,13 +282,12 @@ public class AfterApproveRuleHighpressureIms implements IRule { // -------------------------- 新增/更新逻辑(提取通用SQL值处理,减少冗余) -------------------------- /** - * 主表新增(使用共享的 PersistenceManager) + * 主表新增 * * @param mainDataList 主表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 主表业务主键 */ - private void insertPlanMain(List> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException, DbException { + private void insertPlanMain(List> mainDataList, String cpickmid) throws BusinessException { // 1. 构建 SQL(逻辑与原代码一致,仅执行方式改变) String[] mainFields = { "cpickmid", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", @@ -377,29 +315,26 @@ public class AfterApproveRuleHighpressureIms implements IRule { valuesSb.append("), "); } - // 2. 执行 SQL(使用共享 pm 的 JdbcSession,避免新建连接) - if (valuesSb.length() > 0) { + if (!valuesSb.isEmpty()) { String valuesStr = valuesSb.substring(0, valuesSb.length() - 2); String insertSql = "INSERT INTO BIPPlanMainTab (" + fieldStr + ") VALUES " + valuesStr; - // 关键:用共享 pm 的 JdbcSession 执行,而非 BaseDAO 的 executeUpdate - int rows = pm.getJdbcSession().executeUpdate(insertSql); - logger.info("主表新增成功,cpickmid:" + cpickmid + ",影响行数:" + rows + ""); + int rows = GyImsDbUtil.update(insertSql); + logger.error("主表新增成功,cpickmid:" + cpickmid + ",影响行数:" + rows + ""); } } /** - * 子表新增(使用共享的 PersistenceManager) + * 子表新增 * * @param detailDataList 子表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 子表业务主键 */ - private void insertPlanDetail(List> detailDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { + private void insertPlanDetail(List> detailDataList, String cpickmid) throws BusinessException { String[] detailFields = { "cpickm_bid", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", - "nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" + "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum" }; String fieldStr = String.join(", ", detailFields); StringBuilder valuesSb = new StringBuilder(); @@ -416,24 +351,22 @@ public class AfterApproveRuleHighpressureIms implements IRule { valuesSb.append("), "); } - if (valuesSb.length() > 0) { + if (!valuesSb.isEmpty()) { String valuesStr = valuesSb.substring(0, valuesSb.length() - 2); String insertSql = "INSERT INTO BIPPlanDetailTab (" + fieldStr + ") VALUES " + valuesStr; - // 关键:用共享 pm 的 JdbcSession 执行 - int rows = pm.getJdbcSession().executeUpdate(insertSql); - logger.info("子表新增成功,子表cpickmid:" + cpickmid + ",影响行数:" + rows + ""); + int rows = GyImsDbUtil.update(insertSql); + logger.error("子表新增成功,子表cpickmid:" + cpickmid + ",影响行数:" + rows); } } /** - * 主表更新(使用共享的 PersistenceManager) + * 主表更新 * * @param mainDataList 主表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 主表业务主键 */ - private void updatePlanMain(List> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { + private void updatePlanMain(List> mainDataList, String cpickmid) throws BusinessException { String[] mainFields = { "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", "cmaterialvid", "nastnum", "cdeptid", "cdeptvid", "vsalebillcode", "ccustmaterialid", @@ -453,41 +386,40 @@ public class AfterApproveRuleHighpressureIms implements IRule { 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 safeCpickmid = cpickmid.replace("'", "''"); String updateSql = "UPDATE BIPPlanMainTab SET " + setStr + " WHERE cpickmid = '" + safeCpickmid + "'"; // 关键:用共享 pm 的 JdbcSession 执行 - int rows = pm.getJdbcSession().executeUpdate(updateSql); - logger.info("主表更新成功,cpickmid:" + cpickmid + ",影响行数:" + rows + ""); + int rows = GyImsDbUtil.update(updateSql); + logger.error("主表更新成功,cpickmid:" + cpickmid + ",影响行数:" + rows); } } /** - * 子表更新(使用共享的 PersistenceManager) + * 子表更新 * * @param detailDataList 子表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 子表业务主键 */ - private void updatePlanDetail(List> detailDataList, PersistenceManager pm, String cpickmid) throws BusinessException { + private void updatePlanDetail(List> detailDataList, String cpickmid) throws BusinessException { if (detailDataList.isEmpty()) { - logger.warn("备料计划" + cpickmid + "子表同步数据为空,跳过更新"); + logger.error("备料计划" + cpickmid + "子表同步数据为空,跳过更新"); return; } String[] detailFields = { "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", - "nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" + "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum" }; // 循环更新每条子表数据 for (Map detailData : detailDataList) { String cpickmBid = (String) detailData.get("cpickm_bid"); if (cpickmBid == null || cpickmBid.trim().isEmpty()) { - logger.warn("备料计划" + cpickmid + "子表主键cpickm_bid为空,跳过该子表更新"); + logger.error("备料计划" + cpickmid + "子表主键cpickm_bid为空,跳过该子表更新"); continue; } @@ -499,18 +431,13 @@ public class AfterApproveRuleHighpressureIms implements IRule { } // 执行SQL - if (setSb.length() > 0) { + if (!setSb.isEmpty()) { String setStr = setSb.substring(0, setSb.length() - 2); String safeBid = cpickmBid.replace("'", "''"); String updateSql = "UPDATE BIPPlanDetailTab SET " + setStr + " WHERE cpickm_bid = '" + safeBid + "'"; - // 关键:使用共享的 PersistenceManager 执行 SQL - try { - int rows = pm.getJdbcSession().executeUpdate(updateSql); - logger.info("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows + ""); - } catch (DbException e) { - throw new BusinessException("子表更新失败,SQL: " + updateSql, e); - } + int rows = GyImsDbUtil.update(updateSql); + logger.error("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows); } } } @@ -518,30 +445,10 @@ public class AfterApproveRuleHighpressureIms implements IRule { // -------------------------- 通用工具方法(提取后复用,减少冗余) -------------------------- - /** - * 执行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 configParams) throws BusinessException{ + private boolean checkIfSkipOrg(String code, Map configParams) throws BusinessException { String targetCode = configParams.get("imsOrg"); if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { throw new BusinessException("未配置组织参数"); diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncImsRule.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncImsRule.java index 13e479ed..0e7099d3 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncImsRule.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/AfterApproveSyncImsRule.java @@ -32,25 +32,11 @@ public class AfterApproveSyncImsRule implements IRule { private Map configParams; // BIP数据源 public static final BaseDAO baseDAO = new BaseDAO(); - // IMS数据源 - public BaseDAO imsDao; public AfterApproveSyncImsRule(String 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"; // 表体-表名 diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/PMOAfterApproveRuleHighpressureIms.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/PMOAfterApproveRuleHighpressureIms.java index 1c930ee3..b1638431 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/PMOAfterApproveRuleHighpressureIms.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/PMOAfterApproveRuleHighpressureIms.java @@ -1,17 +1,12 @@ package nc.bs.mmpac.pmo.pac0002.bp.rule; import com.alibaba.fastjson.JSONObject; -import nc.bs.dao.BaseDAO; -import nc.bs.dao.DAOException; import nc.bs.framework.common.NCLocator; import nc.bs.logging.Log; import nc.bs.trade.business.HYPubBO; +import nc.bs.uapbd.util.GyImsDbUtil; import nc.bs.uapbd.util.MyHelper; 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.persist.framework.IMDPersistenceQueryService; 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.pubapp.pattern.exception.ExceptionUtils; -import java.sql.Connection; -import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; @@ -181,91 +174,34 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { logger.warn("备料计划主表数据为空,终止同步,cpickmid:" + targetCpickmid + ""); return; } + // 3. 判断新增/更新 (checkMainExists 方法逻辑不变) + boolean isUpdate = checkMainExists(targetCpickmid); - // 2. 直接通过静态工厂方法获取 PersistenceManager - PersistenceManager pm = null; - JdbcSession jdbcSession = null; - Connection conn = null; - boolean isSuccess = false; - - 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); - } + // 4. 执行主表+子表操作 (传入共享的 pm) + if (isUpdate) { + logger.info("事务内执行更新,cpickmid:" + targetCpickmid + ""); + updatePlanMain(mainDataList, targetCpickmid); + if (!detailDataList.isEmpty()) { + updatePlanDetail(detailDataList, targetCpickmid); } - - isSuccess = true; - logger.info("事务内操作全部成功,准备提交,cpickmid:" + 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); - } + } else { + logger.info("事务内执行新增,cpickmid:" + targetCpickmid); + insertPlanMain(mainDataList, targetCpickmid); + if (!detailDataList.isEmpty()) { + insertPlanDetail(detailDataList, targetCpickmid); } } } /** - * 校验主表是否存在(使用共享的 PersistenceManager) + * 校验主表是否存在 */ - private boolean checkMainExists(PersistenceManager pm, String cpickmid) throws DAOException, DbException { + private boolean checkMainExists(String cpickmid) throws BusinessException { String safeCpickmid = cpickmid.replace("'", "''"); String sql = "SELECT cpickmid FROM BIPPlanMainTab WHERE cpickmid = '" + safeCpickmid + "'"; // 使用共享 pm 的 JdbcSession 执行查询,避免新建连接 - Map existMain = (Map) pm.getJdbcSession().executeQuery(sql, new MapProcessor()); + Map existMain = GyImsDbUtil.queryOne(sql); return existMain != null && !existMain.isEmpty(); } @@ -279,47 +215,47 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { JSONObject mainJson = new JSONObject(); 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() + "' "); - mainJson.put("pk_org", pk_org);//组织_业务单元_工厂 + mainJson.put("pk_org", pk_org);// 组织_业务单元_工厂 mainJson.put("vbillcode", headVO.getVbillcode());// 备料计划单号 - mainJson.put("fbillstatus", headVO.getFbillstatus());//备料状态 - mainJson.put("vbusitypeid", headVO.getVbusitypeid());//备料类型 - mainJson.put("vbusitype", headVO.getVbusitype());//备料类型编码 + mainJson.put("fbillstatus", headVO.getFbillstatus());// 备料状态 + mainJson.put("vbusitypeid", headVO.getVbusitypeid());// 备料类型 + mainJson.put("vbusitype", headVO.getVbusitype());// 备料类型编码 Object cmaterialvid = new HYPubBO().findColValue("bd_material", "code", "nvl(dr,0) = 0 and pk_material='" + headVO.getCmaterialvid() + "' "); - mainJson.put("cmaterialvid", cmaterialvid.toString());//产品编码 - mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);//计划数量; - mainJson.put("cdeptid", headVO.getCdeptid());//用料部门最新版本 - mainJson.put("cdeptvid", headVO.getCdeptid());//用料部门 - mainJson.put("vsalebillcode", headVO.getVsalebillcode());//销售订单号 - mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());//客户物料码 - mainJson.put("cemployeeid", headVO.getCemployeeid());//业务员 - mainJson.put("vfirstmoid", headVO.getVfirstmoid());//源头生产订单 - mainJson.put("vfirstmocode", headVO.getVfirstmocode());//源头生产订单号 - mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());//源头生产订单明细 - mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());//源头生产订单行号 - mainJson.put("vsourcemoid", headVO.getVsourcemoid());//来源生产订单 - mainJson.put("vsourcemocode", headVO.getVsourcemocode());//来源生产订单号 - mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());//来源生产订单明细 - mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());//来源生产订单行号 - mainJson.put("cfirstbillid", headVO.getCfirstbillid());//源头单据 - mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());//源头单据号 - mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());//源头单据类型 - mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());//源头交易类型 - mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());//源头交易类型编码 - mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());//源头单据明细 - mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());//源头单据行号 - mainJson.put("csourcebillid", headVO.getCsourcebillid());//来源单据 - mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());//来源单据号 - mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());//来源单据类型 - mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());//来源交易类型 - mainJson.put("vsrctrantype", headVO.getVsrctrantype());//来源交易类型编码 - mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());//来源单据明细 - mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());//来源单据行号 - mainJson.put("vnote", headVO.getVnote());//备注 - mainJson.put("status", headVO.getStatus());//同步状态 + mainJson.put("cmaterialvid", cmaterialvid.toString());// 产品编码 + mainJson.put("nastnum", headVO.getNastnum() != null ? headVO.getNastnum().doubleValue() : null);// 计划数量; + mainJson.put("cdeptid", headVO.getCdeptid());// 用料部门最新版本 + mainJson.put("cdeptvid", headVO.getCdeptid());// 用料部门 + mainJson.put("vsalebillcode", headVO.getVsalebillcode());// 销售订单号 + mainJson.put("ccustmaterialid", headVO.getCcustmaterialid());// 客户物料码 + mainJson.put("cemployeeid", headVO.getCemployeeid());// 业务员 + mainJson.put("vfirstmoid", headVO.getVfirstmoid());// 源头生产订单 + mainJson.put("vfirstmocode", headVO.getVfirstmocode());// 源头生产订单号 + mainJson.put("vfirstmorowid", headVO.getVfirstmorowid());// 源头生产订单明细 + mainJson.put("vfirstmorowcode", headVO.getVfirstmorowcode());// 源头生产订单行号 + mainJson.put("vsourcemoid", headVO.getVsourcemoid());// 来源生产订单 + mainJson.put("vsourcemocode", headVO.getVsourcemocode());// 来源生产订单号 + mainJson.put("vsourcemorowid", headVO.getVsourcemorowid());// 来源生产订单明细 + mainJson.put("vsourcemorowcode", headVO.getVsourcemorowcode());// 来源生产订单行号 + mainJson.put("cfirstbillid", headVO.getCfirstbillid());// 源头单据 + mainJson.put("vfirstbillcode", headVO.getVfirstbillcode());// 源头单据号 + mainJson.put("vfirstbilltype", headVO.getVfirstbilltype());// 源头单据类型 + mainJson.put("vfirsttrantypeid", headVO.getVfirsttrantypeid());// 源头交易类型 + mainJson.put("vfirsttrantype", headVO.getVfirsttrantype());// 源头交易类型编码 + mainJson.put("cfirstbillrowid", headVO.getCfirstbillrowid());// 源头单据明细 + mainJson.put("vfirstbillrowno", headVO.getVfirstbillrowno());// 源头单据行号 + mainJson.put("csourcebillid", headVO.getCsourcebillid());// 来源单据 + mainJson.put("vsourcebillcode", headVO.getVsourcebillcode());// 来源单据号 + mainJson.put("vsourcebilltype", headVO.getVsourcebilltype());// 来源单据类型 + mainJson.put("vsrctrantypeid", headVO.getVsrctrantypeid());// 来源交易类型 + mainJson.put("vsrctrantype", headVO.getVsrctrantype());// 来源交易类型编码 + mainJson.put("csourcebillrowid", headVO.getCsourcebillrowid());// 来源单据明细 + mainJson.put("vsourcebillrowno", headVO.getVsourcebillrowno());// 来源单据行号 + mainJson.put("vnote", headVO.getVnote());// 备注 + mainJson.put("status", headVO.getStatus());// 同步状态 mainJson.put("billmaker", headVO.getBillmaker()); - ;//制单人 + ;// 制单人 mainJson.put("dmakedate", headVO.getDmakedate()); // UFDate制单时间 - mainJson.put("creator", headVO.getCreator());//创建人 + mainJson.put("creator", headVO.getCreator());// 创建人 mainJson.put("creationtime", headVO.getCreationtime()); // UFDateTime创建时间 return mainJson; } @@ -348,7 +284,7 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { detailJson.put("nplanoutastnum", itemVO.getNplanoutastnum() != null ? itemVO.getNplanoutastnum().doubleValue() : null); // 计划出库数量 detailJson.put("nplanoutnum", itemVO.getNplanoutnum() != null ? itemVO.getNplanoutnum().doubleValue() : null);// 计划出库主数量 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; } @@ -356,13 +292,12 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { // -------------------------- 新增/更新逻辑(提取通用SQL值处理,减少冗余) -------------------------- /** - * 主表新增(使用共享的 PersistenceManager) + * 主表新增 * * @param mainDataList 主表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 主表业务主键 */ - private void insertPlanMain(List> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException, DbException { + private void insertPlanMain(List> mainDataList, String cpickmid) throws BusinessException { // 1. 构建 SQL(逻辑与原代码一致,仅执行方式改变) String[] mainFields = { "cpickmid", "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", @@ -395,24 +330,22 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { String valuesStr = valuesSb.substring(0, valuesSb.length() - 2); String insertSql = "INSERT INTO BIPPlanMainTab (" + fieldStr + ") VALUES " + valuesStr; - // 关键:用共享 pm 的 JdbcSession 执行,而非 BaseDAO 的 executeUpdate - int rows = pm.getJdbcSession().executeUpdate(insertSql); - logger.info("主表新增成功,cpickmid:" + cpickmid + ",影响行数:" + rows + ""); + int rows = GyImsDbUtil.update(insertSql); + logger.error("主表新增成功,cpickmid:" + cpickmid + ",影响行数:" + rows); } } /** - * 子表新增(使用共享的 PersistenceManager) + * 子表新增 * * @param detailDataList 子表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 子表业务主键 */ - private void insertPlanDetail(List> detailDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { + private void insertPlanDetail(List> detailDataList, String cpickmid) throws BusinessException { String[] detailFields = { "cpickm_bid", "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", - "nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" + "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum" }; String fieldStr = String.join(", ", detailFields); StringBuilder valuesSb = new StringBuilder(); @@ -434,19 +367,18 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { String insertSql = "INSERT INTO BIPPlanDetailTab (" + fieldStr + ") VALUES " + valuesStr; // 关键:用共享 pm 的 JdbcSession 执行 - int rows = pm.getJdbcSession().executeUpdate(insertSql); + int rows = GyImsDbUtil.update(insertSql); logger.info("子表新增成功,子表cpickmid:" + cpickmid + ",影响行数:" + rows + ""); } } /** - * 主表更新(使用共享的 PersistenceManager) + * 主表更新 * * @param mainDataList 主表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 主表业务主键 */ - private void updatePlanMain(List> mainDataList, PersistenceManager pm, String cpickmid) throws DAOException, DbException { + private void updatePlanMain(List> mainDataList, String cpickmid) throws BusinessException { String[] mainFields = { "pk_org", "vbillcode", "fbillstatus", "vbusitypeid", "vbusitype", "cmaterialvid", "nastnum", "cdeptid", "cdeptvid", "vsalebillcode", "ccustmaterialid", @@ -466,25 +398,24 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { 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 safeCpickmid = cpickmid.replace("'", "''"); String updateSql = "UPDATE BIPPlanMainTab SET " + setStr + " WHERE cpickmid = '" + safeCpickmid + "'"; // 关键:用共享 pm 的 JdbcSession 执行 - int rows = pm.getJdbcSession().executeUpdate(updateSql); - logger.info("主表更新成功,cpickmid:" + cpickmid + ",影响行数:" + rows + ""); + int rows = GyImsDbUtil.update(updateSql); + logger.error("主表更新成功,cpickmid:" + cpickmid + ",影响行数:" + rows); } } /** - * 子表更新(使用共享的 PersistenceManager) + * 子表更新 * * @param detailDataList 子表数据列表 - * @param pm 共享的 PersistenceManager 实例 * @param cpickmid 子表业务主键 */ - private void updatePlanDetail(List> detailDataList, PersistenceManager pm, String cpickmid) throws BusinessException { + private void updatePlanDetail(List> detailDataList, String cpickmid) throws BusinessException { if (detailDataList.isEmpty()) { logger.warn("备料计划" + cpickmid + "子表同步数据为空,跳过更新"); return; @@ -493,7 +424,7 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { String[] detailFields = { "cpickmid", "pk_org", "vbillcode", "vrowno", "fitemtype", "fitemsource", "cbmaterialvid", "cbunitid", "cbastunitid", "vbchangerate", "nquotastnum", - "nplanoutastnum", "nplanoutnum", "vbdef22","nunituseastnum" + "nplanoutastnum", "nplanoutnum", "vbdef22", "nunituseastnum" }; // 循环更新每条子表数据 @@ -512,18 +443,13 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { } // 执行SQL - if (setSb.length() > 0) { + if (!setSb.isEmpty()) { String setStr = setSb.substring(0, setSb.length() - 2); String safeBid = cpickmBid.replace("'", "''"); String updateSql = "UPDATE BIPPlanDetailTab SET " + setStr + " WHERE cpickm_bid = '" + safeBid + "'"; - // 关键:使用共享的 PersistenceManager 执行 SQL - try { - int rows = pm.getJdbcSession().executeUpdate(updateSql); - logger.info("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows + ""); - } catch (DbException e) { - throw new BusinessException("子表更新失败,SQL: " + updateSql, e); - } + int rows = GyImsDbUtil.update(updateSql); + logger.error("子表更新成功,子表主键:" + cpickmBid + ",影响行数:" + rows); } } } @@ -531,26 +457,6 @@ public class PMOAfterApproveRuleHighpressureIms implements IRule { // -------------------------- 通用工具方法(提取后复用,减少冗余) -------------------------- - /** - * 执行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); - } - } - /** * 判断是否跳过该组织 */