高压-备料计划审批后推送高压MES-修改接口
This commit is contained in:
		
							parent
							
								
									93ef0d982a
								
							
						
					
					
						commit
						900748953c
					
				|  | @ -0,0 +1,204 @@ | |||
| package nc.bs.mmpac.pickm.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.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.vo.bd.defdoc.DefdocVO; | ||||
| import nc.vo.mmpac.pickm.entity.AggPickmVO; | ||||
| import nc.vo.mmpac.pickm.entity.PickmHeadVO; | ||||
| import nc.vo.mmpac.pickm.entity.PickmItemVO; | ||||
| import nc.vo.org.OrgVO; | ||||
| import nc.vo.pmpub.project.ProjectHeadVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||
| import nc.vo.scmpub.util.ArrayUtil; | ||||
| 
 | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 备料审批后推送高压MES 修改 | ||||
|  * | ||||
|  * @author houyi | ||||
|  * @date 2025/9/28 | ||||
|  */ | ||||
| public class AfterApproveRuleHighpressureUpdateMes implements IRule<AggPickmVO> { | ||||
| 
 | ||||
|     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(AggPickmVO[] aggPickmVOS) { | ||||
|         if (ArrayUtil.isEmpty(aggPickmVOS)) { | ||||
|             return; | ||||
|         } | ||||
|         configParams = MyHelper.getConfigParams("gy-config", null); | ||||
|         try { | ||||
|             buildSyncData(aggPickmVOS); | ||||
|         } catch (Exception e) { | ||||
|             logger.error("同步备料计划到高压MES系统失败: " + e.getMessage(), e); | ||||
|             ExceptionUtils.wrappException(e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 构建同步数据 | ||||
|      */ | ||||
|     private void buildSyncData(AggPickmVO[] useVOs) throws BusinessException { | ||||
|         BaseDAO baseDAO = new BaseDAO(); | ||||
| 
 | ||||
|         HYPubBO hybo = new HYPubBO(); | ||||
|         JSONObject list = new JSONObject(); | ||||
|         JSONArray jsonArray = new JSONArray(); | ||||
|         for (AggPickmVO vo : useVOs) { | ||||
|             PickmHeadVO pickmHeadVO = vo.getParentVO(); | ||||
|             PickmItemVO[] itemVOS = (PickmItemVO[]) vo.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(); | ||||
|             singleObj.put("materialPreparationPlanNumber", pickmHeadVO.getVbillcode());// 备料计划单号 | ||||
| //            singleObj.put("bipId", pickmHeadVO.getCpickmid());// 主键ID | ||||
|             // 生产部门 | ||||
|             String deptsql = " select 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", pickmHeadVO.getCdeptid()); // 生产部门Id | ||||
| 
 | ||||
|             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", pickmHeadVO.getVfirstbillrowno()); // 顶级来源单据行号 | ||||
|             singleObj.put("orderQuantity", pickmHeadVO.getNastnum() != null ? pickmHeadVO.getNastnum().doubleValue() : null); // 订单数量(计划数量) | ||||
|             singleObj.put("bomVersion", pickmHeadVO.getVbomversionnumber()); // bom版本 | ||||
|             // 物料信息 | ||||
|             String cpsql = "select code,name,graphid,pk_measdoc,materialspec 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("intervalModel", mrl.get("materialspec")); // (物料的自定义字段) | ||||
|             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 | ||||
| 
 | ||||
|             // 创建子项数组 | ||||
|             JSONArray contentArray = new JSONArray(); | ||||
|             for (PickmItemVO item : itemVOS) { | ||||
|                 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,materialspec 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", material.get("graphid")); // 图号 | ||||
|                 Object unit = hybo.findColValue("bd_measdoc", "code", " pk_measdoc = '" + material.get("pk_measdoc") + "' "); | ||||
|                 itemObj.put("unit", unit); // 规格单位 | ||||
|                 // 生产信息 | ||||
| //                itemObj.put("intervalModel", material.get("materialspec")); // 产品类型 | ||||
|                 itemObj.put("lineNumber", String.valueOf(item.getVrowno())); // 行号 | ||||
|                 // 项目编码 | ||||
|                 String cprojectid = pickmHeadVO.getCprojectid();// 项目id | ||||
|                 String projectCode = MyHelper.getStrValByCondition(ProjectHeadVO.getDefaultTableName(), ProjectHeadVO.PROJECT_CODE, | ||||
|                         ProjectHeadVO.PK_PROJECT + " = '" + cprojectid + "'"); | ||||
|                 singleObj.put("cbprojectid", projectCode); | ||||
|                 // 生产厂商 | ||||
| //                String productor = item.getCbproductorid();// 生产厂商id | ||||
|                 String productorCode = getDefCode("Defdoc-BD006_0xx", item.getCbproductorid()); | ||||
|                 singleObj.put("cbproductorid", productorCode); | ||||
| 
 | ||||
|                 contentArray.add(itemObj); // 将子项添加到数组 | ||||
|             } | ||||
| 
 | ||||
|             singleObj.put("itemList", contentArray); // 将子项数组添加到主对象 | ||||
|             jsonArray.add(singleObj); | ||||
|             list.put("list", jsonArray); | ||||
|         } | ||||
|         pushData(list); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 获取自定义项信息 | ||||
|      */ | ||||
|     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 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("materialRequirementsAdd"); | ||||
|         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 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