feat(material): 新增精密物料推送启源MES的后端action
This commit is contained in:
		
							parent
							
								
									3d0a463d1a
								
							
						
					
					
						commit
						00395876f7
					
				|  | @ -0,0 +1,276 @@ | ||||||
|  | package nccloud.web.uapbd.material.action; | ||||||
|  | 
 | ||||||
|  | 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.jdbc.framework.processor.MapProcessor; | ||||||
|  | import nc.pubitf.uapbd.IMaterialPubService; | ||||||
|  | import nc.util.mmf.framework.base.MMValueCheck; | ||||||
|  | import nc.vo.bd.defdoc.DefdocVO; | ||||||
|  | import nc.vo.bd.material.MaterialVO; | ||||||
|  | import nc.vo.bd.material.plan.MaterialPlanVO; | ||||||
|  | import nc.vo.bd.material.stock.MaterialStockVO; | ||||||
|  | import nc.vo.bd.stordoc.StordocVO; | ||||||
|  | import nc.vo.org.OrgVO; | ||||||
|  | import nc.vo.pub.BusinessException; | ||||||
|  | import nccloud.api.rest.utils.ResultMessageUtil; | ||||||
|  | import nccloud.framework.core.exception.ExceptionUtils; | ||||||
|  | import nccloud.framework.core.json.IJson; | ||||||
|  | import nccloud.framework.web.action.itf.ICommonAction; | ||||||
|  | import nccloud.framework.web.container.IRequest; | ||||||
|  | import nccloud.framework.web.json.JsonFactory; | ||||||
|  | import nccloud.web.mmpub.pub.resexp.PfResumeExceptionNccUtils; | ||||||
|  | 
 | ||||||
|  | import java.util.*; | ||||||
|  | import java.util.stream.Stream; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 精密-物料新增修改后同步启源的物料 | ||||||
|  |  * | ||||||
|  |  * @author mzr | ||||||
|  |  * @date 2025/10/25 | ||||||
|  |  */ | ||||||
|  | public class MaterialJmPushToQyMesAction implements ICommonAction { | ||||||
|  |     private static final String LOG_INFO_NAME = "jmqylog"; | ||||||
|  |     private static final Log logger = Log.getInstance(LOG_INFO_NAME); | ||||||
|  |     private static final String reqUrl = "/IF_QyErpApi.ashx?action=addwlxx"; | ||||||
|  |     private Map<String, String> configParams; | ||||||
|  |     private String pkOrg1 = ""; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public Object doAction(IRequest request) { | ||||||
|  |         String read = request.read(); | ||||||
|  | 
 | ||||||
|  |         HYPubBO hyPub = new HYPubBO(); | ||||||
|  |         try { | ||||||
|  |             IJson json = JsonFactory.create(); | ||||||
|  |             Map<String, Object> info = json.fromJson(read, Map.class); | ||||||
|  |             // 获取所有物料编码 | ||||||
|  |             String pks = (String) info.get("pks"); | ||||||
|  |             if (pks == null) { | ||||||
|  |                 ExceptionUtils.wrapBusinessException("物料不能为空"); | ||||||
|  |             } | ||||||
|  |             configParams = MyHelper.getConfigParams("jm-config", null); | ||||||
|  |             if (configParams.isEmpty()) { | ||||||
|  |                 throw new BusinessException("精密启源接口缺少配置"); | ||||||
|  |             } | ||||||
|  |             pkOrg1 = MyHelper.getStrValByCondition(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, OrgVO.CODE + " = 'C038' and ISBUSINESSUNIT = 'Y'"); | ||||||
|  |             List<MaterialVO> useVOs = new ArrayList<>(); | ||||||
|  |             MaterialVO useVO = (MaterialVO) hyPub.queryByPrimaryKey(MaterialVO.class, pks); | ||||||
|  |             Integer num = MyHelper.checkIfOrg(configParams, pks, "jmOrg"); | ||||||
|  |             if (num <= 0) { | ||||||
|  |                 ExceptionUtils.wrapBusinessException("请先将物料分配给精密"); | ||||||
|  |             } | ||||||
|  |             useVOs.add(useVO); | ||||||
|  |             buildSyncData(useVOs); | ||||||
|  |             return ResultMessageUtil.toJSON(true, "推送成功"); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             return PfResumeExceptionNccUtils.handleResumeException(ex); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 构建同步数据 | ||||||
|  |      */ | ||||||
|  |     private void buildSyncData(List<MaterialVO> useVOs) throws BusinessException { | ||||||
|  |         for (MaterialVO vo : useVOs) { | ||||||
|  |             String pkMaterial = vo.getPk_material(); | ||||||
|  |             // 字段值翻译 | ||||||
|  |             // 计量单位 | ||||||
|  |             Map unitMap = getGoodsInfo(pkMaterial); | ||||||
|  |             Map<String, MaterialPlanVO> planMap = queryMaterialPlanInfoByPks(new String[]{pkMaterial}, pkOrg1, | ||||||
|  |                     new String[]{MaterialPlanVO.DEF2}); | ||||||
|  |             String qyCode = ""; | ||||||
|  |             if (MMValueCheck.isNotEmpty(planMap) && | ||||||
|  |                     MMValueCheck.isNotEmpty(planMap.get(pkMaterial))) { | ||||||
|  |                 qyCode = planMap.get(pkMaterial).getDef2(); | ||||||
|  |             } else { | ||||||
|  |                 qyCode = vo.getCode(); | ||||||
|  |             } | ||||||
|  |             if (MMValueCheck.isEmpty(qyCode)) { | ||||||
|  |                 throw new BusinessException("请先设置启源物料编码"); | ||||||
|  |             } | ||||||
|  |             // 1=未启用;2=已启用;3=已停用; | ||||||
|  |             Integer enablestate = vo.getEnablestate(); | ||||||
|  |             String statusCode = (3 == enablestate) ? "1" : "0"; | ||||||
|  |             Map<String, Object> stockMap = MyHelper.getMapValByCondition(MaterialStockVO.getDefaultTableName(), "def3,def4,martype,pk_stordoc", | ||||||
|  |                     MaterialStockVO.PK_MATERIAL + " = '" + pkMaterial + "' and pk_org = '" + pkOrg1 + "'"); | ||||||
|  |             // 制造件传启源 | ||||||
|  |             if (!"MR".equals(stockMap.get("martype"))) { | ||||||
|  |                 throw new BusinessException("精密物料只有制造件传启源"); | ||||||
|  |             } | ||||||
|  |             // 物料标志和产品分类字段在库存信息页签中,分配物料的时候没有默认值,需要在此处设置 | ||||||
|  |             // 物料标志 | ||||||
|  |             String wlbz = "产品"; | ||||||
|  |             String wlbzId = stockMap.get("def3") + ""; | ||||||
|  |             String defName = getDefName("zdy-jmzz001", wlbzId); | ||||||
|  |             if (MMValueCheck.isNotEmpty(defName)) { | ||||||
|  |                 wlbz = defName; | ||||||
|  |             } | ||||||
|  |             // 产品分类 | ||||||
|  |             String cpfl; | ||||||
|  |             String cpflId = stockMap.get("def4") + ""; | ||||||
|  |             String defName1 = getDefName("zdy-jmzz002", cpflId); | ||||||
|  |             if ("产品".equals(wlbz) && MMValueCheck.isEmpty(defName1)) { | ||||||
|  |                 throw new BusinessException("精密物料的物料标志是产品但缺少产品分类"); | ||||||
|  |             } | ||||||
|  |             cpfl = defName1; | ||||||
|  |             // 主仓库 | ||||||
|  |             String pk_stordoc = stockMap.get("pk_stordoc") + ""; | ||||||
|  |             String warehouseCode = MyHelper.getStrValByCondition(StordocVO.getDefaultTableName(), StordocVO.CODE, | ||||||
|  |                     StordocVO.PK_STORDOC + " = '" + pk_stordoc + "'"); | ||||||
|  |             // 组装数据 | ||||||
|  |             JSONObject singleObj = new JSONObject(); | ||||||
|  |             // 批次编号,用于唯一标识当前传输的物料数据批次,便于追溯和批量处理 | ||||||
|  |             long cts = System.currentTimeMillis(); | ||||||
|  |             singleObj.put("batchid", cts); | ||||||
|  |             JSONObject contentObj = new JSONObject(); | ||||||
|  |             // 计划信息自定义项2(原系统编码)BIP传启源物料档案的物料编码,BIP中物料编码传启源自定义字段“BIP物料编码” | ||||||
|  |             contentObj.put("meswlbh", qyCode); // 启源物料编码 | ||||||
|  |             contentObj.put("bipwlbh", vo.getCode()); // BIP物料编码 | ||||||
|  |             contentObj.put("wlmc", vo.getName()); // 物料名称 | ||||||
|  |             String wlxhgg = MyHelper.skipNull(vo.getMaterialtype()) + MyHelper.skipNull(vo.getMaterialspec()); | ||||||
|  |             contentObj.put("wlxhgg", wlxhgg); // 物料型号规格 | ||||||
|  |             contentObj.put("wlfl", ""); // 物料分类 | ||||||
|  |             contentObj.put("cpfl", cpfl); // 产品分类 | ||||||
|  |             contentObj.put("wlbz", wlbz); // 物料标志 | ||||||
|  |             contentObj.put("sjjldw", unitMap.get("unitname")); // 设计计量单位 | ||||||
|  |             contentObj.put("cgjldw", unitMap.get("deputy_unitname")); // 采购计量单位 | ||||||
|  |             contentObj.put("zhxs", unitMap.getOrDefault("convertRate", "1.00")); // 转换系数 | ||||||
|  |             contentObj.put("flag_fq", statusCode); // 1/0 传递1代表物料废弃 | ||||||
|  |             contentObj.put("zcfck", warehouseCode); // 主存放仓库 | ||||||
|  |             contentObj.put("bz", vo.getMemo()); // 备注信息 | ||||||
|  |             setDefVal(vo, contentObj); | ||||||
|  |             JSONArray contentArr = new JSONArray(); | ||||||
|  |             contentArr.add(contentObj); | ||||||
|  |             singleObj.put("Content", contentArr); | ||||||
|  |             pushData(singleObj); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 设置自定义字段的值 | ||||||
|  |      * | ||||||
|  |      * @param vo | ||||||
|  |      * @param contentObj | ||||||
|  |      */ | ||||||
|  |     private void setDefVal(MaterialVO vo, JSONObject contentObj) { | ||||||
|  |         Map<String, String> defParams = MyHelper.getConfigParams("jmqy-def", null); | ||||||
|  |         Set<String> numFields = new HashSet<>(Arrays.asList( | ||||||
|  |                 "djzl", // 单台重量(净重) | ||||||
|  |                 "djzl_mz",// 单件重量(毛重) | ||||||
|  |                 "jmkzl_bkhs",// 不可回收浇冒口重量 | ||||||
|  |                 "jmkzl_khs", // 可回收浇冒口重量 | ||||||
|  |                 "lxzl"// 铝屑重量 | ||||||
|  |         )); | ||||||
|  |         Set<String> strFields = new HashSet<>(Arrays.asList( | ||||||
|  |                 "cz"// 材质 | ||||||
|  |         )); | ||||||
|  |         // 处理数值型字段 | ||||||
|  |         for (String field : numFields) { | ||||||
|  |             String defField = defParams.get("ma_" + field); | ||||||
|  |             if (MMValueCheck.isEmpty(defField)) { | ||||||
|  |                 contentObj.put(field, 0); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             Object value = vo.getAttributeValue(defField); | ||||||
|  |             if (value == null || value.toString().trim().isEmpty()) { | ||||||
|  |                 contentObj.put(field, 0); | ||||||
|  |             } else { | ||||||
|  |                 contentObj.put(field, value); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // 处理字符串型字段 | ||||||
|  |         for (String field : strFields) { | ||||||
|  |             String defField = defParams.get("ma_" + field); | ||||||
|  |             if (MMValueCheck.isEmpty(defField)) { | ||||||
|  |                 contentObj.put(field, ""); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             Object value = vo.getAttributeValue(defField); | ||||||
|  |             if (value == null) { | ||||||
|  |                 contentObj.put(field, ""); | ||||||
|  |             } else { | ||||||
|  |                 contentObj.put(field, value.toString().trim()); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 推送同步数据 | ||||||
|  |      */ | ||||||
|  |     private void pushData(JSONObject param) throws BusinessException { | ||||||
|  |         // String jsonString = param.toJSONString(); | ||||||
|  |         // 转json字符串的时候保留null值 | ||||||
|  |         String jsonStr = JSON.toJSONString(param, | ||||||
|  |                 SerializerFeature.WriteMapNullValue, | ||||||
|  |                 SerializerFeature.WriteNullStringAsEmpty | ||||||
|  |         ); | ||||||
|  |         logger.error("QMS-Material-param = " + jsonStr); | ||||||
|  |         // NCCForUAPLogger.debug("QMS-Material-param = " + jsonStr); | ||||||
|  |         String baseUrl = configParams.get("qmsBaseUrl"); | ||||||
|  |         String requestUrl = baseUrl + reqUrl; | ||||||
|  |         logger.error("QMS-Material-url = " + requestUrl); | ||||||
|  |         String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); | ||||||
|  |         JSONObject resultObj = JSONObject.parseObject(result); | ||||||
|  |         logger.error("QMS-Material-res = " + result); | ||||||
|  | 
 | ||||||
|  |         if (!"true".equals(resultObj.getString("success"))) { | ||||||
|  |             logger.error("QMS-Material-error,result[" + resultObj.toJSONString() + "]"); | ||||||
|  |             throw new BusinessException("精密传启源物料错误:" + resultObj.getString("message")); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private Map getGoodsInfo(String pkMaterial) throws BusinessException { | ||||||
|  |         String sql = " select a.pk_measdoc, c.name unitname, b.pk_measdoc deputyUnit, d.name deputy_unitname, nvl(b.measrate, '1/1') measrate " + | ||||||
|  |                 "from bd_material a " + | ||||||
|  |                 "left join bd_materialconvert b on a.pk_material = b.pk_material " + | ||||||
|  |                 "left join bd_measdoc c on a.pk_measdoc = c.pk_measdoc " + | ||||||
|  |                 "left join bd_measdoc d on b.pk_measdoc = d.pk_measdoc " + | ||||||
|  |                 "where a.pk_material = '" + pkMaterial + "' "; | ||||||
|  |         Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); | ||||||
|  |         map.put("convertRate", MyHelper.transferSpecialField(map.get("measrate") + "")); | ||||||
|  |         return map; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public 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; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 获取自定义项信息 | ||||||
|  |      */ | ||||||
|  |     private String getDefName(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].getName().trim(); | ||||||
|  |             } | ||||||
|  |         } catch (DAOException e) { | ||||||
|  |             logger.error("JM-error,getDefName[" + e.getMessage() + "]"); | ||||||
|  |         } | ||||||
|  |         return res; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -5,10 +5,14 @@ | ||||||
| 		<label>物料-下载PLM物料文件</label> | 		<label>物料-下载PLM物料文件</label> | ||||||
| 		<clazz>nccloud.web.uapbd.material.action.MaterialPlmDownloadAction</clazz> | 		<clazz>nccloud.web.uapbd.material.action.MaterialPlmDownloadAction</clazz> | ||||||
| 	</action> | 	</action> | ||||||
| 
 |  | ||||||
| 	<action> | 	<action> | ||||||
| 		<name>uapbd.material.pushtoqms</name> | 		<name>uapbd.material.pushtoqms</name> | ||||||
| 		<label>物料推送qms</label> | 		<label>箱变物料推送qms</label> | ||||||
| 		<clazz>nccloud.web.uapbd.material.action.MaterialPushToQmsAction</clazz> | 		<clazz>nccloud.web.uapbd.material.action.MaterialPushToQmsAction</clazz> | ||||||
| 	</action> | 	</action> | ||||||
|  | 	<action> | ||||||
|  | 		<name>uapbd.material.pushtojmqy</name> | ||||||
|  | 		<label>精密物料推送启源MES</label> | ||||||
|  | 		<clazz>nccloud.web.uapbd.material.action.MaterialJmPushToQyMesAction</clazz> | ||||||
|  | 	</action> | ||||||
| </actions> | </actions> | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ | ||||||
|       <actions> |       <actions> | ||||||
|           <action>uapbd.material.downloadPlmFile</action> |           <action>uapbd.material.downloadPlmFile</action> | ||||||
|           <action>uapbd.material.pushtoqms</action> |           <action>uapbd.material.pushtoqms</action> | ||||||
|           <action>qc.checkbill.pushtoQms</action> |           <action>uapbd.material.pushtojmqy</action> | ||||||
|       </actions> |       </actions> | ||||||
|    </authorize> |    </authorize> | ||||||
| </authorizes> | </authorizes> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue