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)