电力电子-艾普MES-BOM和物料-增加异常处理及定时重推
This commit is contained in:
		
							parent
							
								
									0a6c25f799
								
							
						
					
					
						commit
						89a7b81494
					
				|  | @ -53,9 +53,13 @@ public class BomSaveAfterEpicMesRule implements IRule<AggBomVO> { | |||
|                     pushData(data, vos); | ||||
|                 } | ||||
|             } catch (BusinessException e) { | ||||
|                 logDl.error("EpicMes-BOM-exp:" + e.getMessage(), e); | ||||
|                 handleSyncBomExp(vos, "N", e.getMessage()); | ||||
|                 ExceptionUtils.wrappException(e); | ||||
|                 String message = e.getMessage(); | ||||
|                 logDl.error("EpicMes-BOM-exp:" + message, e); | ||||
|                 if (message != null && message.contains("Connection timed out")) { | ||||
|                     handleSyncBomExp(vos, "N", message); | ||||
|                 } else { | ||||
|                     ExceptionUtils.wrappException(e); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | @ -170,7 +174,7 @@ public class BomSaveAfterEpicMesRule implements IRule<AggBomVO> { | |||
|             updateSql = updateSql.replace("[errorCode]", errorCode); | ||||
|             int updatedRows = getDao().executeUpdate(updateSql); | ||||
|         } catch (BusinessException e) { | ||||
|             logDl.error("EpicMes-BOM-updateErrorInfo = " + e.getMessage(), e); | ||||
|             logDl.error("EpicMes-BOM-handleSyncBomExp = " + e.getMessage(), e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ import java.util.Map; | |||
| import java.util.Set; | ||||
| 
 | ||||
| /** | ||||
|  * 定时同步推送失败的BOM到艾普MES | ||||
|  * BOM-艾普MES-定时重推失败的数据 | ||||
|  * | ||||
|  * @author mzr | ||||
|  * @date 20251006 | ||||
|  | @ -51,7 +51,7 @@ public class BomToEpicMesPlugin implements IBackgroundWorkPlugin { | |||
|     @Override | ||||
|     public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException { | ||||
|         try { | ||||
|             String sql = " select * from v_bip_so_cron"; | ||||
|             String sql = " select * from v_mes_bom_cron"; | ||||
|             List<Map<String, String>> pkList = (List<Map<String, String>>) getDao().executeQuery(sql.toString(), new MapListProcessor()); | ||||
|             if (pkList.isEmpty()) { | ||||
|                 return null; | ||||
|  | @ -68,7 +68,7 @@ public class BomToEpicMesPlugin implements IBackgroundWorkPlugin { | |||
|                 if (!data.isEmpty()) { | ||||
|                     pushData(data, vos); | ||||
|                 } | ||||
|             } | ||||
|             } // MATERIAL | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             logDl.error("BomToEpicMesPlugin-exp:" + e.getMessage(), e); | ||||
|  |  | |||
|  | @ -0,0 +1,210 @@ | |||
| package nc.bs.uapbd.task.mes.epic; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.alibaba.fastjson.serializer.SerializerFeature; | ||||
| import nc.bs.dao.BaseDAO; | ||||
| import nc.bs.logging.Log; | ||||
| import nc.bs.pub.pa.PreAlertObject; | ||||
| import nc.bs.pub.taskcenter.BgWorkingContext; | ||||
| import nc.bs.pub.taskcenter.IBackgroundWorkPlugin; | ||||
| import nc.bs.trade.business.HYPubBO; | ||||
| import nc.bs.uapbd.util.MyHelper; | ||||
| import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapListProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.util.mmf.framework.base.MMValueCheck; | ||||
| import nc.vo.bd.material.MaterialVO; | ||||
| import nc.vo.fi.pub.SqlUtils; | ||||
| import nc.vo.org.OrgVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| 
 | ||||
| import java.util.*; | ||||
| 
 | ||||
| /** | ||||
|  * 物料-艾普MES-定时重推失败的数据 | ||||
|  * | ||||
|  * @author mzr | ||||
|  * @date 20251006 | ||||
|  */ | ||||
| public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin { | ||||
|     private static final String LOG_INFO_NAME = "syscron"; | ||||
|     private static final Log logDl = Log.getInstance(LOG_INFO_NAME); | ||||
|     private static final String reqUrl = "/prj-v5-web/ext/api/mrl"; | ||||
|     private Map<String, String> configParams; | ||||
|     private BaseDAO dao; | ||||
| 
 | ||||
|     public BaseDAO getDao() { | ||||
|         if (dao == null) { | ||||
|             dao = new BaseDAO(); | ||||
|         } | ||||
|         return dao; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException { | ||||
|         try { | ||||
|             String sql = " select * from v_mes_material_cron"; | ||||
|             List<Map<String, String>> pkList = (List<Map<String, String>>) getDao().executeQuery(sql.toString(), new MapListProcessor()); | ||||
|             if (pkList.isEmpty()) { | ||||
|                 return null; | ||||
|             } | ||||
|             configParams = MyHelper.getConfigParams("Dldz-config", null); | ||||
|             if (configParams.isEmpty()) { | ||||
|                 return null; | ||||
|             } | ||||
|             HYPubBO hyPub = new HYPubBO(); | ||||
|             List<MaterialVO> voList = new ArrayList<>(); | ||||
|             for (Map<String, String> map : pkList) { | ||||
|                 String pkMaterial = map.get("pk_material"); | ||||
|                 MaterialVO materialVO = (MaterialVO) hyPub.queryByPrimaryKey(MaterialVO.class, pkMaterial); | ||||
|                 voList.add(materialVO); | ||||
|             } | ||||
|             if (!voList.isEmpty()) { | ||||
|                 MaterialVO[] useVOs = voList.toArray(new MaterialVO[0]); | ||||
|                 buildSyncData(useVOs); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             logDl.error("BomToEpicMesPlugin-exp:" + e.getMessage(), e); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 构建同步数据 | ||||
|      */ | ||||
|     private void buildSyncData(MaterialVO[] useVOs) throws BusinessException { | ||||
|         for (MaterialVO vo : useVOs) { | ||||
|             String pkMaterial = vo.getPk_material(); | ||||
|             // 判断物料的业务单元是否是电力电子公司,不是则跳过 | ||||
|             String pkOrg = vo.getPk_org(); | ||||
|             String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); | ||||
|             // 字段值翻译 | ||||
|             // String pk_marbasclass = vo.getPk_marbasclass(); | ||||
|             // String mrlTypeCOde = MyHelper.transferField(MarBasClassVO.getDefaultTableName(), MarBasClassVO.CODE, MarBasClassVO.PK_MARBASCLASS, pk_marbasclass); | ||||
|             // 计量单位 | ||||
|             Map unitMap = getGoodsInfo(pkMaterial); | ||||
| 
 | ||||
|             // 1=未启用;2=已启用;3=已停用; | ||||
|             Integer enablestate = vo.getEnablestate(); | ||||
|             String statusCode = (3 == enablestate) ? "N" : "Y"; | ||||
|             // 组装数据 | ||||
|             JSONObject singleObj = new JSONObject(); | ||||
|             singleObj.put("id", null);// 唯一标识(主键) | ||||
|             singleObj.put("siteCode", orgCode);// 工厂编码 | ||||
|             singleObj.put("mrlCode", vo.getCode());// 物料编码 | ||||
|             singleObj.put("mrlName", vo.getName());// 物料名称 | ||||
|             singleObj.put("unit", unitMap.get("unitname"));// 单位 | ||||
|             singleObj.put("model", vo.getMaterialtype());// 型号 | ||||
|             singleObj.put("specification", vo.getMaterialspec());// 规格 | ||||
|             singleObj.put("type", getType(""));// 类型(I:新增 U:修改 D:删除) | ||||
|             singleObj.put("deputyUnit", unitMap.get("deputy_unitname"));// 副单位 | ||||
|             singleObj.put("auditCode", "1");// 审核码 | ||||
|             singleObj.put("statusCode", statusCode);// 状态码(Y表示启用,N表示停用) | ||||
|             // singleObj.put("mrlTypeErp", getGoodsProject(pkMaterial));// 物料类型ERP(1:专用件,3:通用件) | ||||
|             singleObj.put("mrlType", getGoodsType(pkMaterial));// 物料分类 制造1 其它0 | ||||
|             singleObj.put("convertRate", unitMap.getOrDefault("convertRate", "1"));// 单位换算率 | ||||
|             // singleObj.put("isCheck", "1");// 是否选中(1:是,0:否) | ||||
|             pushData(singleObj, useVOs); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 推送同步数据 | ||||
|      */ | ||||
|     private void pushData(JSONObject param, MaterialVO[] useVOs) throws BusinessException { | ||||
|         // String jsonString = param.toJSONString(); | ||||
|         // 转json字符串的时候保留null值 | ||||
|         String jsonStr = JSON.toJSONString(param, | ||||
|                 SerializerFeature.WriteMapNullValue, | ||||
|                 SerializerFeature.WriteNullStringAsEmpty | ||||
|         ); | ||||
|         logDl.error("EpicMes-Material-param = " + jsonStr); | ||||
|         // NCCForUAPLogger.debug("EpicMes-Material-param = " + jsonStr); | ||||
|         String baseUrl = configParams.get("epicMesUrl"); | ||||
|         String requestUrl = baseUrl + reqUrl; | ||||
|         logDl.error("EpicMes-Material-url = " + requestUrl); | ||||
|         String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); | ||||
|         JSONObject resultObj = JSONObject.parseObject(result); | ||||
|         logDl.error("EpicMes-Material-res = " + result); | ||||
| 
 | ||||
|         if (!"1".equals(resultObj.getString("flag"))) { | ||||
|             // throw new BusinessException("EpicMes-Material-error:" + resultObj.getString("msg")); | ||||
|             logDl.error("EpicMes-Material-error,result[" + resultObj.toJSONString() + "]"); | ||||
|             handleSyncMaterialExp(useVOs, "N", resultObj.getString("msg")); | ||||
|         } else { | ||||
|             handleSyncMaterialExp(useVOs, "Y", ""); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private String getType(String eventType) { | ||||
|         // 类型(I:新增 U:修改 D:删除) | ||||
|         Map<String, String> map = new HashMap<>(); | ||||
|         map.put("1002", "I"); | ||||
|         map.put("1009", "I"); | ||||
|         map.put("1004", "U"); | ||||
|         map.put("1069", "U"); | ||||
|         map.put("1071", "U"); | ||||
|         return map.getOrDefault(eventType, "I"); | ||||
|     } | ||||
| 
 | ||||
|     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 + "' "; | ||||
|         // logDl.error("EpicMes-Material-getUnitInfo-sql = " + sql); | ||||
|         Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); | ||||
|         map.put("convertRate", MyHelper.transferSpecialField(map.get("measrate") + "")); | ||||
|         return map; | ||||
|     } | ||||
| 
 | ||||
|     private String getGoodsType(String pkMaterial) throws BusinessException { | ||||
|         String targetCode = configParams.get("dldzOrg"); | ||||
|         String[] orgItem = targetCode.split(","); | ||||
|         String inStr = SqlUtils.getInStr("b.code", orgItem, Boolean.TRUE); | ||||
|         // 物料-库存信息-物料类型 DR=分销补货;FR=工厂补货;MR=制造件;PR=采购件;OT=委外件;ET=其他 | ||||
|         // mes物料类型 制造1 其它0(ERP多个组织中如果有一个是制造件或虚拟件(其他)就传1) | ||||
|         String mesType = "0"; | ||||
|         // String martype = MyHelper.transferField(MaterialStockVO.getDefaultTableName(), MaterialStockVO.MARTYPE, MaterialStockVO.PK_MATERIAL, pkMaterial); | ||||
|         String countSql = "SELECT count(1)" + | ||||
|                 " FROM bd_materialstock a" + | ||||
|                 " LEFT JOIN org_stockorg b ON a.pk_org = b.pk_stockorg" + | ||||
|                 " WHERE a.dr = 0 AND a.martype IN ('MR','ET') " + | ||||
|                 " AND a.pk_material = '[pkMaterial]'" + | ||||
|                 " AND " + inStr; | ||||
|         countSql = countSql.replace("[pkMaterial]", pkMaterial); | ||||
|         Integer num = (Integer) new BaseDAO().executeQuery(countSql, new ColumnProcessor()); | ||||
|         if (num > 0) { | ||||
|             mesType = "1"; | ||||
|         } | ||||
|         return mesType; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * 更新错误信息 | ||||
|      */ | ||||
|     private void handleSyncMaterialExp(MaterialVO[] vos, String errorCode, String errorMsg) { | ||||
|         if (MMValueCheck.isEmpty(vos)) { | ||||
|             return; | ||||
|         } | ||||
|         Set<String> ids = new HashSet<>(); | ||||
|         for (MaterialVO vo : vos) { | ||||
|             String pkMaterial = vo.getPk_material(); | ||||
|             ids.add(pkMaterial); | ||||
|         } | ||||
|         try { | ||||
|             String inSql = SqlUtils.getInStr("pk_material", ids.toArray(new String[0]), Boolean.TRUE); | ||||
|             String updateSql = "update bd_material set def30 = '[errorCode]' where " + inSql; | ||||
|             updateSql = updateSql.replace("[errorCode]", errorCode); | ||||
|             int updatedRows = getDao().executeUpdate(updateSql); | ||||
|         } catch (BusinessException e) { | ||||
|             logDl.error("EpicMes-Material-handleSyncMaterialExp = " + e.getMessage(), e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -15,17 +15,14 @@ import nc.bs.uapbd.util.MyHelper; | |||
| import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.util.mmf.framework.base.MMValueCheck; | ||||
| import nc.vo.bd.material.MaterialVO; | ||||
| import nc.vo.bd.material.marbasclass.MarBasClassVO; | ||||
| import nc.vo.bd.material.stock.MaterialStockVO; | ||||
| import nc.vo.fi.pub.SqlUtils; | ||||
| import nc.vo.org.OrgVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.*; | ||||
| 
 | ||||
| /** | ||||
|  * 物料新增修改后同步艾普MES的物料 | ||||
|  | @ -38,6 +35,14 @@ public class MaterialToEpicMesListener implements IBusinessListener { | |||
|     private static final Log logDl = Log.getInstance(LOG_INFO_NAME); | ||||
|     private static final String reqUrl = "/prj-v5-web/ext/api/mrl"; | ||||
|     private Map<String, String> configParams; | ||||
|     private BaseDAO dao; | ||||
| 
 | ||||
|     public BaseDAO getDao() { | ||||
|         if (dao == null) { | ||||
|             dao = new BaseDAO(); | ||||
|         } | ||||
|         return dao; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void doAction(IBusinessEvent event) throws BusinessException { | ||||
|  | @ -46,10 +51,11 @@ public class MaterialToEpicMesListener implements IBusinessListener { | |||
|         Object[] objs = e.getObjs(); | ||||
| 
 | ||||
|         // EventType是事件编码 1002-新增后 1004-修改后 1071-状态由停用变为启用后 1069-状态由启用变为停用后 1061批改后 | ||||
|         MaterialVO[] useVOs = null; | ||||
|         try { | ||||
|             if ("1002".equals(eventType) || "1004".equals(eventType) || "1061".equals(eventType) || | ||||
|                     "1071".equals(eventType) || "1069".equals(eventType)) { | ||||
|                 MaterialVO[] useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class); | ||||
|                 useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class); | ||||
|                 configParams = MyHelper.getConfigParams("Dldz-config", null); | ||||
|                 if (configParams.isEmpty()) { | ||||
|                     throw new BusinessException("电力电子的艾普MES接口缺少配置"); | ||||
|  | @ -76,13 +82,14 @@ public class MaterialToEpicMesListener implements IBusinessListener { | |||
|                     voList.add(materialVO); | ||||
|                 } | ||||
|                 if (!voList.isEmpty()) { | ||||
|                     MaterialVO[] useVOs = voList.toArray(new MaterialVO[0]); | ||||
|                     useVOs = voList.toArray(new MaterialVO[0]); | ||||
|                     buildSyncData(useVOs, eventType); | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|         } catch (BusinessException ex) { | ||||
|             logDl.error("EpicMes-Material-exp:" + ex.getMessage(), ex); | ||||
|             handleSyncMaterialExp(useVOs, "N", ex.getMessage()); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -100,8 +107,8 @@ public class MaterialToEpicMesListener implements IBusinessListener { | |||
|                 continue; | ||||
|             } | ||||
|             // 字段值翻译 | ||||
|             String pk_marbasclass = vo.getPk_marbasclass(); | ||||
|             String mrlTypeCOde = MyHelper.transferField(MarBasClassVO.getDefaultTableName(), MarBasClassVO.CODE, MarBasClassVO.PK_MARBASCLASS, pk_marbasclass); | ||||
|             // String pk_marbasclass = vo.getPk_marbasclass(); | ||||
|             // String mrlTypeCOde = MyHelper.transferField(MarBasClassVO.getDefaultTableName(), MarBasClassVO.CODE, MarBasClassVO.PK_MARBASCLASS, pk_marbasclass); | ||||
|             // 计量单位 | ||||
|             Map unitMap = getGoodsInfo(pkMaterial); | ||||
| 
 | ||||
|  | @ -210,4 +217,26 @@ public class MaterialToEpicMesListener implements IBusinessListener { | |||
|         return mesType; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * ¸üдíÎóÐÅÏ¢ | ||||
|      */ | ||||
|     private void handleSyncMaterialExp(MaterialVO[] vos, String errorCode, String errorMsg) { | ||||
|         if (MMValueCheck.isEmpty(vos)) { | ||||
|             return; | ||||
|         } | ||||
|         Set<String> ids = new HashSet<>(); | ||||
|         for (MaterialVO vo : vos) { | ||||
|             String pkMaterial = vo.getPk_material(); | ||||
|             ids.add(pkMaterial); | ||||
|         } | ||||
|         try { | ||||
|             String inSql = SqlUtils.getInStr("pk_material", ids.toArray(new String[0]), Boolean.TRUE); | ||||
|             String updateSql = "update bd_material set def30 = '[errorCode]' where " + inSql; | ||||
|             updateSql = updateSql.replace("[errorCode]", errorCode); | ||||
|             int updatedRows = getDao().executeUpdate(updateSql); | ||||
|         } catch (BusinessException e) { | ||||
|             logDl.error("EpicMes-Material-handleSyncMaterialExp = " + e.getMessage(), e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue