高压MES-生产订单推送-上级单号取值

This commit is contained in:
mzr 2025-10-22 09:05:18 +08:00
parent bc0a0628e0
commit 20a9b73243
1 changed files with 95 additions and 53 deletions

View File

@ -23,12 +23,16 @@ import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
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.res.billtype.MMBillType;
import nc.vo.scmpub.util.ArrayUtil;
import nc.vo.trade.billsource.LightBillVO;
import nc.vo.trade.billsource.LinkQueryType;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import nccloud.vo.trade.billsource.BillFlowVO;
import nccloud.web.riart.billflow.model.BillFlowModel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Stream;
/**
@ -74,9 +78,11 @@ public class AfterApproveSyncHighpressureMesRule implements IRule<PMOAggVO> {
if (checkIfOrg(orgCode, configParams)) {
continue;
}
String cpmohid = pmoHeadVO.getCpmohid();
String vbillcode = pmoHeadVO.getVbillcode();
JSONObject singleObj = new JSONObject();
singleObj.put("bipProcessProductionOrderId", pmoHeadVO.getVbillcode());
singleObj.put("bipId", pmoHeadVO.getCpmohid());// 主键ID
singleObj.put("bipProcessProductionOrderId", vbillcode);
singleObj.put("bipId", cpmohid);// 主键ID
// singleObj.put("orderQuantity", pmoHeadVO.getPlanQuantity()); // 订单数量计划数量
singleObj.put("billDate", pmoHeadVO.getDbilldate().toString()); // 单据日期
singleObj.put("orderVersion", pmoHeadVO.getVersion()); // 版本号
@ -131,10 +137,9 @@ public class AfterApproveSyncHighpressureMesRule implements IRule<PMOAggVO> {
// 上级-上一个生产订单的信息
itemObj.put("bipParentProcessProductionOrderId", null);
itemObj.put("bipParentProcessProductionOrderRowNum", null);
Map<String, String> prevOrderMap = findPrevOrder(cmoid);
if (prevOrderMap != null && !prevOrderMap.isEmpty()) {
itemObj.put("bipParentProcessProductionOrderId", prevOrderMap.get("vsrccode"));
itemObj.put("bipParentProcessProductionOrderRowNum", prevOrderMap.get("vsrcrowno"));
String vsrccode = findPrevOrder(cpmohid, vbillcode);
if (vsrccode != null && !vsrccode.isEmpty()) {
itemObj.put("bipParentProcessProductionOrderId", vsrccode);// 上一个生产订单单号
}
// 顶级-源头单据信息
itemObj.put("bipOriginProcessProductionOrderId", item.getVfirstcode());
@ -215,52 +220,89 @@ public class AfterApproveSyncHighpressureMesRule implements IRule<PMOAggVO> {
}
/**
* 按来源链路逐级向上查找上一张生产订单(55A2)
* 规则
* 1) 若上级为空返回null
* 2) 若到达源头单据且其类型不是55A2返回null
* 3) 若遇到类型为55A2则立即返回该生产订单
* 查询上一个生产订单的信息
*
* @throws BusinessException 业务异常
* @param hid 当前生产订单的ID
* @param vbillcode 当前生产订单的单号
*/
private Map<String, String> findPrevOrder(String currentMoBid) throws BusinessException {
String nextBid = currentMoBid;
while (nextBid != null) {
String sql = "SELECT vsrctrantype, vsrcid, vsrcbid, vsrccode, vsrcrowno, vfirstid, vfirstbid FROM mm_mo WHERE dr = 0 AND cmoid = '" + nextBid + "'";
Map<String, Object> row = (Map<String, Object>) baseDAO.executeQuery(sql, new MapProcessor());
if (row == null) {
return null;
}
String vsrctrantype = (String) row.get("vsrctrantype");
String vsrcid = (String) row.get("vsrcid");
String vsrcbid = (String) row.get("vsrcbid");
String vsrccode = (String) row.get("vsrccode");
String vsrcrowno = (String) row.get("vsrcrowno");
String vfirstid = (String) row.get("vfirstid");
// 上级为空
if (vsrctrantype == null || vsrcid == null || vsrcbid == null) {
return null;
}
// 命中上一张生产订单
if ("55A2".equals(vsrctrantype)) {
Map<String, String> result = new HashMap<>();
result.put("vsrccode", vsrccode);
result.put("vsrcrowno", vsrcrowno);
return result;
}
// 已到达源头但源头不是生产订单则结束返回null
if (vsrcid.equals(vfirstid) && !"55A2".equals(vsrctrantype)) {
return null;
}
// 继续向上下一轮以来源明细作为当前明细
nextBid = vsrcbid;
private String findPrevOrder(String hid, String vbillcode) throws BusinessException {
String preCode = null;
BillFlowModel billFlow = new BillFlowModel();
LightBillVO vo = billFlow.querySourceBillVO(hid, MMBillType.ProduceOrder.getCode(), LinkQueryType.OnlyQueryBill);
if (vo == null) {
return null;
}
return null;
LightBillVO[] sourceBillVOs = vo.getSourceBillVOs();
if (sourceBillVOs == null || sourceBillVOs.length == 0) {
return null;
}
List<BillFlowVO> list = this.dealVO(vo);
if (list == null || list.isEmpty()) {
return null;
}
for (BillFlowVO billFlowVO : list) {
// 判断是否为来源单据 -1来源单据 0本单据 1下游单据
if ("-1".equals(billFlowVO.getIsForward())) {
LightBillVO lightBillVO = billFlowVO.getLightBillVO();
String billType = lightBillVO.getType();
String billCode = lightBillVO.getCode();
// 不断向下寻找流程生产订单直到找到最后一个流程生产订单
if ("55A2".equals(billType) && !billCode.equals(vbillcode)) {
preCode = billCode;
}
}
}
NCCForUAPLogger.debug("preCode = " + preCode);
return preCode;
}
public List<BillFlowVO> dealVO(LightBillVO vo) {
if (vo == null) {
return null;
} else {
Map<String, BillFlowVO> setAll = new LinkedHashMap();
this.getSource(vo, setAll);
List<String> sourceList = setAll.get(vo.getID()).getSourceList();
setAll.get(vo.getID()).setIsForward("0");
setAll.get(vo.getID()).setSourceList(sourceList);
List<BillFlowVO> list = new ArrayList(setAll.values());
return list;
}
}
public void getSource(LightBillVO vo, Map<String, BillFlowVO> setAll) {
if (vo != null) {
BillFlowVO flow = new BillFlowVO();
flow.setLightBillVO(vo);
flow.setIsForward("-1");
List<String> sourceList = flow.getSourceList();
if (vo.getSourceBillVOs() == null) {
if (setAll.get(vo.getID()) == null) {
setAll.put(vo.getID(), flow);
}
} else {
for (LightBillVO sourVO : vo.getSourceBillVOs()) {
sourceList.add(sourVO.getID());
this.getSource(sourVO, setAll);
}
vo.setSourceMap(new HashMap());
flow.setSourceList(sourceList);
setAll.put(vo.getID(), flow);
}
}
}
public Map<String, Object> getSource1(String pk, String tableName) throws BusinessException {
SqlBuilder sqlBuilder = new SqlBuilder();
sqlBuilder.append(" select DISTINCT vsrctype type, vsrcid id");
sqlBuilder.append(" from " + tableName);
sqlBuilder.append(" where dr = 0 and ");
sqlBuilder.append("", pk);
Map<String, Object> result = (Map<String, Object>) baseDAO.executeQuery(sqlBuilder.toString(), new MapProcessor());
return result;
}