Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
d25831d6ba
|
|
@ -6,18 +6,17 @@ import nc.bs.logging.Log;
|
||||||
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.SQLParameter;
|
import nc.jdbc.framework.SQLParameter;
|
||||||
|
import nc.jdbc.framework.processor.ColumnProcessor;
|
||||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
||||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
|
||||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
||||||
|
import nc.vo.org.OrgVO;
|
||||||
import nc.vo.pub.BusinessException;
|
import nc.vo.pub.BusinessException;
|
||||||
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 nccloud.baseapp.core.log.NCCForUAPLogger;
|
import nccloud.baseapp.core.log.NCCForUAPLogger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程生产订单审批后推送高压IMS
|
* 流程生产订单审批后推送高压IMS
|
||||||
|
|
@ -47,6 +46,33 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
|
||||||
return imsDao;
|
return imsDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 表头-表名
|
||||||
|
private static final String HEAD_TABLE = "BIPOrderMainTab";
|
||||||
|
// 表体-表名
|
||||||
|
private static final String BODY_TABLE = "BIPOrderDetailTab";
|
||||||
|
private static final String[] HEAD_COLUMNS = {"cpmohid", "pk_org", "cplanfactoryid", "dbilldate", "vbillcode", "ctrantypeid", "vtrantypecode", "fbillstatus",
|
||||||
|
"approver", "approvertime", "billmaker", "dmakedate", "vnote", "creator", "creationtime", "status"};
|
||||||
|
private static final String[] BODY_COLUMNS = {
|
||||||
|
"cmoid", "cpmohid", "vbillcode", "vrowno", "pk_group", "pk_org", "fitemstatus", "cmaterialvid", "cunitid", "castunitid", "nnum", "nastnum", "vchangerate", "nplanputastnum",
|
||||||
|
"nplanputnum", "nmmastnum", "nmmnum", "cdeptid", "temp_mainmaterialid", "temp_mainmaterialvid", "temp_mainbid", "cemployeeid", "cbomversionid", "vbomversion", "cpackbomid",
|
||||||
|
"vpackbomversion", "crtversionid", "vrtversion", "tplanstarttime", "tplanendtime", "twillendtime", "tactstarttime", "tactendtime", "mocloser", "tmoclosedtime", "vsalebillcode",
|
||||||
|
"cbatchid", "vbatchcode", "vnote", "cproductorid", "cprojectid", "vsrctrantypeid", "vsrctrantype", "vsrctype", "vsrcid", "vsrccode", "vsrcbid", "vsrcrowno", "crequireorg",
|
||||||
|
"crequireorgvid", "trequiredate", "tsupplytime", "vfirsttrantypeid", "vfirsttrantype", "vfirsttype", "vfirstid", "vfirstcode", "vfirstbid", "vfirstrowno", "ninastnum", "ninnum",
|
||||||
|
"vfirstmotype", "cfirstmoid", "vfirstmocode", "cfirstmobid", "vfirstmorowno", "cinwarehouseid", "vbdef31"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表头-定义数值类型字段列表
|
||||||
|
private Set<String> headNumFields = new HashSet<>(Arrays.asList(
|
||||||
|
"nnum", "nastnum", "nplanputastnum", "nplanputnum", "nmmastnum", "nmmnum",
|
||||||
|
"ninastnum", "ninnum"
|
||||||
|
));
|
||||||
|
// 表体-定义数值类型字段列表
|
||||||
|
Set<String> bodyNumFields = new HashSet<>(Arrays.asList(
|
||||||
|
"nnum", "nastnum", "nplanputastnum", "nplanputnum", "nmmastnum", "nmmnum",
|
||||||
|
"ninastnum", "ninnum"
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(PMOAggVO[] pmoAggVOS) {
|
public void process(PMOAggVO[] pmoAggVOS) {
|
||||||
if (ArrayUtil.isEmpty(pmoAggVOS)) {
|
if (ArrayUtil.isEmpty(pmoAggVOS)) {
|
||||||
|
|
@ -62,299 +88,40 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建同步数据
|
* 构建同步数据逻辑,根据主键判断是新增还是更新
|
||||||
*/
|
*/
|
||||||
private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException {
|
private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException {
|
||||||
for (PMOAggVO vo : useVOs) {
|
for (PMOAggVO vo : useVOs) {
|
||||||
PMOHeadVO pmoHeadVO = vo.getParentVO();
|
PMOHeadVO pmoHeadVO = vo.getParentVO();
|
||||||
PMOItemVO[] itemVOS = vo.getChildrenVO();
|
PMOItemVO[] itemVOS = vo.getChildrenVO();
|
||||||
// 判断物料的业务单元是否是高压加工车间W,不是则跳过
|
// 判断订单业务单元是否是高压IMS组织,如果是则跳过
|
||||||
String pkOrg = pmoHeadVO.getPk_org();
|
String pkOrg = pmoHeadVO.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 (checkIfOrg(orgCode, configParams)) {
|
if (checkIfOrg(orgCode, configParams)) {
|
||||||
continue;
|
// continue;
|
||||||
}*/
|
|
||||||
// 表头
|
|
||||||
// cpmohid 流程生产订单
|
|
||||||
// pk_org 工厂最新版本
|
|
||||||
// cplanfactoryid 计划组织最新版本
|
|
||||||
// dbilldate 单据日期
|
|
||||||
// vbillcode 流程生产订单号
|
|
||||||
// ctrantypeid 订单交易类型
|
|
||||||
// vtrantypecode 订单交易类型编码
|
|
||||||
// fbillstatus 订单状态
|
|
||||||
// approver 审批人
|
|
||||||
// approvertime 审批日期
|
|
||||||
// billmaker 制单人
|
|
||||||
// dmakedate 制单日期
|
|
||||||
// vnote 备注
|
|
||||||
// creator 创建人
|
|
||||||
// creationtime 创建时间
|
|
||||||
// status C=创建U=修改2=处理完成
|
|
||||||
// 构建插入表头数据的SQL
|
|
||||||
StringBuilder headSqlBuilder = new StringBuilder();
|
|
||||||
headSqlBuilder.append("INSERT INTO BIPOrderMainTab (");
|
|
||||||
headSqlBuilder.append("cpmohid, pk_org, cplanfactoryid, dbilldate, vbillcode, ");
|
|
||||||
headSqlBuilder.append("ctrantypeid, vtrantypecode, fbillstatus, approver, ");
|
|
||||||
headSqlBuilder.append("approvertime, billmaker, dmakedate, vnote, creator, ");
|
|
||||||
headSqlBuilder.append("creationtime, status");
|
|
||||||
headSqlBuilder.append(") VALUES (");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?").append(", ");
|
|
||||||
headSqlBuilder.append("?");
|
|
||||||
headSqlBuilder.append(")");
|
|
||||||
SQLParameter headParams = new SQLParameter();
|
|
||||||
headParams.addParam(pmoHeadVO.getCpmohid());
|
|
||||||
headParams.addParam(pmoHeadVO.getPk_org());
|
|
||||||
headParams.addParam(pmoHeadVO.getCplanfactoryid());
|
|
||||||
headParams.addParam(skipNull(pmoHeadVO.getDbilldate()));
|
|
||||||
headParams.addParam(pmoHeadVO.getVbillcode());
|
|
||||||
headParams.addParam(pmoHeadVO.getCtrantypeid());
|
|
||||||
headParams.addParam(pmoHeadVO.getVtrantypecode());
|
|
||||||
headParams.addParam(pmoHeadVO.getFbillstatus());
|
|
||||||
headParams.addParam(pmoHeadVO.getApprover());
|
|
||||||
headParams.addParam(skipNull(pmoHeadVO.getApprovertime()));
|
|
||||||
headParams.addParam(pmoHeadVO.getBillmaker());
|
|
||||||
headParams.addParam(skipNull(pmoHeadVO.getDmakedate()));
|
|
||||||
headParams.addParam(pmoHeadVO.getVnote());
|
|
||||||
headParams.addParam(pmoHeadVO.getCreator());
|
|
||||||
headParams.addParam(skipNull(pmoHeadVO.getCreationtime()));
|
|
||||||
headParams.addParam("C");// 默认状态为C(新增)
|
|
||||||
List<Map<String, SQLParameter>> bodyParameterList = new ArrayList<>();
|
|
||||||
for (PMOItemVO item : itemVOS) {
|
|
||||||
// cmoid 流程生产订单明细
|
|
||||||
// vrowno 行号
|
|
||||||
// pk_group 集团
|
|
||||||
// pk_org 工厂最新版本
|
|
||||||
// fitemstatus 行状态
|
|
||||||
// cmaterialvid 产品
|
|
||||||
// cunitid 主单位
|
|
||||||
// castunitid 单位
|
|
||||||
// nnum 主数量
|
|
||||||
// nastnum 数量
|
|
||||||
// vchangerate 换算率
|
|
||||||
// nplanputastnum 计划投入数量
|
|
||||||
// nplanputnum 计划投入主数量
|
|
||||||
// nmmastnum 计划产出数量
|
|
||||||
// nmmnum 计划产出主数量
|
|
||||||
// cdeptid 生产部门
|
|
||||||
// cdeptvid 生产部门版本
|
|
||||||
// cemployeeid 业务员
|
|
||||||
// tplanstarttime 计划开工时间
|
|
||||||
// tplanendtime 计划完工时间
|
|
||||||
// twillendtime 预计完工时间
|
|
||||||
// tactstarttime 实际开工时间
|
|
||||||
// tactendtime 实际完工时间
|
|
||||||
// mocloser 关闭人
|
|
||||||
// tmoclosedtime 关闭时间
|
|
||||||
// cbatchid 生产批次
|
|
||||||
// vbatchcode 生产批次号
|
|
||||||
// vnote 备注
|
|
||||||
// cproductorid 生产厂商
|
|
||||||
// cprojectid 项目
|
|
||||||
// vsrctrantypeid 来源交易类型
|
|
||||||
// vsrctrantype 来源交易类型编码
|
|
||||||
// vsrctype 来源单据类型
|
|
||||||
// vsrcid 来源单据
|
|
||||||
// vsrccode 来源单据号
|
|
||||||
// vsrcbid 来源单据明细
|
|
||||||
// vsrcrowno 来源单据行号
|
|
||||||
// crequireorg 需求库存组织最新版本
|
|
||||||
// crequireorgvid 需求库存组织
|
|
||||||
// vfirsttrantypeid 源头交易类型
|
|
||||||
// vfirsttrantype 源头交易类型编码
|
|
||||||
// vfirsttype 源头单据类型
|
|
||||||
// vfirstid 源头单据
|
|
||||||
// vfirstcode 源头单据号
|
|
||||||
// vfirstbid 源头单据明细
|
|
||||||
// vfirstrowno 源头单据行号
|
|
||||||
// vfirstmotype 源头生产订单类型
|
|
||||||
// cfirstmoid 源头生产订单
|
|
||||||
// vfirstmocode 源头生产订单号
|
|
||||||
// cfirstmobid 源头生产订单行
|
|
||||||
// vfirstmorowno 源头生产订单行号
|
|
||||||
// cinwarehouseid 入库仓库
|
|
||||||
// vbillcode 流程生产订单号
|
|
||||||
// cpmohid 流程生产订单表头主键
|
|
||||||
// vsalebillcode 销售订单号
|
|
||||||
// temp_mainmaterialid 主产品最新版本
|
|
||||||
// temp_mainmaterialvid 主产品
|
|
||||||
// temp_mainbid 主产品行
|
|
||||||
// ninnum 合格入库主数量
|
|
||||||
Map<String, SQLParameter> itemMap = new HashMap<>();
|
|
||||||
StringBuilder bodySqlBuilder = new StringBuilder();
|
|
||||||
bodySqlBuilder.append("INSERT INTO BIPOrderDetailTab (");
|
|
||||||
bodySqlBuilder.append("cmoid, vrowno, pk_group, pk_org, fitemstatus, ");
|
|
||||||
bodySqlBuilder.append("cmaterialvid, cunitid, castunitid, nnum, nastnum, ");
|
|
||||||
bodySqlBuilder.append("vchangerate, nplanputastnum, nplanputnum, nmmastnum, nmmnum, ");
|
|
||||||
bodySqlBuilder.append("cdeptid, cdeptvid, cemployeeid, tplanstarttime, tplanendtime, ");
|
|
||||||
bodySqlBuilder.append("twillendtime, tactstarttime, tactendtime, mocloser, tmoclosedtime, ");
|
|
||||||
bodySqlBuilder.append("cbatchid, vbatchcode, vnote, cproductorid, cprojectid, ");
|
|
||||||
bodySqlBuilder.append("vsrctrantypeid, vsrctrantype, vsrctype, vsrcid, vsrccode, ");
|
|
||||||
bodySqlBuilder.append("vsrcbid, vsrcrowno, crequireorg, crequireorgvid, vfirsttrantypeid, ");
|
|
||||||
bodySqlBuilder.append("vfirsttrantype, vfirsttype, vfirstid, vfirstcode, vfirstbid, ");
|
|
||||||
bodySqlBuilder.append("vfirstrowno, vfirstmotype, cfirstmoid, vfirstmocode, cfirstmobid, ");
|
|
||||||
bodySqlBuilder.append("vfirstmorowno, cinwarehouseid, vbillcode, cpmohid, vsalebillcode, ");
|
|
||||||
bodySqlBuilder.append("temp_mainmaterialid, temp_mainmaterialvid, temp_mainbid, ninnum");
|
|
||||||
bodySqlBuilder.append(") VALUES (");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?").append(", ");
|
|
||||||
bodySqlBuilder.append("?");
|
|
||||||
bodySqlBuilder.append(")");
|
|
||||||
// 添加表体参数
|
|
||||||
SQLParameter bodyParams = new SQLParameter();
|
|
||||||
bodyParams.addParam(item.getCmoid());
|
|
||||||
bodyParams.addParam(item.getVrowno());
|
|
||||||
bodyParams.addParam(item.getPk_group());
|
|
||||||
bodyParams.addParam(item.getPk_org());
|
|
||||||
bodyParams.addParam(item.getFitemstatus());
|
|
||||||
bodyParams.addParam(item.getCmaterialvid());
|
|
||||||
bodyParams.addParam(item.getCunitid());
|
|
||||||
bodyParams.addParam(item.getCastunitid());
|
|
||||||
bodyParams.addParam(skipNull(item.getNnum()));
|
|
||||||
bodyParams.addParam(skipNull(item.getNastnum()));
|
|
||||||
bodyParams.addParam(item.getVchangerate());
|
|
||||||
bodyParams.addParam(skipNull(item.getNplanputastnum()));
|
|
||||||
bodyParams.addParam(skipNull(item.getNplanputnum()));
|
|
||||||
bodyParams.addParam(skipNull(item.getNmmastnum()));
|
|
||||||
bodyParams.addParam(skipNull(item.getNmmnum()));
|
|
||||||
bodyParams.addParam(item.getCdeptid());
|
|
||||||
bodyParams.addParam(item.getCdeptvid());
|
|
||||||
bodyParams.addParam(item.getCemployeeid());
|
|
||||||
bodyParams.addParam(skipNull(item.getTplanstarttime()));
|
|
||||||
bodyParams.addParam(skipNull(item.getTplanendtime()));
|
|
||||||
bodyParams.addParam(skipNull(item.getTwillendtime()));
|
|
||||||
bodyParams.addParam(skipNull(item.getTactstarttime()));
|
|
||||||
bodyParams.addParam(skipNull(item.getTactendtime()));
|
|
||||||
bodyParams.addParam(item.getMocloser());
|
|
||||||
bodyParams.addParam(item.getTmoclosedtime());
|
|
||||||
bodyParams.addParam(item.getCbatchid());
|
|
||||||
bodyParams.addParam(item.getVbatchcode());
|
|
||||||
bodyParams.addParam(item.getVnote());
|
|
||||||
bodyParams.addParam(item.getCproductorid());
|
|
||||||
bodyParams.addParam(item.getCprojectid());
|
|
||||||
bodyParams.addParam(item.getVsrctrantypeid());
|
|
||||||
bodyParams.addParam(item.getVsrctrantype());
|
|
||||||
bodyParams.addParam(item.getVsrctype());
|
|
||||||
bodyParams.addParam(item.getVsrcid());
|
|
||||||
bodyParams.addParam(item.getVsrccode());
|
|
||||||
bodyParams.addParam(item.getVsrcbid());
|
|
||||||
bodyParams.addParam(item.getVsrcrowno());
|
|
||||||
bodyParams.addParam(item.getCrequireorg());
|
|
||||||
bodyParams.addParam(item.getCrequireorgvid());
|
|
||||||
bodyParams.addParam(item.getVfirsttrantypeid());
|
|
||||||
bodyParams.addParam(item.getVfirsttrantype());
|
|
||||||
bodyParams.addParam(item.getVfirsttype());
|
|
||||||
bodyParams.addParam(item.getVfirstid());
|
|
||||||
bodyParams.addParam(item.getVfirstcode());
|
|
||||||
bodyParams.addParam(item.getVfirstbid());
|
|
||||||
bodyParams.addParam(item.getVfirstrowno());
|
|
||||||
bodyParams.addParam(item.getVfirstmotype());
|
|
||||||
bodyParams.addParam(item.getCfirstmoid());
|
|
||||||
bodyParams.addParam(item.getVfirstmocode());
|
|
||||||
bodyParams.addParam(item.getCfirstmobid());
|
|
||||||
bodyParams.addParam(item.getVfirstmorowno());
|
|
||||||
bodyParams.addParam(item.getCinwarehouseid());
|
|
||||||
bodyParams.addParam(pmoHeadVO.getVbillcode());
|
|
||||||
bodyParams.addParam(item.getCpmohid());
|
|
||||||
bodyParams.addParam(item.getVsalebillcode());
|
|
||||||
bodyParams.addParam(item.getTemp_mainmaterialid());
|
|
||||||
bodyParams.addParam(item.getTemp_mainmaterialvid());
|
|
||||||
bodyParams.addParam(item.getTemp_mainbid());
|
|
||||||
bodyParams.addParam(skipNull(item.getNinnum()));
|
|
||||||
itemMap.put(bodySqlBuilder.toString(), bodyParams);
|
|
||||||
bodyParameterList.add(itemMap);
|
|
||||||
}
|
}
|
||||||
pushData(headSqlBuilder.toString(), headParams, bodyParameterList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 获取主键值
|
||||||
* 推送同步数据
|
String headPrimaryKeyValue = (String) pmoHeadVO.getAttributeValue("cpmohid");
|
||||||
*/
|
|
||||||
private void pushData(String headSql, SQLParameter headParams, List<Map<String, SQLParameter>> bodyParameterList) throws BusinessException {
|
// 根据是否存在记录构建相应的SQL
|
||||||
logger.error("gyIms-PMO-headSql = " + headSql);
|
String headSql = buildSQL(HEAD_TABLE, HEAD_COLUMNS, "cpmohid", headPrimaryKeyValue);
|
||||||
int i = getImsDao().executeUpdate(headSql, headParams);
|
SQLParameter headParams = buildHeadParameters(pmoHeadVO, headSql.contains("UPDATE"));
|
||||||
if (i != 1) {
|
|
||||||
NCCForUAPLogger.error("gyIms-PMO-headSql = " + headSql);
|
// 处理表体数据
|
||||||
}
|
List<String> bodySqlList = new ArrayList<>();
|
||||||
for (Map<String, SQLParameter> map : bodyParameterList) {
|
List<SQLParameter> bodyParameterList = new ArrayList<>();
|
||||||
String bodySql = map.keySet().iterator().next();
|
|
||||||
int j = getImsDao().executeUpdate(bodySql, map.get(bodySql));
|
for (PMOItemVO item : itemVOS) {
|
||||||
if (j != 1) {
|
String bodyPrimaryKeyValue = (String) item.getAttributeValue("cmoid");
|
||||||
NCCForUAPLogger.error("gyIms-PMO-bodySql = " + bodySql);
|
String bodySql = buildSQL(BODY_TABLE, BODY_COLUMNS, "cmoid", bodyPrimaryKeyValue);
|
||||||
|
SQLParameter bodyParams = buildBodyParameters(item, pmoHeadVO, bodySql.contains("UPDATE"));
|
||||||
|
bodySqlList.add(bodySql);
|
||||||
|
bodyParameterList.add(bodyParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pushData(headSql, headParams, bodySqlList, bodyParameterList);
|
||||||
}
|
}
|
||||||
// logger.error("gyIms-PMO-res = " + result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
||||||
|
|
@ -371,6 +138,156 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String buildSQL(String tableName, String[] columns, String pkColumn, Object pkValue) throws BusinessException {
|
||||||
|
// 检查记录是否存在
|
||||||
|
String checkSql = "SELECT COUNT(1) FROM " + tableName + " WHERE " + pkColumn + " = '" + pkValue + "'";
|
||||||
|
Integer count = (Integer) getImsDao().executeQuery(checkSql, new ColumnProcessor());
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
// 构建UPDATE SQL
|
||||||
|
return buildUpdateSQL(tableName, columns, pkColumn);
|
||||||
|
} else {
|
||||||
|
// 构建INSERT SQL
|
||||||
|
return buildInsertSQL(tableName, columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildInsertSQL(String tableName, String[] columns) {
|
||||||
|
int columnCount = columns.length;
|
||||||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||||||
|
sqlBuilder.append("INSERT INTO ").append(tableName).append(" (");
|
||||||
|
|
||||||
|
for (int i = 0; i < columnCount; i++) {
|
||||||
|
String column = columns[i];
|
||||||
|
sqlBuilder.append(column);
|
||||||
|
if (i < columnCount - 1) {
|
||||||
|
sqlBuilder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlBuilder.append(") VALUES (");
|
||||||
|
for (int i = 0; i < columnCount; i++) {
|
||||||
|
sqlBuilder.append("?");
|
||||||
|
if (i < columnCount - 1) {
|
||||||
|
sqlBuilder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlBuilder.append(")");
|
||||||
|
return sqlBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildUpdateSQL(String tableName, String[] columns, String pkColumn) {
|
||||||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||||||
|
sqlBuilder.append("UPDATE ").append(tableName).append(" SET ");
|
||||||
|
|
||||||
|
boolean first = true;
|
||||||
|
for (String column : columns) {
|
||||||
|
// 主键字段不更新
|
||||||
|
if (!column.equals(pkColumn)) {
|
||||||
|
if (!first) {
|
||||||
|
sqlBuilder.append(", ");
|
||||||
|
}
|
||||||
|
sqlBuilder.append(column).append(" = ?");
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlBuilder.append(" WHERE ").append(pkColumn).append(" = ?");
|
||||||
|
return sqlBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private SQLParameter buildHeadParameters(PMOHeadVO pmoHeadVO, boolean isUpdate) {
|
||||||
|
SQLParameter headParams = new SQLParameter();
|
||||||
|
|
||||||
|
if (isUpdate) {
|
||||||
|
// UPDATE情况:不包含主键字段在参数前面,主键作为WHERE条件在最后
|
||||||
|
for (String column : HEAD_COLUMNS) {
|
||||||
|
if (!"cpmohid".equals(column)) { // 主键字段不作为更新字段
|
||||||
|
if ("status".equals(column)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object value = pmoHeadVO.getAttributeValue(column);
|
||||||
|
if (headNumFields.contains(column)) {
|
||||||
|
value = skipNullForNumber(value);
|
||||||
|
} else {
|
||||||
|
value = skipNull(value);
|
||||||
|
}
|
||||||
|
headParams.addParam(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// status C=创建U=修改2=处理完成
|
||||||
|
headParams.addParam("U"); // 更新状态为U(修改)
|
||||||
|
// 添加主键作为WHERE条件
|
||||||
|
headParams.addParam(pmoHeadVO.getAttributeValue("cpmohid"));
|
||||||
|
} else {
|
||||||
|
// INSERT情况:包含所有字段
|
||||||
|
for (String column : HEAD_COLUMNS) {
|
||||||
|
if ("status".equals(column)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object value = pmoHeadVO.getAttributeValue(column);
|
||||||
|
if (headNumFields.contains(column)) {
|
||||||
|
value = skipNullForNumber(value);
|
||||||
|
} else {
|
||||||
|
value = skipNull(value);
|
||||||
|
}
|
||||||
|
headParams.addParam(value);
|
||||||
|
}
|
||||||
|
// status C=创建U=修改2=处理完成
|
||||||
|
headParams.addParam("C"); // 默认状态为C(新增)
|
||||||
|
}
|
||||||
|
|
||||||
|
return headParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SQLParameter buildBodyParameters(PMOItemVO item, PMOHeadVO pmoHeadVO, boolean isUpdate) {
|
||||||
|
SQLParameter bodyParams = new SQLParameter();
|
||||||
|
|
||||||
|
if (isUpdate) {
|
||||||
|
// UPDATE情况:不包含主键字段在参数前面,主键作为WHERE条件在最后
|
||||||
|
for (String column : BODY_COLUMNS) {
|
||||||
|
if (!"cmoid".equals(column)) { // 主键字段不作为更新字段
|
||||||
|
Object value;
|
||||||
|
if ("vbillcode".equals(column)) {
|
||||||
|
value = pmoHeadVO.getAttributeValue(column);
|
||||||
|
} else {
|
||||||
|
value = item.getAttributeValue(column);
|
||||||
|
}
|
||||||
|
// 数值字段需要特殊处理空值
|
||||||
|
if (bodyNumFields.contains(column)) {
|
||||||
|
value = skipNullForNumber(value);
|
||||||
|
} else {
|
||||||
|
value = skipNull(value);
|
||||||
|
}
|
||||||
|
bodyParams.addParam(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 添加主键作为WHERE条件
|
||||||
|
bodyParams.addParam(item.getAttributeValue("cmoid"));
|
||||||
|
} else {
|
||||||
|
// INSERT情况:包含所有字段
|
||||||
|
for (String column : BODY_COLUMNS) {
|
||||||
|
Object value;
|
||||||
|
if ("vbillcode".equals(column)) {
|
||||||
|
value = pmoHeadVO.getAttributeValue(column);
|
||||||
|
} else {
|
||||||
|
value = item.getAttributeValue(column);
|
||||||
|
}
|
||||||
|
// 数值字段需要特殊处理空值
|
||||||
|
if (bodyNumFields.contains(column)) {
|
||||||
|
value = skipNullForNumber(value);
|
||||||
|
} else {
|
||||||
|
value = skipNull(value);
|
||||||
|
}
|
||||||
|
bodyParams.addParam(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bodyParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 空值安全处理方法
|
* 空值安全处理方法
|
||||||
*
|
*
|
||||||
|
|
@ -393,5 +310,50 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专门处理数值类型的空值
|
||||||
|
*
|
||||||
|
* @param value 需要处理的值
|
||||||
|
* @return 如果为null则返回0,否则返回转换后的数值
|
||||||
|
*/
|
||||||
|
private Object skipNullForNumber(Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// 数值类型转换
|
||||||
|
if (value instanceof nc.vo.pub.lang.UFDouble) {
|
||||||
|
return ((nc.vo.pub.lang.UFDouble) value).toDouble();
|
||||||
|
} else if (value instanceof Number) {
|
||||||
|
return ((Number) value).doubleValue();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(value.toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送数据到IMS系统
|
||||||
|
*/
|
||||||
|
private void pushData(String headSql, SQLParameter headParams, List<String> bodySqlList, List<SQLParameter> bodyParameterList) throws BusinessException {
|
||||||
|
logger.error("gyIms-PMO-headSql = " + headSql);
|
||||||
|
int headRowsAffected = getImsDao().executeUpdate(headSql, headParams);
|
||||||
|
if (headRowsAffected != 1) {
|
||||||
|
NCCForUAPLogger.debug("gyIms-PMO-headSql = " + headSql);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < bodySqlList.size(); i++) {
|
||||||
|
String bodySql = bodySqlList.get(i);
|
||||||
|
SQLParameter parameter = bodyParameterList.get(i);
|
||||||
|
int bodyRowsAffected = getImsDao().executeUpdate(bodySql, parameter);
|
||||||
|
if (bodyRowsAffected != 1) {
|
||||||
|
NCCForUAPLogger.debug("gyIms-PMO-bodySql = " + bodySql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// logger.error("gyIms-PMO-res = " + result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue