demand: TMS系统 - 运输管理 - 货物组批次根据历史数据计算件数、重量、体积适应同一节点多个供应商计算规则;
TMS系统 - 运输管理 - 货物组批次同一运单分批组批次件数、重量、体积计算适应同一节点多个供应商计算规则 committer: heyu
This commit is contained in:
parent
0f3ed81ea5
commit
5d4e98e766
@ -161,11 +161,13 @@ public class EmisTmsSiteBatchDtlServiceImpl implements IEmisTmsSiteBatchDtlServi
|
||||
EmisTransPlanRule emisTransPlanRule = new EmisTransPlanRule();
|
||||
emisTransPlanRule.setStartSiteCode(startSiteCode);
|
||||
emisTransPlanRule.setNextSiteCode(nextSiteCode);
|
||||
emisTransPlanRule.setSupplierCode(supplierCode);
|
||||
// emisTransPlanRule.setSupplierCode(supplierCode);
|
||||
emisTransPlanRule.setLineCode(emisWaybill.getTransLineType());
|
||||
emisTransPlanRule.setProductType(emisWaybill.getProductType());
|
||||
|
||||
List<EmisTransPlanRule> rules = emisTransPlanRuleMapper.checkTransPlanRule(emisTransPlanRule);
|
||||
List<EmisTransPlanRule> queryRules = emisTransPlanRuleMapper.checkTransPlanRule(emisTransPlanRule);
|
||||
List<EmisTransPlanRule> rules = queryRules.stream()
|
||||
.filter(i -> i.getSupplierCode().contains(supplierCode)).collect(Collectors.toList());
|
||||
|
||||
// 根据起始网点、下一网点和运单号查询TMS组批次
|
||||
List<EmisTmsSiteBatch> existingBatches = emisTmsSiteBatchMapper.selectTmsSiteBatchBySiteAndBillCode(
|
||||
@ -218,32 +220,60 @@ public class EmisTmsSiteBatchDtlServiceImpl implements IEmisTmsSiteBatchDtlServi
|
||||
}
|
||||
}
|
||||
|
||||
// 将existingBatches根据起始网点、下一网点、批次重量、件数、体积分组去重
|
||||
Map<String, List<EmisTmsSiteBatch>> groupedBatches = existingBatches.stream()
|
||||
.filter(Objects::nonNull) // 过滤空值
|
||||
.collect(Collectors.groupingBy(batch -> {
|
||||
// 构建分组键,包含所有相关字段
|
||||
BigDecimal totalWeight = batch.getTotalWeight() != null ? batch.getTotalWeight() : BigDecimal.ZERO;
|
||||
Integer totalParcelQty = batch.getTotalParcelQty() != null ? batch.getTotalParcelQty() : 0;
|
||||
BigDecimal totalVolume = batch.getTotalVolume() != null ? batch.getTotalVolume() : BigDecimal.ZERO;
|
||||
// 先过滤出包含多个供应商编码的rules
|
||||
List<EmisTransPlanRule> multiSupplierRules = queryRules.stream()
|
||||
.filter(transPlanRule -> StringUtils.isNotBlank(transPlanRule.getSupplierCode())
|
||||
&& transPlanRule.getSupplierCode().contains(","))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return batch.getStartSiteCode() + "_" + batch.getNextSiteCode() + "_" +
|
||||
totalWeight + "_" + totalParcelQty + "_" + totalVolume;
|
||||
}));
|
||||
// 处理多供应商规则,将匹配的批次分组
|
||||
List<List<EmisTmsSiteBatch>> matchedBatchGroups = new ArrayList<>();
|
||||
for (EmisTransPlanRule transPlanRule : multiSupplierRules) {
|
||||
String[] supplierCodes = transPlanRule.getSupplierCode().split(",");
|
||||
List<String> supplierCodeList = Arrays.asList(supplierCodes);
|
||||
|
||||
// 找出allBatches中包含指定供应商编码的批次
|
||||
List<EmisTmsSiteBatch> matchedBatches = existingBatches.stream()
|
||||
.filter(batch -> supplierCodeList.contains(batch.getSupplierCode()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!matchedBatches.isEmpty()) {
|
||||
matchedBatchGroups.add(matchedBatches);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有匹配的批次组,进行处理
|
||||
if (!matchedBatchGroups.isEmpty()) {
|
||||
// 将多个list合一去重生成listALL
|
||||
List<EmisTmsSiteBatch> listALL = matchedBatchGroups.stream()
|
||||
.flatMap(List::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 从allBatches中去除包含在listALL中的元素
|
||||
existingBatches.removeAll(listALL);
|
||||
|
||||
// 将每个list中留一个元素插入allBatches中
|
||||
for (List<EmisTmsSiteBatch> batchGroup : matchedBatchGroups) {
|
||||
if (!batchGroup.isEmpty()) {
|
||||
existingBatches.add(batchGroup.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算去重后的批次总重量、总件数、总体积
|
||||
BigDecimal totalWeight = groupedBatches.values().stream()
|
||||
.map(batchList -> batchList.get(0).getTotalWeight())
|
||||
BigDecimal totalWeight = existingBatches.stream()
|
||||
.map(EmisTmsSiteBatch::getTotalWeight)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
Integer totalParcelQty = groupedBatches.values().stream()
|
||||
.map(batchList -> batchList.get(0).getTotalParcelQty())
|
||||
Integer totalParcelQty = existingBatches.stream()
|
||||
.map(EmisTmsSiteBatch::getTotalParcelQty)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(0, Integer::sum);
|
||||
|
||||
BigDecimal totalVolume = groupedBatches.values().stream()
|
||||
.map(batchList -> batchList.get(0).getTotalVolume())
|
||||
BigDecimal totalVolume = existingBatches.stream()
|
||||
.map(EmisTmsSiteBatch::getTotalVolume)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
|
||||
@ -156,13 +156,13 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
|
||||
EmisWaybill emisWaybill = emisWaybillMapper.selectEmisWaybillByBillCode(itemDtl.getBillCode());
|
||||
checkVirtual(itemDtl.getBillCode(), emisWaybill);
|
||||
EmisTransPlanRule rule = checkTransPlanRule(oldSiteBatch, emisWaybill);
|
||||
checkItemDtl(oldSiteBatch, itemDtl, emisWaybill, rule);
|
||||
List<EmisTransPlanRule> rules = checkTransPlanRule(oldSiteBatch, emisWaybill);
|
||||
checkItemDtl(oldSiteBatch, itemDtl, emisWaybill, rules);
|
||||
|
||||
}
|
||||
|
||||
private void checkItemDtl(EmisTmsSiteBatch oldSiteBatch, EmisTmsSiteBatchDtl itemDtl, EmisWaybill emisWaybill,
|
||||
EmisTransPlanRule rule) throws EmisBizError {
|
||||
List<EmisTransPlanRule> rules) throws EmisBizError {
|
||||
// 安全比较:检查批次数据是否与运单数据完全一致
|
||||
boolean isParcelQtyEqual = Objects.equals(emisWaybill.getParcelQty(), itemDtl.getBatchParcelQty());
|
||||
// 重量比较:使用compareTo方法比较大小是否相等
|
||||
@ -174,7 +174,7 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
|
||||
if (isParcelQtyEqual && isWeightEqual && isVolumeEqual) {
|
||||
checkUnique(oldSiteBatch, itemDtl.getBillCode());
|
||||
compareWaybillAndBatch(oldSiteBatch, itemDtl, emisWaybill, rule, false);
|
||||
compareWaybillAndBatch(oldSiteBatch, itemDtl, emisWaybill, rules, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -191,16 +191,19 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
throw new EmisBizError(EmisBizErrorType.FAIL, itemDtl.getBillCode() + "的批次体积必须大于0");
|
||||
}
|
||||
|
||||
compareWaybillAndBatch(oldSiteBatch, itemDtl, emisWaybill, rule, true);
|
||||
compareWaybillAndBatch(oldSiteBatch, itemDtl, emisWaybill, rules, true);
|
||||
}
|
||||
|
||||
private void compareWaybillAndBatch(EmisTmsSiteBatch oldSiteBatch, EmisTmsSiteBatchDtl itemDtl,
|
||||
EmisWaybill emisWaybill, EmisTransPlanRule rule, boolean isBatch) throws EmisBizError {
|
||||
EmisWaybill emisWaybill, List<EmisTransPlanRule> rules, boolean isBatch) throws EmisBizError {
|
||||
// 根据起始网点、下一网点和运单号查询TMS组批次
|
||||
List<EmisTmsSiteBatch> existingBatches = selectTmsSiteBatchBySiteAndBillCode(
|
||||
oldSiteBatch.getStartSiteCode(),
|
||||
oldSiteBatch.getNextSiteCode(),
|
||||
itemDtl.getBillCode(), itemDtl.getId());
|
||||
EmisTransPlanRule rule = rules.stream()
|
||||
.filter(i -> i.getSupplierCode().contains(oldSiteBatch.getSupplierCode())).collect(Collectors.toList())
|
||||
.get(0);
|
||||
|
||||
// 检查rule.supplierCode是否包含多个供应商编码(用逗号隔开)
|
||||
if (StringUtils.isNotBlank(rule.getSupplierCode()) && rule.getSupplierCode().contains(",")) {
|
||||
@ -251,34 +254,62 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
currentBatch.setTotalVolume(itemDtl.getBatchVolume());
|
||||
allBatches.add(currentBatch);
|
||||
|
||||
// 将allBatches根据起始网点、下一网点、批次重量、件数、体积分组去重
|
||||
Map<String, List<EmisTmsSiteBatch>> groupedBatches = allBatches.stream()
|
||||
.collect(Collectors.groupingBy(batch -> {
|
||||
// 去除重量和体积的多余0
|
||||
String weightStr = batch.getTotalWeight() != null
|
||||
? batch.getTotalWeight().stripTrailingZeros().toPlainString()
|
||||
: "0";
|
||||
String volumeStr = batch.getTotalVolume() != null
|
||||
? batch.getTotalVolume().stripTrailingZeros().toPlainString()
|
||||
: "0";
|
||||
List<EmisTmsSiteBatch> countBatches = new ArrayList<>(allBatches);
|
||||
|
||||
return batch.getStartSiteCode() + "_" + batch.getNextSiteCode() + "_" +
|
||||
weightStr + "_" + batch.getTotalParcelQty() + "_" + volumeStr;
|
||||
}));
|
||||
// 先过滤出包含多个供应商编码的rules
|
||||
List<EmisTransPlanRule> multiSupplierRules = rules.stream()
|
||||
.filter(transPlanRule -> StringUtils.isNotBlank(transPlanRule.getSupplierCode())
|
||||
&& transPlanRule.getSupplierCode().contains(","))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 处理多供应商规则,将匹配的批次分组
|
||||
List<List<EmisTmsSiteBatch>> matchedBatchGroups = new ArrayList<>();
|
||||
for (EmisTransPlanRule transPlanRule : multiSupplierRules) {
|
||||
String[] supplierCodes = transPlanRule.getSupplierCode().split(",");
|
||||
List<String> supplierCodeList = Arrays.asList(supplierCodes);
|
||||
|
||||
// 找出countBatches中包含指定供应商编码的批次
|
||||
List<EmisTmsSiteBatch> matchedBatches = countBatches.stream()
|
||||
.filter(batch -> supplierCodeList.contains(batch.getSupplierCode()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!matchedBatches.isEmpty()) {
|
||||
matchedBatchGroups.add(matchedBatches);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有匹配的批次组,进行处理
|
||||
if (!matchedBatchGroups.isEmpty()) {
|
||||
// 将多个list合一去重生成listALL
|
||||
List<EmisTmsSiteBatch> listALL = matchedBatchGroups.stream()
|
||||
.flatMap(List::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 从countBatches中去除包含在listALL中的元素
|
||||
countBatches.removeAll(listALL);
|
||||
|
||||
// 将每个list中留一个元素插入countBatches中
|
||||
for (List<EmisTmsSiteBatch> batchGroup : matchedBatchGroups) {
|
||||
if (!batchGroup.isEmpty()) {
|
||||
countBatches.add(batchGroup.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算去重后的批次总重量、总件数、总体积
|
||||
BigDecimal totalWeight = groupedBatches.values().stream()
|
||||
.map(batchList -> batchList.get(0).getTotalWeight())
|
||||
BigDecimal totalWeight = countBatches.stream()
|
||||
.map(EmisTmsSiteBatch::getTotalWeight)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
Integer totalParcelQty = groupedBatches.values().stream()
|
||||
.map(batchList -> batchList.get(0).getTotalParcelQty())
|
||||
Integer totalParcelQty = countBatches.stream()
|
||||
.map(EmisTmsSiteBatch::getTotalParcelQty)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(0, Integer::sum);
|
||||
|
||||
BigDecimal totalVolume = groupedBatches.values().stream()
|
||||
.map(batchList -> batchList.get(0).getTotalVolume())
|
||||
BigDecimal totalVolume = countBatches.stream()
|
||||
.map(EmisTmsSiteBatch::getTotalVolume)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
@ -372,19 +403,21 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
}
|
||||
}
|
||||
|
||||
private EmisTransPlanRule checkTransPlanRule(EmisTmsSiteBatch oldSiteBatch, EmisWaybill emisWaybill)
|
||||
private List<EmisTransPlanRule> checkTransPlanRule(EmisTmsSiteBatch oldSiteBatch, EmisWaybill emisWaybill)
|
||||
throws EmisBizError {
|
||||
EmisTransPlanRule emisTransPlanRule = new EmisTransPlanRule();
|
||||
emisTransPlanRule.setStartSiteCode(oldSiteBatch.getStartSiteCode());
|
||||
emisTransPlanRule.setNextSiteCode(oldSiteBatch.getNextSiteCode());
|
||||
emisTransPlanRule.setSupplierCode(oldSiteBatch.getSupplierCode());
|
||||
// emisTransPlanRule.setSupplierCode(oldSiteBatch.getSupplierCode());
|
||||
emisTransPlanRule.setLineCode(emisWaybill.getTransLineType());
|
||||
emisTransPlanRule.setProductType(emisWaybill.getProductType());
|
||||
List<EmisTransPlanRule> list = emisTransPlanRuleMapper.checkTransPlanRule(emisTransPlanRule);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
List<EmisTransPlanRule> filterList = list.stream()
|
||||
.filter(i -> i.getSupplierCode().contains(oldSiteBatch.getSupplierCode())).collect(Collectors.toList());
|
||||
if (CollectionUtil.isEmpty(filterList)) {
|
||||
throw new EmisBizError(EmisBizErrorType.FAIL, emisWaybill.getBillCode() + "组批次起始网点、下一网点、供应商与规则不匹配");
|
||||
}
|
||||
return list.get(0);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void checkUnique(EmisTmsSiteBatch emisTmsSiteBatch, String billCode) throws EmisBizError {
|
||||
|
||||
@ -546,11 +546,21 @@
|
||||
b.trans_weight, b.pack_num, b.total_waybill_qty, b.total_settlement_weight,
|
||||
b.op_man, b.remark, b.tenant_id, b.del_flag, b.create_by, b.create_time,
|
||||
b.update_by, b.update_time, b.create_site, b.update_site, b.bl_entering,
|
||||
COALESCE(SUM(d.batch_volume), 0) as total_volume,
|
||||
COALESCE(SUM(d.batch_parcel_qty), 0) as total_parcel_qty,
|
||||
COALESCE(SUM(d.batch_weight), 0) as total_weight
|
||||
CASE
|
||||
WHEN COALESCE(SUM(d.batch_volume), 0) = 0 THEN COALESCE(w.total_volume, 0)
|
||||
ELSE COALESCE(SUM(d.batch_volume), 0)
|
||||
END as total_volume,
|
||||
CASE
|
||||
WHEN COALESCE(SUM(d.batch_parcel_qty), 0) = 0 THEN COALESCE(w.parcel_qty, 0)
|
||||
ELSE COALESCE(SUM(d.batch_parcel_qty), 0)
|
||||
END as total_parcel_qty,
|
||||
CASE
|
||||
WHEN COALESCE(SUM(d.batch_weight), 0) = 0 THEN COALESCE(w.bill_weight, 0)
|
||||
ELSE COALESCE(SUM(d.batch_weight), 0)
|
||||
END as total_weight
|
||||
from emis_tms_site_batch b
|
||||
inner join emis_tms_site_batch_dtl d on b.batch_no = d.batch_no
|
||||
left join emis_waybill w on d.bill_code = w.bill_code and w.del_flag = '0'
|
||||
where b.start_site_code = #{startSiteCode}
|
||||
and b.next_site_code = #{nextSiteCode}
|
||||
and d.bill_code = #{billCode}
|
||||
@ -563,6 +573,7 @@
|
||||
b.clearance_res_status, b.declare_res_status, b.dest_country, b.dest_country_name,
|
||||
b.trans_weight, b.pack_num, b.total_waybill_qty, b.total_settlement_weight,
|
||||
b.op_man, b.remark, b.tenant_id, b.del_flag, b.create_by, b.create_time,
|
||||
b.update_by, b.update_time, b.create_site, b.update_site, b.bl_entering
|
||||
b.update_by, b.update_time, b.create_site, b.update_site, b.bl_entering,
|
||||
w.total_volume, w.parcel_qty, w.total_weight
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user