fix:出库的时候计划外投料直接投工单不走bom,前提计划外只挂一个工单
This commit is contained in:
@@ -99,25 +99,24 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
if (StrUtil.isBlank(materialCode)) {
|
||||
throw new BadRequestException("生产投料回传失败:需求单" + demandId + "物料为空");
|
||||
}
|
||||
|
||||
Map<String, BigDecimal> usedQtyByBom = new LinkedHashMap<>();
|
||||
BigDecimal postedTotal = postByBomRemain(demand, materialCode, lgort,
|
||||
StrUtil.blankToDefault(param.getIostorinv_id(), demand.getId()),
|
||||
bill == null ? null : bill.getBill_code(), usedQtyByBom);
|
||||
if (postedTotal.signum() > 0) {
|
||||
syncDetailAssignQty(bill, materialCode, usedQtyByBom);
|
||||
}
|
||||
bill == null ? null : bill.getBill_code(), usedQtyByBom,param.getAssign_qty());
|
||||
// if (postedTotal.signum() > 0) {
|
||||
// syncDetailAssignQty(bill, materialCode, usedQtyByBom);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 中鼎反馈需求单完成:与出库单实时过账口径一致,
|
||||
* 按各工单BOM剩余量(bom_qty - use_bom_qty)逐工单过账,并维护 BOM 已用数量。
|
||||
*/
|
||||
public void feedbackDemand(PmDemand demand, BigDecimal qty) {
|
||||
public void feedbackDemand(PmDemand demand, BigDecimal feedbackQty) {
|
||||
if (demand == null || StrUtil.isBlank(demand.getId())) {
|
||||
throw new BadRequestException("生产领料回传失败:需求单为空");
|
||||
}
|
||||
if (qty == null || qty.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
if (feedbackQty == null || feedbackQty.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new BadRequestException("生产领料回传失败:需求单" + demand.getId() + "反馈数量无效");
|
||||
}
|
||||
if (StrUtil.isBlank(demand.getSku_code())) {
|
||||
@@ -127,11 +126,13 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
if (StrUtil.isBlank(lgort)) {
|
||||
throw new BadRequestException("生产领料回传失败:需求单" + demand.getId() + "存储地点为空");
|
||||
}
|
||||
//回传SAP
|
||||
BigDecimal postedTotal = postByBomRemain(demand, StrUtil.trim(demand.getSku_code()), lgort,
|
||||
demand.getId(), null, new LinkedHashMap<>());
|
||||
if (postedTotal.compareTo(qty) != 0) {
|
||||
demand.getId(), null, new LinkedHashMap<>(),feedbackQty);
|
||||
|
||||
if (postedTotal.compareTo(feedbackQty) != 0) {
|
||||
log.info("需求单{}反馈数量{}与按BOM剩余量过账数量{}不一致,投料以BOM口径为准",
|
||||
demand.getId(), qty, postedTotal);
|
||||
demand.getId(), feedbackQty, postedTotal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
* @return 本次实际过账的数量合计
|
||||
*/
|
||||
private BigDecimal postByBomRemain(PmDemand demand, String materialCode, String lgort, String requestId,
|
||||
String billCode, Map<String, BigDecimal> usedQtyByBom) {
|
||||
String billCode, Map<String, BigDecimal> usedQtyByBom,BigDecimal feedbackQty) {
|
||||
List<String> orderCodes = splitWorkOrders(demand.getWork_order_code());
|
||||
if (orderCodes.isEmpty()) {
|
||||
throw new BadRequestException("需求单" + demand.getId() + "未绑定工单");
|
||||
@@ -155,28 +156,47 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
|
||||
String today = LocalDate.now().format(DATE_BASIC);
|
||||
BigDecimal postedTotal = BigDecimal.ZERO;
|
||||
//待分配数量
|
||||
BigDecimal unAssertQty = feedbackQty;
|
||||
for (WorkOrderDao workOrder : workOrderList) {
|
||||
WorkOrderBomDao bom = matchBomItem(iWorkOrderService.getOrderBomItem(workOrder.getOrder_code()), materialCode);
|
||||
if (bom == null) {
|
||||
String msg = String.format(
|
||||
"需求单[%s]工单[%s]未匹配到物料[%s]的BOM行,无法过账",
|
||||
demand.getId(), workOrder.getOrder_code(), materialCode);
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
BigDecimal usedQty = nvl(bom.getUse_bom_qty());
|
||||
usedQtyByBom.put(bom.getId(), usedQty);
|
||||
// 本次过账数量 = BOM数量 - 已用BOM数量
|
||||
BigDecimal postQty = nvl(bom.getBom_qty()).subtract(usedQty);
|
||||
if (postQty.signum() <= 0) {
|
||||
log.info("需求单{}工单{}物料{}BOM已领完(bom_qty={},use_bom_qty={}),跳过过账",
|
||||
demand.getId(), workOrder.getOrder_code(), materialCode, bom.getBom_qty(), usedQty);
|
||||
continue;
|
||||
boolean withReserve = StrUtil.startWith(StrUtil.trim(workOrder.getOrder_code()), "G");
|
||||
String rsnum = "";
|
||||
String rspos = "";
|
||||
BigDecimal sapQty = new BigDecimal(feedbackQty.intValue());
|
||||
WorkOrderBomDao bom = null;
|
||||
if (withReserve){
|
||||
bom = matchBomItem(iWorkOrderService.getOrderBomItem(workOrder.getOrder_code()), materialCode);
|
||||
if (bom == null) {
|
||||
String msg = String.format(
|
||||
"需求单[%s]工单[%s]未匹配到物料[%s]的BOM行,无法过账",
|
||||
demand.getId(), workOrder.getOrder_code(), materialCode);
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
BigDecimal usedQty = nvl(bom.getUse_bom_qty());
|
||||
// bom剩余过账数量 = BOM数量 - 已用BOM数量
|
||||
// 当前数量:feedbackQty
|
||||
BigDecimal postQty = nvl(bom.getBom_qty()).subtract(usedQty);
|
||||
if (postQty.signum() <= 0) {
|
||||
log.info("需求单{}工单{}物料{}BOM已领完(bom_qty={},use_bom_qty={}),跳过过账",
|
||||
demand.getId(), workOrder.getOrder_code(), materialCode, bom.getBom_qty(), usedQty);
|
||||
continue;
|
||||
}
|
||||
if (unAssertQty.intValue()<=postQty.intValue()){
|
||||
sapQty = new BigDecimal(unAssertQty.intValue());
|
||||
unAssertQty = BigDecimal.ZERO;
|
||||
}else {
|
||||
sapQty = postQty;
|
||||
unAssertQty = unAssertQty.subtract(postQty);
|
||||
}
|
||||
usedQtyByBom.put(bom.getId(), usedQty.add(sapQty));
|
||||
postedTotal = postedTotal.add(sapQty);
|
||||
}else {
|
||||
unAssertQty = BigDecimal.ZERO;
|
||||
}
|
||||
// 请求号需全局唯一,SAP 侧按 docno 识别一次过账;一个工单一次请求,便于按工单隔离失败
|
||||
String docno = "FEED" + System.currentTimeMillis();
|
||||
ProductionOutboundRequest request = buildRequest(docno, today, workOrder, materialCode, lgort, bom, postQty);
|
||||
|
||||
ProductionOutboundRequest request = buildRequest(docno, today, workOrder, materialCode, lgort, rsnum,rspos, sapQty);
|
||||
PmStockReturn stockReturn = new PmStockReturn();
|
||||
stockReturn.setRequest_Id(requestId);
|
||||
stockReturn.setBill_code(billCode);
|
||||
@@ -184,7 +204,6 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
stockReturn.setStatus(StockReturnStatusEnum.TODO.getCode());
|
||||
stockReturn.setCreate_time(DateUtil.now());
|
||||
stockReturn.setRequest_data(JSON.toJSONString(request));
|
||||
|
||||
boolean success = false;
|
||||
try {
|
||||
JSONObject sapResult = sapApi.productionOutbound(request);
|
||||
@@ -202,12 +221,12 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
stockReturn.setProcess_time(DateUtil.now());
|
||||
}
|
||||
iPmStockReturnService.save(stockReturn);
|
||||
|
||||
if (success) {
|
||||
if (success && withReserve) {
|
||||
// 维护BOM已用数量(原子累加)
|
||||
iWorkOrderService.updateBomUseQty(bom.getId(), postQty);
|
||||
usedQtyByBom.put(bom.getId(), usedQty.add(postQty));
|
||||
postedTotal = postedTotal.add(postQty);
|
||||
iWorkOrderService.updateBomUseQty(bom.getId(), usedQtyByBom.get(bom.getId()));
|
||||
}
|
||||
if (unAssertQty.intValue()<=0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return postedTotal;
|
||||
@@ -283,7 +302,7 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
* 组装单个工单的单条 PP055 报文:数量按 BOM 剩余量过账
|
||||
*/
|
||||
private ProductionOutboundRequest buildRequest(String docno, String today, WorkOrderDao workOrder,
|
||||
String materialCode, String lgort, WorkOrderBomDao bom,
|
||||
String materialCode, String lgort,String rsnum,String rspos,
|
||||
BigDecimal postQty) {
|
||||
ProductionOutboundRequest request = new ProductionOutboundRequest();
|
||||
ProductionOutboundHeader header = new ProductionOutboundHeader();
|
||||
@@ -292,7 +311,6 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
header.setDestSystem(SapConstant.DEST_SYSTEM);
|
||||
header.setRequesttime(System.currentTimeMillis());
|
||||
request.setHeader(header);
|
||||
|
||||
// 仅 G 开头工单带预留号/行项目,其余按计划外投料
|
||||
boolean withReserve = StrUtil.startWith(StrUtil.trim(workOrder.getOrder_code()), "G");
|
||||
ProductionOutboundBody body = new ProductionOutboundBody();
|
||||
@@ -304,8 +322,8 @@ public class SapProductionOutboundDelivery implements CallbackStrategy {
|
||||
body.setLgort(lgort);
|
||||
body.setAufnr(workOrder.getOrder_code());
|
||||
body.setErfmg(postQty.doubleValue());
|
||||
body.setRsnum(withReserve ? StrUtil.blankToDefault(bom.getRsnum(), "") : "");
|
||||
body.setRspos(withReserve ? StrUtil.blankToDefault(bom.getRspos(), "") : "");
|
||||
body.setRsnum(rsnum);
|
||||
body.setRspos(rspos);
|
||||
if (!withReserve) {
|
||||
log.info("工单{}非G开头,按计划外投料过账(不带预留号/行项目)", workOrder.getOrder_code());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user