|
|
@ -340,22 +340,22 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
// 3. 【关键】查询现有明细,构建已存在的产品映射(key = orderNo + "|" + itemNo) |
|
|
// 3. 【关键】查询现有明细,构建已存在的产品映射(key = orderNo + "|" + itemNo) |
|
|
List<InspectionRequestDetailSub> existingSubList = |
|
|
List<InspectionRequestDetailSub> existingSubList = |
|
|
inspectionRequestDetailSubMapper.selectByRequestNo(site, requestNo); |
|
|
inspectionRequestDetailSubMapper.selectByRequestNo(site, requestNo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, InspectionRequestDetailSub> existingSubMap = new HashMap<>(); |
|
|
Map<String, InspectionRequestDetailSub> existingSubMap = new HashMap<>(); |
|
|
Map<String, InspectionRequestDetail> existingDetailMap = new HashMap<>(); |
|
|
Map<String, InspectionRequestDetail> existingDetailMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (InspectionRequestDetailSub sub : existingSubList) { |
|
|
for (InspectionRequestDetailSub sub : existingSubList) { |
|
|
String key = sub.getPoNo() + "|" + sub.getPoItemNo(); |
|
|
String key = sub.getPoNo() + "|" + sub.getPoItemNo(); |
|
|
existingSubMap.put(key, sub); |
|
|
existingSubMap.put(key, sub); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<InspectionRequestDetail> existingDetailList = |
|
|
List<InspectionRequestDetail> existingDetailList = |
|
|
inspectionRequestDetailMapper.selectByRequestNo(site, requestNo); |
|
|
inspectionRequestDetailMapper.selectByRequestNo(site, requestNo); |
|
|
for (InspectionRequestDetail detail : existingDetailList) { |
|
|
for (InspectionRequestDetail detail : existingDetailList) { |
|
|
// Detail没有直接存储PO信息,需要通过itemNo关联 |
|
|
// Detail没有直接存储PO信息,需要通过itemNo关联 |
|
|
// 这里先构建 itemNo -> Detail 的映射 |
|
|
// 这里先构建 itemNo -> Detail 的映射 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建 itemNo -> Detail 的映射(用于后续更新) |
|
|
// 构建 itemNo -> Detail 的映射(用于后续更新) |
|
|
Map<Integer, InspectionRequestDetail> itemNoToDetailMap = new HashMap<>(); |
|
|
Map<Integer, InspectionRequestDetail> itemNoToDetailMap = new HashMap<>(); |
|
|
for (InspectionRequestDetail detail : existingDetailList) { |
|
|
for (InspectionRequestDetail detail : existingDetailList) { |
|
|
@ -381,23 +381,23 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
for (Map.Entry<String, List<InspectionRequestItemVO>> entry : newItemsGroupMap.entrySet()) { |
|
|
for (Map.Entry<String, List<InspectionRequestItemVO>> entry : newItemsGroupMap.entrySet()) { |
|
|
String productKey = entry.getKey(); |
|
|
String productKey = entry.getKey(); |
|
|
List<InspectionRequestItemVO> newItemsList = entry.getValue(); |
|
|
List<InspectionRequestItemVO> newItemsList = entry.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算本次新增的总数量 |
|
|
// 计算本次新增的总数量 |
|
|
BigDecimal newTotalQty = BigDecimal.ZERO; |
|
|
BigDecimal newTotalQty = BigDecimal.ZERO; |
|
|
for (InspectionRequestItemVO item : newItemsList) { |
|
|
for (InspectionRequestItemVO item : newItemsList) { |
|
|
newTotalQty = newTotalQty.add(item.getQty()); |
|
|
newTotalQty = newTotalQty.add(item.getQty()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InspectionRequestItemVO firstItem = newItemsList.get(0); |
|
|
InspectionRequestItemVO firstItem = newItemsList.get(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6. 判断该产品是否已存在于明细中 |
|
|
// 6. 判断该产品是否已存在于明细中 |
|
|
InspectionRequestDetailSub existingSub = existingSubMap.get(productKey); |
|
|
InspectionRequestDetailSub existingSub = existingSubMap.get(productKey); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (existingSub != null) { |
|
|
if (existingSub != null) { |
|
|
// 【情况A】产品已存在,需要累加数量到已有明细 |
|
|
// 【情况A】产品已存在,需要累加数量到已有明细 |
|
|
log.info("产品已存在,累加数量: productKey={}, 原有数量={}, 新增数量={}", |
|
|
log.info("产品已存在,累加数量: productKey={}, 原有数量={}, 新增数量={}", |
|
|
productKey, existingSub.getQty(), newTotalQty); |
|
|
productKey, existingSub.getQty(), newTotalQty); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6.1 锁定PO的验货数量(只锁定本次新增的数量) |
|
|
// 6.1 锁定PO的验货数量(只锁定本次新增的数量) |
|
|
int updateCount = poDetailMapper.lockInspectQty( |
|
|
int updateCount = poDetailMapper.lockInspectQty( |
|
|
site, |
|
|
site, |
|
|
@ -405,7 +405,7 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
firstItem.getItemNo(), |
|
|
firstItem.getItemNo(), |
|
|
newTotalQty |
|
|
newTotalQty |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (updateCount == 0) { |
|
|
if (updateCount == 0) { |
|
|
throw new RuntimeException( |
|
|
throw new RuntimeException( |
|
|
"PO:" + firstItem.getOrderRef1() |
|
|
"PO:" + firstItem.getOrderRef1() |
|
|
@ -413,21 +413,21 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
+ " 可申请验货数量不足" |
|
|
+ " 可申请验货数量不足" |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6.2 更新Sub表的数量(累加) |
|
|
// 6.2 更新Sub表的数量(累加) |
|
|
BigDecimal updatedQty = existingSub.getQty().add(newTotalQty); |
|
|
BigDecimal updatedQty = existingSub.getQty().add(newTotalQty); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateWrapper<InspectionRequestDetailSub> subUpdateWrapper = new UpdateWrapper<>(); |
|
|
UpdateWrapper<InspectionRequestDetailSub> subUpdateWrapper = new UpdateWrapper<>(); |
|
|
subUpdateWrapper.eq("site", site) |
|
|
subUpdateWrapper.eq("site", site) |
|
|
.eq("request_no", requestNo) |
|
|
.eq("request_no", requestNo) |
|
|
.eq("item_no", existingSub.getItemNo()) |
|
|
.eq("item_no", existingSub.getItemNo()) |
|
|
.eq("po_no", firstItem.getOrderNo()) |
|
|
.eq("po_no", firstItem.getOrderNo()) |
|
|
.eq("po_item_no", firstItem.getItemNo()); |
|
|
.eq("po_item_no", firstItem.getItemNo()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InspectionRequestDetailSub updateSub = new InspectionRequestDetailSub(); |
|
|
InspectionRequestDetailSub updateSub = new InspectionRequestDetailSub(); |
|
|
updateSub.setQty(updatedQty); |
|
|
updateSub.setQty(updatedQty); |
|
|
inspectionRequestDetailSubMapper.update(updateSub, subUpdateWrapper); |
|
|
inspectionRequestDetailSubMapper.update(updateSub, subUpdateWrapper); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6.3 更新Detail表的数量(累加) |
|
|
// 6.3 更新Detail表的数量(累加) |
|
|
InspectionRequestDetail existingDetail = itemNoToDetailMap.get(existingSub.getItemNo()); |
|
|
InspectionRequestDetail existingDetail = itemNoToDetailMap.get(existingSub.getItemNo()); |
|
|
if (existingDetail != null) { |
|
|
if (existingDetail != null) { |
|
|
@ -435,26 +435,26 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
detailUpdateWrapper.eq("site", site) |
|
|
detailUpdateWrapper.eq("site", site) |
|
|
.eq("request_no", requestNo) |
|
|
.eq("request_no", requestNo) |
|
|
.eq("item_no", existingSub.getItemNo()); |
|
|
.eq("item_no", existingSub.getItemNo()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InspectionRequestDetail updateDetail = new InspectionRequestDetail(); |
|
|
InspectionRequestDetail updateDetail = new InspectionRequestDetail(); |
|
|
updateDetail.setQty(existingDetail.getQty().add(newTotalQty)); |
|
|
updateDetail.setQty(existingDetail.getQty().add(newTotalQty)); |
|
|
inspectionRequestDetailMapper.update(updateDetail, detailUpdateWrapper); |
|
|
inspectionRequestDetailMapper.update(updateDetail, detailUpdateWrapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("累加完成: productKey={}, 新总数={}", productKey, updatedQty); |
|
|
log.info("累加完成: productKey={}, 新总数={}", productKey, updatedQty); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// 【情况B】产品不存在,需要新增明细行 |
|
|
// 【情况B】产品不存在,需要新增明细行 |
|
|
log.info("产品不存在,新增明细: productKey={}, 数量={}", productKey, newTotalQty); |
|
|
log.info("产品不存在,新增明细: productKey={}, 数量={}", productKey, newTotalQty); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前最大的itemNo |
|
|
// 获取当前最大的itemNo |
|
|
Integer maxItemNo = inspectionRequestDetailMapper.selectMaxItemNo(site, requestNo); |
|
|
Integer maxItemNo = inspectionRequestDetailMapper.selectMaxItemNo(site, requestNo); |
|
|
int newItemNo = (maxItemNo == null ? 0 : maxItemNo) + 1; |
|
|
int newItemNo = (maxItemNo == null ? 0 : maxItemNo) + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询PO信息(用于isChanged判断) |
|
|
// 查询PO信息(用于isChanged判断) |
|
|
java.util.Map<String, Object> poInfo = poDetailMapper.getPoDetailInspectInfo( |
|
|
java.util.Map<String, Object> poInfo = poDetailMapper.getPoDetailInspectInfo( |
|
|
site, firstItem.getOrderNo(), firstItem.getItemNo()); |
|
|
site, firstItem.getOrderNo(), firstItem.getItemNo()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 锁定验货数量 |
|
|
// 锁定验货数量 |
|
|
int updateCount = poDetailMapper.lockInspectQty( |
|
|
int updateCount = poDetailMapper.lockInspectQty( |
|
|
site, |
|
|
site, |
|
|
@ -462,7 +462,7 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
firstItem.getItemNo(), |
|
|
firstItem.getItemNo(), |
|
|
newTotalQty |
|
|
newTotalQty |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (updateCount == 0) { |
|
|
if (updateCount == 0) { |
|
|
throw new RuntimeException( |
|
|
throw new RuntimeException( |
|
|
"PO:" + firstItem.getOrderRef1() |
|
|
"PO:" + firstItem.getOrderRef1() |
|
|
@ -470,7 +470,7 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
+ " 可申请验货数量不足" |
|
|
+ " 可申请验货数量不足" |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存Sub |
|
|
// 保存Sub |
|
|
InspectionRequestDetailSub sub = new InspectionRequestDetailSub(); |
|
|
InspectionRequestDetailSub sub = new InspectionRequestDetailSub(); |
|
|
sub.setSite(site); |
|
|
sub.setSite(site); |
|
|
@ -484,15 +484,15 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
sub.setOrderRef2(firstItem.getOrderRef2()); |
|
|
sub.setOrderRef2(firstItem.getOrderRef2()); |
|
|
sub.setShipMothod(firstItem.getShipMethod()); |
|
|
sub.setShipMothod(firstItem.getShipMethod()); |
|
|
sub.setCrd(firstItem.getCrd()); |
|
|
sub.setCrd(firstItem.getCrd()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算数量是否变更(新增的产品,原始数量为0) |
|
|
// 计算数量是否变更(新增的产品,原始数量为0) |
|
|
Object qtyObj = poInfo.get("waitInspectQty"); |
|
|
Object qtyObj = poInfo.get("waitInspectQty"); |
|
|
BigDecimal originQty = qtyObj == null ? BigDecimal.ZERO : new BigDecimal(qtyObj.toString()); |
|
|
BigDecimal originQty = qtyObj == null ? BigDecimal.ZERO : new BigDecimal(qtyObj.toString()); |
|
|
boolean isChanged = newTotalQty.compareTo(originQty) != 0; |
|
|
boolean isChanged = newTotalQty.compareTo(originQty) != 0; |
|
|
sub.setIsChanged(isChanged ? "Y" : "N"); |
|
|
sub.setIsChanged(isChanged ? "Y" : "N"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inspectionRequestDetailSubMapper.insert(sub); |
|
|
inspectionRequestDetailSubMapper.insert(sub); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存Detail |
|
|
// 保存Detail |
|
|
InspectionRequestDetail detail = new InspectionRequestDetail(); |
|
|
InspectionRequestDetail detail = new InspectionRequestDetail(); |
|
|
detail.setSite(site); |
|
|
detail.setSite(site); |
|
|
@ -504,7 +504,7 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
detail.setStatus("草稿"); |
|
|
detail.setStatus("草稿"); |
|
|
detail.setStatusDb("Draft"); |
|
|
detail.setStatusDb("Draft"); |
|
|
inspectionRequestDetailMapper.insert(detail); |
|
|
inspectionRequestDetailMapper.insert(detail); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("新增明细完成: productKey={}, itemNo={}", productKey, newItemNo); |
|
|
log.info("新增明细完成: productKey={}, itemNo={}", productKey, newItemNo); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -546,7 +546,7 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
// 3. 【关键】在回滚之前,先保存旧明细的原始数量信息(用于后续 isChanged 判断) |
|
|
// 3. 【关键】在回滚之前,先保存旧明细的原始数量信息(用于后续 isChanged 判断) |
|
|
List<InspectionRequestDetailSub> oldSubList = |
|
|
List<InspectionRequestDetailSub> oldSubList = |
|
|
inspectionRequestDetailSubMapper.selectByRequestNo(site, requestNo); |
|
|
inspectionRequestDetailSubMapper.selectByRequestNo(site, requestNo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建旧明细的数量映射:key = orderNo + "|" + itemNo, value = qty |
|
|
// 构建旧明细的数量映射:key = orderNo + "|" + itemNo, value = qty |
|
|
Map<String, BigDecimal> oldQtyMap = new HashMap<>(); |
|
|
Map<String, BigDecimal> oldQtyMap = new HashMap<>(); |
|
|
for (InspectionRequestDetailSub sub : oldSubList) { |
|
|
for (InspectionRequestDetailSub sub : oldSubList) { |
|
|
@ -600,23 +600,23 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
for (Map.Entry<String, List<InspectionRequestItemVO>> entry : itemsGroupMap.entrySet()) { |
|
|
for (Map.Entry<String, List<InspectionRequestItemVO>> entry : itemsGroupMap.entrySet()) { |
|
|
String productKey = entry.getKey(); |
|
|
String productKey = entry.getKey(); |
|
|
List<InspectionRequestItemVO> itemsList = entry.getValue(); |
|
|
List<InspectionRequestItemVO> itemsList = entry.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算该产品的总数量(累加) |
|
|
// 计算该产品的总数量(累加) |
|
|
BigDecimal totalQty = BigDecimal.ZERO; |
|
|
BigDecimal totalQty = BigDecimal.ZERO; |
|
|
for (InspectionRequestItemVO item : itemsList) { |
|
|
for (InspectionRequestItemVO item : itemsList) { |
|
|
totalQty = totalQty.add(item.getQty()); |
|
|
totalQty = totalQty.add(item.getQty()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 使用第一条数据的其他字段 |
|
|
// 使用第一条数据的其他字段 |
|
|
InspectionRequestItemVO firstItem = itemsList.get(0); |
|
|
InspectionRequestItemVO firstItem = itemsList.get(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 数据校验:数量必须为正数 |
|
|
// 数据校验:数量必须为正数 |
|
|
if (totalQty.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
if (totalQty.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
throw new RuntimeException( |
|
|
throw new RuntimeException( |
|
|
"PO:" + firstItem.getOrderNo() + " 行:" + firstItem.getItemNo() + " 的验货数量必须大于0" |
|
|
"PO:" + firstItem.getOrderNo() + " 行:" + firstItem.getItemNo() + " 的验货数量必须大于0" |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 锁定验货数量(使用合并后的总数量) |
|
|
// 锁定验货数量(使用合并后的总数量) |
|
|
int updateCount = poDetailMapper.lockInspectQty( |
|
|
int updateCount = poDetailMapper.lockInspectQty( |
|
|
site, |
|
|
site, |
|
|
@ -1131,7 +1131,7 @@ public class InspectionRequestServiceImpl extends ServiceImpl<InspectionRequestH |
|
|
Map<String, Object> poInfo = poDetailMapper.getPoDetailByOrderRef(site, dto.getPoNo(), dto.getPoItemNo()); |
|
|
Map<String, Object> poInfo = poDetailMapper.getPoDetailByOrderRef(site, dto.getPoNo(), dto.getPoItemNo()); |
|
|
if (poInfo == null) { |
|
|
if (poInfo == null) { |
|
|
throw new RuntimeException(String.format( |
|
|
throw new RuntimeException(String.format( |
|
|
"第%d行:PO号 %s 行号 %s 不存在,请检查外部订单号(order_ref1)和外部行号(order_ref2)", |
|
|
|
|
|
|
|
|
"第%d行:PO号 %s 行号 %s 不存在,请检查外部订单号", |
|
|
rowNum, dto.getPoNo(), dto.getPoItemNo())); |
|
|
rowNum, dto.getPoNo(), dto.getPoItemNo())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|