diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchDtlServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchDtlServiceImpl.java index 7e7c8ce4f..08bb15d76 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchDtlServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchDtlServiceImpl.java @@ -74,7 +74,21 @@ public class EmisTmsSiteBatchDtlServiceImpl implements IEmisTmsSiteBatchDtlServi */ @Override public List selectEmisTmsSiteBatchDtlList(EmisTmsSiteBatchDtl emisTmsSiteBatchDtl) { - return emisTmsSiteBatchDtlMapper.selectEmisTmsSiteBatchDtlList(emisTmsSiteBatchDtl); + List list = emisTmsSiteBatchDtlMapper.selectEmisTmsSiteBatchDtlList(emisTmsSiteBatchDtl); + + // 如果根据batchNo查询,需要对结果按运单号去重 + if (StringUtils.isNotBlank(emisTmsSiteBatchDtl.getBatchNo()) && CollectionUtil.isNotEmpty(list)) { + // 使用LinkedHashMap保持顺序,按运单号去重,保留第一条记录 + Map uniqueMap = new LinkedHashMap<>(); + for (EmisTmsSiteBatchDtl item : list) { + if (StringUtils.isNotBlank(item.getBillCode())) { + uniqueMap.putIfAbsent(item.getBillCode(), item); + } + } + list = new ArrayList<>(uniqueMap.values()); + } + + return list; } /** 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 549999c88..935007d9c 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 @@ -201,6 +201,10 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi oldSiteBatch.getStartSiteCode(), oldSiteBatch.getNextSiteCode(), itemDtl.getBillCode(), itemDtl.getId()); + if (itemDtl.getId() != null) { + existingBatches = existingBatches.stream().filter(i -> !itemDtl.getBatchNo().equals(i.getBatchNo())) + .collect(Collectors.toList()); + } EmisTransPlanRule rule = rules.stream() .filter(i -> i.getSupplierCode().contains(oldSiteBatch.getSupplierCode())).collect(Collectors.toList()) .get(0); @@ -253,6 +257,7 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi currentBatch.setTotalWeight(itemDtl.getBatchWeight()); currentBatch.setTotalParcelQty(itemDtl.getBatchParcelQty()); currentBatch.setTotalVolume(itemDtl.getBatchVolume()); + allBatches.add(currentBatch); List countBatches = new ArrayList<>(allBatches); @@ -496,6 +501,16 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi @Override @Transactional public int addAll(EmisTmsSiteBatch emisTmsSiteBatch) throws EmisBizError { + + // 根据批次号查询是否已存在,已存在则报错 + if (StringUtils.isNotBlank(emisTmsSiteBatch.getBatchNo())) { + EmisTmsSiteBatch existingBatch = emisTmsSiteBatchMapper + .selectTmsSiteBatchByBatchNo(emisTmsSiteBatch.getBatchNo()); + if (existingBatch != null) { + throw new EmisBizError(EmisBizErrorType.EXISTS, "批次号[" + emisTmsSiteBatch.getBatchNo() + "]已存在,不能重复添加"); + } + } + // 插入明细数据 if (!CollectionUtils.isEmpty(emisTmsSiteBatch.getBatchDtlList())) { List distinctBatchDtlList = emisTmsSiteBatch.getBatchDtlList().stream() diff --git a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml index 8284aa5e9..10461f492 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchDtlMapper.xml @@ -33,22 +33,29 @@ select id, bill_code, batch_no, scan_date, scan_status, group_status, scan_man, scan_site, batch_volume, batch_parcel_qty, batch_weight, waybill_batch_status, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_tms_site_batch_dtl - del_flag='0' - and id = #{id} - and ( FIND_IN_SET(`bill_code`,#{billCode}) or bill_code like concat('%', #{billCode}, '%') ) - and ( FIND_IN_SET(`batch_no`,#{batchNo}) or batch_no like concat('%', #{batchNo}, '%') ) - and scan_date = #{scanDate} - and scan_status=#{scanStatus} - and group_status=#{groupStatus} - and scan_man like concat('%', #{scanMan}, '%') - and scan_site =#{scanSite} - and batch_volume = #{batchVolume} - and batch_parcel_qty = #{batchParcelQty} - and batch_weight = #{batchWeight} - and waybill_batch_status = #{waybillBatchStatus} + and id = #{id} + and ( FIND_IN_SET(`bill_code`,#{billCode}) or bill_code like + concat('%', #{billCode}, '%') ) + + + and (FIND_IN_SET(#{batchNo}, `batch_no`) or batch_no = #{batchNo}) + + and scan_date = #{scanDate} + and scan_status=#{scanStatus} + and group_status=#{groupStatus} + and scan_man like concat('%', #{scanMan}, '%') + and scan_site =#{scanSite} + and batch_volume = #{batchVolume} + and batch_parcel_qty = #{batchParcelQty} + and batch_weight = #{batchWeight} + and waybill_batch_status = + #{waybillBatchStatus} + and bill_code in @@ -202,16 +209,16 @@ where id = #{id} - - delete from emis_tms_site_batch_dtl where id = #{id} - + + update emis_tms_site_batch_dtl set del_flag = '1' where id = #{id} + - - delete from emis_tms_site_batch_dtl where id in + + update emis_tms_site_batch_dtl set del_flag = '1' where id in #{id} - + @@ -547,16 +548,16 @@ 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, CASE - WHEN COALESCE(SUM(d.batch_volume), 0) = 0 THEN COALESCE(w.total_volume, 0) - ELSE COALESCE(SUM(d.batch_volume), 0) + WHEN COALESCE(MAX(d.batch_volume), 0) = 0 THEN COALESCE(w.total_volume, 0) + ELSE COALESCE(MAX(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) + WHEN COALESCE(MAX(d.batch_parcel_qty), 0) = 0 THEN COALESCE(w.parcel_qty, 0) + ELSE COALESCE(MAX(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) + WHEN COALESCE(MAX(d.batch_weight), 0) = 0 THEN COALESCE(w.bill_weight, 0) + ELSE COALESCE(MAX(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