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 6f89edced..0e94eea93 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 @@ -3,6 +3,7 @@ package com.logpm.distribution.receiver.report; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -30,6 +31,7 @@ import org.jetbrains.annotations.Nullable; import org.springblade.common.constant.report.ReportConstants; 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; @@ -79,6 +81,9 @@ public class QualityDeliverListener { @Resource private IWarehouseWaybillDetailClient waybillDetailClient; + @Resource + private BladeRedis redisCache; + @RabbitListener(bindings = @QueueBinding( value = @Queue(name = ReportConstants.REPORT_QUALITY_DELIVER_QUEUE, durable = "true"), exchange = @Exchange(name = ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE, type = ExchangeTypes.TOPIC), @@ -97,9 +102,9 @@ public class QualityDeliverListener { if (ObjectUtil.equals(PackageTypeEnums.CMP.getCode(), conditions)) { // 定制品 LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - if(ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())){ + if (ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())) { wrapper.eq(QualityDeliverEntity::getId, qualityDeliverEntity.getId()); - }else{ + } else { wrapper.eq(QualityDeliverEntity::getOrderPackageCode, qualityDeliverEntity.getOrderPackageCode()); } wrapper.lt(QualityDeliverEntity::getBizStatus, 110); @@ -115,9 +120,9 @@ public class QualityDeliverListener { } else if (ObjectUtil.equals(PackageTypeEnums.LTL.getCode(), conditions)) { // 零担 LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - if(ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())){ + if (ObjectUtil.isNotEmpty(qualityDeliverEntity.getId())) { wrapper.eq(QualityDeliverEntity::getId, qualityDeliverEntity.getId()); - }else{ + } else { wrapper.eq(QualityDeliverEntity::getOrderCode, qualityDeliverEntity.getOrderCode()) .eq(QualityDeliverEntity::getCategory, qualityDeliverEntity.getCategory()); } @@ -214,7 +219,7 @@ public class QualityDeliverListener { if (ObjectUtil.equals(PackageTypeEnums.CMP.getCode(), conditions)) { // 订制品 // 构建订制品基础信息 - DistributionParcelListEntity parcelListEntity = parcelListService.selectByOrderPackageCode(qualityDeliverEntity.getOrderPackageCode(), qualityDeliverEntity.getWarehouseId()); + DistributionParcelListEntity parcelListEntity = getDistributionParcelListEntity(qualityDeliverEntity.getOrderPackageCode(), qualityDeliverEntity.getWarehouseId()); buildCmpBasicInfo(qualityDeliverEntity, parcelListEntity); } if (ObjectUtil.equals(PackageTypeEnums.INV.getCode(), conditions)) { @@ -236,6 +241,11 @@ public class QualityDeliverListener { } } + private DistributionParcelListEntity getDistributionParcelListEntity(String orderPackageCode, Long warehouseId) { + DistributionParcelListEntity parcelListEntity = parcelListService.selectByOrderPackageCode(orderPackageCode, warehouseId); + return parcelListEntity; + } + private void buildInvBasicInfo(QualityDeliverEntity qualityDeliverEntity) { String materielName = qualityDeliverEntity.getMaterielName(); DistributionStockListEntity stockListEntity = new DistributionStockListEntity(); @@ -249,7 +259,7 @@ public class QualityDeliverListener { String brandName = stockList.getBrandName(); String sourceType = stockList.getSourceType(); if (StrUtil.equals(sourceType, "1")) { - DistributionParcelListEntity parcelListEntity = parcelListService.selectByOrderPackageCode(qualityDeliverEntity.getOrderPackageCode(), qualityDeliverEntity.getWarehouseId()); + DistributionParcelListEntity parcelListEntity = getDistributionParcelListEntity(qualityDeliverEntity.getOrderPackageCode(), qualityDeliverEntity.getWarehouseId()); buildCmpBasicInfo(qualityDeliverEntity, parcelListEntity); } else { qualityDeliverEntity.setBrandName(brandName); @@ -268,17 +278,17 @@ public class QualityDeliverListener { // factoryCategoryEntity.setBrand(brandName); // factoryCategoryEntity.setType(2); // BasicdataFactoryCategoryEntity categoryEntity = factoryCategoryClient.findEntityByBrandAndMaterielName(factoryCategoryEntity); - // factoryCategoryEntity.setType(1); - // BasicdataFactoryCategoryEntity categoryEntity1 = factoryCategoryClient.findEntityByBrandAndMaterielName(factoryCategoryEntity); - // if (ObjectUtil.isNotEmpty(categoryEntity)) { - // qualityDeliverEntity.setCostCategoryId(categoryEntity.getCategoryId()); - // qualityDeliverEntity.setCostCategory(categoryEntity.getCategory()); - // } - // if (ObjectUtil.isNotEmpty(categoryEntity1)) { - // qualityDeliverEntity.setRevenueCategory(categoryEntity.getCategory()); - // qualityDeliverEntity.setRevenueCategoryId(categoryEntity1.getCategoryId()); - // } - // TODO 从入库单上查询入库时间 + // factoryCategoryEntity.setType(1); + // BasicdataFactoryCategoryEntity categoryEntity1 = factoryCategoryClient.findEntityByBrandAndMaterielName(factoryCategoryEntity); + // if (ObjectUtil.isNotEmpty(categoryEntity)) { + // qualityDeliverEntity.setCostCategoryId(categoryEntity.getCategoryId()); + // qualityDeliverEntity.setCostCategory(categoryEntity.getCategory()); + // } + // if (ObjectUtil.isNotEmpty(categoryEntity1)) { + // qualityDeliverEntity.setRevenueCategory(categoryEntity.getCategory()); + // qualityDeliverEntity.setRevenueCategoryId(categoryEntity1.getCategoryId()); + // } + // TODO 从入库单上查询入库时间 // } } @@ -324,17 +334,17 @@ public class QualityDeliverListener { // 暂存单查询结算品类 // TrunklineAdvanceDetailEntity advanceDetailEntity = advanceDetailClient.findEntityByOrderPackageCode(qualityDeliverEntity.getOrderPackageCode()); // if (ObjectUtil.isNotEmpty(advanceDetailEntity)) { - // qualityDeliverEntity.setCostCategoryId(advanceDetailEntity.getCostCategoryId()); - // qualityDeliverEntity.setCostCategory(advanceDetailEntity.getCostCategoryName()); - // qualityDeliverEntity.setRevenueCategoryId(advanceDetailEntity.getIncomeCategoryId()); - // qualityDeliverEntity.setRevenueCategory(advanceDetailEntity.getIncomeCategoryName()); + // qualityDeliverEntity.setCostCategoryId(advanceDetailEntity.getCostCategoryId()); + // qualityDeliverEntity.setCostCategory(advanceDetailEntity.getCostCategoryName()); + // qualityDeliverEntity.setRevenueCategoryId(advanceDetailEntity.getIncomeCategoryId()); + // qualityDeliverEntity.setRevenueCategory(advanceDetailEntity.getIncomeCategoryName()); // } // 构建订单相关信息 buildOrderInfo(qualityDeliverEntity, qualityDeliverEntity.getWarehouseId(), qualityDeliverEntity.getOrderCode()); } private void buildOrderInfo(QualityDeliverEntity qualityDeliverEntity, Long warehouseId, String orderCode) { - DistributionStockArticleEntity stockArticleEntity = stockArticleService.findStockArticleByOrderCodeAndWarehouseId(orderCode, warehouseId); + DistributionStockArticleEntity stockArticleEntity = getDistributionStockArticleEntity(warehouseId, orderCode); if (ObjectUtil.isNotEmpty(stockArticleEntity)) { // 客户信息 qualityDeliverEntity.setCustomName(stockArticleEntity.getCustomerName()); @@ -356,9 +366,23 @@ public class QualityDeliverListener { } } + private DistributionStockArticleEntity getDistributionStockArticleEntity(Long warehouseId, String orderCode) { + String key = "report:qualityDeliver:stockArticle:" + warehouseId + "_" + orderCode; + String obj = redisCache.get(key); + if (StrUtil.isNotEmpty(obj)) { + return JSONUtil.toBean(obj, DistributionStockArticleEntity.class); + } + DistributionStockArticleEntity stockArticleEntity = stockArticleService.findStockArticleByOrderCodeAndWarehouseId(orderCode, warehouseId); + if (ObjectUtil.isNotEmpty(stockArticleEntity)) { + redisCache.setEx(key, JSONUtil.toJsonStr(stockArticleEntity), 60 * 60L + RandomUtil.randomInt(600)); + return stockArticleEntity; + } + return null; + } + private void buildWaybillInfo(QualityDeliverEntity qualityDeliverEntity, String waybillNumber) { if (StrUtil.isNotEmpty(waybillNumber)) { - WarehouseWaybillEntity byWaybillNo = warehouseWaybillClient.findByWaybillNo(waybillNumber); + WarehouseWaybillEntity byWaybillNo = getWarehouseWaybillEntity(waybillNumber); if (ObjectUtil.isNotEmpty(byWaybillNo)) { // 运单发货信息 qualityDeliverEntity.setShipperUnitId(byWaybillNo.getShipperId()); @@ -380,14 +404,41 @@ public class QualityDeliverListener { } } + private WarehouseWaybillEntity getWarehouseWaybillEntity(String waybillNumber) { + String key = "report:qualityDeliver:waybill:" + waybillNumber; + String obj = redisCache.get(key); + if (StrUtil.isNotEmpty(obj)) { + return JSONUtil.toBean(obj, WarehouseWaybillEntity.class); + } + WarehouseWaybillEntity byWaybillNo = warehouseWaybillClient.findByWaybillNo(waybillNumber); + if (ObjectUtil.isNotEmpty(byWaybillNo)) { + redisCache.setEx(key, JSONUtil.toJsonStr(byWaybillNo), 60 * 60L + RandomUtil.randomInt(600)); + return byWaybillNo; + } + return null; + } + private void warehouseInfo(QualityDeliverEntity qualityDeliverEntity) { - List warehouseEntities = warehouseClient.findWarehousesByIds(Arrays.asList(qualityDeliverEntity.getWarehouseId())); - if (CollUtil.isNotEmpty(warehouseEntities)) { - BasicdataWarehouseEntity warehouseEntity = warehouseEntities.get(0); + BasicdataWarehouseEntity warehouseEntity = getBasicdataWarehouseEntities(qualityDeliverEntity.getWarehouseId()); + if (ObjectUtil.isNotEmpty(warehouseEntity)) { // 事业线 qualityDeliverEntity.setBusinessUnit(warehouseEntity.getBusinessLine()); qualityDeliverEntity.setWarehousePosition(StrUtil.concat(true, Convert.toStr(warehouseEntity.getLongitude()), ",", Convert.toStr(warehouseEntity.getLatitude()))); } } + public BasicdataWarehouseEntity getBasicdataWarehouseEntities(Long warehouseId) { + String key = "report:qualityDeliver:warehouse:" + warehouseId; + String obj = redisCache.get(key); + if (StrUtil.isNotEmpty(obj)) { + return JSONUtil.toBean(obj, BasicdataWarehouseEntity.class); + } + List warehouseEntities = warehouseClient.findWarehousesByIds(Arrays.asList(warehouseId)); + if (CollUtil.isNotEmpty(warehouseEntities)) { + redisCache.setEx(key, JSONUtil.toJsonStr(warehouseEntities.get(0)), 60 * 60L + RandomUtil.randomInt(600)); + return warehouseEntities.get(0); + } + return null; + } + }