|
|
|
@ -52,9 +52,9 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public List<String> createHandlingUnits(CreateHuRequestDto request) { |
|
|
|
log.info("=== 开始创建HU === 包装数: {}, 单包装数量: {}, 最后HU数量: {}", |
|
|
|
log.info("=== 开始创建HU === 包装数: {}, 单包装数量: {}, 最后HU数量: {}", |
|
|
|
request.getPackageCount(), request.getPerPackageQty(), request.getLastPackageQty()); |
|
|
|
|
|
|
|
|
|
|
|
List<String> unitIds = new ArrayList<>(); |
|
|
|
// 查询IFS库存信息进行校验 |
|
|
|
InventoryStock ifsStock = warehouseMapper.selectIfsInventoryStock( |
|
|
|
@ -65,12 +65,12 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
request.getLocationId(), |
|
|
|
request.getWdr() |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 先创建packageCount个完整HU |
|
|
|
for (int i = 0; i < request.getPackageCount(); i++) { |
|
|
|
BigDecimal currentQty = request.getPerPackageQty(); |
|
|
|
log.info("创建第 {} 个完整HU,数量: {}", i + 1, currentQty); |
|
|
|
|
|
|
|
|
|
|
|
// 生成处理单元ID |
|
|
|
String unitId = handlingUnitIdGeneratorService.generateUnitId(request.getSite()); |
|
|
|
|
|
|
|
@ -99,7 +99,7 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setOriginalQty(currentQty); // 使用计算后的数量 |
|
|
|
handlingUnit.setReceiveDate(ifsStock.getManufactureDate()); |
|
|
|
handlingUnit.setHeight(request.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
// 根据料号和单位计算长宽 |
|
|
|
BigDecimal width = null; |
|
|
|
BigDecimal length = null; |
|
|
|
@ -139,7 +139,7 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
if (request.getLastPackageQty() != null && request.getLastPackageQty().compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
BigDecimal remainderQty = request.getLastPackageQty(); |
|
|
|
log.info("创建余数HU,数量: {}", remainderQty); |
|
|
|
|
|
|
|
|
|
|
|
// 生成处理单元ID |
|
|
|
String unitId = handlingUnitIdGeneratorService.generateUnitId(request.getSite()); |
|
|
|
|
|
|
|
@ -168,7 +168,7 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setOriginalQty(remainderQty); |
|
|
|
handlingUnit.setReceiveDate(ifsStock.getManufactureDate()); |
|
|
|
handlingUnit.setHeight(request.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
// 根据料号和单位计算长宽 |
|
|
|
BigDecimal width = null; |
|
|
|
BigDecimal length = null; |
|
|
|
@ -201,7 +201,7 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnitService.save(handlingUnit); |
|
|
|
|
|
|
|
unitIds.add(unitId); |
|
|
|
|
|
|
|
|
|
|
|
log.info("余数HU创建成功: unitId={}", unitId); |
|
|
|
} |
|
|
|
|
|
|
|
@ -209,11 +209,11 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
// 计算总的打印数量(完整HU的数量 + 余数HU的数量) |
|
|
|
BigDecimal totalPrintQty = request.getPerPackageQty() |
|
|
|
.multiply(BigDecimal.valueOf(request.getPackageCount())); |
|
|
|
|
|
|
|
|
|
|
|
if (request.getLastPackageQty() != null && request.getLastPackageQty().compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
totalPrintQty = totalPrintQty.add(request.getLastPackageQty()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("总打印数量: {}", totalPrintQty); |
|
|
|
|
|
|
|
if (ifsStock == null) { |
|
|
|
@ -381,18 +381,18 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
public List<String> batchCreateHandlingUnits(BatchCreateHuRequestDto request) { |
|
|
|
log.info("=== 开始批量创建HU ==="); |
|
|
|
log.info("批量创建HU数量: {}", request.getItems().size()); |
|
|
|
|
|
|
|
|
|
|
|
List<String> allUnitIds = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 逐条创建HU |
|
|
|
for (int i = 0; i < request.getItems().size(); i++) { |
|
|
|
BatchCreateHuRequestDto.BatchCreateHuItem item = request.getItems().get(i); |
|
|
|
|
|
|
|
log.info("正在创建第 {}/{} 个HU: 物料={}, 批次={}, 库位={}", |
|
|
|
i + 1, request.getItems().size(), |
|
|
|
|
|
|
|
log.info("正在创建第 {}/{} 个HU: 物料={}, 批次={}, 库位={}", |
|
|
|
i + 1, request.getItems().size(), |
|
|
|
item.getPartNo(), item.getBatchNo(), item.getLocationId()); |
|
|
|
|
|
|
|
|
|
|
|
// 查询IFS库存信息进行校验 |
|
|
|
InventoryStock ifsStock = warehouseMapper.selectIfsInventoryStock( |
|
|
|
item.getSite(), |
|
|
|
@ -402,18 +402,18 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
item.getLocationId(), |
|
|
|
item.getWdr() |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (ifsStock == null) { |
|
|
|
log.error("未找到IFS库存记录: site={}, partNo={}, batchNo={}, locationId={}", |
|
|
|
log.error("未找到IFS库存记录: site={}, partNo={}, batchNo={}, locationId={}", |
|
|
|
item.getSite(), item.getPartNo(), item.getBatchNo(), item.getLocationId()); |
|
|
|
throw new RuntimeException(String.format( |
|
|
|
"未找到对应的IFS库存记录: 物料=%s, 批次=%s, 库位=%s", |
|
|
|
"未找到对应的IFS库存记录: 物料=%s, 批次=%s, 库位=%s", |
|
|
|
item.getPartNo(), item.getBatchNo(), item.getLocationId())); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 生成处理单元ID |
|
|
|
String unitId = handlingUnitIdGeneratorService.generateUnitId(item.getSite()); |
|
|
|
|
|
|
|
|
|
|
|
// 创建HandlingUnit对象 |
|
|
|
HandlingUnit handlingUnit = new HandlingUnit(); |
|
|
|
handlingUnit.setUnitId(unitId); |
|
|
|
@ -422,7 +422,9 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setUnitTypeDb("ROLL"); |
|
|
|
handlingUnit.setPartNo(item.getPartNo()); |
|
|
|
handlingUnit.setPartDesc(item.getPartDesc()); |
|
|
|
handlingUnit.setQty(item.getQtyOnHand()); // HU数量使用库存数量 |
|
|
|
// HU数量 = 库存数量 - 已打印数量 |
|
|
|
BigDecimal huQty = item.getQtyOnHand().subtract(item.getPrintQty() != null ? item.getPrintQty() : BigDecimal.ZERO); |
|
|
|
handlingUnit.setQty(huQty); |
|
|
|
handlingUnit.setBatchNo(item.getBatchNo()); // 使用每行自己的批次号 |
|
|
|
handlingUnit.setLocationId(item.getLocationId()); |
|
|
|
handlingUnit.setWarehouseId("TEMP"); |
|
|
|
@ -438,11 +440,11 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setSourceType("IFS_INIT"); |
|
|
|
handlingUnit.setOriginalQty(item.getQtyOnHand()); |
|
|
|
handlingUnit.setReceiveDate(ifsStock.getManufactureDate()); |
|
|
|
|
|
|
|
|
|
|
|
// 根据料号和单位计算长宽 |
|
|
|
BigDecimal width = null; |
|
|
|
BigDecimal length = null; |
|
|
|
|
|
|
|
|
|
|
|
String partNo = item.getPartNo(); |
|
|
|
if (partNo != null && partNo.contains("-")) { |
|
|
|
// 如果料号带尾缀,比如70001234-0250,那么width就是250 |
|
|
|
@ -456,40 +458,39 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
log.warn("无法解析料号宽度: {}", partNo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// length就是数量乘以1000再除以width |
|
|
|
if (width != null && width.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
length = item.getQtyOnHand().multiply(BigDecimal.valueOf(1000)) |
|
|
|
.divide(width, 2, java.math.RoundingMode.HALF_UP); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handlingUnit.setWidth(width); |
|
|
|
handlingUnit.setLength(length); |
|
|
|
handlingUnit.setManufactureDate(ifsStock.getManufactureDate()); |
|
|
|
handlingUnit.setExpiredDate(ifsStock.getExpiredDate()); |
|
|
|
handlingUnit.setUmId(item.getUmid()); |
|
|
|
|
|
|
|
|
|
|
|
// 保存HandlingUnit |
|
|
|
handlingUnitService.save(handlingUnit); |
|
|
|
|
|
|
|
|
|
|
|
allUnitIds.add(unitId); |
|
|
|
|
|
|
|
|
|
|
|
// 更新打印数量 |
|
|
|
BigDecimal totalPrintQty = item.getQtyOnHand(); |
|
|
|
|
|
|
|
|
|
|
|
// 校验打印数量不能超过入库数量 |
|
|
|
if (ifsStock.getQtyOnHand() != null) { |
|
|
|
BigDecimal currentPrintQty = ifsStock.getPrintQty() != null ? ifsStock.getPrintQty() : BigDecimal.ZERO; |
|
|
|
BigDecimal newPrintQty = currentPrintQty.add(totalPrintQty); |
|
|
|
BigDecimal newPrintQty = currentPrintQty.add(huQty); |
|
|
|
if (newPrintQty.compareTo(ifsStock.getQtyOnHand()) > 0) { |
|
|
|
log.error("打印数量超过库存数量: 当前已打印={}, 本次打印={}, 库存数量={}", |
|
|
|
currentPrintQty, totalPrintQty, ifsStock.getQtyOnHand()); |
|
|
|
log.error("打印数量超过库存数量: 当前已打印={}, 本次打印={}, 库存数量={}", |
|
|
|
currentPrintQty, huQty, ifsStock.getQtyOnHand()); |
|
|
|
throw new RuntimeException(String.format( |
|
|
|
"打印数量不能超过库存数量!当前已打印:%s,本次打印:%s,库存数量:%s", |
|
|
|
currentPrintQty, totalPrintQty, ifsStock.getQtyOnHand())); |
|
|
|
currentPrintQty, huQty, ifsStock.getQtyOnHand())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
warehouseMapper.updateIfsPrintQty( |
|
|
|
item.getSite(), |
|
|
|
item.getWarehouseId(), |
|
|
|
@ -497,15 +498,15 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
item.getBatchNo(), |
|
|
|
item.getLocationId(), |
|
|
|
item.getWdr(), |
|
|
|
totalPrintQty |
|
|
|
huQty |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
log.info("HU创建成功: unitId={}", unitId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("=== 批量创建HU完成 === 成功创建: {} 个", allUnitIds.size()); |
|
|
|
return allUnitIds; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("=== 批量创建HU失败 === 错误信息: {}", e.getMessage(), e); |
|
|
|
throw new RuntimeException("批量创建HU失败: " + e.getMessage()); |
|
|
|
|