From 691129011a725fcd02aae991fcd3889682132e16 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Tue, 31 Dec 2024 10:19:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E7=B4=A2=E8=8F=B2=E4=BA=9A?= =?UTF-8?q?=E5=B7=A5=E5=8E=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 增加华之韵物流对接 --- .../trunkline/mq/AdvanceOrderListener.java | 149 +++--------------- .../service/ITrunklineAdvanceService.java | 2 + .../impl/TrunklineAdvanceServiceImpl.java | 137 +++++++++++++++- 3 files changed, 161 insertions(+), 127 deletions(-) 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 268bdaf39..69ee9bd74 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 @@ -13,7 +13,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.entity.DistributionParcelListEntity; import com.logpm.distribution.feign.IDistributionParcelListClient; import com.logpm.distribution.feign.IDistributionStockArticleClient; -import com.logpm.factorydata.enums.BrandEnums; import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; import com.logpm.trunkline.entity.TrunklineAdvanceEntity; import com.logpm.trunkline.entity.TrunklineDetailProductEntity; @@ -21,6 +20,7 @@ import com.logpm.trunkline.service.ITrunklineAdvanceDetailService; import com.logpm.trunkline.service.ITrunklineAdvanceService; import com.logpm.trunkline.service.ITrunklineCarsLoadService; import com.logpm.trunkline.service.ITrunklineDetailProductService; +import com.rabbitmq.client.Channel; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.common.constant.factorydata.FactoryDataConstants; @@ -30,10 +30,18 @@ import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.amqp.support.AmqpHeaders; +import org.springframework.messaging.handler.annotation.Header; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * 监听工厂数据转暂存单 @@ -57,131 +65,20 @@ public class AdvanceOrderListener { value = @Queue(name = FactoryDataConstants.Mq.Queues.ADVANCE_ORDER), exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER, type = ExchangeTypes.TOPIC), key = FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER - )) - @Transactional(rollbackFor = Exception.class) - public void advanceOrder(String msg) { + ), ackMode = "MANUAL") + public void advanceOrder(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { // 新增暂存单 - if (StrUtil.isNotBlank(msg)) { - log.info("收到工厂数据暂存单消息:{}", msg); - JSONObject entries = JSONUtil.parseObj(msg); - JSONArray details = entries.getJSONArray("details"); - TrunklineAdvanceEntity advanceEntity = JSONUtil.toBean(entries, TrunklineAdvanceEntity.class); - LambdaQueryWrapper eq = Wrappers.lambdaQuery() - .eq(TrunklineAdvanceEntity::getOrderCode, advanceEntity.getOrderCode()); - if (StrUtil.isNotEmpty(advanceEntity.getTrainNumber())) { - eq.eq(TrunklineAdvanceEntity::getTrainNumber, advanceEntity.getTrainNumber()); - } - // 暂存单 订单自编号 + 车次号 唯一 - List advanceEntities = advanceService.list(eq); - - // 暂存单存在 并且未开单 则将新数据添加到原来的暂存单上 - // 如果已开单则新增暂存单 - if (CollUtil.isNotEmpty(advanceEntities) && ObjectUtil.equal(advanceEntity.getWaybillStatus(), "0")) { - TrunklineAdvanceEntity entity = advanceEntities.get(0); - if (ObjectUtil.isNotEmpty(entity)) { - advanceEntity.setId(entity.getId()); -// advanceEntity.setTotalNum(entity.getTotalNum() + advanceEntity.getTotalNum()); - } - } - 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.isAllEmpty(entity, entity.getOrderPackageCode())) { - orderPackageCodes.add(entity.getOrderPackageCode()); - } - } catch (Exception e) { - // 异常处理,可根据实际情况记录日志或进行其他处理 - log.error("暂存单转换时发生异常: " + detail + ",异常:" + e.getMessage()); - } - }); - // 查询数据库,校验订单包件编码是否重复 - if (CollUtil.isNotEmpty(orderPackageCodes)) { - Map packageCodeByCodes = advanceDetailService.findPackageCodeByCodes(orderPackageCodes); - if (CollUtil.isNotEmpty(packageCodeByCodes)) { - packageCodeSet.addAll(packageCodeByCodes.keySet()); - } - } - } - if (ObjectUtil.isNotNull(advanceEntity)) { - String orderCode = advanceEntity.getOrderCode(); - if (StrUtil.isNotEmpty(orderCode) && orderCode.contains("遗")) { - advanceEntity.setLegacyStatus("1"); - } - // 暂存单不存在则新增,暂存单存在则将暂存单明细往原暂存单中添加 - if (ObjectUtil.isEmpty(advanceEntity.getId())) { - advanceEntity.setCreateUserName(AuthUtil.getNickName()); - advanceService.save(advanceEntity); - } else { - advanceService.updateById(advanceEntity); - } - } - 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())) { - // 金牌如果是重复包条,则单独处理 - if (ObjectUtil.equal(advanceEntity.getBrand(), BrandEnums.JP.getValue())) { - // 金牌按DD单号+包条确定唯一值 - List list = advanceDetailService.list(Wrappers.lambdaQuery() - .eq(TrunklineAdvanceDetailEntity::getOrderPackageCode, advanceDetailEntity.getOrderPackageCode()) - .eq(TrunklineAdvanceDetailEntity::getOrderCode, advanceEntity.getOrderCode()) - ); - if (CollUtil.isNotEmpty(list)) { - // 订单+包件重复则不处理这条数据 - log.error("金牌,订单+包条码重复,订单:{},包条码:{}", advanceEntity.getOrderCode(), advanceDetailEntity.getOrderPackageCode()); - continue; - } else { - // 包件码重复,订单+包件不重复,设置预留字段1 为 1 - advanceDetailEntity.setReserve1("1"); - } - } else { - log.error("非金牌,包条码重复,包条码:{}", advanceDetailEntity.getOrderPackageCode()); - continue; - } - } - advanceDetailEntity.setAdvanceId(advanceEntity.getId()); - // 设置发货时间为当前时间 - if (StrUtil.isEmpty(advanceDetailEntity.getSendDateStr())) { - advanceDetailEntity.setSendDateStr(DateUtil.today()); - } - advanceDetailEntityList.add(advanceDetailEntity); - JSONArray items = detail.getJSONArray("items"); - if (CollUtil.isNotEmpty(items)) { - for (Object itemObj : items) { - JSONObject item = JSONUtil.parseObj(itemObj); - TrunklineDetailProductEntity detailProductEntity = JSONUtil.toBean(item, TrunklineDetailProductEntity.class); - if (ObjectUtil.isNotNull(detailProductEntity)) { - detailProductEntityList.add(detailProductEntity); - } - } - } - } - - } - advanceDetailService.saveBatch(advanceDetailEntityList); - //发送入库包件处理无数据装车数据 - trunklineCarsLoadService.sendRabbitMessageLoadScanData(JSONUtil.toJsonStr(advanceEntity)); - detailProductService.saveBatch(detailProductEntityList); - - //发送报表数据广播 - Long warehouseId = advanceEntity.getWarehouseId(); - String warehouseName = advanceEntity.getWarehouseName(); - String dealerCode = advanceEntity.getDealerCode(); - String dealerName = advanceEntity.getDealerName(); - advanceDetailService.sendReportBasicdataFanout(AuthUtil.getNickName(),AuthUtil.getUserId(),warehouseId,warehouseName,new Date(),advanceDetailEntityList,dealerCode,dealerName); - - } + log.info("收到工厂数据暂存单消息:{}", msg); + try { + advanceService.advanceOrder(msg); + } catch (Exception e) { + e.printStackTrace(); + log.error("收到工厂数据暂存单消息失败: {}", e.getMessage()); + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); } } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java index 5e13956c8..5075071d3 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceService.java @@ -53,4 +53,6 @@ public interface ITrunklineAdvanceService extends BaseService eq = Wrappers.lambdaQuery() + .eq(TrunklineAdvanceEntity::getOrderCode, advanceEntity.getOrderCode()); + if (StrUtil.isNotEmpty(advanceEntity.getTrainNumber())) { + eq.eq(TrunklineAdvanceEntity::getTrainNumber, advanceEntity.getTrainNumber()); + } + // 暂存单 订单自编号 + 车次号 唯一 + List advanceEntities = this.list(eq); + + // 暂存单存在 并且未开单 则将新数据添加到原来的暂存单上 + // 如果已开单则新增暂存单 + if (CollUtil.isNotEmpty(advanceEntities) && ObjectUtil.equal(advanceEntity.getWaybillStatus(), "0")) { + TrunklineAdvanceEntity entity = advanceEntities.get(0); + if (ObjectUtil.isNotEmpty(entity)) { + advanceEntity.setId(entity.getId()); +// advanceEntity.setTotalNum(entity.getTotalNum() + advanceEntity.getTotalNum()); + } + } + 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.isAllEmpty(entity, entity.getOrderPackageCode())) { + orderPackageCodes.add(entity.getOrderPackageCode()); + } + } catch (Exception e) { + // 异常处理,可根据实际情况记录日志或进行其他处理 + log.error("暂存单转换时发生异常: " + detail + ",异常:" + e.getMessage()); + } + }); + // 查询数据库,校验订单包件编码是否重复 + if (CollUtil.isNotEmpty(orderPackageCodes)) { + Map packageCodeByCodes = advanceDetailService.findPackageCodeByCodes(orderPackageCodes); + if (CollUtil.isNotEmpty(packageCodeByCodes)) { + packageCodeSet.addAll(packageCodeByCodes.keySet()); + } + } + } + if (ObjectUtil.isNotNull(advanceEntity)) { + String orderCode = advanceEntity.getOrderCode(); + if (StrUtil.isNotEmpty(orderCode) && orderCode.contains("遗")) { + advanceEntity.setLegacyStatus("1"); + } + // 暂存单不存在则新增,暂存单存在则将暂存单明细往原暂存单中添加 + if (ObjectUtil.isEmpty(advanceEntity.getId())) { + advanceEntity.setCreateUserName(AuthUtil.getNickName()); + this.save(advanceEntity); + } else { + this.updateById(advanceEntity); + } + } + 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())) { + // 金牌如果是重复包条,则单独处理 + if (ObjectUtil.equal(advanceEntity.getBrand(), BrandEnums.JP.getValue())) { + // 金牌按DD单号+包条确定唯一值 + List list = advanceDetailService.list(Wrappers.lambdaQuery() + .eq(TrunklineAdvanceDetailEntity::getOrderPackageCode, advanceDetailEntity.getOrderPackageCode()) + .eq(TrunklineAdvanceDetailEntity::getOrderCode, advanceEntity.getOrderCode()) + ); + if (CollUtil.isNotEmpty(list)) { + // 订单+包件重复则不处理这条数据 + log.error("金牌,订单+包条码重复,订单:{},包条码:{}", advanceEntity.getOrderCode(), advanceDetailEntity.getOrderPackageCode()); + continue; + } else { + // 包件码重复,订单+包件不重复,设置预留字段1 为 1 + advanceDetailEntity.setReserve1("1"); + } + } else { + log.error("非金牌,包条码重复,包条码:{}", advanceDetailEntity.getOrderPackageCode()); + continue; + } + } + advanceDetailEntity.setAdvanceId(advanceEntity.getId()); + // 设置发货时间为当前时间 + if (StrUtil.isEmpty(advanceDetailEntity.getSendDateStr())) { + advanceDetailEntity.setSendDateStr(DateUtil.today()); + } + advanceDetailEntityList.add(advanceDetailEntity); + JSONArray items = detail.getJSONArray("items"); + if (CollUtil.isNotEmpty(items)) { + for (Object itemObj : items) { + JSONObject item = JSONUtil.parseObj(itemObj); + TrunklineDetailProductEntity detailProductEntity = JSONUtil.toBean(item, TrunklineDetailProductEntity.class); + if (ObjectUtil.isNotNull(detailProductEntity)) { + detailProductEntityList.add(detailProductEntity); + } + } + } + } + + } + advanceDetailService.saveBatch(advanceDetailEntityList); + //发送入库包件处理无数据装车数据 + trunklineCarsLoadService.sendRabbitMessageLoadScanData(JSONUtil.toJsonStr(advanceEntity)); + detailProductService.saveBatch(detailProductEntityList); + + //发送报表数据广播 + Long warehouseId = advanceEntity.getWarehouseId(); + String warehouseName = advanceEntity.getWarehouseName(); + String dealerCode = advanceEntity.getDealerCode(); + String dealerName = advanceEntity.getDealerName(); + advanceDetailService.sendReportBasicdataFanout(AuthUtil.getNickName(),AuthUtil.getUserId(),warehouseId,warehouseName,new Date(),advanceDetailEntityList,dealerCode,dealerName); + + } + } + } }