From 34ccf46e7f2dea165516b954c13795c04d8432ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 16 Apr 2025 11:28:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(technology):=20=E4=BC=98=E5=8C=96=20BO?= =?UTF-8?q?M=20=E6=88=90=E6=9C=AC=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新缓存键生成逻辑,增加月份参数 - 优化子 BOM 查询效率,使用 Set 替代 List - 改进 E50 类型 BOM 的成本计算处理 - 修复部分辅助生产费用的计算逻辑 -调整成本配置备份逻辑,备份上月数据 --- .../service/BomCostCalculateService.java | 31 +++++++++++-------- .../technology/service/CostConfigService.java | 4 +-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/BomCostCalculateService.java b/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/BomCostCalculateService.java index 17ec8bb7..bb459687 100644 --- a/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/BomCostCalculateService.java +++ b/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/BomCostCalculateService.java @@ -1,6 +1,7 @@ package com.nflg.product.technology.service; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.nflg.product.technology.constant.BomConstant; import com.nflg.product.technology.constant.TechnologyConfigEnum; @@ -23,6 +24,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.Duration; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -97,7 +99,7 @@ public class BomCostCalculateService { } private EBomCostCacheDTO calculateBom(String rootMaterialNo, String month, boolean isRoot, EBomDTO dto, List datas, BomCostCalculateConfig config, List result) { - String cdata = redisTemplate.opsForValue().get(buildKey(dto)); + String cdata = redisTemplate.opsForValue().get(buildKey(dto, month)); boolean purchaseTypeIsF = materialMainAttrService.purchaseTypeIsF(dto.getMaterialNo()); boolean purchaseTypeIsE50 = materialMainAttrService.purchaseTypeIsE50(dto.getMaterialNo()); if ((isRoot && purchaseTypeIsE50) || StrUtil.isBlank(cdata)) { @@ -125,9 +127,9 @@ public class BomCostCalculateService { cdto.setAuxiliaryDepartmentLaborCost(calculateAuxiliaryDepartmentLaborCost(dto, config, workingHours)); cdto.setAuxiliaryDepartmentExpenses(calculateAuxiliaryDepartmentExpenses(dto, config, workingHours)); cdto.setProductionCosts(calculateProductionCosts(dto, config, workingHours)); - List children = datas.stream() + Set children = datas.stream() .filter(d -> StrUtil.equals(d.getParentMaterialNo(), dto.getMaterialNo())) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); if (CollectionUtil.isEmpty(children)) { cdto.setHasChildren(false); // 计算自身 @@ -197,7 +199,7 @@ public class BomCostCalculateService { if (!(isRoot && purchaseTypeIsE50)) { cdata = JsonUtil.toJson(cdto); //log.debug(cdata); - redisTemplate.opsForValue().set(buildKey(dto), cdata, CACHE_DURATION); + redisTemplate.opsForValue().set(buildKey(dto, month), cdata, CACHE_DURATION); } return cdto; } else { @@ -403,9 +405,10 @@ public class BomCostCalculateService { return price; } - private String buildKey(EBomDTO dto) { - return StrUtil.format("technology:cost:{}:{}", dto.getMaterialNo() - , StrUtil.isBlank(dto.getCurrentVersion()) ? "A00" : dto.getCurrentVersion()); + private String buildKey(EBomDTO dto, String month) { + return StrUtil.format("technology:cost:{}:{}:{}", dto.getMaterialNo() + , StrUtil.isBlank(dto.getCurrentVersion()) ? "A00" : dto.getCurrentVersion() + , StrUtil.isBlank(month) ? DateUtil.format(LocalDateTime.now(), "yyyyMM") : month); } private void getChildren(String materialNo, List datas, String month) { @@ -467,14 +470,16 @@ public class BomCostCalculateService { EBomParentEntity parent = ebomService.getParent(materialNo); VUtils.isTure(Objects.isNull(parent)).throwMessage("无有效bom"); EBomDTO dto = convert(parent, month); - String cdata = redisTemplate.opsForValue().get(buildKey(dto)); + String cdata = redisTemplate.opsForValue().get(buildKey(dto, month)); if (StrUtil.isNotBlank(cdata)) { - return JsonUtil.fromJson(cdata, EBomCostCacheDTO.class); - } else { - return calculate(materialNo, month) - .stream().filter(f -> StrUtil.equals(f.getMaterialNo(), materialNo)).findFirst() - .orElse(null); + EBomCostCacheDTO dto1 = JsonUtil.fromJson(cdata, EBomCostCacheDTO.class); + if (!dto1.isPurchaseTypeIsE50()) { + return dto1; + } } + return calculate(materialNo, month) + .stream().filter(f -> StrUtil.equals(f.getMaterialNo(), materialNo)).findFirst() + .orElse(null); } private BigDecimal getTechnologyConfig(TechnologyConfigEnum type, String month) { diff --git a/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/CostConfigService.java b/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/CostConfigService.java index c10c86c6..0084390f 100644 --- a/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/CostConfigService.java +++ b/nflg_project_dev/nflg-technology/src/main/java/com/nflg/product/technology/service/CostConfigService.java @@ -150,7 +150,7 @@ public class CostConfigService { } public void backupSteelsCostConfig() { - LocalDateTime now = LocalDateTime.now(); + LocalDateTime now = LocalDateTime.now().minusMonths(1); String month = now.format(DateTimeFormatter.ofPattern("yyyyMM")); if (steelsCostConfigHistoryService.lambdaQuery() .eq(SteelsCostConfigHistoryEntity::getMonth, month) @@ -173,7 +173,7 @@ public class CostConfigService { } public void backupPaintCostConfig() { - LocalDateTime now = LocalDateTime.now(); + LocalDateTime now = LocalDateTime.now().minusMonths(1); String month = now.format(DateTimeFormatter.ofPattern("yyyyMM")); if (paintCostConfigHistoryService.lambdaQuery() .eq(PaintCostConfigHistoryEntity::getMonth, month)