|
|
|
@ -88,19 +88,19 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
if (currentStock == null) { |
|
|
|
throw new RuntimeException("未找到原标签库存信息"); |
|
|
|
} |
|
|
|
Float originalQuantity = Float.parseFloat(currentStock.get("qtyOnHand").toString()); |
|
|
|
BigDecimal originalQuantity = parseQuantity(currentStock.get("qtyOnHand"), "原标签库存数量"); |
|
|
|
|
|
|
|
// 获取拆分张数,默认为1(兼容旧版本) |
|
|
|
Integer splitCount = params.get("splitCount") != null ? Integer.parseInt(params.get("splitCount").toString()) : 1; |
|
|
|
Float splitQuantity = Float.parseFloat(params.get("splitQuantity").toString()); |
|
|
|
BigDecimal splitQuantity = parseQuantity(params.get("splitQuantity"), "拆分数量"); |
|
|
|
// 总拆分数量 = 拆分张数 * 每张数量 |
|
|
|
Float totalSplitQuantity = splitCount * splitQuantity; |
|
|
|
Float remainingQuantity = originalQuantity - totalSplitQuantity; |
|
|
|
BigDecimal totalSplitQuantity = splitQuantity.multiply(BigDecimal.valueOf(splitCount)); |
|
|
|
BigDecimal remainingQuantity = originalQuantity.subtract(totalSplitQuantity); |
|
|
|
|
|
|
|
if (splitCount <= 0) { |
|
|
|
throw new RuntimeException("拆分张数必须大于0"); |
|
|
|
} |
|
|
|
if (splitQuantity <= 0 || totalSplitQuantity >= originalQuantity) { |
|
|
|
if (splitQuantity.compareTo(BigDecimal.ZERO) <= 0 || totalSplitQuantity.compareTo(originalQuantity) >= 0) { |
|
|
|
throw new RuntimeException("拆分总数量必须大于0且小于原数量"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -151,9 +151,9 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
insertParams.put("latestInDate", new Date()); |
|
|
|
insertParams.put("activeDate", new Date()); |
|
|
|
insertParams.put("inQty", splitQuantity); |
|
|
|
insertParams.put("outQty", 0.0f); |
|
|
|
insertParams.put("outQty", BigDecimal.ZERO); |
|
|
|
insertParams.put("qtyOnHand", splitQuantity); |
|
|
|
insertParams.put("qtyReserved", 0.0f); |
|
|
|
insertParams.put("qtyReserved", BigDecimal.ZERO); |
|
|
|
insertParams.put("freezeFlag", params.get("freezeFlag")); |
|
|
|
insertParams.put("manufactureDate", params.get("manufactureDate")); |
|
|
|
insertParams.put("expiredDate", params.get("expiredDate")); |
|
|
|
@ -232,9 +232,9 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
String status = (String) params.get("status"); |
|
|
|
String statusTb = (String) params.get("statusTb"); |
|
|
|
|
|
|
|
Float targetQuantity = Float.parseFloat(params.get("targetQuantity").toString()); |
|
|
|
Float sourceQuantity = Float.parseFloat(params.get("sourceQuantity").toString()); |
|
|
|
Float mergedQuantity = targetQuantity + sourceQuantity; |
|
|
|
BigDecimal targetQuantity = parseQuantity(params.get("targetQuantity"), "目标标签数量"); |
|
|
|
BigDecimal sourceQuantity = parseQuantity(params.get("sourceQuantity"), "源标签数量"); |
|
|
|
BigDecimal mergedQuantity = targetQuantity.add(sourceQuantity); |
|
|
|
|
|
|
|
// 1. 更新源标签的库存数量(增加合并后的总数量) |
|
|
|
Map<String, Object> updateSourceParams = new HashMap<>(); |
|
|
|
@ -298,8 +298,8 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
/** |
|
|
|
* 生成标签拆分事务记录 |
|
|
|
*/ |
|
|
|
private void generateSplitTransaction(String site, String buNo, String warehouseId, String originalLabelCode, |
|
|
|
String newLabelCode, String partNo, String batchNo, Float splitQuantity, Float remainingQuantity, String locationCode) { |
|
|
|
private void generateSplitTransaction(String site, String buNo, String warehouseId, String originalLabelCode, |
|
|
|
String newLabelCode, String partNo, String batchNo, BigDecimal splitQuantity, BigDecimal remainingQuantity, String locationCode) { |
|
|
|
logger.info("开始生成标签拆分事务记录,原标签: {}, 新标签: {}", originalLabelCode, newLabelCode); |
|
|
|
|
|
|
|
try { |
|
|
|
@ -336,8 +336,8 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
/** |
|
|
|
* 生成标签合并事务记录 |
|
|
|
*/ |
|
|
|
private void generateMergeTransaction(String site, String buNo, String warehouseId, String sourceLabelCode, |
|
|
|
String targetLabelCode, String partNo, String batchNo, Float sourceQuantity, Float targetQuantity, Float mergedQuantity, String locationCode) { |
|
|
|
private void generateMergeTransaction(String site, String buNo, String warehouseId, String sourceLabelCode, |
|
|
|
String targetLabelCode, String partNo, String batchNo, BigDecimal sourceQuantity, BigDecimal targetQuantity, BigDecimal mergedQuantity, String locationCode) { |
|
|
|
logger.info("开始生成标签合并事务记录,源标签: {}, 目标标签: {}", sourceLabelCode, targetLabelCode); |
|
|
|
|
|
|
|
try { |
|
|
|
@ -374,7 +374,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
* 生成标签拆分事务明细记录 |
|
|
|
*/ |
|
|
|
private void generateSplitTransactionDetails(String transNo, String originalLabelCode, String newLabelCode, |
|
|
|
String partNo, String batchNo, Float splitQuantity, Float remainingQuantity, String site, String buNo) { |
|
|
|
String partNo, String batchNo, BigDecimal splitQuantity, BigDecimal remainingQuantity, String site, String buNo) { |
|
|
|
logger.info("开始生成标签拆分事务明细记录,事务单号: {}", transNo); |
|
|
|
List<TransDetail> transDetailList = new ArrayList<>(); |
|
|
|
|
|
|
|
@ -384,7 +384,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
originalDetail.setTransno(transNo); |
|
|
|
originalDetail.setItemno(1.0); |
|
|
|
originalDetail.setPartno(partNo); |
|
|
|
originalDetail.setTransqty(new BigDecimal(splitQuantity.toString())); |
|
|
|
originalDetail.setTransqty(splitQuantity); |
|
|
|
originalDetail.setBatchno(batchNo); |
|
|
|
originalDetail.setDirection("-"); // 减少方向 |
|
|
|
originalDetail.setOrderref1(originalLabelCode); // 原标签条码 |
|
|
|
@ -399,7 +399,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
newDetail.setTransno(transNo); |
|
|
|
newDetail.setItemno(2.0); |
|
|
|
newDetail.setPartno(partNo); |
|
|
|
newDetail.setTransqty(new BigDecimal(splitQuantity.toString())); |
|
|
|
newDetail.setTransqty(splitQuantity); |
|
|
|
newDetail.setBatchno(batchNo); |
|
|
|
newDetail.setDirection("+"); // 增加方向 |
|
|
|
newDetail.setOrderref1(newLabelCode); // 新标签条码 |
|
|
|
@ -419,8 +419,8 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
/** |
|
|
|
* 添加子明细数据 |
|
|
|
*/ |
|
|
|
private void addSubTransactionDetails(String transNo, String originalLabelCode, String newLabelCode, String batchNo, Float splitQuantity, |
|
|
|
Float remainingQuantity, String site, String buNo, String warehouseId, String locationCode) { |
|
|
|
private void addSubTransactionDetails(String transNo, String originalLabelCode, String newLabelCode, String batchNo, BigDecimal splitQuantity, |
|
|
|
BigDecimal remainingQuantity, String site, String buNo, String warehouseId, String locationCode) { |
|
|
|
logger.info("开始添加子明细数据,事务单号: {}", transNo); |
|
|
|
List<TransDetailSub> subDetailList = new ArrayList<>(); |
|
|
|
|
|
|
|
@ -429,7 +429,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
originalSubDetail.setTransNo(transNo); |
|
|
|
originalSubDetail.setItemNo(1.0); |
|
|
|
originalSubDetail.setSubNo(originalLabelCode); |
|
|
|
originalSubDetail.setSubQty(Double.valueOf(splitQuantity)); |
|
|
|
originalSubDetail.setSubQty(splitQuantity.doubleValue()); |
|
|
|
originalSubDetail.setDirection("-"); |
|
|
|
originalSubDetail.setOrderRef2(buNo); |
|
|
|
originalSubDetail.setOrderRef3(batchNo); |
|
|
|
@ -442,7 +442,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
newSubDetail.setTransNo(transNo); |
|
|
|
newSubDetail.setItemNo(2.0); |
|
|
|
newSubDetail.setSubNo(newLabelCode); |
|
|
|
newSubDetail.setSubQty(Double.valueOf(splitQuantity)); |
|
|
|
newSubDetail.setSubQty(splitQuantity.doubleValue()); |
|
|
|
newSubDetail.setDirection("+"); |
|
|
|
newSubDetail.setOrderRef2(buNo); |
|
|
|
newSubDetail.setOrderRef3(batchNo); |
|
|
|
@ -460,8 +460,8 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
/** |
|
|
|
* 生成标签合并事务明细记录 |
|
|
|
*/ |
|
|
|
private void generateMergeTransactionDetails(String transNo, String sourceLabelCode, String targetLabelCode, |
|
|
|
String partNo, String batchNo, Float sourceQuantity, Float targetQuantity, Float mergedQuantity, String site, String buNo) { |
|
|
|
private void generateMergeTransactionDetails(String transNo, String sourceLabelCode, String targetLabelCode, |
|
|
|
String partNo, String batchNo, BigDecimal sourceQuantity, BigDecimal targetQuantity, BigDecimal mergedQuantity, String site, String buNo) { |
|
|
|
logger.info("开始生成标签合并事务明细记录,事务单号: {}", transNo); |
|
|
|
|
|
|
|
List<TransDetail> transDetailList = new ArrayList<>(); |
|
|
|
@ -472,7 +472,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
targetDetail.setTransno(transNo); |
|
|
|
targetDetail.setItemno(1.0); |
|
|
|
targetDetail.setPartno(partNo); |
|
|
|
targetDetail.setTransqty(new BigDecimal(targetQuantity.toString())); |
|
|
|
targetDetail.setTransqty(targetQuantity); |
|
|
|
targetDetail.setBatchno(batchNo); |
|
|
|
targetDetail.setDirection("-"); // 减少方向 |
|
|
|
targetDetail.setOrderref1(targetLabelCode); // 目标标签条码 |
|
|
|
@ -487,7 +487,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
sourceDetail.setTransno(transNo); |
|
|
|
sourceDetail.setItemno(2.0); |
|
|
|
sourceDetail.setPartno(partNo); |
|
|
|
sourceDetail.setTransqty(new BigDecimal(mergedQuantity.toString())); |
|
|
|
sourceDetail.setTransqty(mergedQuantity); |
|
|
|
sourceDetail.setBatchno(batchNo); |
|
|
|
sourceDetail.setDirection("+"); // 增加方向 |
|
|
|
sourceDetail.setOrderref1(sourceLabelCode); // 源标签条码 |
|
|
|
@ -506,8 +506,8 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
/** |
|
|
|
* 添加子明细数据 |
|
|
|
*/ |
|
|
|
private void addSubTransactionDetails2(String transNo, String sourceLabelCode, String targetLabelCode, String batchNo, Float sourceQuantity, |
|
|
|
Float targetQuantity, Float mergedQuantity, String site, String buNo, String warehouseId, String locationCode) { |
|
|
|
private void addSubTransactionDetails2(String transNo, String sourceLabelCode, String targetLabelCode, String batchNo, BigDecimal sourceQuantity, |
|
|
|
BigDecimal targetQuantity, BigDecimal mergedQuantity, String site, String buNo, String warehouseId, String locationCode) { |
|
|
|
logger.info("开始添加子明细数据,事务单号: {}", transNo); |
|
|
|
List<TransDetailSub> subDetailList = new ArrayList<>(); |
|
|
|
|
|
|
|
@ -516,7 +516,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
originalSubDetail.setTransNo(transNo); |
|
|
|
originalSubDetail.setItemNo(1.0); |
|
|
|
originalSubDetail.setSubNo(sourceLabelCode); |
|
|
|
originalSubDetail.setSubQty(Double.valueOf(targetQuantity)); |
|
|
|
originalSubDetail.setSubQty(targetQuantity.doubleValue()); |
|
|
|
originalSubDetail.setDirection("-"); |
|
|
|
originalSubDetail.setOrderRef2(buNo); |
|
|
|
originalSubDetail.setOrderRef3(batchNo); |
|
|
|
@ -529,7 +529,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
newSubDetail.setTransNo(transNo); |
|
|
|
newSubDetail.setItemNo(2.0); |
|
|
|
newSubDetail.setSubNo(targetLabelCode); |
|
|
|
newSubDetail.setSubQty(Double.valueOf(mergedQuantity)); |
|
|
|
newSubDetail.setSubQty(mergedQuantity.doubleValue()); |
|
|
|
newSubDetail.setDirection("+"); |
|
|
|
newSubDetail.setOrderRef2(buNo); |
|
|
|
newSubDetail.setOrderRef3(batchNo); |
|
|
|
@ -543,4 +543,18 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl<LabelSplitMergeMappe |
|
|
|
} |
|
|
|
logger.info("子明细记录生成成功,共生成 {} 条子明细记录", subDetailList.size()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 统一数量解析,避免浮点精度误差 |
|
|
|
*/ |
|
|
|
private BigDecimal parseQuantity(Object value, String fieldName) { |
|
|
|
if (value == null) { |
|
|
|
throw new RuntimeException(fieldName + "不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
return new BigDecimal(value.toString().trim()); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
throw new RuntimeException(fieldName + "格式不正确: " + value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |