fix(成本分析): 修复一些问题

This commit is contained in:
曹鹏飞 2025-01-08 15:08:31 +08:00
parent 54254bba25
commit 7fc22ba84c
5 changed files with 82 additions and 43 deletions

View File

@ -89,4 +89,11 @@ public class EBomParentEntity implements Serializable {
@ApiModelProperty(value = "1=待复核、2=已复核、3=已退回、4=定版已发布PBOM")
@JsonIgnore
private Integer status;
/**
* 是否有BOM
*/
@TableField(value = "bom_exist")
@ApiModelProperty(value = "是否有BOM")
private Integer bomExist;
}

View File

@ -80,5 +80,8 @@ public class BomCostMultilayerVO implements Serializable {
@ApiModelProperty("物料行id")
private Long materialRowId;
@ApiModelProperty("是否有下级")
private boolean hasChildren = false;
private String relCategoryCode;
}

View File

@ -1,6 +1,7 @@
package com.nflg.product.technology.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nflg.product.base.core.config.BigDecimalSerializer;
import io.swagger.annotations.ApiModel;
@ -23,6 +24,9 @@ public class MaterialTypeCompositionVO implements Serializable {
@ApiModelProperty("物料分类(中类)")
private String materialCategoryName;
@JsonIgnore
private String materialCategoryCode;
@ApiModelProperty("数量")
private BigDecimal num = BigDecimal.ZERO;

View File

@ -56,6 +56,7 @@ public class ProductCostAnalysisService {
EBomParentEntity parent = ebomService.getParent(materialNo);
BomCostMultilayerVO vo = new BomCostMultilayerVO();
vo.setTotalNum(BigDecimal.ONE);
vo.setHasChildren(true);
buildMultilayerChildren(parent.getRowId(), vo, materials, datas, false);
return vo.getChildren();
}
@ -69,6 +70,7 @@ public class ProductCostAnalysisService {
EBomParentEntity parent = ebomService.getParent(materialNo);
BomCostMultilayerVO vo = new BomCostMultilayerVO();
vo.setMaterialNo(parent.getMaterialNo());
vo.setHasChildren(true);
EBomDTO pm = materials.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), parent.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(pm)) {
vo.setMaterialDesc(pm.getMaterialDesc());
@ -99,44 +101,48 @@ public class ProductCostAnalysisService {
private void buildMultilayerChildren(long parentRowId, BomCostMultilayerVO pvo, List<EBomDTO> materials, List<EBomCostCacheDTO> datas, boolean recursion) {
List<EBomChildEntity> children = ebomService.getChildren(parentRowId);
children.forEach(child -> {
BomCostMultilayerVO cvo = new BomCostMultilayerVO();
cvo.setMaterialNo(child.getMaterialNo());
EBomDTO cpm = materials.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(cpm)) {
cvo.setMaterialDesc(cpm.getMaterialDesc());
cvo.setMaterialCategoryName(cpm.getCategoryName());
cvo.setMaterialUnit(cpm.getMaterialUnit());
cvo.setMaterialRowId(cpm.getMaterialRowId());
cvo.setRelCategoryCode(cpm.getRelCategoryCode());
}
if (StrUtil.equals(child.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY)) {
//T项
cvo.setMaterialDesc(child.getMaterialDesc());
}
EBomCostCacheDTO ccost = datas.stream().filter(d -> StrUtil.equals(d.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(ccost)) {
cvo.setNum(child.getNum());
cvo.setTotalNum(cvo.getNum().multiply(pvo.getTotalNum()));
cvo.setTotalCost(ccost.getTotalCost().multiply(cvo.getTotalNum()));
if (ccost.isHasChildren()) {
cvo.setPrice(ccost.getTotalCost());
cvo.setMaterialCost(ccost.getMaterialCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalMaterialCost(ccost.getMaterialCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setPaintCost(ccost.getPaintCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalPaintCost(ccost.getPaintCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setDirectManualProductionCost(ccost.getDirectManualProductionCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalDirectManualProductionCost(ccost.getDirectManualProductionCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
} else {
cvo.setPrice(ccost.isPurchasedParts() ? ccost.getPurchasedPartsCost() : ccost.getSteelsCost());
if (!StrUtil.equals(child.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY)) {
BomCostMultilayerVO cvo = new BomCostMultilayerVO();
cvo.setMaterialNo(child.getMaterialNo());
EBomDTO cpm = materials.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(cpm)) {
cvo.setMaterialDesc(cpm.getMaterialDesc());
cvo.setMaterialCategoryName(cpm.getCategoryName());
cvo.setMaterialUnit(cpm.getMaterialUnit());
cvo.setMaterialRowId(cpm.getMaterialRowId());
cvo.setRelCategoryCode(cpm.getRelCategoryCode());
}
}
pvo.getChildren().add(cvo);
if (recursion) {
//if (StrUtil.equals(child.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY)) {
// //T项
// cvo.setMaterialDesc(child.getMaterialDesc());
//}
EBomCostCacheDTO ccost = datas.stream().filter(d -> StrUtil.equals(d.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(ccost)) {
cvo.setNum(child.getNum());
cvo.setTotalNum(cvo.getNum().multiply(pvo.getTotalNum()));
if (ccost.isHasChildren()) {
cvo.setPrice(ccost.getTotalCost());
cvo.setMaterialCost(ccost.getMaterialCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalMaterialCost(ccost.getMaterialCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setPaintCost(ccost.getPaintCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalPaintCost(ccost.getPaintCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setDirectManualProductionCost(ccost.getDirectManualProductionCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalDirectManualProductionCost(ccost.getDirectManualProductionCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost().setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost().multiply(cvo.getTotalNum()).setScale(2, RoundingMode.UP).toPlainString());
cvo.setTotalCost(ccost.getTotalCost().multiply(cvo.getTotalNum()));
} else {
cvo.setPrice(ccost.isPurchasedParts() ? ccost.getPurchasedPartsCost() : ccost.getSteelsCost());
cvo.setTotalCost(cvo.getPrice().multiply(cvo.getNum()));
}
}
pvo.getChildren().add(cvo);
EBomParentEntity cparent = ebomService.getParent(child.getMaterialNo());
if (Objects.nonNull(cparent)) {
buildMultilayerChildren(cparent.getRowId(), cvo, materials, datas, recursion);
cvo.setHasChildren(cparent.getBomExist() == 1);
if (recursion) {
buildMultilayerChildren(cparent.getRowId(), cvo, materials, datas, recursion);
}
}
}
});
@ -159,7 +165,7 @@ public class ProductCostAnalysisService {
EBomDTO cpm = materials.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), element.getMaterialNo()))
.findFirst()
.orElse(null);
if (Objects.nonNull(cpm) && cpm.getMaterialPrice().compareTo(price) > 0) {
if (Objects.nonNull(cpm) && BigDecimalUtil.compareTo(cpm.getMaterialPrice(), price) > 0) {
element.setMaterialDesc(cpm.getMaterialDesc());
element.setMaterialCategoryName(cpm.getCategoryName());
element.setMaterialUnit(cpm.getMaterialUnit());
@ -168,6 +174,7 @@ public class ProductCostAnalysisService {
element.setInventory(cpm.getInventory());
element.setLeadTime(cpm.getLeadTime());
element.setPrice(cpm.getMaterialPrice());
element.setTotalPrice(element.getPrice().multiply(element.getNum()));
} else {
iterator.remove();
}
@ -192,8 +199,6 @@ public class ProductCostAnalysisService {
if (Objects.isNull(cvo)) {
cvo = new MaterialCostVO();
cvo.setMaterialNo(child.getMaterialNo());
cvo.setTotalPrice(ccost.getTotalCost().multiply(tnum));
//cvo.setPrice(ccost.getTotalCost());
cvo.setNum(tnum);
pvo.getCosts().add(cvo);
} else {
@ -209,6 +214,9 @@ public class ProductCostAnalysisService {
}
private void bindMaterialCompositionVO(BigDecimal num, EBomChildEntity child, List<EBomCostCacheDTO> datas, List<MaterialCostVO> mvos, List<MaterialCostVO> pvos) {
if (StrUtil.equals(BomConstant.PROJECT_TYPE_TEMPORARY, child.getProjectType())) {
return;
}
EBomCostCacheDTO dto = datas.stream().filter(d -> StrUtil.equals(d.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
MaterialCostVO vo = null;
if (dto.isPurchasedParts()) {
@ -280,6 +288,9 @@ public class ProductCostAnalysisService {
}
private void bindMaterialTypeCompositionVO(BigDecimal num, EBomChildEntity child, List<EBomCostCacheDTO> datas, List<MaterialCostVO> vos) {
if (StrUtil.equals(BomConstant.PROJECT_TYPE_TEMPORARY, child.getProjectType())) {
return;
}
EBomCostCacheDTO dto = datas.stream().filter(d -> StrUtil.equals(d.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
MaterialCostVO vo = vos.stream().filter(v -> Objects.equals(v.getMaterialNo(), child.getMaterialNo())).findFirst().orElseGet(() -> {
MaterialCostVO v = new MaterialCostVO();
@ -289,9 +300,9 @@ public class ProductCostAnalysisService {
vos.add(v);
return v;
});
final BigDecimal nt = vo.getNum().add(num.multiply(child.getNum()));
vo.setNum(vo.getNum().add(nt));
vo.setTotalPrice(vo.getNum().multiply(dto.getTotalCost()));
final BigDecimal nt = num.multiply(child.getNum());
//vo.setNum(BigDecimal.ONE);
vo.setTotalPrice(vo.getTotalPrice().add(nt.multiply(dto.getTotalCost())));
EBomParentEntity parent = ebomService.getParent(child.getMaterialNo());
if (Objects.nonNull(parent)) {
List<EBomChildEntity> children = ebomService.getChildren(parent.getRowId());
@ -313,14 +324,15 @@ public class ProductCostAnalysisService {
vos.forEach(v -> {
String code = StrUtil.sub(v.getCategoryCode(), 0, 4);
String type = categories.stream().filter(c -> StrUtil.equals(c.get("category_code"), code)).findFirst().map(m -> m.get("category_name")).orElse(null);
MaterialTypeCompositionVO vv = rvos.stream().filter(r -> StrUtil.equals(r.getMaterialCategoryName(), type)).findFirst()
MaterialTypeCompositionVO vv = rvos.stream().filter(r -> StrUtil.equals(r.getMaterialCategoryCode(), code)).findFirst()
.orElseGet(() -> {
MaterialTypeCompositionVO rv = new MaterialTypeCompositionVO();
rv.setMaterialCategoryCode(code);
rv.setMaterialCategoryName(type);
rvos.add(rv);
return rv;
});
vv.setNum(vv.getNum().add(v.getNum()));
vv.setNum(vv.getNum().add(BigDecimal.ONE));
vv.setTotalCost(vv.getTotalCost().add(v.getTotalPrice()));
});
return rvos;

View File

@ -58,4 +58,17 @@ public class BigDecimalUtil {
return value.intValue();
}
}
public static int compareTo(BigDecimal v1, BigDecimal v2) {
if (v1 == null && v2 == null) {
return 0;
}
if (v2 == null) {
return 1;
}
if (v1 == null) {
return -1;
}
return v1.compareTo(v2);
}
}