|
|
|
@ -3765,4 +3765,216 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
return emailContent.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量合箱功能 - 保存合箱后的箱数据和明细数据 |
|
|
|
* @param mergeData 包含site, buNo, delNo, createBy, boxList的合箱数据 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void mergeBox(Map<String, Object> mergeData) { |
|
|
|
log.info("开始执行批量合箱操作 - delNo: {}", mergeData.get("delNo")); |
|
|
|
|
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String site = (String) mergeData.get("site"); |
|
|
|
String buNo = (String) mergeData.get("buNo"); |
|
|
|
String delNo = (String) mergeData.get("delNo"); |
|
|
|
String createBy = (String) mergeData.get("createBy"); |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<Map<String, Object>> boxList = (List<Map<String, Object>>) mergeData.get("boxList"); |
|
|
|
|
|
|
|
if (boxList == null || boxList.isEmpty()) { |
|
|
|
throw new RuntimeException("箱数据列表不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 获取当前最大序号,用于新增箱数据 |
|
|
|
EcssCoDelPalletHeaderData queryData = new EcssCoDelPalletHeaderData(); |
|
|
|
queryData.setSite(site); |
|
|
|
queryData.setBuNo(buNo); |
|
|
|
queryData.setDelNo(delNo); |
|
|
|
int maxSeqNo = coDelMapper.getCoDelBoxListItemNo(queryData); |
|
|
|
|
|
|
|
log.info("开始保存 {} 个箱的数据,起始序号: {}", boxList.size(), maxSeqNo); |
|
|
|
int savedBoxCount = 0; |
|
|
|
int savedDetailCount = 0; |
|
|
|
|
|
|
|
// 用于记录每个明细的装箱数量,稍后更新surplus_qty |
|
|
|
Map<Integer, BigDecimal> detailPackedQtyMap = new HashMap<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < boxList.size(); i++) { |
|
|
|
Map<String, Object> box = boxList.get(i); |
|
|
|
|
|
|
|
// 使用递增的序号(新增操作) |
|
|
|
int seqNo = maxSeqNo + i; |
|
|
|
|
|
|
|
// 创建箱数据 |
|
|
|
EcssCoDelBoxListData boxListData = new EcssCoDelBoxListData(); |
|
|
|
boxListData.setSite(site); |
|
|
|
boxListData.setBuNo(buNo); |
|
|
|
boxListData.setDelNo(delNo); |
|
|
|
boxListData.setItemNo(seqNo); |
|
|
|
|
|
|
|
// 设置箱数、毛重、净重、Rolls |
|
|
|
Object boxQtyObj = box.get("box_qty"); |
|
|
|
if (boxQtyObj instanceof Integer) { |
|
|
|
boxListData.setBoxQty(BigDecimal.valueOf((Integer) boxQtyObj)); |
|
|
|
} else if (boxQtyObj instanceof String) { |
|
|
|
boxListData.setBoxQty(BigDecimal.valueOf(Integer.parseInt((String) boxQtyObj))); |
|
|
|
} else if (boxQtyObj != null) { |
|
|
|
boxListData.setBoxQty(BigDecimal.valueOf(((Number) boxQtyObj).intValue())); |
|
|
|
} |
|
|
|
|
|
|
|
Object grossWeightObj = box.get("grossWeight"); |
|
|
|
if (grossWeightObj instanceof BigDecimal) { |
|
|
|
boxListData.setGrossWeight((BigDecimal) grossWeightObj); |
|
|
|
} else if (grossWeightObj instanceof Double) { |
|
|
|
boxListData.setGrossWeight(BigDecimal.valueOf((Double) grossWeightObj)); |
|
|
|
} else if (grossWeightObj instanceof String) { |
|
|
|
boxListData.setGrossWeight(new BigDecimal((String) grossWeightObj)); |
|
|
|
} else if (grossWeightObj != null) { |
|
|
|
boxListData.setGrossWeight(BigDecimal.valueOf(((Number) grossWeightObj).doubleValue())); |
|
|
|
} |
|
|
|
|
|
|
|
Object netWeightObj = box.get("netWeight"); |
|
|
|
if (netWeightObj instanceof BigDecimal) { |
|
|
|
boxListData.setNetWeight((BigDecimal) netWeightObj); |
|
|
|
} else if (netWeightObj instanceof Double) { |
|
|
|
boxListData.setNetWeight(BigDecimal.valueOf((Double) netWeightObj)); |
|
|
|
} else if (netWeightObj instanceof String) { |
|
|
|
boxListData.setNetWeight(new BigDecimal((String) netWeightObj)); |
|
|
|
} else if (netWeightObj != null) { |
|
|
|
boxListData.setNetWeight(BigDecimal.valueOf(((Number) netWeightObj).doubleValue())); |
|
|
|
} |
|
|
|
|
|
|
|
Object rollsObj = box.get("rolls"); |
|
|
|
if (rollsObj instanceof Integer) { |
|
|
|
boxListData.setRolls(BigDecimal.valueOf((Integer) rollsObj)); |
|
|
|
} else if (rollsObj instanceof String) { |
|
|
|
boxListData.setRolls(BigDecimal.valueOf(Integer.parseInt((String) rollsObj))); |
|
|
|
} else if (rollsObj != null) { |
|
|
|
boxListData.setRolls(BigDecimal.valueOf(((Number) rollsObj).intValue())); |
|
|
|
} |
|
|
|
|
|
|
|
boxListData.setCreateBy(createBy != null ? createBy : currentUser.getUsername()); |
|
|
|
boxListData.setCreateDate(new Date()); |
|
|
|
|
|
|
|
// 保存箱数据 |
|
|
|
coDelMapper.saveCodelBoxList(boxListData); |
|
|
|
savedBoxCount++; |
|
|
|
|
|
|
|
// 保存明细数据 |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<Map<String, Object>> details = (List<Map<String, Object>>) box.get("details"); |
|
|
|
|
|
|
|
if (details != null && !details.isEmpty()) { |
|
|
|
for (int j = 0; j < details.size(); j++) { |
|
|
|
Map<String, Object> detail = details.get(j); |
|
|
|
|
|
|
|
EcssCoDelPalletDetailData palletDetailData = new EcssCoDelPalletDetailData(); |
|
|
|
palletDetailData.setDelNo(delNo); |
|
|
|
palletDetailData.setSeqNo(seqNo); |
|
|
|
palletDetailData.setBuNo(buNo); |
|
|
|
palletDetailData.setSite(site); |
|
|
|
palletDetailData.setItemNo(j + 1); // 明细序号从1开始 |
|
|
|
|
|
|
|
// 设置明细字段 |
|
|
|
Object itemNoObj1 = detail.get("itemNo"); |
|
|
|
if (itemNoObj1 instanceof Integer) { |
|
|
|
palletDetailData.setNotifyDetailItemNo((Integer) itemNoObj1); |
|
|
|
} else if (itemNoObj1 instanceof String) { |
|
|
|
palletDetailData.setNotifyDetailItemNo(Integer.parseInt((String) itemNoObj1)); |
|
|
|
} else if (itemNoObj1 != null) { |
|
|
|
palletDetailData.setNotifyDetailItemNo(((Number) itemNoObj1).intValue()); |
|
|
|
} |
|
|
|
|
|
|
|
palletDetailData.setPoNo((String) detail.get("poNo")); |
|
|
|
palletDetailData.setPn((String) detail.get("pn")); |
|
|
|
palletDetailData.setPartNo((String) detail.get("pn")); // partNo使用pn的值 |
|
|
|
|
|
|
|
Object qtyObj = detail.get("qty"); |
|
|
|
if (qtyObj instanceof BigDecimal) { |
|
|
|
palletDetailData.setQty((BigDecimal) qtyObj); |
|
|
|
} else if (qtyObj instanceof Integer) { |
|
|
|
palletDetailData.setQty(BigDecimal.valueOf((Integer) qtyObj)); |
|
|
|
} else if (qtyObj instanceof Double) { |
|
|
|
palletDetailData.setQty(BigDecimal.valueOf((Double) qtyObj)); |
|
|
|
} else if (qtyObj instanceof String) { |
|
|
|
palletDetailData.setQty(new BigDecimal((String) qtyObj)); |
|
|
|
} else if (qtyObj != null) { |
|
|
|
palletDetailData.setQty(BigDecimal.valueOf(((Number) qtyObj).doubleValue())); |
|
|
|
} |
|
|
|
|
|
|
|
Object detailRollsObj = detail.get("detailRolls"); |
|
|
|
if (detailRollsObj instanceof BigDecimal) { |
|
|
|
palletDetailData.setRolls((BigDecimal) detailRollsObj); |
|
|
|
} else if (detailRollsObj instanceof Integer) { |
|
|
|
palletDetailData.setRolls(BigDecimal.valueOf((Integer) detailRollsObj)); |
|
|
|
} else if (detailRollsObj instanceof Double) { |
|
|
|
palletDetailData.setRolls(BigDecimal.valueOf((Double) detailRollsObj)); |
|
|
|
} else if (detailRollsObj instanceof String) { |
|
|
|
palletDetailData.setRolls(new BigDecimal((String) detailRollsObj)); |
|
|
|
} else if (detailRollsObj != null) { |
|
|
|
palletDetailData.setRolls(BigDecimal.valueOf(((Number) detailRollsObj).doubleValue())); |
|
|
|
} |
|
|
|
|
|
|
|
palletDetailData.setCreateBy(createBy != null ? createBy : currentUser.getUsername()); |
|
|
|
palletDetailData.setCreateDate(new Date()); |
|
|
|
|
|
|
|
// 保存明细数据 |
|
|
|
coDelMapper.saveCodelPalletDetail(palletDetailData); |
|
|
|
savedDetailCount++; |
|
|
|
|
|
|
|
// 累加该明细的装箱数量 |
|
|
|
Integer notifyDetailItemNo = palletDetailData.getNotifyDetailItemNo(); |
|
|
|
if (notifyDetailItemNo != null && palletDetailData.getQty() != null) { |
|
|
|
BigDecimal currentPackedQty = detailPackedQtyMap.getOrDefault(notifyDetailItemNo, BigDecimal.ZERO); |
|
|
|
detailPackedQtyMap.put(notifyDetailItemNo, currentPackedQty.add(palletDetailData.getQty())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("批量合箱操作完成 - 总共保存 {} 个箱, {} 条明细", savedBoxCount, savedDetailCount); |
|
|
|
|
|
|
|
// 3. 更新发货通知单明细的剩余数量(surplus_qty) |
|
|
|
if (!detailPackedQtyMap.isEmpty()) { |
|
|
|
log.info("开始更新 {} 条明细的剩余数量", detailPackedQtyMap.size()); |
|
|
|
EcssCoDelNotifyHeaderData notifyHeaderData = new EcssCoDelNotifyHeaderData(); |
|
|
|
notifyHeaderData.setSite(site); |
|
|
|
notifyHeaderData.setBuNo(buNo); |
|
|
|
notifyHeaderData.setDelNo(delNo); |
|
|
|
// 查询所有相关的明细数据 |
|
|
|
List<EcssCoDelNotifyDetailData> allDetails = coDelMapper.searchEcssCoDelNotifyDetail(notifyHeaderData); |
|
|
|
Map<Integer, EcssCoDelNotifyDetailData> detailMap = allDetails.stream() |
|
|
|
.collect(Collectors.toMap(EcssCoDelNotifyDetailData::getItemNo, d -> d)); |
|
|
|
|
|
|
|
for (Map.Entry<Integer, BigDecimal> entry : detailPackedQtyMap.entrySet()) { |
|
|
|
Integer itemNo = entry.getKey(); |
|
|
|
BigDecimal packedQty = entry.getValue(); |
|
|
|
|
|
|
|
EcssCoDelNotifyDetailData detailData = detailMap.get(itemNo); |
|
|
|
if (detailData != null) { |
|
|
|
// 计算新的剩余数量:当前剩余数量 - 本次装箱数量 |
|
|
|
BigDecimal currentSurplusQty = detailData.getSurplusQty() != null ? detailData.getSurplusQty() : BigDecimal.ZERO; |
|
|
|
BigDecimal newSurplusQty = currentSurplusQty.subtract(packedQty); |
|
|
|
|
|
|
|
detailData.setSurplusQty(newSurplusQty); |
|
|
|
|
|
|
|
// 更新剩余数量 |
|
|
|
coDelMapper.updateEcssCoDelNotifyDetailSurplus(detailData); |
|
|
|
log.info("更新明细 {} 剩余数量:{} - {} = {}", itemNo, currentSurplusQty, packedQty, newSurplusQty); |
|
|
|
} else { |
|
|
|
log.warn("未找到明细 itemNo: {}", itemNo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("批量合箱操作失败 - delNo: {}, error: {}", delNo, e.getMessage(), e); |
|
|
|
throw new RuntimeException("批量合箱操作失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |