fix:库改需求单
This commit is contained in:
@@ -45,7 +45,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -172,6 +171,7 @@ public class MesToWmsController {
|
||||
ArrayList<PmDemandParam> pmDemandPlatingParams = new ArrayList<>();
|
||||
ArrayList<PmDemandParam> partDemandParams = new ArrayList<>();
|
||||
ArrayList<PmDemandParam> structureDemandParams = new ArrayList<>();
|
||||
ArrayList<PmDemandParam> pmDemandR005Params = new ArrayList<>();
|
||||
Map<String, String> warehouseByMaterial = materialWarehouseMappingService.getWarehouseByMaterialCodes(
|
||||
params.stream().map(PmDemandParam::getSkuCode).collect(Collectors.toSet()));
|
||||
for (PmDemandParam param : params) {
|
||||
@@ -184,12 +184,7 @@ public class MesToWmsController {
|
||||
RegionConstant.H001.equals(warehouseCode) || RegionConstant.H002.equals(warehouseCode)) {
|
||||
structureDemandParams.add(param);
|
||||
} else if (RegionConstant.R005.equals(warehouseCode)) {
|
||||
// 库存足够落 R005 需求单(页面可转普通需求单人工出库),不足直接转普通需求单
|
||||
if (r005StockEnough(param)) {
|
||||
pmDemandR005Service.saveDemand(param);
|
||||
} else {
|
||||
pmDemandParams.add(param);
|
||||
}
|
||||
pmDemandR005Params.add(param);
|
||||
} else {
|
||||
pmDemandParams.add(param);
|
||||
}
|
||||
@@ -198,30 +193,10 @@ public class MesToWmsController {
|
||||
iPmDemandPlatingService.batchCreate(pmDemandPlatingParams);
|
||||
partDemandService.batchCreate(partDemandParams);
|
||||
structureDemandService.batchCreate(structureDemandParams);
|
||||
pmDemandR005Service.batchSave(pmDemandR005Params);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* R005 库存是否足够(可用数量 = 库存数量 - 冻结数量)
|
||||
*/
|
||||
private boolean r005StockEnough(PmDemandParam param) {
|
||||
if (param == null || StringUtils.isEmpty(param.getSkuCode()) || param.getQty() == null) {
|
||||
return false;
|
||||
}
|
||||
StInventoryQuery query = new StInventoryQuery();
|
||||
query.setStorCode(RegionConstant.R005);
|
||||
query.setMaterialCode(param.getSkuCode());
|
||||
List<StInventoryDto> inventories = iStInventoryService.queryInventory(query);
|
||||
BigDecimal available = inventories.stream()
|
||||
.map(row -> {
|
||||
BigDecimal qty = row.getQty() == null ? BigDecimal.ZERO : row.getQty();
|
||||
BigDecimal frozen = row.getFrozenQty() == null ? BigDecimal.ZERO : row.getFrozenQty();
|
||||
return qty.subtract(frozen).max(BigDecimal.ZERO);
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
return available.compareTo(param.getQty()) >= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MES 通用库存调拨:任意个物料从源仓库调拨到目标仓库,
|
||||
|
||||
@@ -316,9 +316,9 @@ PDA 扫码后调用以下接口收货:
|
||||
|
||||
## R005 库改原材料库需求(只记录需求 + 下推出库 + 页面转移)
|
||||
|
||||
- 分流:`mesRequisitionSync` 中 `warehouseCode = R005` 的物料:
|
||||
- R005 **可用库存 ≥ 需求数量**:只写 `pm_demand_r005`(状态 `01` 分配),**MES 同步时不生成出库单、不回传 SAP**;
|
||||
- R005 **库存不足**:需求单转 `pm_demand`(普通需求单)走人工分配/下推流程,不在 R005 表留痕。
|
||||
- 分流:`mesRequisitionSync` 中 `warehouseCode = R005` 的物料**不再校验库存**,与其他仓库需求单一样直接批量保存
|
||||
到 `pm_demand_r005`(`IPmDemandR005Service#batchSave`,状态 `01` 分配;`Status=1` 的行按 MES 撤回处理);
|
||||
MES 同步时不生成出库单、不回传 SAP。
|
||||
- 下推出库(页面「下推出库」按钮,`POST /api/pmDemandR005/push`):
|
||||
- 生成一张 WMS **生产出库**单(仓库取需求单 `inventory_dis`,兜底 R005),
|
||||
明细 `source_bill_code`/`source_billdtl_id` = 需求单ID、`source_bill_type = R005需求单`、
|
||||
|
||||
@@ -18,6 +18,11 @@ public interface IPmDemandR005Service extends IService<PmDemandR005> {
|
||||
|
||||
IPage<PmDemandDto> queryPage(PmDemandQuery query, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 记录 R005 需求(MES 同步批量保存;Status=1 表示 MES 撤回)
|
||||
*/
|
||||
void batchSave(List<PmDemandParam> params);
|
||||
|
||||
/**
|
||||
* 记录 R005 需求(库存充足时由 MES 同步接口调用)
|
||||
*/
|
||||
|
||||
@@ -89,6 +89,35 @@ public class PmDemandR005ServiceImpl extends ServiceImpl<PmDemandR005Mapper, PmD
|
||||
return dtoPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchSave(List<PmDemandParam> params) {
|
||||
if (CollectionUtils.isEmpty(params)) {
|
||||
return;
|
||||
}
|
||||
for (PmDemandParam param : params) {
|
||||
if (param == null) {
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isBlank(param.getId())) {
|
||||
throw new BadRequestException("R005需求同步失败:需求单ID不能为空");
|
||||
}
|
||||
// MES 撤回:状态 1 表示取消该需求单
|
||||
if (Objects.equals(param.getStatus(), "1")) {
|
||||
this.update(new LambdaUpdateWrapper<PmDemandR005>()
|
||||
.eq(PmDemandR005::getId, param.getId())
|
||||
.set(PmDemandR005::getStatus, DemandStatus.CANCEL.getValue())
|
||||
.set(PmDemandR005::getIs_deleted, 1));
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isEmpty(param.getTargetHouseCode())) {
|
||||
throw new BadRequestException("目标库位为空!");
|
||||
}
|
||||
this.saveDemand(param);
|
||||
}
|
||||
log.info("R005需求单批量保存完成,共{}条", params.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDemand(PmDemandParam param) {
|
||||
PmDemandR005 exist = StringUtils.isBlank(param.getId()) ? null : this.getById(param.getId());
|
||||
|
||||
Reference in New Issue
Block a user