refactor(mmpac): 优化生产订单同步到艾普 MES系统的逻辑
This commit is contained in:
parent
36b0bc5756
commit
fe486651bb
|
@ -12,6 +12,8 @@ import nc.impl.pubapp.pattern.rule.IRule;
|
||||||
import nc.itf.arap.goldentax.SysParaInitQuery;
|
import nc.itf.arap.goldentax.SysParaInitQuery;
|
||||||
import nc.jdbc.framework.processor.MapListProcessor;
|
import nc.jdbc.framework.processor.MapListProcessor;
|
||||||
import nc.jdbc.framework.processor.MapProcessor;
|
import nc.jdbc.framework.processor.MapProcessor;
|
||||||
|
import nc.vo.bc.pmpub.project.ProjectHeadVO;
|
||||||
|
import nc.vo.bd.material.MaterialVO;
|
||||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
||||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
|
||||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
||||||
|
@ -22,8 +24,6 @@ import nc.vo.pubapp.pattern.pub.SqlBuilder;
|
||||||
import nc.vo.scmpub.util.ArrayUtil;
|
import nc.vo.scmpub.util.ArrayUtil;
|
||||||
import nccloud.commons.lang.StringUtils;
|
import nccloud.commons.lang.StringUtils;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -40,7 +40,8 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
|
|
||||||
private static final Log obmlog = Log.getInstance(LOG_INFO_NAME);
|
private static final Log obmlog = Log.getInstance(LOG_INFO_NAME);
|
||||||
|
|
||||||
private static final String MES_PMO_SYNC_URL = "/prj-v5-web/ext/api/wrokOrder";
|
private static final String MES_PMO_URL = "/prj-v5-web/ext/api/workOrder";
|
||||||
|
private static final String MES_CODE_URL = "/prj-v5-web/ext/api/releaseNo";
|
||||||
|
|
||||||
private static final BaseDAO dao = new BaseDAO();
|
private static final BaseDAO dao = new BaseDAO();
|
||||||
|
|
||||||
|
@ -68,18 +69,17 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
JSONObject data = buildSyncData(aggVO);
|
JSONObject data = buildSyncData(aggVO);
|
||||||
pushData(data);
|
pushOrderData(data);
|
||||||
|
|
||||||
JSONObject buildSyncData = buildSyncData1(aggVO);
|
JSONObject buildSyncData = buildSyncCodeData(aggVO);
|
||||||
jsonArray.add(buildSyncData);
|
jsonArray.add(buildSyncData);
|
||||||
}
|
}
|
||||||
if (jsonArray.size() > 0) {
|
if (!jsonArray.isEmpty()) {
|
||||||
pushNoData("/prj-v5-web/ext/api/releaseNo", jsonArray);
|
pushCodeData(jsonArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
obmlog.info("生产订单同步到艾普MES系统处理完成。");
|
obmlog.info("生产订单同步到艾普MES系统处理完成。");
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
obmlog.error("同步生产订单到艾普MES系统失败: " + e.getMessage(), e);
|
obmlog.error("同步生产订单到艾普MES系统失败: " + e.getMessage(), e);
|
||||||
ExceptionUtils.wrappException(e);
|
ExceptionUtils.wrappException(e);
|
||||||
|
@ -87,16 +87,16 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用MES接口并处理特定错误
|
* 调用MES的生产工单接口推送ERP的流程生产订单和备料计划
|
||||||
*
|
*
|
||||||
* @param param 请求体
|
* @param param 请求体
|
||||||
* @throws BusinessException 如果发生非特定可忽略的错误
|
* @throws BusinessException 如果发生非特定可忽略的错误
|
||||||
*/
|
*/
|
||||||
private void pushData(JSONObject param) throws BusinessException {
|
private void pushOrderData(JSONObject param) throws BusinessException {
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
try {
|
try {
|
||||||
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
|
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
|
||||||
String requestUrl = baseUrl + MES_PMO_SYNC_URL;
|
String requestUrl = baseUrl + MES_PMO_URL;
|
||||||
responseString = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
|
responseString = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
|
||||||
obmlog.info(" 艾普MES系统原始返回: " + responseString);
|
obmlog.info(" 艾普MES系统原始返回: " + responseString);
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
aggvoList.add(aggVo);
|
aggvoList.add(aggVo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 按照部门区分生产订单,只传消弧车间、电容车间、成套车间(部门是配置项)
|
// 按照部门筛选生产订单,只传消弧车间、电容车间、成套车间(部门是配置项)
|
||||||
|
|
||||||
return aggvoList;
|
return aggvoList;
|
||||||
}
|
}
|
||||||
|
@ -129,36 +129,55 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
* 组装数据-流程生产订单+备料计划
|
* 组装数据-流程生产订单+备料计划
|
||||||
*/
|
*/
|
||||||
private JSONObject buildSyncData(PMOAggVO aggVO) throws BusinessException {
|
private JSONObject buildSyncData(PMOAggVO aggVO) throws BusinessException {
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
PMOHeadVO headVo = aggVO.getParentVO();
|
PMOHeadVO headVo = aggVO.getParentVO();
|
||||||
// PMOItemVO[] pmoItems = aggVO.getChildrenVO();
|
// 目前电力电子只做一个表体的订单,故只处理的流程生产订单第一个子表行
|
||||||
JSONObject orderParam = new JSONObject();
|
PMOItemVO pmoItem = aggVO.getChildrenVO()[0];
|
||||||
orderParam.put("id", null); // 唯一标识(主键)
|
// 翻译字段值
|
||||||
orderParam.put("siteCode", null);// 工厂编码
|
// 组织
|
||||||
orderParam.put("contractNo", null);// 合同号
|
|
||||||
orderParam.put("workOrderCode", headVo.getVbillcode());// 工单号
|
|
||||||
orderParam.put("qty", null); // 计划数量,字符串类型
|
|
||||||
orderParam.put("produCode", null); // 产品编码
|
|
||||||
orderParam.put("produName", null); // 产品名称
|
|
||||||
orderParam.put("bomCode", null); // BOM 编码
|
|
||||||
orderParam.put("planBeginDate", null); // 计划开始时间(毫秒级时间戳)
|
|
||||||
orderParam.put("planEndDate", null); // 计划完成时间(毫秒级时间戳)
|
|
||||||
orderParam.put("endDate", null); // 试验结束时间(毫秒级时间戳)
|
|
||||||
orderParam.put("type", "I"); // 类型:I:新增 U:修改 D:删除
|
|
||||||
orderParam.put("auditCode", "Y"); // 审核状态(Y:已审核 N:未审核)
|
|
||||||
orderParam.put("contractName", null); // 合同名称
|
|
||||||
orderParam.put("transferPlanTime", null); // 生产转检计划时间(格式为YYYY-MM-DD)
|
|
||||||
orderParam.put("receiptScheduledTime", null); // 完工入库时间(格式为YYYY-MM-DD)
|
|
||||||
String pkOrg = headVo.getPk_org();
|
String pkOrg = headVo.getPk_org();
|
||||||
String selectFields = FactoryVO.CODE + "," + FactoryVO.NAME;
|
String selectFields = FactoryVO.CODE + "," + FactoryVO.NAME;
|
||||||
Map<String, Object> orgMap = MyHelper.transferFields(FactoryVO.getDefaultTableName(), selectFields, FactoryVO.PK_FACTORY, pkOrg);
|
Map<String, Object> orgMap = MyHelper.transferFields(FactoryVO.getDefaultTableName(), selectFields, FactoryVO.PK_FACTORY, pkOrg);
|
||||||
orderParam.put("companyCode", orgMap.get(FactoryVO.CODE)); // 公司编码
|
// 物料
|
||||||
orderParam.put("companyName", orgMap.get(FactoryVO.NAME)); // 公司名称
|
String cmaterialid = pmoItem.getCmaterialid();
|
||||||
|
selectFields = MaterialVO.CODE + "," + MaterialVO.NAME;
|
||||||
|
Map<String, Object> goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), selectFields, MaterialVO.PK_MATERIAL, cmaterialid);
|
||||||
|
// 项目
|
||||||
|
String cprojectid = pmoItem.getCprojectid();
|
||||||
|
selectFields = ProjectHeadVO.PROJECT_CODE + "," + ProjectHeadVO.PROJECT_NAME;
|
||||||
|
Map<String, Object> projectMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), selectFields, ProjectHeadVO.PK_PROJECT, cprojectid);
|
||||||
|
// 组装数据
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
JSONObject orderParam = new JSONObject();
|
||||||
|
orderParam.put("id", null); // 唯一标识(主键)
|
||||||
|
orderParam.put("siteCode", null);// 工厂编码
|
||||||
|
if (projectMap != null) {
|
||||||
|
orderParam.put("contractNo", projectMap.get(ProjectHeadVO.PROJECT_CODE));// 合同号
|
||||||
|
orderParam.put("contractName", projectMap.get(ProjectHeadVO.PROJECT_NAME)); // 合同名称
|
||||||
|
}
|
||||||
|
orderParam.put("workOrderCode", headVo.getVbillcode());// 工单号
|
||||||
|
orderParam.put("qty", String.valueOf(pmoItem.getNastnum())); // 计划数量,字符串类型
|
||||||
|
if (goodsMap != null) {
|
||||||
|
orderParam.put("produCode", goodsMap.get(MaterialVO.CODE)); // 产品编码
|
||||||
|
orderParam.put("produName", goodsMap.get(MaterialVO.NAME)); // 产品名称
|
||||||
|
}
|
||||||
|
// cbomversionid 生产BOM版本
|
||||||
|
orderParam.put("bomCode", null); // BOM 编码
|
||||||
|
orderParam.put("planBeginDate", pmoItem.getTplanstarttime().getMillis()); // 计划开始时间(毫秒级时间戳)
|
||||||
|
orderParam.put("planEndDate", pmoItem.getTplanendtime()); // 计划完成时间(毫秒级时间戳)
|
||||||
|
// orderParam.put("endDate", null); // 试验结束时间(毫秒级时间戳)
|
||||||
|
orderParam.put("type", "I"); // 类型:I:新增 U:修改 D:删除
|
||||||
|
orderParam.put("auditCode", "Y"); // 审核状态(Y:已审核 N:未审核)
|
||||||
|
// orderParam.put("transferPlanTime", null); // 生产转检计划时间(格式为YYYY-MM-DD)
|
||||||
|
// orderParam.put("receiptScheduledTime", null); // 完工入库时间(格式为YYYY-MM-DD)
|
||||||
|
if (orgMap != null) {
|
||||||
|
orderParam.put("companyCode", orgMap.get(FactoryVO.CODE)); // 公司编码
|
||||||
|
orderParam.put("companyName", orgMap.get(FactoryVO.NAME)); // 公司名称
|
||||||
|
}
|
||||||
JSONArray orderArr = new JSONArray();
|
JSONArray orderArr = new JSONArray();
|
||||||
orderArr.add(orderParam);
|
orderArr.add(orderParam);
|
||||||
// 流程生产订单
|
// 流程生产订单
|
||||||
data.put("workOrders", orderArr);
|
data.put("workOrders", orderArr);
|
||||||
data.put("mrls", getPickmInfo(headVo.getPrimaryKey())); // 备料计划
|
data.put("mrls", getPickmInfo(pmoItem.getPrimaryKey())); // 备料计划
|
||||||
// {
|
// {
|
||||||
// "workOrders": [// 流程生产订单
|
// "workOrders": [// 流程生产订单
|
||||||
// {
|
// {
|
||||||
|
@ -204,6 +223,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
* @throws BusinessException
|
* @throws BusinessException
|
||||||
*/
|
*/
|
||||||
private JSONArray getPickmInfo(String sourceId) throws BusinessException {
|
private JSONArray getPickmInfo(String sourceId) throws BusinessException {
|
||||||
|
// vsourcemorowid 来源生产订单明细id
|
||||||
JSONArray pickmArr = new JSONArray();
|
JSONArray pickmArr = new JSONArray();
|
||||||
if (StringUtils.isEmpty(sourceId) || "~".equals(sourceId)) {
|
if (StringUtils.isEmpty(sourceId) || "~".equals(sourceId)) {
|
||||||
return pickmArr;
|
return pickmArr;
|
||||||
|
@ -216,7 +236,8 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
sqlBuilder.append(" left join bd_measdoc d on b.cbastunitid = d.pk_measdoc");
|
sqlBuilder.append(" left join bd_measdoc d on b.cbastunitid = d.pk_measdoc");
|
||||||
sqlBuilder.append(" where b.dr = 0");
|
sqlBuilder.append(" where b.dr = 0");
|
||||||
sqlBuilder.append(" and ");
|
sqlBuilder.append(" and ");
|
||||||
sqlBuilder.append("a.csourcebillid", sourceId);
|
// sqlBuilder.append("a.csourcebillid", sourceId);
|
||||||
|
sqlBuilder.append("a.vsourcemorowid", sourceId);// 来源生产订单明细id
|
||||||
List<Map<String, Object>> result = (List<Map<String, Object>>) dao.executeQuery(sqlBuilder.toString(), new MapListProcessor());
|
List<Map<String, Object>> result = (List<Map<String, Object>>) dao.executeQuery(sqlBuilder.toString(), new MapListProcessor());
|
||||||
for (Map<String, Object> objectMap : result) {
|
for (Map<String, Object> objectMap : result) {
|
||||||
JSONObject bodyJson = new JSONObject();
|
JSONObject bodyJson = new JSONObject();
|
||||||
|
@ -230,32 +251,7 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private JSONObject buildSyncCodeData(PMOAggVO vo) throws BusinessException {
|
||||||
* 转换特殊字段 如 1/1 转换为小数 1.0
|
|
||||||
*/
|
|
||||||
private String transferSpecialField(String field) {
|
|
||||||
if (field == null || field.trim().isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String[] split = field.split("/");
|
|
||||||
if (split.length == 2) {
|
|
||||||
String numStr = split[0].trim();
|
|
||||||
String denStr = split[1].trim();
|
|
||||||
if (denStr.equals("0")) {
|
|
||||||
return "0.00"; // 分母不能为零
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
BigDecimal numerator = new BigDecimal(numStr);
|
|
||||||
BigDecimal denominator = new BigDecimal(denStr);
|
|
||||||
return numerator.divide(denominator, 2, RoundingMode.HALF_UP).toString();
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return field; // 非法数字,返回原字段
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject buildSyncData1(PMOAggVO vo) throws BusinessException {
|
|
||||||
// [
|
// [
|
||||||
// {
|
// {
|
||||||
// "siteCode": "", // 工厂编码
|
// "siteCode": "", // 工厂编码
|
||||||
|
@ -288,18 +284,24 @@ public class AfterApproveSyncEpicMesRule implements IRule<PMOAggVO> {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushNoData(String requestUrl, JSONArray param) throws BusinessException {
|
/**
|
||||||
|
* 推送出厂编号
|
||||||
|
*
|
||||||
|
* @param param 传参
|
||||||
|
* @throws BusinessException
|
||||||
|
*/
|
||||||
|
private void pushCodeData(JSONArray param) throws BusinessException {
|
||||||
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
|
String baseUrl = SysParaInitQuery.getParaString("GLOBLE00000000000000", "EPICMESURL");
|
||||||
baseUrl = "http://192.168.55.39:8080";
|
baseUrl = "http://192.168.55.39:8080";
|
||||||
requestUrl = baseUrl + requestUrl;
|
String requestUrl = baseUrl + MES_CODE_URL;
|
||||||
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
|
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, param.toJSONString());
|
||||||
JSONObject resultObj = JSONObject.parseObject(result);
|
JSONObject resultObj = JSONObject.parseObject(result);
|
||||||
obmlog.error("AfterApproveSyncEpicMesRule-pushData-req = " + result);
|
obmlog.error("AfterApproveSyncEpicMesRule-pushCodeData-req = " + result);
|
||||||
|
|
||||||
if ("false".equals(resultObj.getString("success"))) {
|
if ("false".equals(resultObj.getString("success"))) {
|
||||||
throw new BusinessException("AfterApproveSyncEpicMesRule-pushData-failerror:" + resultObj.getString("msg"));
|
obmlog.error("AfterApproveSyncEpicMesRule-pushCodeData-fail:" + resultObj.getString("msg"));
|
||||||
} else {
|
} else {
|
||||||
obmlog.error("AfterApproveSyncEpicMesRule-pushData-suc,result[" + resultObj.toJSONString() + "]");
|
obmlog.error("AfterApproveSyncEpicMesRule-pushCodeData-suc,result[" + resultObj.toJSONString() + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue