流程生产订单审批后推送高压IMS
This commit is contained in:
		
							parent
							
								
									4f213a1dee
								
							
						
					
					
						commit
						93ef0d982a
					
				|  | @ -0,0 +1,385 @@ | |||
| package nc.bs.mmpac.pmo.pac0002.bp.rule; | ||||
| 
 | ||||
| 
 | ||||
| import nc.bs.dao.BaseDAO; | ||||
| import nc.bs.logging.Log; | ||||
| import nc.bs.uapbd.util.MyHelper; | ||||
| import nc.impl.pubapp.pattern.rule.IRule; | ||||
| import nc.jdbc.framework.SQLParameter; | ||||
| import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO; | ||||
| import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO; | ||||
| import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||
| import nc.vo.scmpub.util.ArrayUtil; | ||||
| import nccloud.baseapp.core.log.NCCForUAPLogger; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 流程生产订单审批后推送高压IMS | ||||
|  * | ||||
|  * @author mzr | ||||
|  * @date 2025/9/27 | ||||
|  */ | ||||
| public class AfterApproveSyncImsRule implements IRule<PMOAggVO> { | ||||
| 
 | ||||
|     private static final String LOG_INFO_NAME = "gymeslog"; | ||||
|     private static final Log logger = Log.getInstance(LOG_INFO_NAME); | ||||
|     private Map<String, String> configParams; | ||||
|     // BIP数据源 | ||||
|     public static final BaseDAO baseDAO = new BaseDAO(); | ||||
|     // IMS数据源 | ||||
|     public static final BaseDAO imsDao = new BaseDAO("gyims"); | ||||
| 
 | ||||
|     @Override | ||||
|     public void process(PMOAggVO[] pmoAggVOS) { | ||||
|         if (ArrayUtil.isEmpty(pmoAggVOS)) { | ||||
|             return; | ||||
|         } | ||||
|         configParams = MyHelper.getConfigParams("gy-config", null); | ||||
|         try { | ||||
|             buildSyncData(pmoAggVOS); | ||||
|         } catch (Exception e) { | ||||
|             logger.error("同步生产订单到高压IMS系统失败: " + e.getMessage(), e); | ||||
|             ExceptionUtils.wrappException(e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 构建同步数据 | ||||
|      */ | ||||
|     private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException { | ||||
|         for (PMOAggVO vo : useVOs) { | ||||
|             PMOHeadVO pmoHeadVO = vo.getParentVO(); | ||||
|             PMOItemVO[] itemVOS = vo.getChildrenVO(); | ||||
|             // 判断物料的业务单元是否是高压加工车间W,不是则跳过 | ||||
|             String pkOrg = pmoHeadVO.getPk_org(); | ||||
|             /*String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); | ||||
|             if (checkIfOrg(orgCode, configParams)) { | ||||
|                 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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 推送同步数据 | ||||
|      */ | ||||
|     private void pushData(String headSql, SQLParameter headParams, List<Map<String, SQLParameter>> bodyParameterList) throws BusinessException { | ||||
|         logger.error("gyIms-PMO-headSql = " + headSql); | ||||
|         int i = imsDao.executeUpdate(headSql, headParams); | ||||
|         if (i != 1) { | ||||
|             NCCForUAPLogger.error("gyIms-PMO-headSql = " + headSql); | ||||
|         } | ||||
|         for (Map<String, SQLParameter> map : bodyParameterList) { | ||||
|             String bodySql = map.keySet().iterator().next(); | ||||
|             int j = imsDao.executeUpdate(bodySql, map.get(bodySql)); | ||||
|             if (j != 1) { | ||||
|                 NCCForUAPLogger.error("gyIms-PMO-bodySql = " + bodySql); | ||||
|             } | ||||
|         } | ||||
|         // logger.error("gyIms-PMO-res = " + result); | ||||
|     } | ||||
| 
 | ||||
|     private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException { | ||||
|         String targetCode = configParams.get("imsOrg"); | ||||
|         if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { | ||||
|             throw new BusinessException("未配置组织参数"); | ||||
|         } | ||||
|         String[] orgItem = targetCode.split(","); | ||||
|         for (String orgCode : orgItem) { | ||||
|             if (!orgCode.isEmpty() && orgCode.equals(code)) { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 空值安全处理方法 | ||||
|      * | ||||
|      * @param value 需要处理的值 | ||||
|      * @return 如果是null则返回默认值,否则返回原值 | ||||
|      */ | ||||
|     private Object skipNull(Object value) { | ||||
|         if (value == null) { | ||||
|             return ""; | ||||
|         } | ||||
|         // 处理具体类型的转换 | ||||
|         if (value instanceof nc.vo.pub.lang.UFDouble) { | ||||
|             return ((nc.vo.pub.lang.UFDouble) value).toDouble(); | ||||
|         } else if (value instanceof nc.vo.pub.lang.UFDateTime) { | ||||
|             return ((nc.vo.pub.lang.UFDateTime) value).toString(); | ||||
|         } else if (value instanceof nc.vo.pub.lang.UFDate) { | ||||
|             return ((nc.vo.pub.lang.UFDate) value).toString(); | ||||
|         } else { | ||||
|             return value.toString(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue