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); + } }