bom替代料接口调整

This commit is contained in:
mzr 2025-09-15 21:44:33 +08:00
parent 5d68e40f57
commit 84ad04810b
3 changed files with 1847 additions and 1818 deletions

View File

@ -0,0 +1,24 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package nccloud.api.mmbd.bom;
import java.util.List;
import java.util.Map;
import nc.vo.bd.bom.bom0202.entity.AggBomVO;
import nc.vo.pub.BusinessException;
import org.json.JSONString;
public interface IAPIBomBusinessService {
JSONString insert(List<Map<String, Object>> var1);
JSONString update(List<Map<String, Object>> var1);
JSONString query(Map<String, Object> var1);
AggBomVO[] updateBomWithParam(AggBomVO[] aggvos, boolean isFromBom, boolean isecn, boolean isCheckEcn,
boolean isOnApprove) throws BusinessException;
}

View File

@ -6,15 +6,6 @@
package nccloud.openapi.mmbd.bom; package nccloud.openapi.mmbd.bom;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import nc.bs.bd.bom.bom0202.bp.BomPubBP;
import nc.bs.bd.bom.bom0202.bp.BomUpdateBP;
import nc.bs.framework.common.NCLocator; import nc.bs.framework.common.NCLocator;
import nc.bs.trade.business.HYPubBO; import nc.bs.trade.business.HYPubBO;
import nc.itf.bd.bom.bom0202.IBomBillMaintainService; import nc.itf.bd.bom.bom0202.IBomBillMaintainService;
@ -22,13 +13,10 @@ import nc.itf.bd.bom.bom0202.IBomBillQueryService;
import nc.jdbc.framework.generator.IdGenerator; import nc.jdbc.framework.generator.IdGenerator;
import nc.mmbd.utils.factoryparam.MMBDFactoryParameter; import nc.mmbd.utils.factoryparam.MMBDFactoryParameter;
import nc.uif.pub.exception.UifException; import nc.uif.pub.exception.UifException;
import nc.util.mmf.framework.base.MMArrayUtil;
import nc.util.mmf.framework.base.MMValueCheck; import nc.util.mmf.framework.base.MMValueCheck;
import nc.util.mmf.framework.gc.GCBillTransferTool;
import nc.vo.bd.bom.bom0202.entity.AggBomVO; import nc.vo.bd.bom.bom0202.entity.AggBomVO;
import nc.vo.bd.bom.bom0202.entity.BomItemVO; import nc.vo.bd.bom.bom0202.entity.BomItemVO;
import nc.vo.bd.bom.bom0202.entity.BomReplVO; import nc.vo.bd.bom.bom0202.entity.BomReplVO;
import nc.vo.bd.bom.bom0202.message.MMBDLangConstBom0202;
import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus; import nc.vo.pub.VOStatus;
@ -37,9 +25,18 @@ import nc.vo.pub.lang.UFDouble;
import nccloud.api.mmbd.bom.IAPIBomBusinessService; import nccloud.api.mmbd.bom.IAPIBomBusinessService;
import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.api.rest.utils.ResultMessageUtil;
import nccloud.framework.core.exception.ExceptionUtils; import nccloud.framework.core.exception.ExceptionUtils;
//import nccloud.framework.service.ServiceLocator;
import nccloud.ws.rest.resource.AbstractNCCRestResource; import nccloud.ws.rest.resource.AbstractNCCRestResource;
import org.json.JSONString; import org.json.JSONString;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Path("mmbd/bom") @Path("mmbd/bom")
public class BomResource extends AbstractNCCRestResource { public class BomResource extends AbstractNCCRestResource {
public BomResource() { public BomResource() {
@ -50,11 +47,11 @@ public class BomResource extends AbstractNCCRestResource {
@Consumes({"application/json"}) @Consumes({"application/json"})
@Produces({"application/json"}) @Produces({"application/json"})
public JSONString insert(JSONObject para) { public JSONString insert(JSONObject para) {
List<Map<String, Object>> paramList = (List)para.get("data"); List<Map<String, Object>> paramList = (List) para.get("data");
if (MMValueCheck.isEmpty(paramList)) { if (MMValueCheck.isEmpty(paramList)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
} else { } else {
IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class);
JSONString result = service.insert(paramList); JSONString result = service.insert(paramList);
return result; return result;
} }
@ -68,7 +65,7 @@ public class BomResource extends AbstractNCCRestResource {
if (MMValueCheck.isEmpty(paramList)) { if (MMValueCheck.isEmpty(paramList)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
} else { } else {
IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class);
JSONString result = service.insert(paramList); JSONString result = service.insert(paramList);
return result; return result;
} }
@ -79,11 +76,11 @@ public class BomResource extends AbstractNCCRestResource {
@Consumes({"application/json"}) @Consumes({"application/json"})
@Produces({"application/json"}) @Produces({"application/json"})
public JSONString update(JSONObject para) { public JSONString update(JSONObject para) {
List<Map<String, Object>> paramList = (List)para.get("data"); List<Map<String, Object>> paramList = (List) para.get("data");
if (MMValueCheck.isEmpty(paramList)) { if (MMValueCheck.isEmpty(paramList)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
} else { } else {
IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class);
JSONString result = service.update(paramList); JSONString result = service.update(paramList);
return result; return result;
} }
@ -97,7 +94,7 @@ public class BomResource extends AbstractNCCRestResource {
if (MMValueCheck.isEmpty(paramList)) { if (MMValueCheck.isEmpty(paramList)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
} else { } else {
IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class);
JSONString result = service.update(paramList); JSONString result = service.update(paramList);
return result; return result;
} }
@ -111,7 +108,7 @@ public class BomResource extends AbstractNCCRestResource {
if (MMValueCheck.isEmpty(paramMap)) { if (MMValueCheck.isEmpty(paramMap)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,未传入查询条件", "1"); return ResultMessageUtil.exceptionToJSON("传入数据异常,未传入查询条件", "1");
} else { } else {
IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class);
JSONString result = service.query(paramMap); JSONString result = service.query(paramMap);
return result; return result;
} }
@ -125,108 +122,108 @@ public class BomResource extends AbstractNCCRestResource {
if (MMValueCheck.isEmpty(paramMap)) { if (MMValueCheck.isEmpty(paramMap)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,未传入更新数据", "1"); return ResultMessageUtil.exceptionToJSON("传入数据异常,未传入更新数据", "1");
} else { } else {
try{ try {
IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class);
// List<> IBomBillQueryService qry = (IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class);
IBomBillQueryService qry = (IBomBillQueryService)NCLocator.getInstance().lookup(IBomBillQueryService.class); IBomBillMaintainService bomBillMaintainService = (IBomBillMaintainService) NCLocator.getInstance().lookup(IBomBillMaintainService.class);
IBomBillMaintainService bomBillMaintainService = (IBomBillMaintainService)NCLocator.getInstance().lookup(IBomBillMaintainService.class);
List<AggBomVO> bomReplVOS = new ArrayList<>(); List<AggBomVO> bomReplVOS = new ArrayList<>();
for (Map<String, Object> param : paramMap) { for (Map<String, Object> param : paramMap) {
String cbomid = (String) param.get("cbomid"); String cbomid = (String) param.get("cbomid");
String targetCbomReplaceId = (String) param.get("cbom_replaceid"); // 目标替代ID String targetCbomReplaceId = (String) param.get("cbom_replaceid"); // 目标替代ID
String targetCbomBid = (String) param.get("cbombid"); // 目标物料项ID String targetCbomBid = (String) param.get("cbombid"); // 目标物料项ID
// 校验必要参数 // 校验必要参数
if (MMValueCheck.isEmpty(cbomid) || MMValueCheck.isEmpty(targetCbomBid)) { if (MMValueCheck.isEmpty(cbomid) || MMValueCheck.isEmpty(targetCbomBid)) {
ExceptionUtils.wrapBusinessException("cbomid和cbombid为必传参数"); ExceptionUtils.wrapBusinessException("cbomid和cbombid为必传参数");
}
// 查询BOM数据
AggBomVO[] aggbomvos = qry.queryAggBomByBomID(new String[]{cbomid});
if (MMValueCheck.isEmpty(aggbomvos)) {
ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0057"));
}
for (AggBomVO aggBomVO : aggbomvos) {
BomItemVO[] bomItemVOS = aggBomVO.getChildrenVO();
if (MMValueCheck.isEmpty(bomItemVOS)) {
continue; // 无物料项则跳过
} }
for (BomItemVO bomItemVO : bomItemVOS) { // 查询BOM数据
// 匹配目标物料项 AggBomVO[] aggbomvos = qry.queryAggBomByBomID(new String[]{cbomid});
if (targetCbomBid.equals(bomItemVO.getCbom_bid())) { if (MMValueCheck.isEmpty(aggbomvos)) {
BomReplVO[] replVOS = bomItemVO.getRepl(); ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0057"));
List<BomReplVO> replList = MMValueCheck.isEmpty(replVOS) }
? new ArrayList<>()
: new ArrayList<>(Arrays.asList(replVOS));
boolean isUpdated = false; for (AggBomVO aggBomVO : aggbomvos) {
BomItemVO[] bomItemVOS = aggBomVO.getChildrenVO();
if (MMValueCheck.isEmpty(bomItemVOS)) {
continue; // 无物料项则跳过
}
// 存在cbom_replaceid则更新 for (BomItemVO bomItemVO : bomItemVOS) {
if (!MMValueCheck.isEmpty(targetCbomReplaceId)) { // 匹配目标物料项
for (BomReplVO replVO : replList) { if (targetCbomBid.equals(bomItemVO.getCbom_bid())) {
if (targetCbomReplaceId.equals(replVO.getCbom_replaceid())) { BomReplVO[] replVOS = bomItemVO.getRepl();
// 设置属性复用工具方法 List<BomReplVO> replList = MMValueCheck.isEmpty(replVOS)
setReplVOProperties(replVO, param); ? new ArrayList<>()
replVO.setStatus(VOStatus.UPDATED); : new ArrayList<>(Arrays.asList(replVOS));
isUpdated = true;
break; boolean isUpdated = false;
// 存在cbom_replaceid则更新
if (!MMValueCheck.isEmpty(targetCbomReplaceId)) {
for (BomReplVO replVO : replList) {
if (targetCbomReplaceId.equals(replVO.getCbom_replaceid())) {
// 设置属性复用工具方法
setReplVOProperties(replVO, param);
replVO.setStatus(VOStatus.UPDATED);
isUpdated = true;
break;
}
} }
} }
// 不存在cbom_replaceid则新增
if (!isUpdated && MMValueCheck.isEmpty(targetCbomReplaceId)) {
BomReplVO newReplVO = new BomReplVO();
IdGenerator idGenerator = NCLocator.getInstance().lookup(IdGenerator.class);
newReplVO.setCbom_replaceid(idGenerator.generate()); // 生成新ID
newReplVO.setCbom_bid(targetCbomBid); // 关联当前物料项
// 计算新行号(原有替代项数量 + 1) * 10
int existingCount = replList.size();
int newRowNumber = (existingCount + 1) * 10;
newReplVO.setVrowno(String.valueOf(newRowNumber)); // 设置新行号
// 设置其他属性会覆盖param中的vrowno确保按规则生成
setReplVOProperties(newReplVO, param);
newReplVO.setStatus(VOStatus.NEW);
replList.add(newReplVO);
}
// 更新物料项的替代项数组
bomItemVO.setRepl(replList.toArray(new BomReplVO[0]));
} }
// 不存在cbom_replaceid则新增
if (!isUpdated && MMValueCheck.isEmpty(targetCbomReplaceId)) {
BomReplVO newReplVO = new BomReplVO();
IdGenerator idGenerator = NCLocator.getInstance().lookup(IdGenerator.class);
newReplVO.setCbom_replaceid(idGenerator.generate()); // 生成新ID
newReplVO.setCbom_bid(targetCbomBid); // 关联当前物料项
// 计算新行号(原有替代项数量 + 1) * 10
int existingCount = replList.size();
int newRowNumber = (existingCount + 1) * 10;
newReplVO.setVrowno(String.valueOf(newRowNumber)); // 设置新行号
// 设置其他属性会覆盖param中的vrowno确保按规则生成
setReplVOProperties(newReplVO, param);
newReplVO.setStatus(VOStatus.NEW);
replList.add(newReplVO);
}
// 更新物料项的替代项数组
bomItemVO.setRepl(replList.toArray(new BomReplVO[0]));
} }
// 更新BOM
aggBomVO.setChildrenVO(bomItemVOS);
AggBomVO[] result = service.updateBomWithParam(
new AggBomVO[]{aggBomVO},
false,
false,
MMBDFactoryParameter.getMMECN001Value(
aggBomVO.getParentVO().getAttributeValue("pk_org").toString()
).booleanValue(),
true
);
bomReplVOS.addAll(Arrays.asList(result));
} }
// 更新BOM
aggBomVO.setChildrenVO(bomItemVOS);
AggBomVO[] result = this.updateBomWithParam(
new AggBomVO[]{aggBomVO},
false,
false,
MMBDFactoryParameter.getMMECN001Value(
aggBomVO.getParentVO().getAttributeValue("pk_org").toString()
).booleanValue(),
true
);
bomReplVOS.addAll(Arrays.asList(result));
} }
}
return ResultMessageUtil.toJSON(bomReplVOS, "BOM更新成功"); return ResultMessageUtil.toJSON(bomReplVOS, "BOM更新成功");
}catch (BusinessException e) { } catch (BusinessException e) {
throw new RuntimeException(e); return ResultMessageUtil.exceptionToJSON(e);
} }
} }
} }
// 提取属性设置为工具方法减少冗余 // 提取属性设置为工具方法减少冗余
private void setReplVOProperties(BomReplVO replVO, Map<String, Object> param) throws UifException { private void setReplVOProperties(BomReplVO replVO, Map<String, Object> param) throws UifException {
HYPubBO hybo = new HYPubBO(); HYPubBO hybo = new HYPubBO();
@ -238,8 +235,8 @@ public class BomResource extends AbstractNCCRestResource {
// } // }
if (param.containsKey("creplmaterialvid")) { if (param.containsKey("creplmaterialvid")) {
String mrlCode= (String) param.get("creplmaterialvid"); String mrlCode = (String) param.get("creplmaterialvid");
String mrlid=(String) hybo.findColValue("bd_material","pk_material"," code = '" + mrlCode + "' "); String mrlid = (String) hybo.findColValue("bd_material", "pk_material", " code = '" + mrlCode + "' ");
replVO.setCreplmaterialvid(mrlid); replVO.setCreplmaterialvid(mrlid);
} }
@ -273,34 +270,6 @@ public class BomResource extends AbstractNCCRestResource {
} }
} }
} }
public AggBomVO[] updateBomWithParam(AggBomVO[] aggvos, boolean isFromBom, boolean isecn, boolean isCheckEcn,
boolean isOnApprove) throws BusinessException {
if (MMArrayUtil.isEmpty(aggvos)) {
return null;
}
try {
// 检查该BOM是否被删除因为如果BOM树状维护将BOM删除了不允许修改该条记录
Set<String> bomids = new HashSet<String>();
for (AggBomVO vo : aggvos) {
bomids.add(vo.getPrimaryKey());
}
Set<String> checkResult = BomPubBP.getBomID(bomids.toArray(new String[] {}));
if (checkResult != null && checkResult.size() < bomids.size()) {
nc.vo.pubapp.pattern.exception.ExceptionUtils.wrappBusinessException(MMBDLangConstBom0202.getBOM_DELETED());
}
// 加锁 + 检查ts
GCBillTransferTool<AggBomVO> transTool = new GCBillTransferTool<AggBomVO>(aggvos);
// 补全前台VO
AggBomVO[] fullBills = transTool.getClientFullInfoBill();
// 获得修改前vo
AggBomVO[] originBills = transTool.getOriginBills();
BomUpdateBP bp = new BomUpdateBP();
return bp.update(fullBills, originBills, isCheckEcn, isOnApprove, isFromBom, isecn);
} catch (Exception e) {
nc.vo.pubapp.pattern.exception.ExceptionUtils.marsh(e);
}
return null;
}
public String getModule() { public String getModule() {
return "mmbd"; return "mmbd";