流程生产订单点击备料计划重算推送高压MES
This commit is contained in:
		
							parent
							
								
									8ed886eb99
								
							
						
					
					
						commit
						2e1795ce48
					
				|  | @ -6,6 +6,7 @@ | |||
| package nc.bs.mmpac.pmo.pac0002.bp; | ||||
| 
 | ||||
| import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterPickmRecalUpdateBuyingreqRule; | ||||
| import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterPickmRuleHighpressureRule; | ||||
| import nc.bs.mmpac.pmo.pac0002.pluginpoint.PMOPluginPoint; | ||||
| import nc.bs.mmpac.pmo.pac0002.rule.PMOPickmRecalRule; | ||||
| import nc.bs.mmpac.pmo.pac0002.rule.PMOPickmRecalStatusRule; | ||||
|  | @ -34,5 +35,7 @@ public class PMOPickmRecalBP { | |||
|         processer.addBeforeRule(bomrtrule); | ||||
|         IRule<PMOAggVO> aggVOIRule = new AfterPickmRecalUpdateBuyingreqRule(); | ||||
|         processer.addBeforeRule(aggVOIRule); | ||||
|         //流程生产订单点击备料计划重算推送高压MES | ||||
|         processer.addBeforeRule(new AfterPickmRuleHighpressureRule()); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,298 @@ | |||
| package nc.bs.mmpac.pmo.pac0002.bp.rule; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.alibaba.fastjson.serializer.SerializerFeature; | ||||
| 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.trade.business.HYSuperDMO; | ||||
| import nc.bs.uapbd.util.MyHelper; | ||||
| import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; | ||||
| import nc.impl.pubapp.pattern.rule.IRule; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.md.model.MetaDataException; | ||||
| import nc.md.persist.framework.IMDPersistenceQueryService; | ||||
| import nc.pubitf.uapbd.IMaterialPubService; | ||||
| import nc.uif.pub.exception.UifException; | ||||
| import nc.util.mmf.framework.base.MMValueCheck; | ||||
| import nc.vo.bd.defdoc.DefdocVO; | ||||
| import nc.vo.bd.material.plan.MaterialPlanVO; | ||||
| import nc.vo.mmpac.pickm.entity.AggPickmVO; | ||||
| import nc.vo.mmpac.pickm.entity.PickmHeadVO; | ||||
| import nc.vo.mmpac.pickm.entity.PickmItemVO; | ||||
| import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO; | ||||
| import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO; | ||||
| import nc.vo.org.OrgVO; | ||||
| import nc.vo.pmpub.project.ProjectHeadVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||
| 
 | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.*; | ||||
| import java.util.stream.Stream; | ||||
| 
 | ||||
| /** | ||||
|  * 流程生产订单备料重算后下推备料计划修改mes | ||||
|  */ | ||||
| public class AfterPickmRuleHighpressureRule 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; | ||||
| 
 | ||||
|     // -------------------------- 线程安全的日期格式化工具(解决SimpleDateFormat线程安全问题) -------------------------- | ||||
|     private static final ThreadLocal<SimpleDateFormat> DATETIME_FORMATTER = ThreadLocal.withInitial( | ||||
|             () -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") | ||||
|     ); | ||||
|     private static final ThreadLocal<SimpleDateFormat> DATE_FORMATTER = ThreadLocal.withInitial( | ||||
|             () -> new SimpleDateFormat("yyyy-MM-dd") | ||||
|     ); | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public void process(PMOAggVO[] pmoAggVOS) { | ||||
|         // 1. 根据生产订单查询备料计划 | ||||
|         String cmoid = null; | ||||
|         for (int i = 0; i < pmoAggVOS.length; i++) { | ||||
|             PMOAggVO pmoAggVO = pmoAggVOS[i]; | ||||
|             PMOItemVO[] childrenVO = pmoAggVO.getChildrenVO(); | ||||
|             // 循环生产报告子表 | ||||
|             for (int j = 0; j < childrenVO.length; j++) { | ||||
|                 PMOItemVO pmoItemVO = childrenVO[j]; | ||||
|                 cmoid = pmoItemVO.getCmoid(); | ||||
|             } | ||||
|         } | ||||
|         String whereSql = "nvl(mm_pickm.dr,0) = 0 and mm_pickm.vsourcemorowid = '" + cmoid + "'"; | ||||
|         IMDPersistenceQueryService aggvoQueryService = NCLocator.getInstance() | ||||
|                 .lookup(IMDPersistenceQueryService.class); | ||||
|         // 根据主键查询得到aggvo | ||||
|         @SuppressWarnings("unchecked") | ||||
|         ArrayList<AggPickmVO> aggVOs = null; | ||||
|         try { | ||||
|             aggVOs = (ArrayList<AggPickmVO>) aggvoQueryService | ||||
|                     .queryBillOfVOByCond(AggPickmVO.class, whereSql, true, false); | ||||
|         } catch (MetaDataException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } | ||||
|         if (aggVOs.size() <= 0) { | ||||
|             logger.info("待同步的备料计划数组为空,直接返回"); | ||||
|             return; | ||||
|         } | ||||
|         // 2. 数组转换 | ||||
|         AggPickmVO[] aggPickmVOS = aggVOs.toArray(new AggPickmVO[0]); | ||||
|         // 3. 加载配置参数(失败直接抛业务异常,阻断流程) | ||||
|         try { | ||||
|             configParams = MyHelper.getConfigParams("gy-config", null); | ||||
|             if (configParams == null || configParams.isEmpty()) { | ||||
|                 throw new BusinessException("同步高压MES系统失败:未加载到\"gy-config\"配置参数"); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             logger.error("加载同步配置参数失败", e); | ||||
|             ExceptionUtils.wrappException(new BusinessException("加载配置参数异常:" + e.getMessage(), e)); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // 4. 构建同步数据并执行同步(统一异常捕获) | ||||
|         try { | ||||
|             List<Map<String, Object>> mainDataList = new ArrayList<>(); // 主表数据 | ||||
|             List<Map<String, Object>> detailDataList = new ArrayList<>(); // 子表数据 | ||||
|             buildSyncData(aggPickmVOS, mainDataList, detailDataList); | ||||
| 
 | ||||
|             // 5. 若有数据则执行同步(取第一个主表的cpickmid作为关键标识,若主表为空则不同步) | ||||
| //            String targetCpickmid = mainDataList.isEmpty() ? null : (String) mainDataList.get(0).get("cpickmid"); | ||||
| //            pushIms(mainDataList, detailDataList, targetCpickmid); | ||||
|         } | ||||
| //        catch (BusinessException e) { | ||||
| //            // 业务异常:直接包装抛出(NC框架会处理) | ||||
| //            logger.error("备料计划同步IMS业务异常,关键备料单号:" + getCpickmidFromAgg(aggPickmVOS) + ""); | ||||
| //            ExceptionUtils.wrappException(e); | ||||
| //        } | ||||
|         catch (Exception e) { | ||||
|             // 未知异常:转为业务异常,避免上游捕获到RuntimeException | ||||
|             logger.error("同步备料计划到高压MES系统失败: " + e.getMessage(), e); | ||||
|             ExceptionUtils.wrappException(e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     private void buildSyncData(AggPickmVO[] aggPickmVOS, List<Map<String, Object>> mainDataList, List<Map<String, Object>> detailDataList) throws BusinessException { | ||||
|         BaseDAO baseDAO = new BaseDAO(); | ||||
| 
 | ||||
|         HYPubBO hybo = new HYPubBO(); | ||||
|         JSONObject list = new JSONObject(); | ||||
|         JSONArray jsonArray = new JSONArray(); | ||||
|         for (AggPickmVO aggVO : aggPickmVOS) { | ||||
|             PickmHeadVO pickmHeadVO = aggVO.getParentVO(); | ||||
|             PickmItemVO[] itemVOS = (PickmItemVO[]) aggVO.getChildrenVO(); | ||||
|             // 判断物料的业务单元是否是高压公司,不是则跳过 | ||||
|             String pkOrg = pickmHeadVO.getPk_org(); | ||||
|             String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); | ||||
|             if (checkIfOrg(orgCode, configParams)) { | ||||
|                 continue; | ||||
|             } | ||||
|             JSONObject singleObj = new JSONObject(); | ||||
|             // 创建子项数组 | ||||
|             JSONArray contentArray = new JSONArray(); | ||||
| 
 | ||||
|             singleObj.put("materialPreparationPlanNumber", pickmHeadVO.getVbillcode());// 备料计划单号 | ||||
|             singleObj.put("bipId", pickmHeadVO.getCpickmid());// 主键ID | ||||
|             // 生产部门 | ||||
|             String deptsql = " select code,name from org_dept  where  pk_dept='" + pickmHeadVO.getCdeptid() + "' and  dr=0 "; | ||||
|             Map<String, Object> dept = (Map<String, Object>) baseDAO.executeQuery(deptsql, new MapProcessor()); | ||||
|             singleObj.put("bipDeptName", dept.get("name")); // 生产部门 | ||||
|             singleObj.put("bipDeptId", dept.get("code")); // 生产部门编码 | ||||
| 
 | ||||
|             singleObj.put("bipProcessProductionOrderId", pickmHeadVO.getVsourcemocode()); // 流程生产订单号 | ||||
|             singleObj.put("bipProcessProductionOrderRowNum", pickmHeadVO.getVsourcemorowcode()); // 来源单据号行号 | ||||
|             singleObj.put("bipParentProcessProductionOrderId", pickmHeadVO.getVfirstbillcode()); // 上级来源单据号 | ||||
|             singleObj.put("bipParentProcessProductionOrderRowNum", pickmHeadVO.getVfirstbillrowno()); // 上级来源单据行号 | ||||
|             singleObj.put("bipOriginProcessProductionOrderId", pickmHeadVO.getVsalebillcode()); // 顶级来源单据号 | ||||
|             singleObj.put("bipOriginProcessProductionOrderRowNum", ""); // 顶级来源单据行号 | ||||
|             singleObj.put("orderQuantity", pickmHeadVO.getNastnum() != null ? pickmHeadVO.getNastnum().doubleValue() : null); // 订单数量(计划数量) | ||||
|             singleObj.put("bomVersion", pickmHeadVO.getVbomversionnumber()); // bom版本 | ||||
|             // 物料信息 | ||||
|             String cpsql = "select code,name,graphid,pk_measdoc,materialtype from bd_material where pk_material = '" + pickmHeadVO.getCmaterialvid() + "' "; | ||||
|             Map<String, Object> mrl = (Map<String, Object>) baseDAO.executeQuery(cpsql, new MapProcessor()); | ||||
|             singleObj.put("productCode", mrl.get("code")); // 产品编码 | ||||
|             singleObj.put("productName", mrl.get("name")); // 产品名称 | ||||
| 
 | ||||
|             singleObj.put("processCode", "(物料的自定义字段)"); // 产品编码的工序(物料的自定义字段) | ||||
|             singleObj.put("requiredDate", pickmHeadVO.getDmakedate().toString()); // 需用日期 | ||||
|             String sql1 = " select user_name from sm_user where cuserid = '" + pickmHeadVO.getModifier() + "' "; | ||||
|             String bipCreateBy = (String) baseDAO.executeQuery(sql1, new ColumnProcessor()); | ||||
| 
 | ||||
|             singleObj.put("bipUpdateBy", bipCreateBy); // 修改人ID | ||||
| 
 | ||||
|             // 创建子项数组 | ||||
|             for (PickmItemVO item : itemVOS) { | ||||
|                 String cmaterialvid = item.getCbmaterialid(); | ||||
|                 Map<String, MaterialPlanVO> planMap = queryMaterialPlanInfoByPks(new String[]{cmaterialvid}, pkOrg, | ||||
|                         new String[]{MaterialPlanVO.DEF1}); | ||||
|                 String drawingNumber = ""; | ||||
|                 if (MMValueCheck.isNotEmpty(planMap) && | ||||
|                         MMValueCheck.isNotEmpty(planMap.get(cmaterialvid))) { | ||||
|                     drawingNumber = planMap.get(cmaterialvid).getDef1(); | ||||
|                 } | ||||
| 
 | ||||
|                 JSONObject itemObj = new JSONObject(); | ||||
| 
 | ||||
|                 itemObj.put("bipChildId", item.getCpickm_bid()); // 子项主键ID | ||||
|                 itemObj.put("quantityPerSet", item.getNunituseastnum() != null ? item.getNunituseastnum().doubleValue() : null); // 单套数量(单位用量) | ||||
|                 itemObj.put("reservedQuantity", item.getNatpastnum() != null ? item.getNatpastnum().doubleValue() : null); // 预留数量 | ||||
|                 itemObj.put("cumulativePendingQuantity", item.getNshouldastnum() != null ? item.getNshouldastnum().doubleValue() : null); // 累计待发数量 | ||||
|                 itemObj.put("cumulativeIssuedQuantity", item.getNaccoutastnum() != null ? item.getNaccoutastnum().doubleValue() : null); // 累计出库数量 | ||||
|                 itemObj.put("totalQuantity", item.getNplanoutnum() != null ? item.getNplanoutnum().doubleValue() : null); // 总数量(计划出库主数量) | ||||
| 
 | ||||
|                 // 物料信息 | ||||
|                 String mrlsql = "select code,name,graphid,pk_measdoc,materialtype from bd_material where pk_material = '" + item.getCbmaterialid() + "' "; | ||||
|                 Map<String, Object> material = (Map<String, Object>) baseDAO.executeQuery(mrlsql, new MapProcessor()); | ||||
|                 itemObj.put("materialCode", material.get("code")); // 物料编码 | ||||
|                 itemObj.put("materialName", material.get("name")); // 物料名称 | ||||
|                 itemObj.put("drawingNumber", drawingNumber); | ||||
| 
 | ||||
|                 Object unit = hybo.findColValue("bd_measdoc", "code", " pk_measdoc = '" + material.get("pk_measdoc") + "' "); | ||||
|                 itemObj.put("unit", unit); // 规格单位 | ||||
|                 // 生产信息 | ||||
|                 itemObj.put("intervalModel", material.get("materialtype")); // 产品类型 | ||||
|                 itemObj.put("lineNumber", String.valueOf(item.getVrowno())); // 行号 | ||||
|                 // 项目编码 | ||||
|                 String cprojectid = item.getCbprojectid();// 项目id | ||||
|                 String projectCode = MyHelper.getStrValByCondition(ProjectHeadVO.getDefaultTableName(), ProjectHeadVO.PROJECT_CODE, | ||||
|                         ProjectHeadVO.PK_PROJECT + " = '" + cprojectid + "'"); | ||||
|                 itemObj.put("cbprojectid", projectCode); | ||||
|                 // 生产厂商 | ||||
|                 String productorCode = getDefCode("BD006_0xx", item.getCbproductorid()); | ||||
|                 itemObj.put("cbproductorid", productorCode); | ||||
| 
 | ||||
|                 contentArray.add(itemObj); // 将子项添加到数组 | ||||
|             } | ||||
|             singleObj.put("itemList", contentArray); // 将子项数组添加到主对象 | ||||
|             jsonArray.add(singleObj); | ||||
|             list.put("list", jsonArray); | ||||
|         } | ||||
|         if (!list.isEmpty()) { | ||||
|             pushData(list); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 推送同步数据 | ||||
|      */ | ||||
|     private void pushData(JSONObject param) throws BusinessException { | ||||
|         // 转json字符串的时候保留null值 | ||||
|         String jsonStr = JSON.toJSONString(param, | ||||
|                 SerializerFeature.WriteMapNullValue, | ||||
|                 SerializerFeature.WriteNullStringAsEmpty | ||||
|         ); | ||||
|         logger.error("gyMes-Pickm-param = " + jsonStr); | ||||
|         String baseUrl = configParams.get("mesBaseUrl"); | ||||
|         String requestUrl = baseUrl + configParams.get("materialRequirementsUpdate"); | ||||
|         logger.error("gyMes-Pickm-url = " + requestUrl); | ||||
|         String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); | ||||
|         JSONObject resultObj = JSONObject.parseObject(result); | ||||
|         logger.error("gyMes-Pickm-res = " + result); | ||||
| 
 | ||||
|         if (!"200".equals(resultObj.getString("code"))) { | ||||
|             logger.error("gyMes-Pickm-error,result[" + resultObj.toJSONString() + "]"); | ||||
|             throw new BusinessException("备料计划推送高压MES错误:" + resultObj.getString("msg")); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 获取自定义项信息 | ||||
|      */ | ||||
|     private String getDefCode(String code, String pk_defdoc) { | ||||
|         String res = ""; | ||||
|         String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 )  and dr = 0 and pk_defdoc = '" + pk_defdoc + "'"; | ||||
|         try { | ||||
|             DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); | ||||
|             if (defdocVOs != null && defdocVOs.length > 0) { | ||||
|                 res = defdocVOs[0].getCode().trim(); | ||||
|             } | ||||
|         } catch (DAOException e) { | ||||
|             logger.error("gyMes-SaleOrder-error,getDefCode[" + e.getMessage() + "]"); | ||||
|         } | ||||
|         return res; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 判断是否跳过该组织 | ||||
|      */ | ||||
|     private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException { | ||||
|         String targetCode = configParams.get("gyOrg"); | ||||
|         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; | ||||
|     } | ||||
| 
 | ||||
|     public static Map<String, MaterialPlanVO> queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg, | ||||
|                                                                          String[] fields) throws BusinessException { | ||||
|         Map<String, MaterialPlanVO> map = null; | ||||
|         List<String> vids = Stream.of(pks).filter(Objects::nonNull).distinct().toList(); | ||||
|         if (vids.isEmpty()) { | ||||
|             map = new HashMap<>(); | ||||
|         } else { | ||||
|             map = NCLocator.getInstance().lookup(IMaterialPubService.class) | ||||
|                     .queryMaterialPlanInfoByPks(vids.toArray(new String[0]), pk_stockorg, fields); | ||||
|         } | ||||
| 
 | ||||
|         return map; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue