|
|
|
@ -10,11 +10,13 @@ import com.gaotao.modules.warehouse.dao.InventoryStockMapper; |
|
|
|
import com.gaotao.modules.warehouse.dao.WarehouseMapper; |
|
|
|
import com.gaotao.modules.warehouse.entity.InventoryStock; |
|
|
|
import com.gaotao.modules.warehouse.entity.dto.CreateHuRequestDto; |
|
|
|
import com.gaotao.modules.warehouse.entity.dto.BatchCreateHuRequestDto; |
|
|
|
import com.gaotao.modules.warehouse.service.IfsInventoryInitService; |
|
|
|
import com.gaotao.modules.warehouse.service.InventoryStockService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
@ -24,6 +26,7 @@ import java.util.List; |
|
|
|
/** |
|
|
|
* IFS库存初始化服务实现类 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
|
|
|
|
@ -49,6 +52,9 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public List<String> createHandlingUnits(CreateHuRequestDto request) { |
|
|
|
log.info("=== 开始创建HU === 包装数: {}, 单包装数量: {}, 最后HU数量: {}", |
|
|
|
request.getPackageCount(), request.getPerPackageQty(), request.getLastPackageQty()); |
|
|
|
|
|
|
|
List<String> unitIds = new ArrayList<>(); |
|
|
|
// 查询IFS库存信息进行校验 |
|
|
|
InventoryStock ifsStock = warehouseMapper.selectIfsInventoryStock( |
|
|
|
@ -59,8 +65,12 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
request.getLocationId(), |
|
|
|
request.getWdr() |
|
|
|
); |
|
|
|
// 根据包装数创建多个HandlingUnit |
|
|
|
|
|
|
|
// 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()); |
|
|
|
|
|
|
|
@ -72,7 +82,7 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setUnitTypeDb("ROLL"); |
|
|
|
handlingUnit.setPartNo(request.getPartNo()); |
|
|
|
handlingUnit.setPartDesc(request.getPartDesc()); |
|
|
|
handlingUnit.setQty(request.getPerPackageQty()); |
|
|
|
handlingUnit.setQty(currentQty); // 使用计算后的数量 |
|
|
|
handlingUnit.setBatchNo(request.getBatchNo()); |
|
|
|
handlingUnit.setLocationId(request.getLocationId()); |
|
|
|
handlingUnit.setWarehouseId("TEMP"); |
|
|
|
@ -86,9 +96,10 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setCreatedDate(new Date()); |
|
|
|
handlingUnit.setCreatedBy("SYSTEM"); |
|
|
|
handlingUnit.setSourceType("IFS_INIT"); |
|
|
|
handlingUnit.setOriginalQty(request.getPerPackageQty()); |
|
|
|
handlingUnit.setOriginalQty(currentQty); // 使用计算后的数量 |
|
|
|
handlingUnit.setReceiveDate(ifsStock.getManufactureDate()); |
|
|
|
handlingUnit.setHeight(request.getHeight()); |
|
|
|
|
|
|
|
// 根据料号和单位计算长宽 |
|
|
|
BigDecimal width = null; |
|
|
|
BigDecimal length = null; |
|
|
|
@ -107,8 +118,8 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
} |
|
|
|
|
|
|
|
// length就是数量乘以1000再除以width |
|
|
|
if (width!=null && width.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
length = request.getPerPackageQty().multiply(BigDecimal.valueOf(1000)) |
|
|
|
if (width != null && width.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
length = currentQty.multiply(BigDecimal.valueOf(1000)) |
|
|
|
.divide(width, 2, java.math.RoundingMode.HALF_UP); |
|
|
|
} |
|
|
|
|
|
|
|
@ -118,18 +129,92 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
handlingUnit.setExpiredDate(ifsStock.getExpiredDate()); |
|
|
|
handlingUnit.setUmId(request.getUmid()); |
|
|
|
|
|
|
|
|
|
|
|
// 保存HandlingUnit |
|
|
|
handlingUnitService.save(handlingUnit); |
|
|
|
|
|
|
|
unitIds.add(unitId); |
|
|
|
} |
|
|
|
|
|
|
|
// 生成HU后,更新inventory_stock_ifs的print_qty字段 |
|
|
|
// 计算总的打印数量(包装数 * 每包装数量) |
|
|
|
Integer totalPrintQty = request.getPackageCount() * request.getPerPackageQty().intValue(); |
|
|
|
// 2. 如果有余数,创建1个余数HU |
|
|
|
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()); |
|
|
|
|
|
|
|
// 创建HandlingUnit对象 |
|
|
|
HandlingUnit handlingUnit = new HandlingUnit(); |
|
|
|
handlingUnit.setUnitId(unitId); |
|
|
|
handlingUnit.setSite(request.getSite()); |
|
|
|
handlingUnit.setUnitType("ROLL"); |
|
|
|
handlingUnit.setUnitTypeDb("ROLL"); |
|
|
|
handlingUnit.setPartNo(request.getPartNo()); |
|
|
|
handlingUnit.setPartDesc(request.getPartDesc()); |
|
|
|
handlingUnit.setQty(remainderQty); // 使用余数数量 |
|
|
|
handlingUnit.setBatchNo(request.getBatchNo()); |
|
|
|
handlingUnit.setLocationId(request.getLocationId()); |
|
|
|
handlingUnit.setWarehouseId("TEMP"); |
|
|
|
handlingUnit.setWdr(request.getWdr()); |
|
|
|
handlingUnit.setStatus("ACTIVE"); |
|
|
|
handlingUnit.setStatusDb("ACTIVE"); |
|
|
|
handlingUnit.setFreezeFlag("N"); |
|
|
|
handlingUnit.setReserveFlag("N"); |
|
|
|
handlingUnit.setMergedFlag("N"); |
|
|
|
handlingUnit.setInStockFlag("Y"); |
|
|
|
handlingUnit.setCreatedDate(new Date()); |
|
|
|
handlingUnit.setCreatedBy("SYSTEM"); |
|
|
|
handlingUnit.setSourceType("IFS_INIT"); |
|
|
|
handlingUnit.setOriginalQty(remainderQty); |
|
|
|
handlingUnit.setReceiveDate(ifsStock.getManufactureDate()); |
|
|
|
handlingUnit.setHeight(request.getHeight()); |
|
|
|
|
|
|
|
// 根据料号和单位计算长宽 |
|
|
|
BigDecimal width = null; |
|
|
|
BigDecimal length = null; |
|
|
|
|
|
|
|
String partNo = request.getPartNo(); |
|
|
|
if (partNo != null && partNo.contains("-")) { |
|
|
|
String[] parts = partNo.split("-"); |
|
|
|
String suffix = parts[parts.length - 1]; |
|
|
|
try { |
|
|
|
int widthVal = Integer.parseInt(suffix); |
|
|
|
width = BigDecimal.valueOf(widthVal); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 默认值处理 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// length就是数量乘以1000再除以width |
|
|
|
if (width != null && width.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
length = remainderQty.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(request.getUmid()); |
|
|
|
|
|
|
|
// 保存余数HandlingUnit |
|
|
|
handlingUnitService.save(handlingUnit); |
|
|
|
|
|
|
|
unitIds.add(unitId); |
|
|
|
|
|
|
|
log.info("余数HU创建成功: unitId={}", unitId); |
|
|
|
} |
|
|
|
|
|
|
|
// 生成HU后,更新inventory_stock_ifs的print_qty字段 |
|
|
|
// 计算总的打印数量(完整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) { |
|
|
|
throw new RuntimeException("未找到对应的IFS库存记录"); |
|
|
|
@ -137,12 +222,12 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
|
|
|
|
// 校验打印数量不能超过入库数量 |
|
|
|
if (ifsStock.getQtyOnHand() != null) { |
|
|
|
Integer currentPrintQty = ifsStock.getPrintQty() != null ? ifsStock.getPrintQty().intValue() : 0; |
|
|
|
int newPrintQty = currentPrintQty + totalPrintQty; |
|
|
|
if (newPrintQty > ifsStock.getQtyOnHand().intValue()) { |
|
|
|
BigDecimal currentPrintQty = ifsStock.getPrintQty() != null ? ifsStock.getPrintQty() : BigDecimal.ZERO; |
|
|
|
BigDecimal newPrintQty = currentPrintQty.add(totalPrintQty); |
|
|
|
if (newPrintQty.compareTo(ifsStock.getQtyOnHand()) > 0) { |
|
|
|
throw new RuntimeException(String.format( |
|
|
|
"打印数量不能超过库存数量!当前已打印:%d,本次打印:%d,库存数量:%d", |
|
|
|
currentPrintQty, totalPrintQty, ifsStock.getQtyOnHand().intValue())); |
|
|
|
"打印数量不能超过库存数量!当前已打印:%s,本次打印:%s,库存数量:%s", |
|
|
|
currentPrintQty, totalPrintQty, ifsStock.getQtyOnHand())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -283,4 +368,147 @@ public class IfsInventoryInitServiceImpl implements IfsInventoryInitService { |
|
|
|
|
|
|
|
return unitIds; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author System |
|
|
|
* @Description 批量创建HandlingUnit - 一次请求创建多个HU |
|
|
|
* @Date 2025/01/14 |
|
|
|
* @Param [BatchCreateHuRequestDto] |
|
|
|
* @return List<String> |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
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(), |
|
|
|
item.getPartNo(), item.getBatchNo(), item.getLocationId()); |
|
|
|
|
|
|
|
// 查询IFS库存信息进行校验 |
|
|
|
InventoryStock ifsStock = warehouseMapper.selectIfsInventoryStock( |
|
|
|
item.getSite(), |
|
|
|
item.getWarehouseId(), |
|
|
|
item.getPartNo(), |
|
|
|
item.getBatchNo(), |
|
|
|
item.getLocationId(), |
|
|
|
item.getWdr() |
|
|
|
); |
|
|
|
|
|
|
|
if (ifsStock == null) { |
|
|
|
log.error("未找到IFS库存记录: site={}, partNo={}, batchNo={}, locationId={}", |
|
|
|
item.getSite(), item.getPartNo(), item.getBatchNo(), item.getLocationId()); |
|
|
|
throw new RuntimeException(String.format( |
|
|
|
"未找到对应的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); |
|
|
|
handlingUnit.setSite(item.getSite()); |
|
|
|
handlingUnit.setUnitType("ROLL"); |
|
|
|
handlingUnit.setUnitTypeDb("ROLL"); |
|
|
|
handlingUnit.setPartNo(item.getPartNo()); |
|
|
|
handlingUnit.setPartDesc(item.getPartDesc()); |
|
|
|
handlingUnit.setQty(item.getQtyOnHand()); // HU数量使用库存数量 |
|
|
|
handlingUnit.setBatchNo(item.getBatchNo()); // 使用每行自己的批次号 |
|
|
|
handlingUnit.setLocationId(item.getLocationId()); |
|
|
|
handlingUnit.setWarehouseId("TEMP"); |
|
|
|
handlingUnit.setWdr(item.getWdr()); |
|
|
|
handlingUnit.setStatus("ACTIVE"); |
|
|
|
handlingUnit.setStatusDb("ACTIVE"); |
|
|
|
handlingUnit.setFreezeFlag("N"); |
|
|
|
handlingUnit.setReserveFlag("N"); |
|
|
|
handlingUnit.setMergedFlag("N"); |
|
|
|
handlingUnit.setInStockFlag("Y"); |
|
|
|
handlingUnit.setCreatedDate(new Date()); |
|
|
|
handlingUnit.setCreatedBy("SYSTEM"); |
|
|
|
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 |
|
|
|
String[] parts = partNo.split("-"); |
|
|
|
String suffix = parts[parts.length - 1]; |
|
|
|
try { |
|
|
|
int widthVal = Integer.parseInt(suffix); |
|
|
|
width = BigDecimal.valueOf(widthVal); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 默认值处理 |
|
|
|
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); |
|
|
|
if (newPrintQty.compareTo(ifsStock.getQtyOnHand()) > 0) { |
|
|
|
log.error("打印数量超过库存数量: 当前已打印={}, 本次打印={}, 库存数量={}", |
|
|
|
currentPrintQty, totalPrintQty, ifsStock.getQtyOnHand()); |
|
|
|
throw new RuntimeException(String.format( |
|
|
|
"打印数量不能超过库存数量!当前已打印:%s,本次打印:%s,库存数量:%s", |
|
|
|
currentPrintQty, totalPrintQty, ifsStock.getQtyOnHand())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
warehouseMapper.updateIfsPrintQty( |
|
|
|
item.getSite(), |
|
|
|
item.getWarehouseId(), |
|
|
|
item.getPartNo(), |
|
|
|
item.getBatchNo(), |
|
|
|
item.getLocationId(), |
|
|
|
item.getWdr(), |
|
|
|
totalPrintQty |
|
|
|
); |
|
|
|
|
|
|
|
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()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |