流程生产订单推QMS
This commit is contained in:
		
							parent
							
								
									470de890c8
								
							
						
					
					
						commit
						51ba56ae81
					
				|  | @ -5,54 +5,30 @@ import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.alibaba.fastjson.serializer.SerializerFeature; | ||||
| import nc.bs.bd.assignservice.multiorg.MultiOrgAssignVO; | ||||
| import nc.bs.bd.baseservice.ArrayClassConvertUtil; | ||||
| import nc.bs.businessevent.IBusinessEvent; | ||||
| import nc.bs.businessevent.bd.BDCommonEvent; | ||||
| import nc.bs.dao.BaseDAO; | ||||
| import nc.bs.framework.common.NCLocator; | ||||
| import nc.bs.logging.Log; | ||||
| import nc.bs.mmpac.pmo.pac0002.bp.rule.util.SyncEpicMesUtil; | ||||
| 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.SQLParameter; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.vo.bc.pmpub.project.ProjectHeadVO; | ||||
| import nc.vo.bd.bom.bom0202.entity.BomVO; | ||||
| import nc.vo.bd.material.MaterialVO; | ||||
| import nc.vo.bd.material.MaterialVersionVO; | ||||
| import nc.vo.bd.material.marbasclass.MarBasClassVO; | ||||
| import nc.vo.cmp.util.StringUtils; | ||||
| 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.FactoryVO; | ||||
| import nc.vo.org.OrgVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||
| import nc.vo.pubapp.pattern.pub.SqlBuilder; | ||||
| import nc.vo.scmpub.util.ArrayUtil; | ||||
| import nc.vo.so.m30.entity.SaleOrderBVO; | ||||
| import nc.vo.vorg.DeptVersionVO; | ||||
| import nccloud.baseapp.core.log.NCCForUAPLogger; | ||||
| import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; | ||||
| 
 | ||||
| import java.math.BigDecimal; | ||||
| import java.math.RoundingMode; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.*; | ||||
| import java.util.Date; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 流程生产订单审批后推送艾普MES | ||||
|  * 箱变-流程生产订单审批后推送QMS | ||||
|  * | ||||
|  * @author mzr | ||||
|  * @date 2025/7/3 | ||||
|  * @author lihao | ||||
|  * @date 2025/8/25 | ||||
|  */ | ||||
| public class AfterApproveSyncEpicQMSRule implements IRule<PMOAggVO> { | ||||
| 
 | ||||
| public class AfterApproveSyncQMSRule implements IRule<PMOAggVO> { | ||||
| 
 | ||||
|     private static final String LOG_INFO_NAME = "qyMesLog"; | ||||
|     private static final Log logger = Log.getInstance(LOG_INFO_NAME); | ||||
|  | @ -64,7 +40,7 @@ public class AfterApproveSyncEpicQMSRule implements IRule<PMOAggVO> { | |||
|         try { | ||||
|             configParams = MyHelper.getConfigParams("xb-config", null); | ||||
|             if (configParams.isEmpty()) { | ||||
|                throw new BusinessException("箱变的QMS接口缺少配置"); | ||||
|                 throw new BusinessException("箱变的QMS接口缺少配置"); | ||||
|             } | ||||
|             buildSyncData(pmoAggVOS); | ||||
|         } catch (BusinessException e) { | ||||
|  | @ -89,15 +65,15 @@ public class AfterApproveSyncEpicQMSRule implements IRule<PMOAggVO> { | |||
|             // ×é×°Êý¾Ý | ||||
|             JSONObject singleObj = new JSONObject(); | ||||
|             PMOHeadVO pmoHeadVO = vo.getParentVO(); | ||||
|             PMOItemVO[] itemVOS=vo.getChildrenVO(); | ||||
|             singleObj.put("batchid",new Date()); | ||||
|             singleObj.put("scdh",pmoHeadVO.getVbillcode()); | ||||
|             singleObj.put("xdrq",pmoHeadVO.getDbilldate()); | ||||
|             PMOItemVO[] itemVOS = vo.getChildrenVO(); | ||||
|             singleObj.put("batchid", new Date()); | ||||
|             singleObj.put("scdh", pmoHeadVO.getVbillcode()); | ||||
|             singleObj.put("xdrq", pmoHeadVO.getDbilldate()); | ||||
|             String sql = " select user_name from sm_user where cuserid = '" + pmoHeadVO.getBillmaker() + "' "; | ||||
|             String billmakerName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); | ||||
| 
 | ||||
|             singleObj.put("jhy",billmakerName); | ||||
|             singleObj.put("bz",pmoHeadVO.getVnote()); | ||||
|             singleObj.put("jhy", billmakerName); | ||||
|             singleObj.put("bz", pmoHeadVO.getVnote()); | ||||
|             // ´¦ÀíContentÊý×é | ||||
|             JSONArray contentArray = new JSONArray(); | ||||
|             for (PMOItemVO item : itemVOS) { | ||||
|  | @ -109,11 +85,11 @@ public class AfterApproveSyncEpicQMSRule implements IRule<PMOAggVO> { | |||
| // | ||||
| //                Object name = hybo.findColValue("bd_material", "name", "pk_material = '"+item.getCmaterialvid()+"' "); | ||||
|                 String wlsql = " select code,name,materialspec,materialtype from bd_material where pk_material = '" + item.getCmaterialvid() + "' "; | ||||
|                 Map<String,Object> mrlmap = (Map<String, Object>) baseDAO.executeQuery(wlsql, new ColumnProcessor()); | ||||
|                 Map<String, Object> mrlmap = (Map<String, Object>) baseDAO.executeQuery(wlsql, new ColumnProcessor()); | ||||
| 
 | ||||
|                 itemObj.put("wlbh", mrlmap.get("code")); | ||||
|                 itemObj.put("wlmc", mrlmap.get("name")); | ||||
|                 itemObj.put("wlxhgg", mrlmap.get("materialspec")+(String)mrlmap.get("materialtype")); | ||||
|                 itemObj.put("wlxhgg", mrlmap.get("materialspec") + (String) mrlmap.get("materialtype")); | ||||
|                 itemObj.put("jhsl", item.getNastnum()); | ||||
|                 itemObj.put("jhrq", item.getTplanendtime()); | ||||
|                 itemObj.put("bz", item.getVnote()); | ||||
|  | @ -172,19 +148,6 @@ public class AfterApproveSyncEpicQMSRule implements IRule<PMOAggVO> { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     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("QMS-Material-getUnitInfo-sql = " + sql); | ||||
|         Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); | ||||
|         map.put("convertRate", MyHelper.transferSpecialField(map.get("measrate") + "")); | ||||
|         return map; | ||||
|     } | ||||
| 
 | ||||
|     private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException { | ||||
|         String targetCode = configParams.get("xbOrg"); | ||||
|         if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { | ||||
|  | @ -0,0 +1,166 @@ | |||
| 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 nccloud.baseapp.core.log.NCCForUAPLogger; | ||||
| 
 | ||||
| import java.util.Date; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 精密-流程生产订单投放后推送QMS | ||||
|  * | ||||
|  * @author mzr | ||||
|  * @date 2025/9/9 | ||||
|  */ | ||||
| public class AfterPutSyncQMSRule implements IRule<PMOAggVO> { | ||||
| 
 | ||||
|     private static final String LOG_INFO_NAME = "qyMesLog"; | ||||
|     private static final Log logger = Log.getInstance(LOG_INFO_NAME); | ||||
|     private static final String reqUrl = "/IF_QyErpApi.ashx?action=addscjh"; | ||||
|     private Map<String, String> configParams; | ||||
| 
 | ||||
|     @Override | ||||
|     public void process(PMOAggVO[] pmoAggVOS) { | ||||
|         try { | ||||
|             configParams = MyHelper.getConfigParams("xb-config", null); | ||||
|             if (configParams.isEmpty()) { | ||||
|                 throw new BusinessException("箱变的QMS接口缺少配置"); | ||||
|             } | ||||
|             buildSyncData(pmoAggVOS); | ||||
|         } catch (BusinessException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 构建同步数据 | ||||
|      */ | ||||
|     private void buildSyncData(PMOAggVO[] useVOs) throws BusinessException { | ||||
|         BaseDAO baseDAO = new BaseDAO(); | ||||
| 
 | ||||
|         HYPubBO hybo = new HYPubBO(); | ||||
|         for (PMOAggVO vo : useVOs) { | ||||
|             // 判断物料的业务单元是否是箱变公司,不是则跳过 | ||||
|             String pkOrg = vo.getParentVO().getPk_org(); | ||||
|             String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); | ||||
|             if (checkIfOrg(orgCode, configParams)) { | ||||
|                 continue; | ||||
|             } | ||||
|             // 组装数据 | ||||
|             JSONObject singleObj = new JSONObject(); | ||||
|             PMOHeadVO pmoHeadVO = vo.getParentVO(); | ||||
|             PMOItemVO[] itemVOS = vo.getChildrenVO(); | ||||
|             singleObj.put("batchid", new Date()); | ||||
|             singleObj.put("scdh", pmoHeadVO.getVbillcode()); | ||||
|             singleObj.put("xdrq", pmoHeadVO.getDbilldate()); | ||||
|             String sql = " select user_name from sm_user where cuserid = '" + pmoHeadVO.getBillmaker() + "' "; | ||||
|             String billmakerName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); | ||||
| 
 | ||||
|             singleObj.put("jhy", billmakerName); | ||||
|             singleObj.put("bz", pmoHeadVO.getVnote()); | ||||
|             // 处理Content数组 | ||||
|             JSONArray contentArray = new JSONArray(); | ||||
|             for (PMOItemVO item : itemVOS) { | ||||
|                 JSONObject itemObj = new JSONObject(); | ||||
|                 itemObj.put("sgdh", pmoHeadVO.getVbillcode()); | ||||
|                 itemObj.put("xshth", item.getCprojectid()); | ||||
| //                itemObj.put("htqdxh", item.getHtqdxh()); | ||||
| //                Object no = hybo.findColValue("bd_material", "code", "pk_material = '"+item.getCmaterialvid()+"' "); | ||||
| // | ||||
| //                Object name = hybo.findColValue("bd_material", "name", "pk_material = '"+item.getCmaterialvid()+"' "); | ||||
|                 String wlsql = " select code,name,materialspec,materialtype from bd_material where pk_material = '" + item.getCmaterialvid() + "' "; | ||||
|                 Map<String, Object> mrlmap = (Map<String, Object>) baseDAO.executeQuery(wlsql, new ColumnProcessor()); | ||||
| 
 | ||||
|                 itemObj.put("wlbh", mrlmap.get("code")); | ||||
|                 itemObj.put("wlmc", mrlmap.get("name")); | ||||
|                 itemObj.put("wlxhgg", mrlmap.get("materialspec") + (String) mrlmap.get("materialtype")); | ||||
|                 itemObj.put("jhsl", item.getNastnum()); | ||||
|                 itemObj.put("jhrq", item.getTplanendtime()); | ||||
|                 itemObj.put("bz", item.getVnote()); | ||||
|                 contentArray.add(itemObj); | ||||
|             } | ||||
| 
 | ||||
|             singleObj.put("Content", contentArray); | ||||
|             /* | ||||
|              { | ||||
|                   "batchid": "PO202408001", | ||||
|                   "scdh": "PROD202408001", | ||||
|                   "xdrq": "2024-08-21", | ||||
|                   "jhy": "张三", | ||||
|                   "bz": "紧急生产订单,优先安排", | ||||
|                   "Content": [ | ||||
|                     { | ||||
|                       "sgdh": "CON202408001", | ||||
|                       "xshth": "SALE202408001", | ||||
|                       "htqdxh": "001", | ||||
|                       "wlbh": "ACC26711", | ||||
|                       "wlmc": "铜排", | ||||
|                       "wlxhgg": "15558190831", | ||||
|                       "jhsl": "100", | ||||
|                       "jhrq": "2024-08-25", | ||||
|                       "bz": "需符合材质要求" | ||||
|                     } | ||||
|                   ] | ||||
|                 } | ||||
|              */ | ||||
|             pushData(singleObj); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 推送同步数据 | ||||
|      */ | ||||
|     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 (!"success".equals(resultObj.getString("success"))) { | ||||
|             // throw new BusinessException("QMS-Material-error:" + resultObj.getString("msg")); | ||||
|             logger.error("QMS-Material-error,result[" + resultObj.toJSONString() + "]"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException { | ||||
|         String targetCode = configParams.get("xbOrg"); | ||||
|         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