refactor(technology): 优化 BOM 成本计算逻辑
- 更新缓存键生成逻辑,增加月份参数 - 优化子 BOM 查询效率,使用 Set 替代 List - 改进 E50 类型 BOM 的成本计算处理 - 修复部分辅助生产费用的计算逻辑 -调整成本配置备份逻辑,备份上月数据
This commit is contained in:
parent
0fef01e0c8
commit
34ccf46e7f
|
|
@ -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<EBomDTO> datas, BomCostCalculateConfig config, List<EBomCostCacheDTO> 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<EBomDTO> children = datas.stream()
|
||||
Set<EBomDTO> 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<EBomDTO> 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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue