From 0d278b4310244ac5758c1844743b50d43228c191 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Tue, 17 Dec 2024 10:05:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E9=85=8D=E9=80=81=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 整体优化配送明细报表广播消息 --- .../entity/QualityDeliverEntity.java | 5 + .../dto/ReportQualityDeliverDTO.java | 2 + .../DistributionDeliveryListMapper.java | 32 +- .../mapper/QualityDeliverMapper.java | 10 + .../mapper/QualityDeliverMapper.xml | 41 ++ .../report/BillPlanReportListener.java | 45 +- .../report/BillReViewReportListener.java | 16 +- .../report/BillSignforReportListener.java | 8 +- .../report/CarStartReportListener.java | 85 ++-- .../report/ConsigneeArriveReportListener.java | 101 ++--- .../report/DeliverFinishReportListener.java | 33 +- .../report/LoadingReportListener.java | 104 +++-- .../receiver/report/PlanReportListener.java | 166 ++++--- .../report/QualityDeliverListener.java | 133 +++--- .../receiver/report/ReViewReportListener.java | 87 ++-- .../receiver/report/ReportListener.java | 419 ++++++++++++++++++ .../receiver/report/ReportService.java | 11 + .../report/ReservationPlanReportListener.java | 201 ++++++--- .../report/ReturnWarehouseReportListener.java | 24 +- .../report/SignforReportListener.java | 87 ++-- .../receiver/report/StockReportListener.java | 105 +++-- .../service/IQualityDeliverService.java | 8 + .../DistributionReservationServiceImpl.java | 2 + .../impl/QualityDeliverServiceImpl.java | 20 + 24 files changed, 1188 insertions(+), 557 deletions(-) create mode 100644 blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportListener.java create mode 100644 blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportService.java diff --git a/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/QualityDeliverEntity.java b/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/QualityDeliverEntity.java index 399f8f970..c57ecb68d 100644 --- a/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/QualityDeliverEntity.java +++ b/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/QualityDeliverEntity.java @@ -579,6 +579,11 @@ public class QualityDeliverEntity extends TenantEntity { */ @ApiModelProperty(value = "复核人") private String reviewUserName; + /** + * 复核数量 + */ + @ApiModelProperty(value = "复核数量") + private Integer reviewNum; /** * 复核时间 复核时间=回库时间 */ diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/ReportQualityDeliverDTO.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/ReportQualityDeliverDTO.java index 07ac1afe5..0932208a7 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/ReportQualityDeliverDTO.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/ReportQualityDeliverDTO.java @@ -21,4 +21,6 @@ public class ReportQualityDeliverDTO implements Serializable { private BizOperationEnums operation; + private String node; + } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionDeliveryListMapper.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionDeliveryListMapper.java index 663aff2ef..2049f710d 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionDeliveryListMapper.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionDeliveryListMapper.java @@ -19,17 +19,36 @@ package com.logpm.distribution.mapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.logpm.basicdata.entity.BasicdataWarehouseEntity; import com.logpm.distribution.dto.DistributionDeliveryListDTO; import com.logpm.distribution.dto.DistributionLoadingNumDTO; import com.logpm.distribution.dto.app.DistributionAppDeliveryListDTO; -import com.logpm.distribution.entity.*; +import com.logpm.distribution.entity.DisStockListDetailEntity; +import com.logpm.distribution.entity.DistributionDeliveryListEntity; +import com.logpm.distribution.entity.DistributionLoadscanAbnormalEntity; +import com.logpm.distribution.entity.DistributionLoadscanEntity; +import com.logpm.distribution.entity.DistributionLoadscaninvnEntity; +import com.logpm.distribution.entity.DistributionParcelListEntity; +import com.logpm.distribution.entity.DistributionReservationEntity; +import com.logpm.distribution.entity.DistributionReservationStockarticleEntity; +import com.logpm.distribution.entity.DistributionSignforEntity; +import com.logpm.distribution.entity.DistributionStockArticleEntity; import com.logpm.distribution.excel.DistributionDeliveryListExcel; -import com.logpm.distribution.vo.*; -import com.logpm.distribution.vo.app.*; +import com.logpm.distribution.vo.DisStockListDetailVO; +import com.logpm.distribution.vo.DistributionDeliveryListPrintReponseVO; +import com.logpm.distribution.vo.DistributionDeliveryListPrintRequestVO; +import com.logpm.distribution.vo.DistributionDeliveryListVO; +import com.logpm.distribution.vo.DistributionDeliveryWordVO; +import com.logpm.distribution.vo.DistributionParcelNumberVO; +import com.logpm.distribution.vo.DistributionReservationStocklistVO; +import com.logpm.distribution.vo.DistributionRetentionScanVo; +import com.logpm.distribution.vo.DistributionStockArticleVO; +import com.logpm.distribution.vo.app.DistributionAppDeliveryListVO; +import com.logpm.distribution.vo.app.DistributionAppDetailVO; +import com.logpm.distribution.vo.app.DistributionAppNewDeliveryListVO; +import com.logpm.distribution.vo.app.DistributionAppParcelListVO; +import com.logpm.distribution.vo.app.DistributionAppStockArticleVO; import com.logpm.oldproject.dto.SignPushDataDTO; import org.apache.ibatis.annotations.Param; -import org.springblade.common.model.PackageData; import java.util.List; import java.util.Map; @@ -530,11 +549,12 @@ public interface DistributionDeliveryListMapper extends BaseMapper selectDeliveryZeroOrderInfoDetail(Long id, Long id1); + List selectDeliveryZeroOrderInfoDetail(@Param("stockArticleId") Long id, @Param("deliveryId") Long id1); /** * 配送计划内的定制品计划查询 diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.java index 3e836dfe6..e92c8f1b9 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.java @@ -18,6 +18,7 @@ package com.logpm.distribution.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.logpm.distribution.entity.QualityDeliverEntity; +import org.apache.ibatis.annotations.Param; /** * 配送明细 Mapper 接口 @@ -27,4 +28,13 @@ import com.logpm.distribution.entity.QualityDeliverEntity; */ public interface QualityDeliverMapper extends BaseMapper { + void deleteByPlanReservationCode(@Param("reservationCode") String reservationCode); + + void deleteEntityById(@Param("id") Long id); + + void delStockingOperation(@Param("id") Long id); + + void delPlanDelivery(@Param("id") Long id); + + void delDistributionCarStart(@Param("id") Long id); } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.xml b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.xml index c23aaa783..97031ad79 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.xml +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/QualityDeliverMapper.xml @@ -6,5 +6,46 @@ + + delete from logpm_quality_deliver where plan_reservation_code = #{reservationCode} + + + delete from logpm_quality_deliver where id = #{id} + + + + update logpm_quality_deliver + set stockup_code = null, + stockup_user_name = null, + stockup_finish_time = null, + stockup_create_time = null, + stock_num = null, + stock_allocation = null, + stockup_type = null + where id = #{id} + + + update logpm_quality_deliver + set plan_train_number = null, + delivery_time = null, + delivery_type = null, + delivery_kind = null, + vehicle_name = null, + driver_name = null, + delivery_fee = null, + distribution_company = null, + delivery_plan_time = null, + plan_type = null, + delivery_create_user_name = null, + yn_whole_vehicle = null + where id = #{id} + + + + update logpm_quality_deliver + set start_car_user_name = null, + start_car_time = null + where id = #{id} + diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillPlanReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillPlanReportListener.java index 57c334d7c..a9667d752 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillPlanReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillPlanReportListener.java @@ -2,20 +2,14 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; -import com.logpm.distribution.pros.DistributionProperties; -import com.logpm.distribution.service.IQualityDeliverService; import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; @@ -23,11 +17,6 @@ import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; import org.springblade.common.model.workNode.DeliveryOfPickupPlanVO; import org.springblade.core.tool.utils.BeanUtil; -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; @@ -43,28 +32,13 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class BillPlanReportListener { +public class BillPlanReportListener implements ReportService { - @Resource - private IQualityDeliverService qualityDeliverService; @Resource private IFactoryDataClient factoryDataClient; - @Resource - private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillPlan.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillPlan.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getBillPlanReport()) { - return; - } - log.info("自提任务生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -72,21 +46,6 @@ public class BillPlanReportListener { Long warehouseId = bean.getWarehouseId(); BizOperationEnums bizOperation = bean.getBizOperation(); List details = vo.getPackageDataList(); - if (BizOperationEnums.MODIFY.equals(bizOperation) || BizOperationEnums.DELETE.equals(bizOperation)) { - // 根据预约单号查询出所有这个预约单下的数据 先置空 - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getPlanTrainNumber, null) - .set(QualityDeliverEntity::getDeliveryTime, null) - .set(QualityDeliverEntity::getDeliveryType, null) - .set(QualityDeliverEntity::getVehicleName, null) - .set(QualityDeliverEntity::getBizCode, null) - .set(QualityDeliverEntity::getDriverName, null) - .set(QualityDeliverEntity::getDeliveryPlanTime, null) - .set(QualityDeliverEntity::getDeliveryCreateUserName, null) - .eq(QualityDeliverEntity::getBizCode, vo.getPickupBatch()) - .ne(QualityDeliverEntity::getBizStatus, 110); - qualityDeliverService.update(wrapper); - } if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillReViewReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillReViewReportListener.java index 6c7b400ae..b93ff6597 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillReViewReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillReViewReportListener.java @@ -2,7 +2,6 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.logpm.distribution.dto.ReportQualityDeliverDTO; @@ -40,7 +39,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class BillReViewReportListener { +public class BillReViewReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -49,19 +48,8 @@ public class BillReViewReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillSignReview.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillSignReview.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getBillReviewReport()) { - return; - } - log.info("自提复核生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillSignforReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillSignforReportListener.java index 28fc72b64..fbd8c22d6 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillSignforReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/BillSignforReportListener.java @@ -40,7 +40,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class BillSignforReportListener { +public class BillSignforReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -49,11 +49,7 @@ public class BillSignforReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillSign.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillSign.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { if (!destinationProperties.getReport().getBillSignforReport()) { return; diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/CarStartReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/CarStartReportListener.java index 75723cd5a..6da3207fa 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/CarStartReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/CarStartReportListener.java @@ -1,29 +1,27 @@ package com.logpm.distribution.receiver.report; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; import com.logpm.distribution.pros.DistributionProperties; import com.logpm.distribution.service.IQualityDeliverService; import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; +import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.model.CarStartVO; import org.springblade.common.model.NodeFanoutMsg; -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; import javax.annotation.Resource; +import java.util.List; /** * 发车生成明细报表 @@ -34,7 +32,7 @@ import javax.annotation.Resource; @Slf4j @Component @AllArgsConstructor -public class CarStartReportListener { +public class CarStartReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -43,42 +41,53 @@ public class CarStartReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndCarStart.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndCarStart.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getCarStartReport()) { - return; - } - log.info("发车生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); CarStartVO vo = JSONUtil.toBean(entries, CarStartVO.class); BizOperationEnums bizOperation = bean.getBizOperation(); - if (BizOperationEnums.DELETE.equals(bizOperation)) { - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getStartCarUserName, null) - .set(QualityDeliverEntity::getStartCarTime, null) - .eq(QualityDeliverEntity::getLoadTrainNumber, vo.getTrainNumber()) - .eq(QualityDeliverEntity::getLoadLicensePlate, vo.getVehicleName()) - .ne(QualityDeliverEntity::getBizStatus, 110); - qualityDeliverService.update(wrapper); - } - if (BizOperationEnums.ADD.equals(bizOperation)) { - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getStartCarUserName, vo.getDriverName()) - .set(QualityDeliverEntity::getStartCarTime, bean.getOperatorTime()) - .eq(QualityDeliverEntity::getLoadTrainNumber, vo.getTrainNumber()) - .eq(QualityDeliverEntity::getLoadLicensePlate, vo.getVehicleName()) - .ne(QualityDeliverEntity::getBizStatus, 110); - qualityDeliverService.update(wrapper); + // 装车车次号 + 车牌 + String trainNumber = vo.getTrainNumber(); + String vehicleName = vo.getVehicleName(); + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery() + .select(QualityDeliverEntity::getId) + .eq(QualityDeliverEntity::getLoadTrainNumber, trainNumber) + .eq(QualityDeliverEntity::getLoadLicensePlate, vehicleName) + ); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() + .startCarUserName(bean.getOperator()) + .startCarTime(bean.getOperatorTime()) + .build(); + if (BizOperationEnums.DELETE.equals(bizOperation)) { + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } + } + if (BizOperationEnums.ADD.equals(bizOperation)) { + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } + } } } + private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.DISTRIBUTION_CAR_START.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); + } + } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ConsigneeArriveReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ConsigneeArriveReportListener.java index ffb4e2c9f..914daf99c 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ConsigneeArriveReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ConsigneeArriveReportListener.java @@ -1,29 +1,27 @@ package com.logpm.distribution.receiver.report; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; -import com.logpm.distribution.pros.DistributionProperties; import com.logpm.distribution.service.IQualityDeliverService; import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; +import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.model.ConsigneeArriveVO; import org.springblade.common.model.NodeFanoutMsg; -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; import javax.annotation.Resource; +import java.util.List; /** * 配送到达生成明细报表 @@ -34,65 +32,58 @@ import javax.annotation.Resource; @Slf4j @Component @AllArgsConstructor -public class ConsigneeArriveReportListener { +public class ConsigneeArriveReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @Resource private IFactoryDataClient factoryDataClient; - @Resource - private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndConsigneeArrive.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndConsigneeArrive.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getConsigneeArriveReport()) { - return; - } - log.info("配送到达生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); ConsigneeArriveVO vo = JSONUtil.toBean(entries, ConsigneeArriveVO.class); BizOperationEnums bizOperation = bean.getBizOperation(); - if (BizOperationEnums.DELETE.equals(bizOperation)) { - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getArriveCarUserName, null) - .set(QualityDeliverEntity::getArriveCarTime, null) - .set(QualityDeliverEntity::getArriveProvince, null) - .set(QualityDeliverEntity::getArriveCity, null) - .set(QualityDeliverEntity::getArriveDistrict, null) - .set(QualityDeliverEntity::getArriveTownship, null) - .set(QualityDeliverEntity::getArriveAddress, null) - .set(QualityDeliverEntity::getArrivePositioning, null) - .eq(QualityDeliverEntity::getLoadLicensePlate, vo.getVehicleName()) - .eq(QualityDeliverEntity::getLoadTrainNumber, vo.getTrainNumber()) - .eq(QualityDeliverEntity::getBizCode, vo.getReservationCode()) - .ne(QualityDeliverEntity::getBizStatus, 110); - qualityDeliverService.update(wrapper); - } - if (BizOperationEnums.ADD.equals(bizOperation)) { - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getArriveCarUserName, vo.getDriverName()) - .set(QualityDeliverEntity::getArriveCarTime, bean.getOperatorTime()) - .set(QualityDeliverEntity::getArriveProvince, vo.getProvince()) - .set(QualityDeliverEntity::getArriveCity, vo.getCity()) - .set(QualityDeliverEntity::getArriveDistrict, vo.getDistrict()) - .set(QualityDeliverEntity::getArriveTownship, vo.getTownship()) - .set(QualityDeliverEntity::getArriveAddress, vo.getAddress()) - .set(QualityDeliverEntity::getArrivePositioning, vo.getPositioning()) - .eq(QualityDeliverEntity::getLoadTrainNumber, vo.getTrainNumber()) - .eq(QualityDeliverEntity::getLoadLicensePlate, vo.getVehicleName()) - .eq(QualityDeliverEntity::getBizCode, vo.getReservationCode()) - .ne(QualityDeliverEntity::getBizStatus, 110); - qualityDeliverService.update(wrapper); + // 装车车次号 + 车牌 + String reservationCode = vo.getReservationCode(); + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery() + .select(QualityDeliverEntity::getId) + .eq(QualityDeliverEntity::getPlanReservationCode, reservationCode) + ); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() + .arriveCarUserName(vo.getDriverName()) + .arriveCarTime(DateUtil.formatDateTime(bean.getOperatorTime())) + .arriveProvince(vo.getProvince()) + .arriveCity(vo.getCity()) + .arriveDistrict(vo.getDistrict()) + .arriveTownship(vo.getTownship()) + .arriveAddress(vo.getAddress()) + .arrivePositioning(vo.getPositioning()) + .build(); + if (BizOperationEnums.ADD.equals(bizOperation)) { + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } + } } } + private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.DISTRIBUTION_CAR_ARRIVED.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); + } + } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/DeliverFinishReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/DeliverFinishReportListener.java index 406513416..e1abd2eec 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/DeliverFinishReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/DeliverFinishReportListener.java @@ -25,18 +25,12 @@ import com.logpm.statistics.vo.ExpenseDispatchPriceCategoryVO; import com.logpm.statistics.vo.ExpenseDispatchPriceVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.BooleanZeroOneEnums; import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.workNode.FinishDistributionTrainVO; import org.springblade.common.utils.GaoDeApiUtil; -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; @@ -60,7 +54,7 @@ import java.util.stream.Collectors; @Slf4j @Component @AllArgsConstructor -public class DeliverFinishReportListener { +public class DeliverFinishReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -75,29 +69,8 @@ public class DeliverFinishReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillAndFinish.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillAndFinish.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) - public void buildPickUpReport(String msg) { - this.buildReport(msg); - - } - - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndFinish.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndFinish.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getDeliverFinishReport()) { - return; - } - log.info("车次完成生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -106,7 +79,6 @@ public class DeliverFinishReportListener { // 根据车次查询出包件明细,然后计算对应的成本 List entities = qualityDeliverService.list(Wrappers.lambdaQuery() .eq(QualityDeliverEntity::getSignTrainNumber, trainNumber) - .eq(QualityDeliverEntity::getBizStatus, 100) ); if (CollUtil.isNotEmpty(entities)) { // 按签收车分组 @@ -888,7 +860,6 @@ public class DeliverFinishReportListener { } } } - } if (CollUtil.isNotEmpty(valueMap)) { // 修改配送明细信息 diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/LoadingReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/LoadingReportListener.java index 4c1cba4e8..d620e9b32 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/LoadingReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/LoadingReportListener.java @@ -1,10 +1,12 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; import com.logpm.distribution.pros.DistributionProperties; @@ -13,23 +15,20 @@ import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; import org.springblade.common.model.DistributionLoadVO; import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; -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; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 装车生成明细报表 @@ -40,7 +39,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class LoadingReportListener { +public class LoadingReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -49,19 +48,7 @@ public class LoadingReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndLoading.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndLoading.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getLoadingReport()) { - return; - } - log.info("装车生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -69,6 +56,26 @@ public class LoadingReportListener { Long warehouseId = bean.getWarehouseId(); BizOperationEnums bizOperation = bean.getBizOperation(); List details = vo.getPackageDataList(); + // 单号 referenceCode + String referenceCode = vo.getTrainNumber(); + Map> cmpMap = new HashMap<>(); + Map> ltlMap = new HashMap<>(); + Map> invMap = new HashMap<>(); + if (StrUtil.isNotEmpty(referenceCode)) { + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery() + .eq(QualityDeliverEntity::getPlanTrainNumber, referenceCode)); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + cmpMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + ltlMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) + .collect(Collectors.groupingBy(item -> item.getCategory() + item.getOrderCode())); + invMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + } + } if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() @@ -83,36 +90,49 @@ public class LoadingReportListener { .bizCode(vo.getReservationCode()) .build(); if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { - qualityDeliverEntity.setConditions(1); + // qualityDeliverEntity.setConditions(1); qualityDeliverEntity.setLoadNum(1); - sendReport(bizOperation, qualityDeliverEntity); + // 装车包件是计划内的 更新 + if (cmpMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(cmpMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { - qualityDeliverEntity.setOrderCode(detail.getOrderCode()); - qualityDeliverEntity.setCategory(detail.getProductName()); - qualityDeliverEntity.setConditions(2); - sendReport(bizOperation, qualityDeliverEntity); + // qualityDeliverEntity.setOrderCode(detail.getOrderCode()); + // qualityDeliverEntity.setCategory(detail.getProductName()); + // qualityDeliverEntity.setConditions(2); + if (ltlMap.containsKey(detail.getProductName() + detail.getOrderCode())) { + qualityDeliverEntity.setId(ltlMap.get(detail.getProductName() + detail.getOrderCode()).get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { - qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); - qualityDeliverEntity.setMallName(detail.getMallName()); - qualityDeliverEntity.setMaterielCode(detail.getMaterialCode()); - qualityDeliverEntity.setMaterielName(detail.getMaterialName()); - qualityDeliverEntity.setConditions(3); - sendReport(bizOperation, qualityDeliverEntity); + // qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); + // qualityDeliverEntity.setMallName(detail.getMallName()); + // qualityDeliverEntity.setMaterielCode(detail.getMaterialCode()); + // qualityDeliverEntity.setMaterielName(detail.getMaterialName()); + // qualityDeliverEntity.setConditions(3); + qualityDeliverEntity.setLoadNum(1); + if (invMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(invMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } } } } - private void sendReport(BizOperationEnums bizOperation, QualityDeliverEntity qualityDeliverEntity) { - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(BizOperationEnums.MODIFY).build(); - factoryDataClient.sendMessage(SendMsg.builder() - .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) - .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) - .message(JSONUtil.toJsonStr(dto)) - .delay(3000) - .build()); - } + private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.DISTRIBUTION_LOADING.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); } } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/PlanReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/PlanReportListener.java index 3b8961b95..082c22d58 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/PlanReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/PlanReportListener.java @@ -2,11 +2,10 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; @@ -16,7 +15,7 @@ import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; @@ -25,11 +24,6 @@ import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; import org.springblade.common.model.PlanDriverbindCarVO; import org.springblade.common.model.ReservationVO; -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; @@ -37,6 +31,7 @@ import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -48,7 +43,7 @@ import java.util.stream.Collectors; @Slf4j @Component @AllArgsConstructor -public class PlanReportListener { +public class PlanReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -57,19 +52,8 @@ public class PlanReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndPlan.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndPlan.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getLoadingReport()) { - return; - } - log.info("配送计划生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -86,28 +70,26 @@ public class PlanReportListener { vehicleName = planDriverbindCars.stream().map(PlanDriverbindCarVO::getCarPlate).collect(Collectors.joining(",")); driverName = planDriverbindCars.stream().map(PlanDriverbindCarVO::getDriverName).collect(Collectors.joining(",")); } - Map invMap = new HashMap<>(); - if (BizOperationEnums.MODIFY.equals(bizOperation) || BizOperationEnums.DELETE.equals(bizOperation)) { - // 根据预约单号查询出所有这个预约单下的数据 先置空 - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getDeliveryTime, null) - .set(QualityDeliverEntity::getDeliveryType, null) - .set(QualityDeliverEntity::getDeliveryKind, null) - .set(QualityDeliverEntity::getVehicleName, null) - .set(QualityDeliverEntity::getDriverName, null) - .set(QualityDeliverEntity::getDistributionCompany, null) - .set(QualityDeliverEntity::getDeliveryPlanTime, null) - .set(QualityDeliverEntity::getDeliveryCreateUserName, null) - .set(QualityDeliverEntity::getYnWholeVehicle, null) - .set(QualityDeliverEntity::getDeliveryFee, null) - .eq(QualityDeliverEntity::getPlanTrainNumber, vo.getTrainNumber()) - .ne(QualityDeliverEntity::getBizStatus, 110); - if (BizOperationEnums.DELETE.equals(bizOperation)) { - wrapper.set(QualityDeliverEntity::getPlanTrainNumber, null); + Set reservationCodeSet = reservationVOList.stream().map(ReservationVO::getReservationCode).collect(Collectors.toSet()); + Map> cmpMap = new HashMap<>(); + Map> ltlMap = new HashMap<>(); + Map> invMap = new HashMap<>(); + if(CollUtil.isNotEmpty(reservationCodeSet)){ + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery().in(QualityDeliverEntity::getPlanReservationCode, reservationCodeSet)); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + cmpMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) + .collect(Collectors.groupingBy(item -> item.getPlanReservationCode() + item.getOrderPackageCode())); + ltlMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) + .collect(Collectors.groupingBy(item -> item.getPlanReservationCode() + item.getCategory() + item.getOrderCode())); + invMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) + .collect(Collectors.groupingBy(item -> item.getPlanReservationCode() + item.getMallName() + item.getMaterielCode())); } - qualityDeliverService.update(wrapper); } for (ReservationVO reservationVO : reservationVOList) { + String reservationCode = reservationVO.getReservationCode(); List details = reservationVO.getPackageDataList(); if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { @@ -130,59 +112,97 @@ public class PlanReportListener { .build(); if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { qualityDeliverEntity.setConditions(1); - qualityDeliverEntity.setPlanNum(1); - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(BizOperationEnums.MODIFY).build(); - factoryDataClient.sendMessage(SendMsg.builder() - .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) - .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) - .message(JSONUtil.toJsonStr(dto)) - .delay(3000) - .build()); + if (cmpMap.containsKey(reservationCode + detail.getPackageCode())) { + qualityDeliverEntity.setId(cmpMap.get(reservationCode + detail.getPackageCode()).get(0).getId()); + if (BizOperationEnums.DELETE.equals(bizOperation)) { + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } else { + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { qualityDeliverEntity.setOrderCode(detail.getOrderCode()); qualityDeliverEntity.setCategory(detail.getProductName()); qualityDeliverEntity.setConditions(2); - qualityDeliverEntity.setPlanNum(detail.getNumber()); - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(BizOperationEnums.MODIFY).build(); - factoryDataClient.sendMessage(SendMsg.builder() - .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) - .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) - .message(JSONUtil.toJsonStr(dto)) - .delay(3000) - .build()); + if (ltlMap.containsKey(reservationCode + detail.getProductName() + detail.getOrderCode())) { + qualityDeliverEntity.setId(ltlMap.get(reservationCode + detail.getProductName() + detail.getOrderCode()).get(0).getId()); + if (BizOperationEnums.DELETE.equals(bizOperation)) { + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } else { + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { - invMap.put(detail.getMallName() + detail.getMaterialCode(), qualityDeliverEntity); qualityDeliverEntity.setBizCode(reservationVO.getReservationCode()); qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); qualityDeliverEntity.setMallName(detail.getMallName()); qualityDeliverEntity.setMaterielCode(detail.getMaterialCode()); qualityDeliverEntity.setMaterielName(detail.getMaterialName()); qualityDeliverEntity.setConditions(3); - qualityDeliverEntity.setPlanNum(1); - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - invMap.put(detail.getMallName() + detail.getMaterialCode(), qualityDeliverEntity); + if (invMap.containsKey(reservationCode + detail.getMallName() + detail.getMaterialCode())) { + List qualityDeliverEntities = invMap.get(reservationCode + detail.getMallName() + detail.getMaterialCode()); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + if (BizOperationEnums.DELETE.equals(bizOperation)) { + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } + } else { + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } + } + } } } } } - } - if (CollUtil.isNotEmpty(invMap)) { - for (Map.Entry entry : invMap.entrySet()) { - QualityDeliverEntity qualityDeliverEntity = entry.getValue(); - qualityDeliverService.update(qualityDeliverEntity, Wrappers.lambdaUpdate() - .eq(QualityDeliverEntity::getPlanTrainNumber, qualityDeliverEntity.getPlanTrainNumber()) - .eq(QualityDeliverEntity::getMallName, qualityDeliverEntity.getMallName()) - .eq(QualityDeliverEntity::getMaterielCode, qualityDeliverEntity.getMaterielCode()) - .eq(QualityDeliverEntity::getConditions, 3) - .lt(QualityDeliverEntity::getBizStatus, 110) - ); + // 系统中有的包件在当前不存在,则删除 + Set cmpSet = details.stream() + .filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.CMP)) + .map(i-> reservationCode + i.getPackageCode()).collect(Collectors.toSet()); + for (Map.Entry> entry : cmpMap.entrySet()) { + String key = entry.getKey(); + if (!cmpSet.contains(key)) { + sendReport(entry.getValue().get(0), BizOperationEnums.DELETE); + } + } + Set ltlSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.LTL)) + .map(i -> reservationCode + i.getProductName() + i.getOrderCode()).collect(Collectors.toSet()); + for (Map.Entry> entry : ltlMap.entrySet()) { + String key = entry.getKey(); + if (!ltlSet.contains(key)) { + sendReport(entry.getValue().get(0), BizOperationEnums.DELETE); + } + } + Set invSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.INV)) + .map(i -> reservationCode + i.getMallName() + i.getMaterialCode()).collect(Collectors.toSet()); + for (Map.Entry> entry : invMap.entrySet()) { + String key = entry.getKey(); + if (!invSet.contains(key)) { + List value = entry.getValue(); + for (QualityDeliverEntity entity : value) { + sendReport(entity, BizOperationEnums.DELETE); + } + } } } } } + private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.PLAN_DELIVERY.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); + } + } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/QualityDeliverListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/QualityDeliverListener.java index 62acef4e6..1f1a1702a 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/QualityDeliverListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/QualityDeliverListener.java @@ -15,10 +15,12 @@ import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.DistributionParcelListEntity; import com.logpm.distribution.entity.DistributionStockArticleEntity; import com.logpm.distribution.entity.DistributionStockListEntity; +import com.logpm.distribution.entity.DistributionStockListInfoEntity; import com.logpm.distribution.entity.QualityDeliverEntity; import com.logpm.distribution.pros.DistributionProperties; import com.logpm.distribution.service.IDistributionParcelListService; import com.logpm.distribution.service.IDistributionStockArticleService; +import com.logpm.distribution.service.IDistributionStockListInfoService; import com.logpm.distribution.service.IDistributionStockListService; import com.logpm.distribution.service.IQualityDeliverService; import com.logpm.trunkline.feign.ITrunklineAdvanceDetailClient; @@ -29,16 +31,12 @@ import com.logpm.warehouse.feign.IWarehouseWaybillDetailClient; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable; -import org.springblade.common.constant.report.ReportConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; import org.springblade.core.redis.cache.BladeRedis; -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; import javax.annotation.Resource; import java.util.Arrays; @@ -53,7 +51,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class QualityDeliverListener { +public class QualityDeliverListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -73,6 +71,9 @@ public class QualityDeliverListener { @Resource private IDistributionStockListService stockListService; + @Resource + private IDistributionStockListInfoService stockListInfoService; + @Resource private IBasicdataFactoryCategoryClient factoryCategoryClient; @@ -87,62 +88,65 @@ public class QualityDeliverListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = ReportConstants.REPORT_QUALITY_DELIVER_QUEUE, durable = "true"), - exchange = @Exchange(name = ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE, type = ExchangeTypes.TOPIC), - key = ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY - )) - public void data(String msg) throws InterruptedException { - if (!destinationProperties.getReport().getQualityDeliver()) { - return; - } - log.info("配送明细基础表处理: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } + @Transactional + public void buildReport(String msg) { ReportQualityDeliverDTO bean = JSONUtil.toBean(msg, ReportQualityDeliverDTO.class); + String node = bean.getNode(); String data = bean.getData(); QualityDeliverEntity qualityDeliverEntity = JSONUtil.toBean(data, QualityDeliverEntity.class); Integer conditions = qualityDeliverEntity.getConditions(); if (ObjectUtil.equals(bean.getOperation(), BizOperationEnums.MODIFY)) { - if (ObjectUtil.equals(PackageTypeEnums.CMP.getCode(), conditions)) { - // 定制品 - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - if (ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())) { - wrapper.eq(QualityDeliverEntity::getId, qualityDeliverEntity.getId()); - } else { - wrapper.eq(QualityDeliverEntity::getOrderPackageCode, qualityDeliverEntity.getOrderPackageCode()); - } - wrapper.lt(QualityDeliverEntity::getBizStatus, 110); - saveOrUpdate(wrapper, qualityDeliverEntity); - } else if (ObjectUtil.equals(PackageTypeEnums.INV.getCode(), conditions)) { - // 库存品 - LambdaQueryWrapper wrapper = buildInvWrapper(qualityDeliverEntity); - if (wrapper == null) { - return; - } - // 查询不存在时更新,存在时修改 - saveOrUpdate(wrapper, qualityDeliverEntity); - } else if (ObjectUtil.equals(PackageTypeEnums.LTL.getCode(), conditions)) { - // 零担 - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - if (ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())) { - wrapper.eq(QualityDeliverEntity::getId, qualityDeliverEntity.getId()); - } else { - wrapper.eq(QualityDeliverEntity::getOrderCode, qualityDeliverEntity.getOrderCode()) - .eq(QualityDeliverEntity::getCategory, qualityDeliverEntity.getCategory()); - } - wrapper.lt(QualityDeliverEntity::getBizStatus, 110); - if (StrUtil.isNotEmpty(qualityDeliverEntity.getBizCode())) { - wrapper.eq(QualityDeliverEntity::getBizCode, qualityDeliverEntity.getBizCode()); - } - saveOrUpdate(wrapper, qualityDeliverEntity); - } + qualityDeliverService.updateById(qualityDeliverEntity); + // if (ObjectUtil.equals(PackageTypeEnums.CMP.getCode(), conditions)) { + // // 定制品 + // LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + // if (ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())) { + // wrapper.eq(QualityDeliverEntity::getId, qualityDeliverEntity.getId()); + // } else { + // wrapper.eq(QualityDeliverEntity::getOrderPackageCode, qualityDeliverEntity.getOrderPackageCode()); + // } + // wrapper.lt(QualityDeliverEntity::getBizStatus, 110); + // saveOrUpdate(wrapper, qualityDeliverEntity); + // } else if (ObjectUtil.equals(PackageTypeEnums.INV.getCode(), conditions)) { + // // 库存品 + // LambdaQueryWrapper wrapper = buildInvWrapper(qualityDeliverEntity); + // if (wrapper == null) { + // return; + // } + // // 查询不存在时更新,存在时修改 + // saveOrUpdate(wrapper, qualityDeliverEntity); + // } else if (ObjectUtil.equals(PackageTypeEnums.LTL.getCode(), conditions)) { + // // 零担 + // LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + // if (ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())) { + // wrapper.eq(QualityDeliverEntity::getId, qualityDeliverEntity.getId()); + // } else { + // wrapper.eq(QualityDeliverEntity::getOrderCode, qualityDeliverEntity.getOrderCode()) + // .eq(QualityDeliverEntity::getCategory, qualityDeliverEntity.getCategory()); + // } + // wrapper.lt(QualityDeliverEntity::getBizStatus, 110); + // if (StrUtil.isNotEmpty(qualityDeliverEntity.getBizCode())) { + // wrapper.eq(QualityDeliverEntity::getBizCode, qualityDeliverEntity.getBizCode()); + // } + // saveOrUpdate(wrapper, qualityDeliverEntity); + // } } if (ObjectUtil.equals(bean.getOperation(), BizOperationEnums.ADD)) { - if (ObjectUtil.equals(PackageTypeEnums.INV.getCode(), conditions)) { - // 查询不存在时更新,存在时修改 - saveOrUpdate(null, qualityDeliverEntity); + // 查询不存在时更新,存在时修改 + saveOrUpdate(null, qualityDeliverEntity); + } + if (ObjectUtil.equals(bean.getOperation(), BizOperationEnums.DELETE)) { + if (StrUtil.equals(node, WorkNodeEnums.PLANNED_RESERVATION.getValue())){ + qualityDeliverService.deleteEntityById(qualityDeliverEntity.getId()); + } + if (StrUtil.equals(node, WorkNodeEnums.STOCKING_OPERATION.getValue())){ + qualityDeliverService.delStockingOperation(qualityDeliverEntity.getId()); + } + if (StrUtil.equals(node, WorkNodeEnums.PLAN_DELIVERY.getValue())){ + qualityDeliverService.delPlanDelivery(qualityDeliverEntity.getId()); + } + if (StrUtil.equals(node, WorkNodeEnums.DISTRIBUTION_CAR_START.getValue())){ + qualityDeliverService.delDistributionCarStart(qualityDeliverEntity.getId()); } } } @@ -265,9 +269,16 @@ public class QualityDeliverListener { String brandName = stockList.getBrandName(); String sourceType = stockList.getSourceType(); if (StrUtil.equals(sourceType, "1")) { - DistributionParcelListEntity parcelListEntity = getDistributionParcelListEntity(qualityDeliverEntity.getOrderPackageCode(), qualityDeliverEntity.getWarehouseId()); - buildCmpBasicInfo(qualityDeliverEntity, parcelListEntity); + // 定制品转的库存品先查出包条码 + List list = stockListInfoService.list(Wrappers.lambdaQuery().eq(DistributionStockListInfoEntity::getStockListId, stockList.getId())); + if (CollUtil.isNotEmpty(list)) { + DistributionStockListInfoEntity distributionStockListInfoEntity = list.get(0); + DistributionParcelListEntity parcelListEntity = getDistributionParcelListEntity(distributionStockListInfoEntity.getPackageCode(), qualityDeliverEntity.getWarehouseId()); + buildCmpBasicInfo(qualityDeliverEntity, parcelListEntity); + } } else { + qualityDeliverEntity.setBeginWarehouseName(stockList.getWarehouseName()); + qualityDeliverEntity.setBeginWarehouseInTime(stockList.getWarehousingTime()); qualityDeliverEntity.setBrandName(brandName); qualityDeliverEntity.setMallCode(stockList.getMarketCode()); qualityDeliverEntity.setMallId(stockList.getMarketId()); @@ -313,6 +324,10 @@ public class QualityDeliverListener { // 物料编码 qualityDeliverEntity.setMaterielCode(parcelListEntity.getMaterialCode()); } + // 包条码 + if (StrUtil.isNotEmpty(parcelListEntity.getOrderPackageCode())) { + qualityDeliverEntity.setOrderPackageCode(parcelListEntity.getOrderPackageCode()); + } // 订单号 qualityDeliverEntity.setOrderCode(parcelListEntity.getOrderCode()); // 工厂车次号 @@ -352,12 +367,14 @@ public class QualityDeliverListener { private void buildOrderInfo(QualityDeliverEntity qualityDeliverEntity, Long warehouseId, String orderCode) { DistributionStockArticleEntity stockArticleEntity = getDistributionStockArticleEntity(warehouseId, orderCode); if (ObjectUtil.isNotEmpty(stockArticleEntity)) { + qualityDeliverEntity.setOrderNumber(stockArticleEntity.getTotalNumber()); // 客户信息 qualityDeliverEntity.setCustomName(stockArticleEntity.getCustomerName()); qualityDeliverEntity.setCustomPhone(stockArticleEntity.getCustomerTelephone()); qualityDeliverEntity.setCustomAddress(stockArticleEntity.getCustomerAddress()); // 商场信息 qualityDeliverEntity.setMallName(stockArticleEntity.getMallName()); + qualityDeliverEntity.setMallId(stockArticleEntity.getMallId()); qualityDeliverEntity.setMallCode(stockArticleEntity.getMallCode()); // 服务号 qualityDeliverEntity.setServiceNumber(stockArticleEntity.getServiceNumber()); diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReViewReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReViewReportListener.java index af4683960..b0eb33f8b 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReViewReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReViewReportListener.java @@ -1,10 +1,12 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; import com.logpm.distribution.pros.DistributionProperties; @@ -13,23 +15,21 @@ import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; import org.springblade.common.model.DistributionSignforVO; import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; -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; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 文员复核生成明细报表 @@ -40,7 +40,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class ReViewReportListener { +public class ReViewReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -49,25 +49,34 @@ public class ReViewReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndrecheck.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndrecheck.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getReViewReport()) { - return; - } - log.info("文员复核生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); DistributionSignforVO vo = JSONUtil.toBean(entries, DistributionSignforVO.class); Long warehouseId = bean.getWarehouseId(); BizOperationEnums bizOperation = bean.getBizOperation(); + String reservationCode = vo.getReservationCode(); + Map> cmpMap = new HashMap<>(); + Map> ltlMap = new HashMap<>(); + Map> invMap = new HashMap<>(); + if (StrUtil.isNotEmpty(reservationCode)) { + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery() + .eq(QualityDeliverEntity::getPlanReservationCode, reservationCode) + ); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + cmpMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + ltlMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) + .collect(Collectors.groupingBy(item -> item.getCategory() + item.getOrderCode())); + invMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + } + } List details = vo.getPackageDataList(); if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { @@ -77,39 +86,53 @@ public class ReViewReportListener { .orderPackageCode(detail.getPackageCode()) .reviewUserName(bean.getOperator()) .reviewTime(bean.getOperatorTime()) + .reviewNum(detail.getNumber()) .bizCode(vo.getReservationCode()) .bizStatus(100) .build(); if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { qualityDeliverEntity.setConditions(1); - sendReport(bizOperation, qualityDeliverEntity); + if (cmpMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(cmpMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(BizOperationEnums.MODIFY, qualityDeliverEntity); + } else { + // 不在计划内被扫描到了 特殊处理 + } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { qualityDeliverEntity.setOrderCode(detail.getOrderCode()); qualityDeliverEntity.setCategory(detail.getProductName()); qualityDeliverEntity.setConditions(2); - sendReport(bizOperation, qualityDeliverEntity); + if (ltlMap.containsKey(detail.getProductName() + detail.getOrderCode())) { + qualityDeliverEntity.setId(ltlMap.get(detail.getProductName() + detail.getOrderCode()).get(0).getId()); + sendReport(BizOperationEnums.MODIFY, qualityDeliverEntity); + } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); qualityDeliverEntity.setMallName(detail.getMallName()); qualityDeliverEntity.setMaterielCode(detail.getMaterialCode()); qualityDeliverEntity.setMaterielName(detail.getMaterialName()); qualityDeliverEntity.setConditions(3); - sendReport(bizOperation, qualityDeliverEntity); + if (invMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(invMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(BizOperationEnums.MODIFY, qualityDeliverEntity); + } } } } } - private void sendReport(BizOperationEnums bizOperation, QualityDeliverEntity qualityDeliverEntity) { - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(BizOperationEnums.MODIFY).build(); - factoryDataClient.sendMessage(SendMsg.builder() - .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) - .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) - .message(JSONUtil.toJsonStr(dto)) - .delay(3000) - .build()); - } + private void sendReport(BizOperationEnums operationEnums, QualityDeliverEntity qualityDeliverEntity) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.CLERK_REVIEW.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); } } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportListener.java new file mode 100644 index 000000000..a832e55fc --- /dev/null +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportListener.java @@ -0,0 +1,419 @@ +package com.logpm.distribution.receiver.report; + +import cn.hutool.core.util.StrUtil; +import com.logpm.distribution.pros.DistributionProperties; +import com.rabbitmq.client.Channel; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.report.ReportConstants; +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.amqp.support.AmqpHeaders; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.List; + +/** + * 配送明细报表作业节点监听器 + * + * @author zhaoqiaobo + * @create 2024-03-18 0:02 + */ +@Slf4j +@Component +@AllArgsConstructor +public class ReportListener { + + private final DistributionProperties destinationProperties; + private final List reportServices; + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillPlan.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillPlan.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void billPlanReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getBillPlanReport()) { + flag = Boolean.FALSE; + } + log.info("自提任务生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(BillPlanReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("自提任务生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillSignReview.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillSignReview.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void billReViewReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getBillReviewReport()) { + flag = Boolean.FALSE; + } + log.info("自提复核生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(BillReViewReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("自提复核生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillSign.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillSign.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void billSignforReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getBillSignforReport()) { + flag = Boolean.FALSE; + } + log.info("自提签收扫描生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(BillSignforReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("自提签收扫描生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndCarStart.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndCarStart.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void carStartReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getCarStartReport()) { + flag = Boolean.FALSE; + } + log.info("发车生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(CarStartReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("发车生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndConsigneeArrive.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndConsigneeArrive.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void consigneeArriveReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getConsigneeArriveReport()) { + flag = Boolean.FALSE; + } + log.info("配送到达生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(ConsigneeArriveReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("配送到达生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndFinish.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndFinish.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void deliverFinishReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getDeliverFinishReport()) { + flag = Boolean.FALSE; + } + log.info("车次完成生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(DeliverFinishReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("车次完成生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndLoading.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndLoading.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void loadingReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getLoadingReport()) { + flag = Boolean.FALSE; + } + log.info("装车生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(LoadingReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("装车生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndPlan.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndPlan.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void planReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getPlanReport()) { + flag = Boolean.FALSE; + } + log.info("配送计划生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(PlanReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("配送计划生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.reservation.OwnReservation.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.reservation.OwnReservation.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void reservationPlanReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getReservationPlanReport()) { + flag = Boolean.FALSE; + } + log.info("预约计划生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(ReservationPlanReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("预约计划生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndReturnWarehouse.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndReturnWarehouse.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void returnWarehouseReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getReturnWarehouseReport()) { + flag = Boolean.FALSE; + } + log.info("回库生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(ReturnWarehouseReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("回库生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndrecheck.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndrecheck.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void reViewReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getReViewReport()) { + flag = Boolean.FALSE; + } + log.info("文员复核生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(ReViewReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("文员复核生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.DeliveryAndSignfor.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndSignfor.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void signforReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getSignforReport()) { + flag = Boolean.FALSE; + } + log.info("签收扫描生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(SignforReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("签收扫描生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = FanoutConstants.distribution.stock.QUEUE.REPORT, durable = "true"), + exchange = @Exchange(name = FanoutConstants.distribution.stock.EXCHANGE, type = ExchangeTypes.FANOUT) + ), ackMode = "MANUAL") + public void stockReportListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getStockReport()) { + flag = Boolean.FALSE; + } + log.info("备货生成明细报表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(StockReportListener.class).buildReport(msg); + } catch (Exception e) { + log.error("备货生成明细报表失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = ReportConstants.REPORT_QUALITY_DELIVER_QUEUE, durable = "true"), + exchange = @Exchange(name = ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE, type = ExchangeTypes.TOPIC), + key = ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY + ), ackMode = "MANUAL") + public void qualityDeliverListener(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { + Boolean flag = Boolean.TRUE; + if (!destinationProperties.getReport().getQualityDeliver()) { + flag = Boolean.FALSE; + } + log.info("配送明细基础表: {}", msg); + if (StrUtil.isEmpty(msg)) { + flag = Boolean.FALSE; + } + if (flag) { + try { + selectReportService(QualityDeliverListener.class).buildReport(msg); + } catch (Exception e) { + log.error("配送明细基础表处理失败: {}", e.getMessage()); + } + } + try { + channel.basicAck(tag, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + + private ReportService selectReportService(Class clazz) { + // 根据某些条件选择具体的实现类 + for (ReportService reportService : reportServices) { + if (clazz.isInstance(reportService)) { + return reportService; + } + } + // 默认返回第一个实现类 + return reportServices.get(0); + } + +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportService.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportService.java new file mode 100644 index 000000000..54e257385 --- /dev/null +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReportService.java @@ -0,0 +1,11 @@ +package com.logpm.distribution.receiver.report; + +/** + * @Author: zqb + * @Date: 2024/12/10 + */ +public interface ReportService { + + void buildReport(String msg); + +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReservationPlanReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReservationPlanReportListener.java index 703ae20ed..2079f89cf 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReservationPlanReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReservationPlanReportListener.java @@ -1,21 +1,20 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; -import com.logpm.distribution.pros.DistributionProperties; -import com.logpm.distribution.service.IQualityDeliverService; +import com.logpm.distribution.mapper.QualityDeliverMapper; import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; @@ -23,16 +22,14 @@ import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; import org.springblade.common.model.ReservationVO; import org.springblade.core.tool.utils.BeanUtil; -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; -import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /** * 预约计划生成明细报表 @@ -43,29 +40,13 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class ReservationPlanReportListener { +public class ReservationPlanReportListener implements ReportService { - @Resource - private IQualityDeliverService qualityDeliverService; - @Resource - private IFactoryDataClient factoryDataClient; - @Resource - private DistributionProperties destinationProperties; + private final IFactoryDataClient factoryDataClient; + private final QualityDeliverMapper qualityDeliverMapper; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.reservation.OwnReservation.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.reservation.OwnReservation.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) - public void buildReport(String msg) throws InterruptedException { - if (!destinationProperties.getReport().getReservationPlanReport()) { - return; - } - - log.info("预约计划生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } + @Transactional(rollbackFor = Exception.class) + public void buildReport(String msg) { NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -73,21 +54,30 @@ public class ReservationPlanReportListener { Long warehouseId = bean.getWarehouseId(); BizOperationEnums bizOperation = bean.getBizOperation(); List details = vo.getPackageDataList(); - if (BizOperationEnums.MODIFY.equals(bizOperation) || BizOperationEnums.DELETE.equals(bizOperation)) { - // 根据预约单号查询出所有这个预约单下的数据 先置空 - LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() - .set(QualityDeliverEntity::getPlanReservationCreateTime, null) - .set(QualityDeliverEntity::getPlanReservationCode, null) - .set(QualityDeliverEntity::getBizCode, null) - .set(QualityDeliverEntity::getPlanReservationTime, null) - .set(QualityDeliverEntity::getPlanReservationUser, null) - .set(QualityDeliverEntity::getPlanNum, null) - .set(QualityDeliverEntity::getReservationConsignee, null) - .set(QualityDeliverEntity::getReservationConsigneePhone, null) - .set(QualityDeliverEntity::getReservationConsigneeAddr, null) - .eq(QualityDeliverEntity::getPlanReservationCode, vo.getReservationCode()) - .ne(QualityDeliverEntity::getBizStatus, 110); - qualityDeliverService.update(wrapper); + String reservationCode = vo.getReservationCode(); + Map> cmpMap = new HashMap<>(); + Map> ltlMap = new HashMap<>(); + Map> invMap = new HashMap<>(); + if (StrUtil.isNotEmpty(reservationCode)) { + List qualityDeliverEntities = qualityDeliverMapper.selectList(Wrappers.lambdaQuery().eq(QualityDeliverEntity::getPlanReservationCode, reservationCode)); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + // 取消预约 将表中数据全删 + if (BizOperationEnums.DELETE.equals(bizOperation)) { + for (QualityDeliverEntity qualityDeliverEntity : qualityDeliverEntities) { + sendReport(qualityDeliverEntity, bizOperation); + } + return; + } + cmpMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + ltlMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) + .collect(Collectors.groupingBy(item -> item.getCategory() + item.getOrderCode())); + invMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) + .collect(Collectors.groupingBy(item -> item.getMallName() + item.getMaterielCode() + item.getIncomingBatch())); + } } if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { @@ -101,7 +91,6 @@ public class ReservationPlanReportListener { .planReservationTime(vo.getReservationDate()) .planReservationUser(bean.getOperator()) .planNum(detail.getNumber()) - // .serviceType(vo.getDeliveryType()) .reservationConsignee(vo.getConsignee()) .reservationConsigneePhone(vo.getDeliveryPhone()) .reservationConsigneeAddr(vo.getDeliveryAddress()) @@ -109,13 +98,25 @@ public class ReservationPlanReportListener { if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { qualityDeliverEntity.setConditions(1); qualityDeliverEntity.setPlanNum(1); - sendReport(bizOperation, qualityDeliverEntity, BizOperationEnums.MODIFY); + // 存在订制品则修改 不存在则新增 + if (cmpMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(cmpMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } else { + sendReport(qualityDeliverEntity, BizOperationEnums.ADD); + } } if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { qualityDeliverEntity.setOrderCode(detail.getOrderCode()); qualityDeliverEntity.setCategory(detail.getProductName()); qualityDeliverEntity.setConditions(2); - sendReport(bizOperation, qualityDeliverEntity, BizOperationEnums.MODIFY); + // 存在零担则修改 不存在则新增 + if (ltlMap.containsKey(detail.getProductName() + detail.getOrderCode())) { + qualityDeliverEntity.setId(ltlMap.get(detail.getProductName() + detail.getOrderCode()).get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } else { + sendReport(qualityDeliverEntity, BizOperationEnums.ADD); + } } if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); @@ -124,28 +125,98 @@ public class ReservationPlanReportListener { qualityDeliverEntity.setMaterielName(detail.getMaterialName()); qualityDeliverEntity.setConditions(3); Integer number = detail.getNumber(); - for (int i = 0; i < number; i++) { - QualityDeliverEntity entity = new QualityDeliverEntity(); - BeanUtil.copyProperties(qualityDeliverEntity, entity); - entity.setPlanNum(1); - sendReport(bizOperation, entity, BizOperationEnums.ADD); + // 存在库存品则修改 不存在则新增 + // 当前库存品数据大于已有数量 则新增增量部分,如果当前库存品数量小于已有数量 需要删除数据 1 删除操作只针对未备货的数据 2 全删或者只删除部分 + if (invMap.containsKey(detail.getMallName() + detail.getMaterialCode() + detail.getPickupBatch())) { + List qualityDeliverEntities = invMap.get(detail.getMallName() + detail.getMaterialCode() + detail.getPickupBatch()); + int size = qualityDeliverEntities.size(); + if (number > size) { + for (int i = 0; i < number - size; i++) { + QualityDeliverEntity entity = new QualityDeliverEntity(); + BeanUtil.copyProperties(qualityDeliverEntity, entity); + entity.setPlanNum(1); + sendReport(entity, BizOperationEnums.ADD); + } + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + qualityDeliverEntity.setPlanNum(1); + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } + } else if (number == size) { + for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { + qualityDeliverEntity.setId(deliverEntity.getId()); + qualityDeliverEntity.setPlanNum(1); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } + } else { + List collect = qualityDeliverEntities.stream() + .filter(item -> StrUtil.isEmpty(item.getOrderPackageCode())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + int i = size - number; + if (i >= collect.size()) { + for (QualityDeliverEntity entity : collect) { + sendReport(entity, BizOperationEnums.DELETE); + } + } else { + for (int j = 0; j < i; j++) { + sendReport(collect.get(j), BizOperationEnums.DELETE); + } + } + } + } + } else { + for (int i = 0; i < number; i++) { + QualityDeliverEntity entity = new QualityDeliverEntity(); + BeanUtil.copyProperties(qualityDeliverEntity, entity); + entity.setPlanNum(1); + sendReport(entity, BizOperationEnums.ADD); + } + } + } + } + // 系统中有的包件在当前不存在,则删除 + Set cmpSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.CMP)).map(PackageData::getPackageCode).collect(Collectors.toSet()); + for (Map.Entry> entry : cmpMap.entrySet()) { + String key = entry.getKey(); + if (!cmpSet.contains(key)) { + sendReport(entry.getValue().get(0), BizOperationEnums.DELETE); + } + } + Set ltlSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.LTL)) + .map(i -> i.getProductName() + i.getOrderCode()).collect(Collectors.toSet()); + for (Map.Entry> entry : ltlMap.entrySet()) { + String key = entry.getKey(); + if (!ltlSet.contains(key)) { + sendReport(entry.getValue().get(0), BizOperationEnums.DELETE); + } + } + Set invSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.INV)) + .map(i -> i.getMallName() + i.getMaterialCode() + i.getPickupBatch()).collect(Collectors.toSet()); + for (Map.Entry> entry : invMap.entrySet()) { + String key = entry.getKey(); + if (!invSet.contains(key)) { + List value = entry.getValue(); + for (QualityDeliverEntity entity : value) { + sendReport(entity, BizOperationEnums.DELETE); } } - } } } - private void sendReport(BizOperationEnums bizOperation, QualityDeliverEntity qualityDeliverEntity, BizOperationEnums bizOperationEnums) { - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(bizOperationEnums).build(); - factoryDataClient.sendMessage(SendMsg.builder() - .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) - .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) - .message(JSONUtil.toJsonStr(dto)) - .delay(3000) - .build()); - } + private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.PLANNED_RESERVATION.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); } } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReturnWarehouseReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReturnWarehouseReportListener.java index 6aec684f1..6b3f1010a 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReturnWarehouseReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/ReturnWarehouseReportListener.java @@ -2,7 +2,6 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.logpm.distribution.dto.ReportQualityDeliverDTO; @@ -13,18 +12,12 @@ import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; import org.springblade.common.model.DistributionSignforVO; import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; -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; @@ -40,7 +33,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class ReturnWarehouseReportListener { +public class ReturnWarehouseReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -49,19 +42,8 @@ public class ReturnWarehouseReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndReturnWarehouse.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndReturnWarehouse.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getReturnWarehouseReport()) { - return; - } - log.info("回库生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -78,7 +60,7 @@ public class ReturnWarehouseReportListener { .reviewUserName(bean.getOperator()) .reviewTime(bean.getOperatorTime()) .bizCode(vo.getReservationCode()) - .bizStatus(100) + .bizStatus(-1) .build(); if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { qualityDeliverEntity.setConditions(1); diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/SignforReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/SignforReportListener.java index fef058866..47815d7e4 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/SignforReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/SignforReportListener.java @@ -2,10 +2,12 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; import com.logpm.distribution.pros.DistributionProperties; @@ -14,23 +16,21 @@ import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; import org.springblade.common.model.DistributionSignforVO; import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; -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; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 签收扫描生成明细报表 @@ -41,7 +41,7 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class SignforReportListener { +public class SignforReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @@ -50,19 +50,8 @@ public class SignforReportListener { @Resource private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.DeliveryAndSignfor.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.DeliveryAndSignfor.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getSignforReport()) { - return; - } - log.info("签收扫描生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -70,6 +59,26 @@ public class SignforReportListener { Long warehouseId = bean.getWarehouseId(); BizOperationEnums bizOperation = bean.getBizOperation(); List details = vo.getPackageDataList(); + String reservationCode = vo.getReservationCode(); + Map> cmpMap = new HashMap<>(); + Map> ltlMap = new HashMap<>(); + Map> invMap = new HashMap<>(); + if (StrUtil.isNotEmpty(reservationCode)) { + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery() + .eq(QualityDeliverEntity::getPlanReservationCode, reservationCode) + ); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + cmpMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + ltlMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) + .collect(Collectors.groupingBy(item -> item.getCategory() + item.getOrderCode())); + invMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + } + } if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() @@ -86,17 +95,26 @@ public class SignforReportListener { .signType(vo.getOperatMode()) .bizCode(vo.getReservationCode()) .bizStatus(90) + .signStatus("已签收") .build(); if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { qualityDeliverEntity.setConditions(1); qualityDeliverEntity.setSignNum(1); - sendReport(bizOperation, qualityDeliverEntity); + if (cmpMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(cmpMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(BizOperationEnums.MODIFY, qualityDeliverEntity); + } else { + // 不在计划内被扫描到了 特殊处理 + } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { qualityDeliverEntity.setOrderCode(detail.getOrderCode()); qualityDeliverEntity.setCategory(detail.getProductName()); qualityDeliverEntity.setSignNum(detail.getNumber()); qualityDeliverEntity.setConditions(2); - sendReport(bizOperation, qualityDeliverEntity); + if (ltlMap.containsKey(detail.getProductName() + detail.getOrderCode())) { + qualityDeliverEntity.setId(ltlMap.get(detail.getProductName() + detail.getOrderCode()).get(0).getId()); + sendReport(BizOperationEnums.MODIFY, qualityDeliverEntity); + } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); qualityDeliverEntity.setMallName(detail.getMallName()); @@ -104,22 +122,27 @@ public class SignforReportListener { qualityDeliverEntity.setMaterielName(detail.getMaterialName()); qualityDeliverEntity.setSignNum(1); qualityDeliverEntity.setConditions(3); - sendReport(bizOperation, qualityDeliverEntity); + if (invMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(invMap.get(detail.getPackageCode()).get(0).getId()); + sendReport(BizOperationEnums.MODIFY, qualityDeliverEntity); + } } } } } - private void sendReport(BizOperationEnums bizOperation, QualityDeliverEntity qualityDeliverEntity) { - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(BizOperationEnums.MODIFY).build(); - factoryDataClient.sendMessage(SendMsg.builder() - .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) - .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) - .message(JSONUtil.toJsonStr(dto)) - .delay(3000) - .build()); - } + private void sendReport(BizOperationEnums operationEnums, QualityDeliverEntity qualityDeliverEntity) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.DISTRIBUTION_SIGN_FOR.getValue()) + .build(); + factoryDataClient.sendMessage(SendMsg.builder() + .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) + .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) + .message(JSONUtil.toJsonStr(dto)) + .delay(3000) + .build()); } } diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/StockReportListener.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/StockReportListener.java index 8e65940a9..494774161 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/StockReportListener.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/StockReportListener.java @@ -1,6 +1,7 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; @@ -8,29 +9,26 @@ import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.distribution.dto.ReportQualityDeliverDTO; import com.logpm.distribution.entity.QualityDeliverEntity; -import com.logpm.distribution.pros.DistributionProperties; import com.logpm.distribution.service.IQualityDeliverService; import com.logpm.factorydata.feign.IFactoryDataClient; import com.logpm.factorydata.vo.SendMsg; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.constant.broadcast.FanoutConstants; +import org.springblade.common.constant.WorkNodeEnums; import org.springblade.common.constant.report.ReportConstants; import org.springblade.common.enums.BizOperationEnums; import org.springblade.common.enums.PackageTypeEnums; import org.springblade.common.model.NodeFanoutMsg; import org.springblade.common.model.PackageData; import org.springblade.common.model.StockUpVO; -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; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 备货生成明细报表 @@ -41,28 +39,15 @@ import java.util.List; @Slf4j @Component @AllArgsConstructor -public class StockReportListener { +public class StockReportListener implements ReportService { @Resource private IQualityDeliverService qualityDeliverService; @Resource private IFactoryDataClient factoryDataClient; - @Resource - private DistributionProperties destinationProperties; - @RabbitListener(bindings = @QueueBinding( - value = @Queue(name = FanoutConstants.distribution.stock.QUEUE.REPORT, durable = "true"), - exchange = @Exchange(name = FanoutConstants.distribution.stock.EXCHANGE, type = ExchangeTypes.FANOUT) - )) -// @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = Exception.class) public void buildReport(String msg) { - if (!destinationProperties.getReport().getStockReport()) { - return; - } - log.info("备货生成明细报表: {}", msg); - if (StrUtil.isEmpty(msg)) { - return; - } NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); Object main = bean.getMain(); JSONObject entries = JSONUtil.parseObj(main); @@ -70,6 +55,25 @@ public class StockReportListener { Long warehouseId = bean.getWarehouseId(); BizOperationEnums bizOperation = bean.getBizOperation(); List details = vo.getPackageDataList(); + // 单号 referenceCode + String referenceCode = vo.getReferenceCode(); + Map> cmpMap = new HashMap<>(); + Map> ltlMap = new HashMap<>(); + Map> invMap = new HashMap<>(); + if (StrUtil.isNotEmpty(referenceCode)) { + List qualityDeliverEntities = qualityDeliverService.list(Wrappers.lambdaQuery().eq(QualityDeliverEntity::getPlanReservationCode, referenceCode)); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + cmpMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) + .collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); + ltlMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) + .collect(Collectors.groupingBy(item -> item.getCategory() + item.getOrderCode())); + invMap = qualityDeliverEntities.stream() + .filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) + .collect(Collectors.groupingBy(item -> item.getMallName() + item.getMaterielCode())); + } + } if (CollUtil.isNotEmpty(details)) { for (PackageData detail : details) { QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() @@ -86,16 +90,26 @@ public class StockReportListener { if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { qualityDeliverEntity.setConditions(1); qualityDeliverEntity.setStockNum(1); - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - sendReport(qualityDeliverEntity); + if (cmpMap.containsKey(detail.getPackageCode())) { + qualityDeliverEntity.setId(cmpMap.get(detail.getPackageCode()).get(0).getId()); + if (BizOperationEnums.DELETE.equals(bizOperation)) { + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } else { + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { qualityDeliverEntity.setOrderCode(detail.getOrderCode()); qualityDeliverEntity.setCategory(detail.getProductName()); qualityDeliverEntity.setConditions(2); qualityDeliverEntity.setStockNum(detail.getNumber()); - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - sendReport(qualityDeliverEntity); + if (ltlMap.containsKey(detail.getProductName() + detail.getOrderCode())) { + qualityDeliverEntity.setId(ltlMap.get(detail.getProductName() + detail.getOrderCode()).get(0).getId()); + if (BizOperationEnums.DELETE.equals(bizOperation)) { + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } else { + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } } } else if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { qualityDeliverEntity.setBizCode(vo.getReferenceCode()); @@ -105,19 +119,24 @@ public class StockReportListener { qualityDeliverEntity.setMaterielName(detail.getMaterialName()); qualityDeliverEntity.setConditions(3); qualityDeliverEntity.setStockNum(1); - if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { - List list = qualityDeliverService.list(Wrappers.lambdaQuery() - .select(QualityDeliverEntity::getId) - .eq(QualityDeliverEntity::getBizCode, qualityDeliverEntity.getBizCode()) - .eq(QualityDeliverEntity::getMallName, qualityDeliverEntity.getMallName()) - .eq(QualityDeliverEntity::getMaterielCode, qualityDeliverEntity.getMaterielCode()) - .isNull(QualityDeliverEntity::getOrderPackageCode) - .lt(QualityDeliverEntity::getBizStatus, 110) - .last(" limit 1") - ); - if(CollUtil.isNotEmpty(list)){ - qualityDeliverEntity.setId(list.get(0).getId()); - sendReport(qualityDeliverEntity); + if (invMap.containsKey(detail.getMallName() + detail.getMaterialCode())) { + List qualityDeliverEntities = invMap.get(detail.getMallName() + detail.getMaterialCode()); + if (CollUtil.isNotEmpty(qualityDeliverEntities)) { + if (BizOperationEnums.DELETE.equals(bizOperation)) { + List collect = qualityDeliverEntities.stream() + .filter(i -> StrUtil.equals(i.getOrderPackageCode(), detail.getPackageCode())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + qualityDeliverEntity.setId(collect.get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); + } + } else { + List collect = qualityDeliverEntities.stream().filter( i -> StrUtil.isEmpty(i.getStockupCode())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + qualityDeliverEntity.setId(collect.get(0).getId()); + sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); + } + } } } } @@ -125,8 +144,12 @@ public class StockReportListener { } } - private void sendReport(QualityDeliverEntity qualityDeliverEntity) { - ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(BizOperationEnums.MODIFY).build(); + private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { + ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() + .data(JSONUtil.toJsonStr(qualityDeliverEntity)) + .operation(operationEnums) + .node(WorkNodeEnums.STOCKING_OPERATION.getValue()) + .build(); factoryDataClient.sendMessage(SendMsg.builder() .exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) .routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IQualityDeliverService.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IQualityDeliverService.java index 87ebb1605..b95a5f694 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IQualityDeliverService.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IQualityDeliverService.java @@ -32,4 +32,12 @@ public interface IQualityDeliverService extends BaseService