diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsSiteBatchDtlMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsSiteBatchDtlMapper.java index 803cfd10a..1ff4b802c 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsSiteBatchDtlMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTmsSiteBatchDtlMapper.java @@ -94,4 +94,10 @@ public interface EmisTmsSiteBatchDtlMapper extends BaseMapper selectEmisTmsSiteBatchDtlByBatchNo(@Param("batchNo") String batchNo); + /** + * + * @param batchDtl + * @return + */ + int updateBatchDtlByBillCode(EmisTmsSiteBatchDtl batchDtl); } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java index 71ac0b675..753f525ec 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java @@ -5371,9 +5371,34 @@ public class EmisBaseService { // 如果查询结果数量大于0,说明该运单已分批,抛出业务异常 if (batchDtlList != null && batchDtlList.size() > 0) { + // 提取批次号并去重 + Set batchNoSet = batchDtlList.stream() + .map(EmisTmsSiteBatchDtl::getBatchNo) + .filter(StringUtils::isNotBlank) + .collect(Collectors.toSet()); + + String batchNoStr = String.join(",", batchNoSet); throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, - "运单[" + emisWaybillSave.getBillCode() + "]已分批,不允许修改件数、重量、体积"); + "运单[" + emisWaybillSave.getBillCode() + "]已分批,不允许修改件数、重量、体积。" + "批次号:" + batchNoStr); } + updateBatchDtlByBillCode(emisWaybillSave); + } + + /** + * 根据运单号更新批次详情表 + * + * @param emisWaybillSave 保存的运单信息 + */ + private void updateBatchDtlByBillCode(EmisWaybill emisWaybillSave) { + EmisTmsSiteBatchDtl batchDtl = new EmisTmsSiteBatchDtl(); + + batchDtl.setBatchParcelQty(emisWaybillSave.getParcelQty()); + batchDtl.setBatchWeight(emisWaybillSave.getBillWeight()); + batchDtl.setBatchVolume(emisWaybillSave.getTotalVolume()); + batchDtl.setBillCode(emisWaybillSave.getBillCode()); + + emisTmsSiteBatchDtlMapper.updateBatchDtlByBillCode(batchDtl); + } public static void main(String[] args) throws ParseException { diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java index f7365f3a3..31ca48dbf 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java @@ -163,11 +163,18 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi } - private void checkItemDtl(EmisTmsSiteBatch oldSiteBatch, EmisTmsSiteBatchDtl itemDtl, EmisWaybill emisWaybill, + private void checkItemDtl(EmisTmsSiteBatch oldSiteBatch, EmisTmsSiteBatchDtl itemDtl, EmisWaybill emisWaybill, EmisTransPlanRule rule) throws EmisBizError { - if (emisWaybill.getParcelQty().equals(itemDtl.getBatchParcelQty()) - && emisWaybill.getBillWeight().equals(itemDtl.getBatchWeight()) - && emisWaybill.getTotalVolume().equals(itemDtl.getBatchVolume())) { + // 安全比较:检查批次数据是否与运单数据完全一致 + boolean isParcelQtyEqual = Objects.equals(emisWaybill.getParcelQty(), itemDtl.getBatchParcelQty()); + // 重量比较:使用compareTo方法比较大小是否相等 + boolean isWeightEqual = emisWaybill.getBillWeight() != null && itemDtl.getBatchWeight() != null + && emisWaybill.getBillWeight().compareTo(itemDtl.getBatchWeight()) == 0; + // 体积比较:使用compareTo方法比较大小是否相等 + boolean isVolumeEqual = emisWaybill.getTotalVolume() != null && itemDtl.getBatchVolume() != null + && emisWaybill.getTotalVolume().compareTo(itemDtl.getBatchVolume()) == 0; + + if (isParcelQtyEqual && isWeightEqual && isVolumeEqual) { checkUnique(oldSiteBatch, itemDtl.getBillCode()); return; } @@ -189,7 +196,7 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi List existingBatches = selectTmsSiteBatchBySiteAndBillCode( oldSiteBatch.getStartSiteCode(), oldSiteBatch.getNextSiteCode(), - itemDtl.getBillCode(),itemDtl.getId()); + itemDtl.getBillCode(), itemDtl.getId()); // 创建包含当前批次的临时批次列表用于分组去重 List allBatches = new ArrayList<>(existingBatches); @@ -224,6 +231,42 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi .filter(Objects::nonNull) .reduce(BigDecimal.ZERO, BigDecimal::add); + if (totalParcelQty < emisWaybill.getParcelQty()) { + if (totalWeight.compareTo(emisWaybill.getBillWeight()) >= 0) { + throw new EmisBizError(EmisBizErrorType.FAIL, + "因为:" + itemDtl.getBillCode() + "的批次总件数(" + totalParcelQty + ")小于运单件数(" + + emisWaybill.getParcelQty() + ");所以:" + + itemDtl.getBillCode() + "的批次总重量(" + totalWeight + ")应小于运单重量(" + + emisWaybill.getBillWeight() + ")"); + } + + if (totalVolume.compareTo(emisWaybill.getTotalVolume()) >= 0) { + throw new EmisBizError(EmisBizErrorType.FAIL, + "因为:" + itemDtl.getBillCode() + "的批次总件数(" + totalParcelQty + ")小于运单件数(" + + emisWaybill.getParcelQty() + ");所以:" + + itemDtl.getBillCode() + "的批次总体积(" + totalVolume + ")应小于运单体积(" + + emisWaybill.getTotalVolume() + ")"); + } + } + + if (totalParcelQty == emisWaybill.getParcelQty()) { + if (totalWeight.compareTo(emisWaybill.getBillWeight()) != 0) { + throw new EmisBizError(EmisBizErrorType.FAIL, + "因为:" + itemDtl.getBillCode() + "的批次总件数(" + totalParcelQty + ")等于运单件数(" + + emisWaybill.getParcelQty() + ");所以:" + + itemDtl.getBillCode() + "的批次总重量(" + totalWeight + ")应等于运单重量(" + + emisWaybill.getBillWeight() + ")"); + } + + if (totalVolume.compareTo(emisWaybill.getTotalVolume()) != 0) { + throw new EmisBizError(EmisBizErrorType.FAIL, + "因为:" + itemDtl.getBillCode() + "的批次总件数(" + totalParcelQty + ")等于运单件数(" + + emisWaybill.getParcelQty() + ");所以:" + + itemDtl.getBillCode() + "的批次总体积(" + totalVolume + ")应等于运单体积(" + + emisWaybill.getTotalVolume() + ")"); + } + } + // 校验总重量、总件数、总体积不能超过运单数据 if (totalWeight.compareTo(emisWaybill.getBillWeight()) > 0) { throw new EmisBizError(EmisBizErrorType.FAIL, @@ -257,9 +300,13 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi if (matchingBatch != null) { // 检查批次重量、体积、件数是否一致 - if (!Objects.equals(matchingBatch.getTotalWeight(), itemDtl.getBatchWeight()) || - !Objects.equals(matchingBatch.getTotalVolume(), itemDtl.getBatchVolume()) || - !Objects.equals(matchingBatch.getTotalParcelQty(), itemDtl.getBatchParcelQty())) { + boolean isBatchWeightEqual = matchingBatch.getTotalWeight() != null && itemDtl.getBatchWeight() != null + && matchingBatch.getTotalWeight().compareTo(itemDtl.getBatchWeight()) == 0; + boolean isBatchVolumeEqual = matchingBatch.getTotalVolume() != null && itemDtl.getBatchVolume() != null + && matchingBatch.getTotalVolume().compareTo(itemDtl.getBatchVolume()) == 0; + boolean isBatchParcelQtyEqual = Objects.equals(matchingBatch.getTotalParcelQty(), itemDtl.getBatchParcelQty()); + + if (!isBatchWeightEqual || !isBatchVolumeEqual || !isBatchParcelQtyEqual) { throw new EmisBizError(EmisBizErrorType.FAIL, itemDtl.getBillCode() + "的批次重量、体积、件数与批次" + matchingBatch.getBatchNo() + "不一致,请检查后重新录入"); } diff --git a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml index 71ac88565..a35954e88 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml @@ -223,4 +223,14 @@ set del_flag = '1' where batch_no = #{batchNo} and del_flag = '0' + + + update emis_tms_site_batch_dtl + + batch_volume = #{batchVolume}, + batch_parcel_qty = #{batchParcelQty}, + batch_weight = #{batchWeight} + + where bill_code = #{billCode} and del_flag = '0' + \ No newline at end of file