From f837998bd46f32072cfc62117a3bd6eabd34a0a4 Mon Sep 17 00:00:00 2001 From: "pref_mail@163.com" Date: Wed, 17 Jul 2024 15:27:33 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E7=AD=BE=E6=94=B6=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E7=9A=84=E4=BD=9C=E4=B8=9A=E8=8A=82=E7=82=B9=EF=BC=8C?= =?UTF-8?q?=E9=87=87=E7=94=A8=E5=B9=BF=E6=92=AD=E6=96=B9=E5=BC=8F=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=A4=84=E7=90=86=202.=E5=8F=96=E6=B6=88=E4=BA=86?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=AD=BE=E6=94=B6=E6=89=AB=E6=8F=8F=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E5=95=86=E5=AE=B6=E7=AB=AF=E7=9A=84=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=203.=E4=BF=AE=E6=94=B9=E5=BC=80=E5=8D=95=E7=9A=84=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E5=95=86=E5=AE=B6=E7=AB=AF=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/RabbitConstant.java | 8 -- .../constant/broadcast/FanoutConstants.java | 21 ++- .../common/model/BroadcastNodeData.java | 60 +++++++++ .../service/IDistributionNodeWorkService.java | 76 +++++++++++ .../impl/DistributionNodeWorkServiceImpl.java | 125 ++++++++++++++++++ .../impl/DistributionSignforServiceImpl.java | 71 +++++----- .../DistrilbutionBillLadingServiceImpl.java | 102 +++++++------- .../factory/receiver/NodeWorkHandler.java | 57 ++++++++ .../config/RabbitMqConfiguration.java | 28 ---- .../mq/OpenWaybillToBusinessListener.java | 65 +++++++-- .../service/IOpenOrderAsyncService.java | 2 +- .../impl/OpenOrderAsyncServiceImpl.java | 3 +- .../service/impl/OpenOrderServiceImpl.java | 36 +---- 13 files changed, 486 insertions(+), 168 deletions(-) create mode 100644 blade-biz-common/src/main/java/org/springblade/common/model/BroadcastNodeData.java create mode 100644 blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionNodeWorkService.java create mode 100644 blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionNodeWorkServiceImpl.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/NodeWorkHandler.java diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java b/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java index e3ad3f8e9..2f62971c1 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/RabbitConstant.java @@ -171,14 +171,6 @@ public interface RabbitConstant { String OPEN_ORDER_LOAD_SCAN_ROUTING = "open_order_load_scan_routing" + ModuleNameConstant.DEVAUTH; - /****************运单创建推送商家数据start *************************/ - - String OPEN_WAYBILL_TO_BUSINESS_DATA_QUEUE = "open_waybill_to_business_data_queue" + ModuleNameConstant.DEVAUTH; - String OPEN_WAYBILL_TO_BUSINESS_DATA_EXCHANGE = "open_waybill_to_business_data_exchange" + ModuleNameConstant.DEVAUTH; - String OPEN_WAYBILL_TO_BUSINESS_DATA_ROUTING = "open_waybill_to_business_data_routing" + ModuleNameConstant.DEVAUTH; - - - /****************运单创建推送商家数据end *************************/ /****************库内入库推送商家数据start *************************/ diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/broadcast/FanoutConstants.java b/blade-biz-common/src/main/java/org/springblade/common/constant/broadcast/FanoutConstants.java index 8b71a7c35..e00823ddb 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/broadcast/FanoutConstants.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/broadcast/FanoutConstants.java @@ -19,7 +19,10 @@ public abstract class FanoutConstants { interface QUEUE { String STATISTICSDATA_CREATEPACKAGEINFO = "fanout.trunkline.openWaybill.statisticsdata.createPackageinfo" + ModuleNameConstant.DEVAUTH; - + // 开单检测数据 --商家端 + String SEND_BUSINESS_DATA_BY_OPENWAYBILL_DATA = "fanout.trunkline.openWaybill.send_business_data.open" + ModuleNameConstant.DEVAUTH; + // 改单数据 --商家端 + String SEND_BUSINESS_DATA_BY_UPDATEWAYBILL_DATA = "fanout.trunkline.openWaybill.send_business_data.update" + ModuleNameConstant.DEVAUTH; } } @@ -155,4 +158,20 @@ public abstract class FanoutConstants { } + /** + * 配送 + */ + public interface distribution { + interface signfor{ + String EXCHANGE = "fanout.distribution.signfor" + ModuleNameConstant.DEVAUTH; + interface QUEUE { + String FACTORY_NODE_WORK_DISTRIBUTION_SIGNFOR_QUERY = "fanout.factory.node_work.distribution.signfor_query"+ ModuleNameConstant.DEVAUTH; + } + } + + + } + + + } diff --git a/blade-biz-common/src/main/java/org/springblade/common/model/BroadcastNodeData.java b/blade-biz-common/src/main/java/org/springblade/common/model/BroadcastNodeData.java new file mode 100644 index 000000000..a44f2814b --- /dev/null +++ b/blade-biz-common/src/main/java/org/springblade/common/model/BroadcastNodeData.java @@ -0,0 +1,60 @@ +package org.springblade.common.model; + +import com.alibaba.fastjson.JSONObject; + +/** + * 节点作业数据传输对象 + */ +public class BroadcastNodeData extends JSONObject { + + /** + * 当前作业租户ID + */ + private String tenantId; + + /** + * 作业人名称 + */ + private String userName; + + /** + * 操作时间 + */ + private String operationTime; + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getOperationTime() { + return operationTime; + } + + public void setOperationTime(String operationTime) { + this.operationTime = operationTime; + } + + @Override + public String toJSONString() { + + + // 需要 将当前类的属性增加的到json的输出 + this.put("tenantId", tenantId); + this.put("userName", userName); + this.put("operationTime", operationTime); + + return super.toJSONString(); + } +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionNodeWorkService.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionNodeWorkService.java new file mode 100644 index 000000000..79524a1e0 --- /dev/null +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionNodeWorkService.java @@ -0,0 +1,76 @@ +package com.logpm.distribution.service; + +import com.logpm.distribution.entity.DistributionParcelListEntity; + +/** + *

+ * 配送作业节点 推送给服务 + *

+ */ +public interface IDistributionNodeWorkService { + + // 签收作业节点 + + /** + * 装车 + */ + void nodeLoad(); + + /** + * 异常装车 + */ + void abnormalLoading(); + + /** + * 取消装车 + */ + void cancelLoading(); + + /** + * 发车 + */ + void carStart(); + + /** + * 配送到达 + */ + void carArrived(); + + + /** + * 签收 + */ + void signFor(DistributionParcelListEntity parcelListEntity, Long taskId, String operationTime, String destinationWarehouse); + + + /** + * 签收复核 + */ + void signForCheck(); + + /** + * 自提签收扫描 + */ + void billofladingSignfor(DistributionParcelListEntity parcelListEntity,Long taskId,String operationTime, String destinationWarehouse); + + /** + * 自提签收复核 + */ + void billofladingSignforCheck(); + + /** + * 滞留 + */ + void retention(); + + /** + * 异常签收 + */ + void abnormalSignfor(); + + /** + * 配送失败 + */ + void fail(); + +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionNodeWorkServiceImpl.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionNodeWorkServiceImpl.java new file mode 100644 index 000000000..0a678802b --- /dev/null +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionNodeWorkServiceImpl.java @@ -0,0 +1,125 @@ +package com.logpm.distribution.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.logpm.distribution.entity.DistributionParcelListEntity; +import com.logpm.distribution.entity.DistributionReservationEntity; +import com.logpm.distribution.service.IDistributionNodeWorkService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.model.BroadcastNodeData; +import org.springblade.common.model.FanoutMsg; +import org.springblade.core.secure.utils.AuthUtil; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +@Slf4j +public class DistributionNodeWorkServiceImpl implements IDistributionNodeWorkService { + + private final RabbitTemplate rabbitTemplate; + + @Override + public void nodeLoad() { + + } + + @Override + public void abnormalLoading() { + + } + + @Override + public void cancelLoading() { + + } + + @Override + public void carStart() { + + } + + @Override + public void carArrived() { + + } + + @Override + public void signFor(DistributionParcelListEntity parcelListEntity, Long taskId, String operationTime, String destinationWarehouse) { + + log.info(">>>>>>>>>> signFor 签收扫描 {}", parcelListEntity.getOrderPackageCode()); + BroadcastNodeData broadcastNodeData = new BroadcastNodeData(); + broadcastNodeData.put("orderPackageCode", parcelListEntity.getOrderPackageCode()); + broadcastNodeData.put("distributionContactId", taskId); +// broadcastNodeData.put("distributionContactCode", distributionReservationEntity.getReservationCode()); + broadcastNodeData.put("destinationWarehouse", destinationWarehouse); + broadcastNodeData.put("brand", parcelListEntity.getBrandName()); + broadcastNodeData.setOperationTime(operationTime); + broadcastNodeData.setUserName(AuthUtil.getUserName()); + broadcastNodeData.setTenantId(AuthUtil.getTenantId()); + + FanoutMsg build = FanoutMsg.builder().msg(broadcastNodeData.toJSONString()) + .exchange(FanoutConstants.distribution.signfor.EXCHANGE).build(); + + sendFanoutMsg(build); + } + + + @Override + public void signForCheck() { + + } + + @Override + public void billofladingSignfor(DistributionParcelListEntity parcelListEntity,Long taskId,String operationTime, String destinationWarehouse) { + log.info(">>>>>>>>>> billofladingSignfor 自提扫描 {}", parcelListEntity.getOrderPackageCode()); + + + BroadcastNodeData broadcastNodeData = new BroadcastNodeData(); + broadcastNodeData.put("orderPackageCode", parcelListEntity.getOrderPackageCode()); + broadcastNodeData.put("distributionContactId", taskId); +// broadcastNodeData.put("distributionContactCode", distributionReservationEntity.getReservationCode()); + broadcastNodeData.put("destinationWarehouse", destinationWarehouse); + broadcastNodeData.put("brand", parcelListEntity.getBrandName()); + broadcastNodeData.setOperationTime(operationTime); + broadcastNodeData.setUserName(AuthUtil.getUserName()); + broadcastNodeData.setTenantId(AuthUtil.getTenantId()); + + FanoutMsg build = FanoutMsg.builder().msg(broadcastNodeData.toJSONString()) + .exchange(FanoutConstants.distribution.signfor.EXCHANGE).build(); + + sendFanoutMsg(build); + + } + + @Override + public void billofladingSignforCheck() { + + } + + @Override + public void retention() { + + } + + @Override + public void abnormalSignfor() { + + } + + @Override + public void fail() { + + } + + + @Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(value = 3000, multiplier = 1.5)) + private void sendFanoutMsg(FanoutMsg fanoutMsg) { + + rabbitTemplate.convertAndSend(fanoutMsg.getExchange(), null, fanoutMsg.getMsg()); + + } +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java index c09fb6260..ceab5ec09 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java @@ -242,6 +242,9 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl selectDistributionSignforPage(IPage page, DistributionSignforVO distributionSignfor) { @@ -2490,6 +2493,8 @@ public class DistributionSignforServiceImpl extends BaseServiceImplquery().lambda() .eq(DistributionSignforEntity::getReservationId, distrilbutionloadingscanDTO.getReservationId()) ); @@ -2523,13 +2525,13 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl jsonObjects = new ArrayList<>(); @@ -2722,12 +2723,8 @@ public class DistributionSignforServiceImpl extends BaseServiceImplquery().lambda() - .eq(DistributionParcelListEntity::getOrderPackageCode, distrilbutionloadingscanDTO.getBarcode()) - .eq(DistributionParcelListEntity::getWarehouseId, myCurrentWarehouse.getId()) - ); - if (Func.isNotEmpty(one) && one.getConditions() == 2) { - log.warn("#####################此包件不是定制品 {}", one.getConditions()); + if (Func.isNotEmpty(parcelListEntity) && parcelListEntity.getConditions() == 2) { + log.warn("#####################此包件不是定制品 {}", parcelListEntity.getConditions()); return Resp.scanFail("此包件不是定制品", "此包件不是定制品"); } List parcelListEntities = distributionDeliveryListMapper.selectPackageListByDeliveryListId(distrilbutionloadingscanDTO.getDeliveryId()); @@ -2796,15 +2793,8 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl>>> 签收推送报错", e); - } + // 节点作业推送 + sendNodeWorkDataBroadcast(parcelListEntity, distributionReservationEntity, singleTime, myCurrentWarehouse); return Resp.scanSuccessWithData("签收成功", str, orderPackageCodes); @@ -2814,6 +2804,20 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl>>> 签收作业节点广播报错", e); + } + } + /** * @param orderPackageCode * @param reservationCode @@ -3074,7 +3078,9 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl detailEntities = distributionReservationMapper.selectInventoryListByReservation(distributionSignforEntity.getReservationId()); - if (detailEntities.size() > 0 && Func.isNotEmpty(detailEntities)) { + if (!detailEntities.isEmpty() && Func.isNotEmpty(detailEntities)) { loadingInventoryNum += detailEntities.stream().mapToInt(DisStockListDetailEntity::getNum).sum(); signingInventoryNum += detailEntities.stream().mapToInt(DisStockListDetailEntity::getNum).sum(); boolean flag = detailEntities.stream().allMatch(s -> Func.isNotEmpty(s.getStockPackageCode())); @@ -5310,7 +5318,8 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl> packageMap = distributionParcelListEntities.stream().collect(Collectors.groupingBy(DistributionParcelListEntity::getConditions)); List ladingScanEntities = new ArrayList<>(); if (!packageMap.isEmpty()) { - ladingScanEntities = handleSignPackage(packageMap, distrilbutionBillLading.getId(), myCurrentWarehouse.getId()); + ladingScanEntities = handleSignPackage(packageMap, distrilbutionBillLading.getId(), myCurrentWarehouse); if (!ladingScanEntities.isEmpty()) { // 进行签收扫描数据补录 distributionBillLadingScanService.saveBatch(ladingScanEntities); @@ -1382,7 +1351,7 @@ public class DistrilbutionBillLadingServiceImpl extends BaseServiceImpl handleSignPackage(Map> packageMap, Long id, Long warehouseId) { + public List handleSignPackage(Map> packageMap, Long id, BasicdataWarehouseEntity myCurrentWarehouse) { String method = "###################DistributionBillLadingServiceImpl.handleSignPackage"; List ladingScanEntities = new ArrayList<>(); List orderCodes = new ArrayList<>(); @@ -1402,7 +1371,7 @@ public class DistrilbutionBillLadingServiceImpl extends BaseServiceImpl pushMap = new HashMap<>(); - pushMap.put("orderPackageCode", coding); - pushMap.put("operationTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - pushMap.put("distributionContactId", billLadingId); - pushMap.put("destinationWarehouse", myCurrentWarehouse.getName()); - - rabbitTemplate.convertAndSend(RabbitConstant.MT_BUSINESS_DATA_2_FACTORY_EXCHANGE, RabbitConstant.MT_BUSINESS_DATA_2_FACTORY_ROUTING, pushMap, message -> { - message.getMessageProperties() - .setHeader("x-delay", 3000); - return message; - }); - } +// if (distributionParcelListEntity.getBrandName().equals("梦天")){ +// Map pushMap = new HashMap<>(); +// pushMap.put("orderPackageCode", coding); +// pushMap.put("operationTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); +// pushMap.put("distributionContactId", billLadingId); +// pushMap.put("destinationWarehouse", myCurrentWarehouse.getName()); +// +// rabbitTemplate.convertAndSend(RabbitConstant.MT_BUSINESS_DATA_2_FACTORY_EXCHANGE, RabbitConstant.MT_BUSINESS_DATA_2_FACTORY_ROUTING, pushMap, message -> { +// message.getMessageProperties() +// .setHeader("x-delay", 3000); +// return message; +// }); +// } } @@ -3335,6 +3314,21 @@ public class DistrilbutionBillLadingServiceImpl extends BaseServiceImpl>>> 自提签收作业节点广播报错", e); + } + } /** * pda扫描 diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/NodeWorkHandler.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/NodeWorkHandler.java new file mode 100644 index 000000000..aae180552 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/NodeWorkHandler.java @@ -0,0 +1,57 @@ +package com.logpm.factory.receiver; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.logpm.factory.mt.service.IMtFactoryDataService; +import com.logpm.factorydata.enums.BrandEnums; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.model.BroadcastNodeData; +import org.springframework.amqp.core.ExchangeTypes; +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.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +/** + * 作业节点数据监听 + */ +@Slf4j +@AllArgsConstructor +@Component +public class NodeWorkHandler { + + private final IMtFactoryDataService mtFactoryDataService; + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.signfor.QUEUE.FACTORY_NODE_WORK_DISTRIBUTION_SIGNFOR_QUERY), + exchange = @Exchange(name = FanoutConstants.distribution.signfor.EXCHANGE, type = ExchangeTypes.FANOUT) + )) + public void distributionSignforQuery(String message) { + + try { + JSONObject jsonObject = JSONUtil.parseObj(message); + String orderPackageCode = jsonObject.getStr("orderPackageCode"); + String operationTime = jsonObject.getStr("operationTime"); + String distributionContactId = jsonObject.getStr("distributionContactId"); + String destinationWarehouse = jsonObject.getStr("destinationWarehouse"); + // 获取品牌BrandEnums.MTMM.getValue() + String o = jsonObject.getStr("brand"); + switch (o) { + case "梦天" : + log.info("工厂节点数据监听:1"); + mtFactoryDataService.qianshouScanForNewSystem(orderPackageCode, operationTime, distributionContactId, destinationWarehouse); + break; + default: + log.info("签收扫描没有找到品牌: {}",o); + } + }catch (Exception e){ + log.error("工厂节点数据监听异常", e); + } + + + } + +} diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/RabbitMqConfiguration.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/RabbitMqConfiguration.java index f69f45af9..4f41cda88 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/RabbitMqConfiguration.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/RabbitMqConfiguration.java @@ -104,32 +104,4 @@ public class RabbitMqConfiguration { return BindingBuilder.bind(hwyOpenOrderLoadScanQueue).to(hwyOpenOrderLoadScanExchange).with(RabbitConstant.HWY_ORDER_STATUS_ROUTING).noargs(); } - @Bean - public Queue openWaybillToBusinessQueue() { - return new Queue(RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_QUEUE, true); - } - @Bean - public CustomExchange openWaybillToBusinessExchange() { - Map args = Maps.newHashMap(); - args.put("x-delayed-type", "direct"); - return new CustomExchange(RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_EXCHANGE, "x-delayed-message", true, false, args); - } - @Bean - public Binding openWaybillToBusinessBinding(Queue openWaybillToBusinessQueue, CustomExchange openWaybillToBusinessExchange) { - return BindingBuilder.bind(openWaybillToBusinessQueue).to(openWaybillToBusinessExchange).with(RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_ROUTING).noargs(); - } - - - - - - - - - - - - - - } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/OpenWaybillToBusinessListener.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/OpenWaybillToBusinessListener.java index 19a160c43..d59c025cc 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/OpenWaybillToBusinessListener.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/OpenWaybillToBusinessListener.java @@ -1,5 +1,7 @@ package com.logpm.trunkline.mq; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.logpm.distribution.entity.DistributionParcelListEntity; import com.logpm.trunkline.entity.TrunklineAdvanceEntity; @@ -22,15 +24,17 @@ import jodd.util.ArraysUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.common.constant.RabbitConstant; +import org.springblade.common.constant.broadcast.FanoutConstants; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.entity.Tenant; import org.springblade.system.feign.ISysClient; -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.amqp.core.ExchangeTypes; +import org.springframework.amqp.rabbit.annotation.*; import org.springframework.messaging.Message; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @@ -51,9 +55,8 @@ import java.util.stream.Collectors; @Slf4j @AllArgsConstructor @Component -@RabbitListener(queues = RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_QUEUE) -public class -OpenWaybillToBusinessListener { +//@RabbitListener(queues = RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_QUEUE) +public class OpenWaybillToBusinessListener { private final IWarehouseWaybillClient warehouseWaybillClient; @@ -73,18 +76,58 @@ OpenWaybillToBusinessListener { private ITrunklineWaybillTrackService trunklineWaybillTrackService; - @RabbitHandler - public void openWaybillToBusinessDataHandler(Map map, Message message, Channel channel) { + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.trunkline.OPENWAYBILL.QUEUE.SEND_BUSINESS_DATA_BY_OPENWAYBILL_DATA), + exchange = @Exchange(name = FanoutConstants.trunkline.OPENWAYBILL.EXCHANGE, type = ExchangeTypes.FANOUT) + )) + @Transactional(rollbackFor = Exception.class) + public void openWaybillToBusinessDataHandler(String message) { - Long waybillId = (Long) map.get("messageData"); + JSONObject jsonObject = JSONUtil.parseObj(message); + Long waybillId = jsonObject.getLong("waybillId"); + if (ObjectUtil.isEmpty(waybillId)) { + log.warn("运单ID为null"); + return; + } + WarehouseWaybillEntity byWaybillId = warehouseWaybillClient.findByWaybillId(waybillId); + + R> tenantList = sysClient.getTenantList(); + Tenant tenant = null; + if (tenantList.isSuccess()) { + List data = tenantList.getData(); + for (Tenant datum : data) { + if (datum.getTenantType() == 2 && datum.getTenantName().equals(byWaybillId.getConsignee().trim())) { + tenant = datum; + break; + } + } + } + + + if (tenant != null) { + extractedTenant(tenant, byWaybillId); + } + } + + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.trunkline.OPENWAYBILL.QUEUE.SEND_BUSINESS_DATA_BY_UPDATEWAYBILL_DATA), + exchange = @Exchange(name = FanoutConstants.trunkline.OPENWAYBILL.EXCHANGE, type = ExchangeTypes.FANOUT) + )) + @Transactional(rollbackFor = Exception.class) + public void updateWaybillToBusinessDataHandler(String message) { + + + JSONObject jsonObject = JSONUtil.parseObj(message); + Long waybillId = jsonObject.getLong("waybillId"); if (ObjectUtil.isEmpty(waybillId)) { log.warn("运单ID为null"); return; } WarehouseWaybillEntity byWaybillId = warehouseWaybillClient.findByWaybillId(waybillId); - String oldConsignee = (String) map.get("oldConsignee"); + String oldConsignee = (String) jsonObject.get("oldConsignee"); R> tenantList = sysClient.getTenantList(); Tenant tenant = null; @@ -96,7 +139,7 @@ OpenWaybillToBusinessListener { tenant = datum; } - if (datum.getTenantType() == 2 && datum.getTenantName().equals(oldConsignee.trim())) { + if (oldConsignee!=null && datum.getTenantType() == 2 && datum.getTenantName().equals(oldConsignee.trim())) { oldTenant = datum; } @@ -124,6 +167,8 @@ OpenWaybillToBusinessListener { } + + private void extractedTenant(Tenant tenant, WarehouseWaybillEntity byWaybillId) { List waybillIds = new ArrayList<>(); diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderAsyncService.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderAsyncService.java index a2447b480..d75fcf07d 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderAsyncService.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IOpenOrderAsyncService.java @@ -25,7 +25,7 @@ public interface IOpenOrderAsyncService { void sendOpenWaybillFanout(WarehouseWaybillEntity waybillEntity, List details, List advanceIds); - void sendUpdateWaybillFanout(WarehouseWaybillEntity waybillEntity, List details, List advanceIds); + void sendUpdateWaybillFanout(WarehouseWaybillEntity waybillEntity, List details, List advanceIds,String oldConsignee); void dealwithBillladingInfo(List advanceIds,Long warehouseId,String warehouseName,Long waybillId,String waybillNo); } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderAsyncServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderAsyncServiceImpl.java index 0cdf4c539..1d1d67f84 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderAsyncServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderAsyncServiceImpl.java @@ -609,7 +609,7 @@ public class OpenOrderAsyncServiceImpl implements IOpenOrderAsyncService { @LogpmAsync("asyncExecutor") @Override - public void sendUpdateWaybillFanout(WarehouseWaybillEntity waybillEntity, List details,List advanceIds) { + public void sendUpdateWaybillFanout(WarehouseWaybillEntity waybillEntity, List details,List advanceIds,String oldConsignee) { Integer waybillType = waybillEntity.getWaybillType(); String waybillNo = waybillEntity.getWaybillNo(); @@ -620,6 +620,7 @@ public class OpenOrderAsyncServiceImpl implements IOpenOrderAsyncService { jsonObject.put("waybillId",waybillEntity.getId()); jsonObject.put("waybillNo",waybillNo); jsonObject.put("waybillType",waybillType); + jsonObject.put("oldConsignee",oldConsignee); Long consigneeId = waybillEntity.getConsigneeId(); BasicdataClientEntity basicdataClientEntity = basicdataClientClient.findEntityById(consigneeId); if(Objects.isNull(basicdataClientEntity)){ diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java index 692066c2c..ee0c44439 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java @@ -616,22 +616,6 @@ public class OpenOrderServiceImpl implements IOpenOrderService { openOrderAsyncService.sendOpenWaybillFanout(waybillEntity, details, advanceIds); - Map mapState = new HashMap(); - mapState.put("messageId", CommonUtil.getUUID()); - mapState.put("messageData", waybillId); - mapState.put("createTime", System.currentTimeMillis()); - try { - rabbitTemplate.convertAndSend(RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_EXCHANGE, RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_ROUTING, mapState, message -> { - message.getMessageProperties() - .setHeader("x-delay", 5000); - return message; - }); - } catch (Exception customerException) { - log.error(">>>>>>>>>>>>>>>>>>>>>>>>>> 消息推送失败~ 请联系管理员! ", customerException); - - } - - Map map = new HashMap<>(); map.put("waybillId", waybillId); return R.data(map); @@ -2144,13 +2128,11 @@ public class OpenOrderServiceImpl implements IOpenOrderService { //异步存入日志 openOrderAsyncService.saveUpdateLog(waybillId, waybillNo, "888", editReson, "备注:"+refer+" 修改内容:"+updateMsg, AuthUtil.getNickName(), AuthUtil.getUserId(), warehouseId, warehouseName,waybillEntity); - List wayBillDetailList = warehouseWaybillDetailClient.findListByWaybillNo(waybillNo); List waybillIds = new ArrayList<>(); waybillIds.add(waybillId); List advanceIds = trunklineWaybillOrderService.findAdvanceIdsByWaybillIds(waybillIds); - openOrderAsyncService.sendUpdateWaybillFanout(waybillEntity,wayBillDetailList,advanceIds); List parcelListEntityList = distributionParcelListClient.findAllParcelListByAdvanceIds(advanceIds); @@ -2206,23 +2188,7 @@ public class OpenOrderServiceImpl implements IOpenOrderService { } } - - - Map mapState = new HashMap(); - mapState.put("messageId", CommonUtil.getUUID()); - mapState.put("messageData", waybillId); - mapState.put("oldConsignee", oldConsignee); - mapState.put("createTime", System.currentTimeMillis()); - try { - rabbitTemplate.convertAndSend(RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_EXCHANGE, RabbitConstant.OPEN_WAYBILL_TO_BUSINESS_DATA_ROUTING, mapState, message -> { - message.getMessageProperties() - .setHeader("x-delay", 5000); - return message; - }); - } catch (Exception customerException) { - log.error(">>>>>>>>>>>>>>>>>>>>>>>>>> 消息推送失败~ 请联系管理员! ", customerException); - - } + openOrderAsyncService.sendUpdateWaybillFanout(waybillEntity,wayBillDetailList,advanceIds,oldConsignee); return R.success("改单成功"); }