fix(成本分析): 修复价格计算和单层成本排序问题
This commit is contained in:
parent
c47d47d62e
commit
475b124cc3
|
|
@ -27,11 +27,6 @@ public class EBomDTO {
|
|||
*/
|
||||
private String materialUnit;
|
||||
|
||||
/**
|
||||
* 单重
|
||||
*/
|
||||
private BigDecimal unitWeight;
|
||||
|
||||
/**
|
||||
* 最近采购价格
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -78,12 +78,12 @@ public class EBomChildEntity implements Serializable {
|
|||
// @ApiModelProperty(value = "物料分类编码")
|
||||
// private String materialCategoryCode;
|
||||
|
||||
/**
|
||||
* 单重
|
||||
*/
|
||||
@TableField(value = "unit_weight")
|
||||
@ApiModelProperty(value = "单重")
|
||||
private BigDecimal unitWeight;
|
||||
///**
|
||||
// * 单重
|
||||
// */
|
||||
//@TableField(value = "unit_weight")
|
||||
//@ApiModelProperty(value = "单重")
|
||||
//private BigDecimal unitWeight;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
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.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
@ -21,6 +24,8 @@ import java.util.List;
|
|||
public class HighValuePurchasedPartsVO implements Serializable {
|
||||
|
||||
@ApiModelProperty("总金额")
|
||||
@JsonFormat(pattern = "#.##")
|
||||
@JsonSerialize(using = BigDecimalSerializer.class)
|
||||
private BigDecimal totalCost = BigDecimal.ZERO;
|
||||
|
||||
@ApiModelProperty("物料列表")
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ public class BomCostCalculateService {
|
|||
private BigDecimal calculatePaintCost(EBomDTO dto) {
|
||||
PaintCostConfigEntity entity = paintCostConfigService.getCost(dto.getGroupName());
|
||||
if (Objects.nonNull(entity)) {
|
||||
return NumberUtil.mul(dto.getUnitWeight(), entity.getCost());
|
||||
return NumberUtil.mul(dto.getNum(), entity.getCost());
|
||||
} else {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
|
@ -291,7 +291,7 @@ public class BomCostCalculateService {
|
|||
private BigDecimal calculateSteelsCost(EBomDTO dto) {
|
||||
//是钢材
|
||||
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;
|
||||
if (StrUtil.isNotBlank(dto.getGroupName())) {
|
||||
SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getGroupName());
|
||||
|
|
|
|||
|
|
@ -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.util.JsonUtil;
|
||||
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.SessionCallback;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
|
|
@ -70,7 +71,7 @@ public class EBomService {
|
|||
|
||||
public List<EBomChildEntity> getChildren(long 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;
|
||||
if (CollectionUtil.isEmpty(kvs)) {
|
||||
entities = ebomChildService.lambdaQuery()
|
||||
|
|
@ -78,9 +79,19 @@ public class EBomService {
|
|||
.orderByAsc(EBomChildEntity::getOrderNumber)
|
||||
.list();
|
||||
if (CollectionUtil.isNotEmpty(entities)) {
|
||||
BoundSetOperations<String, String> boundSetOps = redisTemplate.boundSetOps(key);
|
||||
boundSetOps.add(entities.stream().map(JsonUtil::toJson).toArray(String[]::new));
|
||||
boundSetOps.expire(CACHE_DURATION_CHILD);
|
||||
Map<String, Double> scoreMembers = new HashMap<>();
|
||||
for (EBomChildEntity entity : entities) {
|
||||
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 {
|
||||
entities = kvs.stream().map((v) -> JsonUtil.fromJson(v, EBomChildEntity.class)).collect(Collectors.toList());
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package com.nflg.product.technology.util;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
|
||||
@Slf4j
|
||||
public class JsonUtil {
|
||||
|
||||
private static final ObjectMapper objectmapper = new ObjectMapper();
|
||||
|
|
@ -13,6 +15,7 @@ public class JsonUtil {
|
|||
try {
|
||||
return objectmapper.readValue(json, clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("JSON反序列化失败", e);
|
||||
throw new NflgBusinessException(STATE.BusinessError, "JSON反序列化失败");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue