流程生产订单审批后推送艾普MES调整
This commit is contained in:
parent
4c505d6b7e
commit
92c621ce56
|
@ -1,15 +1,16 @@
|
|||
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.itf.arap.goldentax.SysParaInitQuery;
|
||||
import nc.jdbc.framework.processor.MapListProcessor;
|
||||
import nc.jdbc.framework.processor.MapProcessor;
|
||||
import nc.vo.bc.pmpub.project.ProjectHeadVO;
|
||||
|
@ -24,7 +25,6 @@ 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 nccloud.baseapp.core.log.NCCForUAPLogger;
|
||||
import nccloud.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -39,12 +39,13 @@ import java.util.Map;
|
|||
*/
|
||||
public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||
|
||||
private static final String LOG_INFO_NAME = "DLDZLOG";
|
||||
private static final String LOG_INFO_NAME = "dldzlog";
|
||||
|
||||
private static final Log obmlog = Log.getInstance(LOG_INFO_NAME);
|
||||
private static final Log logDl = Log.getInstance(LOG_INFO_NAME);
|
||||
|
||||
private static final String pmoUrl = "/prj-v5-web/ext/api/workOrder";
|
||||
private static final String codeUrl = "/prj-v5-web/ext/api/releaseNo";
|
||||
private Map<String, String> configParams;
|
||||
|
||||
private static final BaseDAO dao = new BaseDAO();
|
||||
|
||||
|
@ -54,13 +55,16 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
configParams = MyHelper.getConfigParams("Dldz-config");
|
||||
if (configParams.isEmpty()) {
|
||||
throw new BusinessException("电力电子的艾普MES接口缺少配置");
|
||||
}
|
||||
List<PMOAggVO> filteredOrders = checkAndFilterBillSrcOrg(pmoAggVOS);
|
||||
if (filteredOrders.isEmpty()) {
|
||||
obmlog.debug("没有符合条件的生产订单需要同步到艾普MES系统。");
|
||||
logDl.error("没有符合条件的生产订单需要同步到艾普MES系统。");
|
||||
return;
|
||||
}
|
||||
|
||||
obmlog.info("开始同步生产订单到艾普MES系统,符合条件的订单数量: " + filteredOrders.size());
|
||||
logDl.info("开始同步生产订单到艾普MES系统,符合条件的订单数量: " + filteredOrders.size());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
// 推送到艾普MES系统
|
||||
for (PMOAggVO aggVO : filteredOrders) {
|
||||
|
@ -68,45 +72,56 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
PMOItemVO[] bodys = aggVO.getChildrenVO();
|
||||
|
||||
if (bodys == null || bodys.length == 0) {
|
||||
obmlog.warn("生产订单 " + head.getVbillcode() + " 没有行信息,跳过同步。");
|
||||
logDl.error("生产订单 " + head.getVbillcode() + " 没有行信息,跳过同步。");
|
||||
continue;
|
||||
}
|
||||
JSONObject data = buildSyncData(aggVO);
|
||||
pushOrderData(data);
|
||||
pushData(pmoUrl, data);
|
||||
|
||||
JSONObject buildSyncData = buildSyncCodeData(aggVO);
|
||||
jsonArray.add(buildSyncData);
|
||||
}
|
||||
if (!jsonArray.isEmpty()) {
|
||||
pushCodeData(jsonArray);
|
||||
pushData(codeUrl, jsonArray);
|
||||
}
|
||||
|
||||
obmlog.info("生产订单同步到艾普MES系统处理完成。");
|
||||
logDl.info("生产订单同步到艾普MES系统处理完成。");
|
||||
|
||||
} catch (Exception e) {
|
||||
obmlog.error("同步生产订单到艾普MES系统失败: " + e.getMessage(), e);
|
||||
logDl.error("同步生产订单到艾普MES系统失败: " + e.getMessage(), e);
|
||||
ExceptionUtils.wrappException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用MES的生产工单接口推送ERP的流程生产订单和备料计划
|
||||
* 调用MES的生产工单接口推送ERP的流程生产订单和备料计划或推送出厂编号
|
||||
*
|
||||
* @param param 请求体
|
||||
* @throws BusinessException 如果发生非特定可忽略的错误
|
||||
*/
|
||||
private void pushOrderData(JSONObject param) throws BusinessException {
|
||||
private void pushData(String reqUrl, Object param) throws BusinessException {
|
||||
String responseString = null;
|
||||
try {
|
||||
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
|
||||
String requestUrl = baseUrl + pmoUrl;
|
||||
responseString = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
|
||||
obmlog.info(" 艾普MES系统原始返回: " + responseString);
|
||||
// 转json字符串的时候保留null值
|
||||
String jsonStr = JSON.toJSONString(param,
|
||||
SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty
|
||||
);
|
||||
logDl.error("EpicMes-PMO-param = " + jsonStr);
|
||||
String baseUrl = configParams.get("epicMesUrl");
|
||||
String requestUrl = baseUrl + reqUrl;
|
||||
logDl.error(" EpicMes-PMO-url = " + requestUrl);
|
||||
responseString = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
|
||||
logDl.error(" EpicMes-PMO-res = " + responseString);
|
||||
|
||||
// JSONObject jsonResponse = JSONObject.parseObject(responseString);
|
||||
JSONObject resultObj = JSONObject.parseObject(responseString);
|
||||
if (!"1".equals(resultObj.getString("flag"))) {
|
||||
logDl.error("EpicMes-PMO-error,result[" + resultObj.toJSONString() + "]");
|
||||
throw new BusinessException("艾普MES返回错误信息:" + resultObj.getString("msg"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
obmlog.error(" 调用MES或处理响应时发生错误。原始响应: " + responseString + " 错误: " + e.getMessage(), e);
|
||||
throw new BusinessException("调用MES或处理响应时发生错误:" + e.getMessage(), e);
|
||||
logDl.error(" 调用MES或处理响应时发生错误。原始响应: " + responseString + " 错误: " + e.getMessage(), e);
|
||||
throw new BusinessException("调用艾普MES或处理响应时发生错误:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +134,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
String pkOrg = aggVo.getParentVO().getPk_org();
|
||||
String orgCode = MyHelper.transferField(FactoryVO.getDefaultTableName(), FactoryVO.CODE, FactoryVO.PK_FACTORY, pkOrg);
|
||||
// 检查当前组织是否为电力电子
|
||||
if (MyHelper.checkIfDldzOrg(orgCode)) {
|
||||
if (MyHelper.checkIfDldzOrg(orgCode, configParams)) {
|
||||
continue;
|
||||
}
|
||||
// 按照部门筛选生产订单,只传消弧车间、电容车间、成套车间(部门是配置项)
|
||||
|
@ -127,7 +142,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
String cdeptid = childrenVO.getCdeptid();
|
||||
String deptCode = MyHelper.transferField(DeptVO.getDefaultTableName(), DeptVO.CODE, DeptVO.PK_DEPT, cdeptid);
|
||||
// 如果部门不在范围内则跳过本次循环
|
||||
String deptRange = "5020151,5020147,5020148";
|
||||
String deptRange = configParams.get("deptRange");
|
||||
if (deptCode == null || !deptRange.contains(deptCode)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -180,8 +195,8 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
}
|
||||
// cbomversionid 生产BOM版本
|
||||
orderParam.put("bomCode", bomCode); // BOM 编码
|
||||
NCCForUAPLogger.debug("计划开始时间:" + pmoItem.getTplanstarttime().getMillis());
|
||||
NCCForUAPLogger.debug("计划完成时间:" + pmoItem.getTplanendtime().getMillis());
|
||||
// NCCForUAPLogger.debug("计划开始时间:" + pmoItem.getTplanstarttime().getMillis());
|
||||
// NCCForUAPLogger.debug("计划完成时间:" + pmoItem.getTplanendtime().getMillis());
|
||||
orderParam.put("planBeginDate", pmoItem.getTplanstarttime().getMillis()); // 计划开始时间(毫秒级时间戳)
|
||||
orderParam.put("planEndDate", pmoItem.getTplanendtime().getMillis()); // 计划完成时间(毫秒级时间戳)
|
||||
// orderParam.put("endDate", null); // 试验结束时间(毫秒级时间戳)
|
||||
|
@ -258,6 +273,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
sqlBuilder.append(" and ");
|
||||
// sqlBuilder.append("a.csourcebillid", sourceId);
|
||||
sqlBuilder.append("a.vsourcemorowid", sourceId);// 来源生产订单明细id
|
||||
// logDl.error("查询备料计划数据:" + sqlBuilder);
|
||||
List<Map<String, Object>> result = (List<Map<String, Object>>) dao.executeQuery(sqlBuilder.toString(), new MapListProcessor());
|
||||
for (Map<String, Object> objectMap : result) {
|
||||
JSONObject bodyJson = new JSONObject();
|
||||
|
@ -267,6 +283,9 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
bodyJson.put("unit", objectMap.get("unit"));// 单位
|
||||
pickmArr.add(bodyJson);
|
||||
}
|
||||
if (pickmArr.isEmpty()) {
|
||||
logDl.error("查询备料计划为空,sourceId = " + sourceId + ",sql = " + sqlBuilder);
|
||||
}
|
||||
return pickmArr;
|
||||
|
||||
}
|
||||
|
@ -281,13 +300,17 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
// "releaseNo": [] // 出厂编号
|
||||
// }
|
||||
//]
|
||||
|
||||
PMOHeadVO hvo = vo.getParentVO();
|
||||
PMOItemVO pmoItem = vo.getChildrenVO()[0];
|
||||
// 生产部门 cdeptid
|
||||
String cdeptid = pmoItem.getCdeptid();
|
||||
String deptCode = MyHelper.transferField(DeptVO.getDefaultTableName(), DeptVO.CODE, DeptVO.PK_DEPT, cdeptid);
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("siteCode", null); // 已存在的billCode字段
|
||||
obj.put("workOrderCode", vo.getParentVO().getVbillcode());
|
||||
obj.put("siteCode", deptCode);
|
||||
obj.put("workOrderCode", hvo.getVbillcode());
|
||||
|
||||
BaseDAO dao = new BaseDAO();
|
||||
String orgsql = "select code,name from org_factory where pk_factory = '" + vo.getParentVO().getPk_org() + "' ";
|
||||
String orgsql = "select code,name from org_factory where pk_factory = '" + hvo.getPk_org() + "' ";
|
||||
Map<String, Object> tr = (Map<String, Object>) dao.executeQuery(orgsql, new MapProcessor());
|
||||
obj.put("companyCode", tr.get("code"));
|
||||
obj.put("companyName", tr.get("name"));
|
||||
|
@ -296,7 +319,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
HYPubBO hybo = new HYPubBO();
|
||||
Object materialtype = hybo.findColValue("bd_material_v", "materialtype", "pk_source = '" + item.getCmaterialid() + "' ");
|
||||
|
||||
String detailItem = materialtype + vo.getParentVO().getDbilldate().toStdString().substring(0, 3) + vo.getParentVO().getDbilldate().toStdString().substring(5, 6) + "0001";
|
||||
String detailItem = materialtype + hvo.getDbilldate().toStdString().substring(0, 3) + hvo.getDbilldate().toStdString().substring(5, 6) + "0001";
|
||||
jsonArray.add(detailItem);
|
||||
}
|
||||
obj.put("releaseNo", jsonArray);
|
||||
|
@ -304,25 +327,4 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
|||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送出厂编号
|
||||
*
|
||||
* @param param 传参
|
||||
* @throws BusinessException
|
||||
*/
|
||||
private void pushCodeData(JSONArray param) throws BusinessException {
|
||||
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
|
||||
baseUrl = "http://192.168.55.39:8080";
|
||||
String requestUrl = baseUrl + codeUrl;
|
||||
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
|
||||
JSONObject resultObj = JSONObject.parseObject(result);
|
||||
obmlog.error("AfterApproveSyncEpicMesRule-pushCodeData-req = " + result);
|
||||
|
||||
if ("false".equals(resultObj.getString("success"))) {
|
||||
obmlog.error("AfterApproveSyncEpicMesRule-pushCodeData-fail:" + resultObj.getString("msg"));
|
||||
} else {
|
||||
obmlog.error("AfterApproveSyncEpicMesRule-pushCodeData-suc,result[" + resultObj.toJSONString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue