高压-流程生产订单取消审批后推送高压MES-删除接口
This commit is contained in:
		
							parent
							
								
									9401a7b4be
								
							
						
					
					
						commit
						9f392d2142
					
				|  | @ -93,5 +93,7 @@ public class PMOApproveBP { | |||
|         ICompareRule<PMOAggVO> auditSupplyRule = new PMOApproveUnAuditSupplyRule(); | ||||
|         processer.addAfterRule(auditSupplyRule); | ||||
|         processer.addAfterRule(new AfterUnApproveSyncEpicMesRule()); | ||||
|         // 生产订单取消审批后推送高压MES | ||||
|         processer.addAfterRule(new AfterApproveCancelSyncHighpressureMesRule()); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,141 @@ | |||
| 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.logging.Log; | ||||
| import nc.bs.trade.business.HYPubBO; | ||||
| 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.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.org.OrgVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||
| import nc.vo.scmpub.util.ArrayUtil; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 流程生产订单取消审批后推送高压MES-删除接口 | ||||
|  * | ||||
|  * @author houyi | ||||
|  * @date 2025/9/28 | ||||
|  */ | ||||
| public class AfterApproveCancelSyncHighpressureMesRule 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; | ||||
| 
 | ||||
|     @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("同步生产订单到高压MES系统失败: " + e.getMessage(), e); | ||||
|             ExceptionUtils.wrappException(e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 构建同步数据 | ||||
|      */ | ||||
|     private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException { | ||||
|         BaseDAO baseDAO = new BaseDAO(); | ||||
| 
 | ||||
|         HYPubBO hybo = new HYPubBO(); | ||||
|         JSONObject list = new JSONObject(); | ||||
|         JSONArray jsonArray = new JSONArray(); | ||||
|         for (PMOAggVO vo : useVOs) { | ||||
|             PMOHeadVO pmoHeadVO = vo.getParentVO(); | ||||
|             PMOItemVO[] itemVOS = vo.getChildrenVO(); | ||||
|             // 判断物料的业务单元是否是高压公司,不是则跳过 | ||||
|             String pkOrg = pmoHeadVO.getPk_org(); | ||||
|             String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); | ||||
|             if (checkIfOrg(orgCode, configParams)) { | ||||
|                 continue; | ||||
|             } | ||||
| //            JSONObject singleObj = new JSONObject(); | ||||
|             String sql1 = " select user_name from sm_user where cuserid = '" + pmoHeadVO.getModifier() + "' "; | ||||
|             String bipCreateBy = (String) baseDAO.executeQuery(sql1, new ColumnProcessor()); | ||||
|             list.put("bipUpdateBy", bipCreateBy); // 修改人ID | ||||
| 
 | ||||
|             // 创建子项数组 | ||||
|             JSONArray contentArray = new JSONArray(); | ||||
|             JSONArray cmoidArray = new JSONArray(); | ||||
|             for (PMOItemVO item : itemVOS) { | ||||
|                 // 填充子项基础信息 | ||||
|                 String cmoid = item.getCmoid(); | ||||
|                 cmoidArray.add(cmoid); | ||||
|             } | ||||
|             ArrayList<Object> cmoidObj = new ArrayList<>(Arrays.asList(cmoidArray.toArray())); | ||||
|             // 使用 String.join 进行字符串拼接 | ||||
|             String result = ""; | ||||
|             StringBuilder sb = new StringBuilder(); | ||||
|             if (cmoidObj.size() > 1) { | ||||
|                 for (int i = 0; i < cmoidObj.size(); i++) { | ||||
|                     sb.append("'").append(cmoidObj.get(i)).append("'"); | ||||
|                     if (i < cmoidObj.size() - 1) { | ||||
|                         sb.append(","); | ||||
|                     } | ||||
|                 } | ||||
|                 result = sb.toString(); | ||||
|             } else { | ||||
|                 result = "'" + (String) cmoidObj.get(0) + "'"; | ||||
|             } | ||||
|             list.put("bipChildId", result); // 子项主键ID | ||||
| 
 | ||||
|         } | ||||
|         pushData(list); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 推送同步数据 | ||||
|      */ | ||||
|     private void pushData(JSONObject param) throws BusinessException { | ||||
|         // 转json字符串的时候保留null值 | ||||
|         String jsonStr = JSON.toJSONString(param, | ||||
|                 SerializerFeature.WriteMapNullValue, | ||||
|                 SerializerFeature.WriteNullStringAsEmpty | ||||
|         ); | ||||
|         logger.error("gyMes-PMO-param = " + jsonStr); | ||||
|         String baseUrl = configParams.get("mesBaseUrl"); | ||||
|         String requestUrl = baseUrl + configParams.get("productionOrderCancel"); | ||||
|         logger.error("gyMes-PMO-url = " + requestUrl); | ||||
|         String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); | ||||
|         JSONObject resultObj = JSONObject.parseObject(result); | ||||
|         logger.error("gyMes-PMO-res = " + result); | ||||
| 
 | ||||
|         if (!"200".equals(resultObj.getString("code"))) { | ||||
|             logger.error("gyMes-PMO-error,result[" + resultObj.toJSONString() + "]"); | ||||
|             throw new BusinessException("流程生产订单推送高压MES错误:" + resultObj.getString("msg")); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     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; | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue