Browse Source

feat(all): 优化配送明细报表消费

1 增加公共的仓库,运单,订单查询缓存,提高消费效率
visual
zhaoqiaobo 3 months ago
parent
commit
985ab508f0
  1. 103
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/QualityDeliverListener.java

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

Loading…
Cancel
Save