From 076b557b4688181bbac5fa38cb4a1e90c852b8fd Mon Sep 17 00:00:00 2001 From: zhaoqiaobo Date: Fri, 12 Apr 2024 17:35:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(service):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=BF=97=E9=82=A6=E6=95=B0=E6=8D=AE=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E4=BB=B6=E9=87=8D=E5=A4=8D=E5=88=99=E4=B8=8D?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=8C=85=E4=BB=B6=E6=95=B0=E6=8D=AE=E5=92=8C?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=88=90=E5=8C=85=E4=BB=B6=E7=9A=84=E6=9A=82?= =?UTF-8?q?=E5=AD=98=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zbom/mapper/OrderPackageMapper.xml | 4 +- .../zbom/mq/ZbomFactoryOrderListener.java | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml index 5af4ea546..07669e4c4 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml @@ -64,7 +64,7 @@ group by re.depart_code, t.platform_order_code diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java index 819de6934..2ae6874a7 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java @@ -50,11 +50,14 @@ import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * 监听志邦订单数据 @@ -81,7 +84,7 @@ public class ZbomFactoryOrderListener { key = FactoryDataConstants.Mq.RoutingKeys.ZBOM_FACTORY_ORDER )) @Transactional(rollbackFor = Exception.class) - public void factoryOrder(String msg) { + public void factoryOrder(String msg, Set packageCodeSet) { if (StrUtil.isEmpty(msg)) { log.error("消息内容为空"); return; @@ -101,15 +104,34 @@ public class ZbomFactoryOrderListener { log.error("入库单号已推送过了"); return; } + // 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存 + Set packageCode = new HashSet<>(); + List details = zbReceiptDTO.getDetails(); + if (CollUtil.isNotEmpty(details)) { + // 收集包件编码 + List collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + List packageCodes = orderPackageService.findByPackageCodes(collect); + if (CollUtil.isNotEmpty(packageCodes)) { + // 将packageCodes中的数据存到packageCode中 + packageCodes.forEach(item -> { + packageCode.add(item.getPackageCode()); + }); + } + } + } ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity(); BeanUtil.copyProperties(zbReceiptDTO, zbReceiptEntity); // 保存订单数据 receiptService.save(zbReceiptEntity); - List details = zbReceiptDTO.getDetails(); if (CollUtil.isNotEmpty(details)) { List packageEntities = new ArrayList<>(); List packageInfoEntities = new ArrayList<>(); for (OrderPackageDTO detail : details) { + if (packageCode.contains(detail.getPackageCode())) { + log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不保存。", detail.getPackageCode()); + continue; + } ZbOrderPackageEntity packageEntity = new ZbOrderPackageEntity(); BeanUtil.copyProperties(detail, packageEntity); packageEntity.setReceiptId(zbReceiptEntity.getId()); @@ -118,6 +140,9 @@ public class ZbomFactoryOrderListener { // 保存包件数据 orderPackageService.saveBatch(packageEntities); for (OrderPackageDTO detail : details) { + if (packageCode.contains(detail.getPackageCode())) { + continue; + } Long detailId = null; for (ZbOrderPackageEntity packageEntity : packageEntities) { if (ObjectUtil.equal(packageEntity.getPackageCode(), detail.getPackageCode())) { @@ -138,10 +163,10 @@ public class ZbomFactoryOrderListener { packageInfoService.saveBatch(packageInfoEntities); } // 处理暂存单 - buildAdvance(zbReceiptDTO); + buildAdvance(zbReceiptDTO, packageCode); } - private void buildAdvance(ZBReceiptDTO zbReceiptDTO) { + private void buildAdvance(ZBReceiptDTO zbReceiptDTO, Set packageCode) { // 新起线程构建暂存单发送mq ThreadPoolUtil.getThreadPool().submit(() -> { Long startWarehouseId = null; @@ -161,6 +186,10 @@ public class ZbomFactoryOrderListener { List details = zbReceiptDTO.getDetails(); // 入库单号 + 订单自编号 + 发车单号 一个暂存单 for (OrderPackageDTO detail : details) { + if (packageCode.contains(detail.getPackageCode())) { + log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不生成暂存单。", detail.getPackageCode()); + continue; + } String taskCode = zbReceiptDTO.getTaskCode(); String departCode = zbReceiptDTO.getDepartCode(); String platformOrderCode = detail.getPlatformOrderCode(); From 08ba9490b58dfb21aa4096a6c1977a2362d176ae Mon Sep 17 00:00:00 2001 From: zhaoqiaobo Date: Fri, 12 Apr 2024 18:22:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(all):=20=E4=BF=AE=E6=94=B9=E6=9A=82?= =?UTF-8?q?=E5=AD=98=E5=8D=95=E4=BF=9D=E5=AD=98=E6=97=B6=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logpm/trunkline/TrunkLineApplication.java | 1 - .../mapper/TrunklineAdvanceDetailMapper.java | 12 ++++++ .../mapper/TrunklineAdvanceDetailMapper.xml | 15 +++++++ .../trunkline/mq/AdvanceOrderListener.java | 36 +++++++++++++++- .../ITrunklineAdvanceDetailService.java | 41 ++++++++++++------- .../TrunklineAdvanceDetailServiceImpl.java | 6 +++ 6 files changed, 94 insertions(+), 17 deletions(-) diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java index 5e3b60b60..d17b93470 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java @@ -19,7 +19,6 @@ package com.logpm.trunkline; import org.springblade.common.constant.ModuleNameConstant; import org.springblade.core.cloud.client.BladeCloudApplication; import org.springblade.core.launch.BladeApplication; -import org.springblade.core.transaction.annotation.SeataCloudApplication; /** * Demo启动器 diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java index 029f43f2b..b4ed1808f 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java @@ -12,6 +12,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Set; @Mapper public interface TrunklineAdvanceDetailMapper extends BaseMapper { @@ -47,4 +48,15 @@ public interface TrunklineAdvanceDetailMapper extends BaseMapper findNoIncomingPackageCode(@Param("advanceId") Long advanceId); Integer findListByAdvanceIdAndPackageStatus(@Param("advanceId") Long advanceId, @Param("packageStatus") String packageStatus); + + /** + * ݰ뼯ϲݿдڵİ롣 + * + * @param orderPackageCodes ļϣΪSet + * һΪյļϣָҪѯĶ롣 + * @return һList͵ļϣ붩ƥİ롣 + * ûҵƥİ룬򷵻һռϡ + */ + List findPackageCodeByCodes(@Param("orderPackageCodes") Set orderPackageCodes); + } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml index 84a453172..c6f498d1d 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml @@ -196,5 +196,20 @@ and package_status = #{packageStatus} and is_deleted = 0 + diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java index 7e43cf89f..3ae1af344 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java @@ -24,7 +24,9 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * 监听工厂数据转暂存单 @@ -50,19 +52,49 @@ public class AdvanceOrderListener { public void advanceOrder(String msg) { // 新增暂存单 if (StrUtil.isNotBlank(msg)) { + log.info("收到工厂数据暂存单消息:{}", msg); JSONObject entries = JSONUtil.parseObj(msg); + JSONArray details = entries.getJSONArray("details"); TrunklineAdvanceEntity advanceEntity = JSONUtil.toBean(entries, TrunklineAdvanceEntity.class); + Set packageCodeSet = new HashSet<>(); + if (CollUtil.isNotEmpty(details)) { + // 使用HashSet代替ArrayList以优化内存使用和检查重复值 + Set orderPackageCodes = new HashSet<>(); + details.forEach(detail -> { + try { + // 更具描述性的变量命名 + JSONObject jsonObject = JSONUtil.parseObj(detail); + TrunklineAdvanceDetailEntity entity = JSONUtil.toBean(jsonObject, TrunklineAdvanceDetailEntity.class); + // 检查转换后的实体不为null,且其orderPackageCode非null + if (!ObjectUtil.hasEmpty(entity, entity.getOrderPackageCode())) { + orderPackageCodes.add(entity.getOrderPackageCode()); + } + } catch (Exception e) { + // 异常处理,可根据实际情况记录日志或进行其他处理 + log.error("暂存单转换时发生异常: " + detail + ",异常:" + e.getMessage()); + } + }); + // 查询数据库,校验订单包件编码是否重复 + if (CollUtil.isNotEmpty(orderPackageCodes)) { + List codes = advanceDetailService.findPackageCodeByCodes(orderPackageCodes); + if (CollUtil.isNotEmpty(codes)) { + packageCodeSet.addAll(codes); + } + } + } if (ObjectUtil.isNotNull(advanceEntity)) { advanceService.save(advanceEntity); } - JSONArray details = entries.getJSONArray("details"); - if (CollUtil.isNotEmpty(details)) { + if (ObjectUtil.isNotEmpty(advanceEntity) && CollUtil.isNotEmpty(details)) { List advanceDetailEntityList = new ArrayList<>(); List detailProductEntityList = new ArrayList<>(); for (Object detailObj : details) { JSONObject detail = JSONUtil.parseObj(detailObj); TrunklineAdvanceDetailEntity advanceDetailEntity = JSONUtil.toBean(detail, TrunklineAdvanceDetailEntity.class); if (ObjectUtil.isNotNull(advanceDetailEntity)) { + if (CollUtil.isNotEmpty(packageCodeSet) && packageCodeSet.contains(advanceDetailEntity.getOrderPackageCode())) { + continue; + } advanceDetailEntity.setAdvanceId(advanceEntity.getId()); advanceDetailEntityList.add(advanceDetailEntity); JSONArray items = detail.getJSONArray("items"); diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java index 6b05d8fca..b208f07ab 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java @@ -13,48 +13,61 @@ import org.springblade.core.tool.api.R; import java.util.List; import java.util.Map; +import java.util.Set; public interface ITrunklineAdvanceDetailService extends BaseService { - void updatePackageStatusById(String packageStatus, Long advanceDetailId,Long warehouseId,String warehouseName); + void updatePackageStatusById(String packageStatus, Long advanceDetailId, Long warehouseId, String warehouseName); - TrunklineAdvanceDetailEntity findEntityByOrderPackageCodeAndWarehouseId(String orderPackageCode, Long warehouseId); + TrunklineAdvanceDetailEntity findEntityByOrderPackageCodeAndWarehouseId(String orderPackageCode, Long warehouseId); - List findList(Long advanceId); + List findList(Long advanceId); - List findGoodsListByAdvanceIds(List advanceIds); + List findGoodsListByAdvanceIds(List advanceIds); AdvanceDetailStockNumVO findStockNumByAdvanceIds(List advanceIds); List findBillladingPackageByAdvanceIdsAnd(List advanceIds); - IPage advanceDetailPageList(AdvanceDetailDTO advanceDetailDTO); + IPage advanceDetailPageList(AdvanceDetailDTO advanceDetailDTO); - TrunklineAdvanceDetailEntity findEntityByOrderPackageCode(String orderPackageCode); + TrunklineAdvanceDetailEntity findEntityByOrderPackageCode(String orderPackageCode); - Integer getIncomingNum(Long advanceId); + Integer getIncomingNum(Long advanceId); - TrunklineAdvanceDetailEntity findEntityByOrderPackageCodeAndTrainNumberAndServiceNumAndOrderCode(String orderPackageCode, String trainNumber, String serviceNum, String orderCode); + TrunklineAdvanceDetailEntity findEntityByOrderPackageCodeAndTrainNumberAndServiceNumAndOrderCode(String orderPackageCode, String trainNumber, String serviceNum, String orderCode); Integer getNumByAdvanceId(Long advanceId); - OrderPackgeCodeDataVO showAdvancePackgeCode(Map params) throws Exception; + OrderPackgeCodeDataVO showAdvancePackgeCode(Map params) throws Exception; List findListByAdvanceId(Long advanceId); List findOrderPackageCodesByAdvanceId(Long advanceId); - void deleteByAdvanceId(Long advanceId); + void deleteByAdvanceId(Long advanceId); - R deleteAdvanceDetail(AdvanceDetailDTO advanceDetailDTO); + R deleteAdvanceDetail(AdvanceDetailDTO advanceDetailDTO); - Integer findTotalNumByOrderCode(String orderCode); + Integer findTotalNumByOrderCode(String orderCode); void updateWaybillNoByAdvanceId(Long advanceId, String waybillNo, Long waybillId); List findIncomingWarehouseName(Long advanceId); - List findNoIncomingPackageCode(Long advanceId); + List findNoIncomingPackageCode(Long advanceId); + + Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus); + + + /** + * ݰ뼯ϲݴ浥дڵİ롣 + * + * @param orderPackageCodes ļϣΪSet + * ҪѯĶΨһʶϡ + * @return һList͵бĶƥа롣 + * ûҵƥİ룬򷵻ؿб + */ + List findPackageCodeByCodes(Set orderPackageCodes); - Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus); } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java index f42bee842..c29ddb416 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; @Slf4j @Service @@ -250,4 +251,9 @@ public class TrunklineAdvanceDetailServiceImpl extends BaseServiceImpl findPackageCodeByCodes(Set orderPackageCodes) { + return baseMapper.findPackageCodeByCodes(orderPackageCodes); + } }