高压MES-生产订单推送-上级单号取值
This commit is contained in:
parent
bc0a0628e0
commit
20a9b73243
|
|
@ -23,12 +23,16 @@ import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
||||||
import nc.vo.org.OrgVO;
|
import nc.vo.org.OrgVO;
|
||||||
import nc.vo.pub.BusinessException;
|
import nc.vo.pub.BusinessException;
|
||||||
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
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.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.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -74,9 +78,11 @@ public class AfterApproveSyncHighpressureMesRule implements IRule<PMOAggVO> {
|
||||||
if (checkIfOrg(orgCode, configParams)) {
|
if (checkIfOrg(orgCode, configParams)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
String cpmohid = pmoHeadVO.getCpmohid();
|
||||||
|
String vbillcode = pmoHeadVO.getVbillcode();
|
||||||
JSONObject singleObj = new JSONObject();
|
JSONObject singleObj = new JSONObject();
|
||||||
singleObj.put("bipProcessProductionOrderId", pmoHeadVO.getVbillcode());
|
singleObj.put("bipProcessProductionOrderId", vbillcode);
|
||||||
singleObj.put("bipId", pmoHeadVO.getCpmohid());// 主键ID
|
singleObj.put("bipId", cpmohid);// 主键ID
|
||||||
// singleObj.put("orderQuantity", pmoHeadVO.getPlanQuantity()); // 订单数量(计划数量)
|
// singleObj.put("orderQuantity", pmoHeadVO.getPlanQuantity()); // 订单数量(计划数量)
|
||||||
singleObj.put("billDate", pmoHeadVO.getDbilldate().toString()); // 单据日期
|
singleObj.put("billDate", pmoHeadVO.getDbilldate().toString()); // 单据日期
|
||||||
singleObj.put("orderVersion", pmoHeadVO.getVersion()); // 版本号
|
singleObj.put("orderVersion", pmoHeadVO.getVersion()); // 版本号
|
||||||
|
|
@ -131,10 +137,9 @@ public class AfterApproveSyncHighpressureMesRule implements IRule<PMOAggVO> {
|
||||||
// 上级-上一个生产订单的信息
|
// 上级-上一个生产订单的信息
|
||||||
itemObj.put("bipParentProcessProductionOrderId", null);
|
itemObj.put("bipParentProcessProductionOrderId", null);
|
||||||
itemObj.put("bipParentProcessProductionOrderRowNum", null);
|
itemObj.put("bipParentProcessProductionOrderRowNum", null);
|
||||||
Map<String, String> prevOrderMap = findPrevOrder(cmoid);
|
String vsrccode = findPrevOrder(cpmohid, vbillcode);
|
||||||
if (prevOrderMap != null && !prevOrderMap.isEmpty()) {
|
if (vsrccode != null && !vsrccode.isEmpty()) {
|
||||||
itemObj.put("bipParentProcessProductionOrderId", prevOrderMap.get("vsrccode"));
|
itemObj.put("bipParentProcessProductionOrderId", vsrccode);// 上一个生产订单单号
|
||||||
itemObj.put("bipParentProcessProductionOrderRowNum", prevOrderMap.get("vsrcrowno"));
|
|
||||||
}
|
}
|
||||||
// 顶级-源头单据信息
|
// 顶级-源头单据信息
|
||||||
itemObj.put("bipOriginProcessProductionOrderId", item.getVfirstcode());
|
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 {
|
private String findPrevOrder(String hid, String vbillcode) throws BusinessException {
|
||||||
String nextBid = currentMoBid;
|
String preCode = null;
|
||||||
while (nextBid != null) {
|
BillFlowModel billFlow = new BillFlowModel();
|
||||||
String sql = "SELECT vsrctrantype, vsrcid, vsrcbid, vsrccode, vsrcrowno, vfirstid, vfirstbid FROM mm_mo WHERE dr = 0 AND cmoid = '" + nextBid + "'";
|
LightBillVO vo = billFlow.querySourceBillVO(hid, MMBillType.ProduceOrder.getCode(), LinkQueryType.OnlyQueryBill);
|
||||||
Map<String, Object> row = (Map<String, Object>) baseDAO.executeQuery(sql, new MapProcessor());
|
if (vo == null) {
|
||||||
if (row == null) {
|
return 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;
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue