fix(成本分析): 修复价格计算和单层成本排序问题

This commit is contained in:
曹鹏飞 2025-01-05 21:53:28 +08:00
parent c47d47d62e
commit 475b124cc3
6 changed files with 35 additions and 21 deletions

View File

@ -27,11 +27,6 @@ public class EBomDTO {
*/ */
private String materialUnit; private String materialUnit;
/**
* 单重
*/
private BigDecimal unitWeight;
/** /**
* 最近采购价格 * 最近采购价格
*/ */

View File

@ -78,12 +78,12 @@ public class EBomChildEntity implements Serializable {
// @ApiModelProperty(value = "物料分类编码") // @ApiModelProperty(value = "物料分类编码")
// private String materialCategoryCode; // private String materialCategoryCode;
/** ///**
* 单重 // * 单重
*/ // */
@TableField(value = "unit_weight") //@TableField(value = "unit_weight")
@ApiModelProperty(value = "单重") //@ApiModelProperty(value = "单重")
private BigDecimal unitWeight; //private BigDecimal unitWeight;
/** /**
* 数量 * 数量

View File

@ -1,5 +1,8 @@
package com.nflg.product.technology.pojo.vo; package com.nflg.product.technology.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nflg.product.base.core.config.BigDecimalSerializer;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -21,6 +24,8 @@ import java.util.List;
public class HighValuePurchasedPartsVO implements Serializable { public class HighValuePurchasedPartsVO implements Serializable {
@ApiModelProperty("总金额") @ApiModelProperty("总金额")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalCost = BigDecimal.ZERO; private BigDecimal totalCost = BigDecimal.ZERO;
@ApiModelProperty("物料列表") @ApiModelProperty("物料列表")

View File

@ -205,7 +205,7 @@ public class BomCostCalculateService {
private BigDecimal calculatePaintCost(EBomDTO dto) { private BigDecimal calculatePaintCost(EBomDTO dto) {
PaintCostConfigEntity entity = paintCostConfigService.getCost(dto.getGroupName()); PaintCostConfigEntity entity = paintCostConfigService.getCost(dto.getGroupName());
if (Objects.nonNull(entity)) { if (Objects.nonNull(entity)) {
return NumberUtil.mul(dto.getUnitWeight(), entity.getCost()); return NumberUtil.mul(dto.getNum(), entity.getCost());
} else { } else {
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
@ -291,7 +291,7 @@ public class BomCostCalculateService {
private BigDecimal calculateSteelsCost(EBomDTO dto) { private BigDecimal calculateSteelsCost(EBomDTO dto) {
//是钢材 //是钢材
BigDecimal price = Optional.ofNullable(dto.getLastPurchasePrice()).orElse(BigDecimal.ZERO); BigDecimal price = Optional.ofNullable(dto.getLastPurchasePrice()).orElse(BigDecimal.ZERO);
BigDecimal unitWeight = Optional.ofNullable(dto.getUnitWeight()).orElse(BigDecimal.ZERO); BigDecimal unitWeight = Optional.ofNullable(dto.getNum()).orElse(BigDecimal.ZERO);
BigDecimal wastage = BigDecimal.ZERO; BigDecimal wastage = BigDecimal.ZERO;
if (StrUtil.isNotBlank(dto.getGroupName())) { if (StrUtil.isNotBlank(dto.getGroupName())) {
SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getGroupName()); SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getGroupName());

View File

@ -6,15 +6,16 @@ import com.nflg.product.technology.pojo.entity.EBomChildEntity;
import com.nflg.product.technology.pojo.entity.EBomParentEntity; import com.nflg.product.technology.pojo.entity.EBomParentEntity;
import com.nflg.product.technology.util.JsonUtil; import com.nflg.product.technology.util.JsonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration; import java.time.Duration;
import java.util.List; import java.util.*;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@ -70,7 +71,7 @@ public class EBomService {
public List<EBomChildEntity> getChildren(long parentRowId) { public List<EBomChildEntity> getChildren(long parentRowId) {
String key = buildChildCacheKey(parentRowId); String key = buildChildCacheKey(parentRowId);
Set<String> kvs = redisTemplate.opsForSet().members(key); Set<String> kvs = redisTemplate.opsForZSet().range(key, 0, -1);
List<EBomChildEntity> entities = null; List<EBomChildEntity> entities = null;
if (CollectionUtil.isEmpty(kvs)) { if (CollectionUtil.isEmpty(kvs)) {
entities = ebomChildService.lambdaQuery() entities = ebomChildService.lambdaQuery()
@ -78,9 +79,19 @@ public class EBomService {
.orderByAsc(EBomChildEntity::getOrderNumber) .orderByAsc(EBomChildEntity::getOrderNumber)
.list(); .list();
if (CollectionUtil.isNotEmpty(entities)) { if (CollectionUtil.isNotEmpty(entities)) {
BoundSetOperations<String, String> boundSetOps = redisTemplate.boundSetOps(key); Map<String, Double> scoreMembers = new HashMap<>();
boundSetOps.add(entities.stream().map(JsonUtil::toJson).toArray(String[]::new)); for (EBomChildEntity entity : entities) {
boundSetOps.expire(CACHE_DURATION_CHILD); scoreMembers.put(JsonUtil.toJson(entity), Double.valueOf(entity.getOrderNumber()));
}
redisTemplate.executePipelined(new SessionCallback<Object>() {
@Override
public Object execute(RedisOperations operations) throws DataAccessException {
BoundZSetOperations<String, String> zSetOps = operations.boundZSetOps(key);
scoreMembers.forEach(zSetOps::add);
zSetOps.expire(CACHE_DURATION_CHILD);
return null;
}
});
} }
} else { } else {
entities = kvs.stream().map((v) -> JsonUtil.fromJson(v, EBomChildEntity.class)).collect(Collectors.toList()); entities = kvs.stream().map((v) -> JsonUtil.fromJson(v, EBomChildEntity.class)).collect(Collectors.toList());

View File

@ -3,8 +3,10 @@ package com.nflg.product.technology.util;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.nflg.product.base.core.exception.NflgBusinessException; import com.nflg.product.base.core.exception.NflgBusinessException;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE; import nflg.product.common.constant.STATE;
@Slf4j
public class JsonUtil { public class JsonUtil {
private static final ObjectMapper objectmapper = new ObjectMapper(); private static final ObjectMapper objectmapper = new ObjectMapper();
@ -13,6 +15,7 @@ public class JsonUtil {
try { try {
return objectmapper.readValue(json, clazz); return objectmapper.readValue(json, clazz);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("JSON反序列化失败", e);
throw new NflgBusinessException(STATE.BusinessError, "JSON反序列化失败"); throw new NflgBusinessException(STATE.BusinessError, "JSON反序列化失败");
} }
} }