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

This commit is contained in:
曹鹏飞 2025-01-07 20:22:07 +08:00
parent 1278f3f13e
commit 54254bba25
12 changed files with 161 additions and 162 deletions

View File

@ -47,7 +47,7 @@ public class ProductCostAnalysisApi extends BaseApi {
@GetMapping("getBomCostSingleLayer")
@ApiOperation("获取Bom组件成本(单层)")
public ResultVO<List<BomCostSingleLayerVO>> getBomCostSingleLayer(@Valid @RequestParam @NotBlank String materialNo) {
public ResultVO<List<BomCostMultilayerVO>> getBomCostSingleLayer(@Valid @RequestParam @NotBlank String materialNo) {
return ResultVO.success(productCostAnalysisService.getBomCostSingleLayer(materialNo));
}

View File

@ -1,5 +1,15 @@
package com.nflg.product.technology.constant;
import java.util.Arrays;
import java.util.List;
public class BomConstant {
public static final String PROJECT_TYPE_TEMPORARY = "T";
/**
* 钢件类别
*/
public static final List<String> STEELS_CATEGORY_CODE = Arrays.asList("10010101", "10010102", "10010103", "10010104", "10010105", "10010110");
}

View File

@ -20,6 +20,10 @@ public class EBomCostCacheDTO implements Serializable {
*/
private BigDecimal steelsCost = BigDecimal.ZERO;
/**
* 损耗成本
*/
private BigDecimal wasteCost = BigDecimal.ZERO;
/**
* 外购件成本
*/
@ -82,14 +86,16 @@ public class EBomCostCacheDTO implements Serializable {
private String categoryCode;
private boolean hasChildren;
/**
* 材料成本
* 材料成本
*/
@JsonIgnore
private BigDecimal materialCost;
public BigDecimal getMaterialCost() {
return getSteelsCost().add(getPurchasedPartsCost());
return getSteelsCost().add(getPurchasedPartsCost()).add(getWasteCost());
}
/**

View File

@ -51,44 +51,28 @@ public class BomCostMultilayerVO implements Serializable {
private BigDecimal totalCost;
@ApiModelProperty("单件材料成本")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal materialCost;
private String materialCost = "-";
@ApiModelProperty("材料成本")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalMaterialCost;
private String totalMaterialCost = "-";
@ApiModelProperty("单件油漆成本")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal paintCost;
private String paintCost = "-";
@ApiModelProperty("油漆成本")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalPaintCost;
private String totalPaintCost = "-";
@ApiModelProperty("单件标准人工工资")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal directManualProductionCost;
private String directManualProductionCost = "-";
@ApiModelProperty("标准人工工资")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalDirectManualProductionCost;
private String totalDirectManualProductionCost = "-";
@ApiModelProperty("单件辅助费用")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal auxiliaryManufacturingCost;
private String auxiliaryManufacturingCost = "-";
@ApiModelProperty("辅助费用")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalAuxiliaryManufacturingCost;
private String totalAuxiliaryManufacturingCost = "-";
@ApiModelProperty("子物料列表")
private List<BomCostMultilayerVO> children = new ArrayList<>();

View File

@ -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;
@ -19,6 +22,8 @@ import java.util.List;
public class ManufactureCostVO implements Serializable {
@ApiModelProperty("制作成本")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalCost;
@ApiModelProperty("费用列表")

View File

@ -37,9 +37,9 @@ public class MaterialCostVO implements Serializable {
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalPrice = BigDecimal.ZERO;
public BigDecimal getTotalPrice() {
return price.multiply(num);
}
//public BigDecimal getTotalPrice() {
// return price.multiply(num);
//}
@ApiModelProperty("物料描述")
private String materialDesc;

View File

@ -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 @@ public class NameCostInfoVO implements Serializable {
private String name;
@ApiModelProperty("金额")
@JsonFormat(pattern = "#.##")
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal cost;
@ApiModelProperty("占比")

View File

@ -21,6 +21,9 @@ public class PaintCostConfigVO extends EntityBase implements Serializable {
@ApiModelProperty(value = "主键行id")
private Integer id;
@ApiModelProperty("分类代码")
private String code;
@ApiModelProperty("标签名称")
private String name;

View File

@ -21,6 +21,9 @@ public class SteelsCostConfigVO extends EntityBase implements Serializable {
@ApiModelProperty(value = "主键行id")
private Integer id;
@ApiModelProperty("分类代码")
private String code;
@ApiModelProperty("分类名称")
private String name;

View File

@ -1,7 +1,6 @@
package com.nflg.product.technology.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.product.technology.constant.BomConstant;
import com.nflg.product.technology.pojo.BomCostCalculateConfig;
@ -62,11 +61,6 @@ public class BomCostCalculateService {
*/
private static final Duration CACHE_DURATION = Duration.ofHours(1);
/**
* 钢件类别
*/
private static final List<String> STEELS_CATEGORY_CODE = Arrays.asList("10010101", "10010102", "10010103", "10010104", "10010105", "10010110");
public List<EBomCostCacheDTO> calculate(String materialNo) {
VUtils.isTure(StrUtil.isBlank(materialNo)).throwMessage("物料编号不能为空");
List<EBomDTO> datas = new ArrayList<>();
@ -112,26 +106,30 @@ public class BomCostCalculateService {
cdto.setPaintCost(calculatePaintCost(dto));
cdto.setProductionCosts(calculateProductionCosts(dto, config, workingHours));
if (CollectionUtil.isEmpty(children)) {
cdto.setHasChildren(false);
// 计算自身
cdto.setPurchasedParts(!STEELS_CATEGORY_CODE.contains(dto.getMaterialCategoryCode()));
cdto.setPurchasedParts(!BomConstant.STEELS_CATEGORY_CODE.contains(dto.getMaterialCategoryCode()));
if (cdto.isPurchasedParts()) {
// 外购件只计算采购成本
cdto.setPurchasedPartsCost(calculatePurchasedPartsCost(dto));
} else {
// 非外购件计算材料成本和制作成本
// 计算制作成本
// 计算材料成本
cdto.setSteelsCost(calculateSteelsCost(dto));
// 计算损耗成本
cdto.setWasteCost(calculateWasteCost(dto));
}
} else {
cdto.setHasChildren(true);
cdto.setPurchasedParts(false);
//计算子级成本
List<EBomCostCacheDTO> childrenCost = children.parallelStream()
.map(c -> calculateBom(c, datas, config, result))
.collect(Collectors.toList());
List<ProductionCostDTO> productionCosts = new ArrayList<>();
for (EBomCostCacheDTO c : childrenCost) {
EBomDTO dto1 = children.stream().filter(cc -> StrUtil.equals(cc.getMaterialNo(), c.getMaterialNo())).findFirst().orElse(null);
cdto.setSteelsCost(cdto.getSteelsCost().add(c.getSteelsCost().multiply(dto1.getNum())));
cdto.setSteelsCost(cdto.getSteelsCost().add(c.getWasteCost().multiply(dto1.getNum())));
cdto.setPurchasedPartsCost(cdto.getPurchasedPartsCost().add(c.getPurchasedPartsCost().multiply(dto1.getNum())));
cdto.setPieceRateSalary(cdto.getPieceRateSalary().add(c.getPieceRateSalary().multiply(dto1.getNum())));
cdto.setWelfareExpenses(cdto.getWelfareExpenses().add(c.getWelfareExpenses().multiply(dto1.getNum())));
@ -142,20 +140,19 @@ public class BomCostCalculateService {
cdto.setAuxiliaryDepartmentLaborCost(cdto.getAuxiliaryDepartmentLaborCost().add(c.getAuxiliaryDepartmentLaborCost().multiply(dto1.getNum())));
cdto.setAuxiliaryDepartmentExpenses(cdto.getAuxiliaryDepartmentExpenses().add(c.getAuxiliaryDepartmentExpenses().multiply(dto1.getNum())));
cdto.setPaintCost(cdto.getPaintCost().add(c.getPaintCost().multiply(dto1.getNum())));
if (CollectionUtil.isNotEmpty(cdto.getProductionCosts())) {
cdto.getProductionCosts().forEach(pc -> {
ProductionCostDTO pdto = productionCosts.parallelStream()
if (CollectionUtil.isNotEmpty(c.getProductionCosts())) {
c.getProductionCosts().forEach(pc -> {
ProductionCostDTO pdto = cdto.getProductionCosts().parallelStream()
.filter(p -> StrUtil.equals(p.getName(), pc.getName()))
.findFirst()
.orElse(null);
if (Objects.isNull(pdto)) {
pdto = new ProductionCostDTO();
pdto.setName(pc.getName());
productionCosts.add(pdto);
cdto.getProductionCosts().add(pdto);
}
pdto.setCost(pdto.getCost().add(pc.getCost().multiply(dto1.getNum())));
});
cdto.setProductionCosts(productionCosts);
}
}
}
@ -177,32 +174,27 @@ public class BomCostCalculateService {
private List<ProductionCostDTO> calculateProductionCosts(EBomDTO d, BomCostCalculateConfig config, List<WorkingHourDTO> workHours) {
List<ProductionCostDTO> productionCosts = new ArrayList<>();
BigDecimal hourlyWages;
BigDecimal benefit;
BigDecimal auxiliaryMaterialsAndConsumables;
BigDecimal feeEquipmentDepreciation;
BigDecimal feeWorkshopLaborCost;
BigDecimal feeWorkshopOffice;
BigDecimal auxiliaryDepartmentLaborCosts;
BigDecimal assistantFee;
for (VirtualWorkingItemVO vw : config.getVirtualWorkings()) {
ProductionCostDTO dto = new ProductionCostDTO();
dto.setName(vw.getWorkingTypeName());
hourlyWages = Optional.ofNullable(config.getManday().getHourlyWages()).orElse(BigDecimal.ZERO);
benefit = Optional.ofNullable(config.getManday().getBenefit()).orElse(BigDecimal.ZERO);
auxiliaryMaterialsAndConsumables = Optional.ofNullable(vw.getConsumablesFee()).orElse(BigDecimal.ZERO);
feeEquipmentDepreciation = Optional.ofNullable(vw.getEquipmentDepreciationFee()).orElse(BigDecimal.ZERO);
feeWorkshopLaborCost = Optional.ofNullable(vw.getWorkshopLaborFee()).orElse(BigDecimal.ZERO);
feeWorkshopOffice = Optional.ofNullable(vw.getWorkshopOfficeFee()).orElse(BigDecimal.ZERO);
auxiliaryDepartmentLaborCosts = Optional.ofNullable(vw.getAssistantLaborFee()).orElse(BigDecimal.ZERO);
assistantFee = Optional.ofNullable(vw.getAssistantFee()).orElse(BigDecimal.ZERO);
BigDecimal hourlyWages = Optional.ofNullable(config.getManday().getHourlyWages()).orElse(BigDecimal.ZERO);
BigDecimal benefit = Optional.ofNullable(config.getManday().getBenefit()).orElse(BigDecimal.ZERO);
BigDecimal auxiliaryMaterialsAndConsumables = Optional.ofNullable(vw.getConsumablesFee()).orElse(BigDecimal.ZERO);
BigDecimal feeEquipmentDepreciation = Optional.ofNullable(vw.getEquipmentDepreciationFee()).orElse(BigDecimal.ZERO);
BigDecimal feeWorkshopLaborCost = Optional.ofNullable(vw.getWorkshopLaborFee()).orElse(BigDecimal.ZERO);
BigDecimal feeWorkshopOffice = Optional.ofNullable(vw.getWorkshopOfficeFee()).orElse(BigDecimal.ZERO);
BigDecimal auxiliaryDepartmentLaborCosts = Optional.ofNullable(vw.getAssistantLaborFee()).orElse(BigDecimal.ZERO);
BigDecimal assistantFee = Optional.ofNullable(vw.getAssistantFee()).orElse(BigDecimal.ZERO);
BigDecimal gs = getGsForWorkingType(d, workHours, vw);
dto.setCost(hourlyWages.add(benefit).add(auxiliaryMaterialsAndConsumables).add(feeEquipmentDepreciation)
.add(feeEquipmentDepreciation).add(feeWorkshopLaborCost).add(feeWorkshopOffice)
.add(auxiliaryDepartmentLaborCosts).add(assistantFee)
.multiply(getGsForWorkingType(d, workHours, vw)));
.add(feeWorkshopLaborCost).add(feeWorkshopOffice).add(auxiliaryDepartmentLaborCosts).add(assistantFee)
.multiply(gs));
productionCosts.add(dto);
if (dto.getCost().compareTo(BigDecimal.ZERO) > 0) {
log.debug(StrUtil.format("BOM成本计算 {} 制作成本 {},价格: {}", d.getMaterialNo(), dto.getName(), dto.getCost()));
log.debug(StrUtil.format(
"BOM成本计算 {} 制作成本 {},价格: {},其中工时: {},工时工资: {},人工福利: {},水电费、生产耗材费用: {},设备折旧: {},车间管理人工费: {},车间办公室费用: {},辅助部门人工费: {},辅助部门费用: {}"
, d.getMaterialNo(), dto.getName(), dto.getCost(), gs, hourlyWages, benefit, auxiliaryMaterialsAndConsumables
, feeEquipmentDepreciation, feeWorkshopLaborCost, feeWorkshopOffice, auxiliaryDepartmentLaborCosts, assistantFee));
}
}
return productionCosts;
@ -210,11 +202,7 @@ public class BomCostCalculateService {
private BigDecimal calculatePaintCost(EBomDTO dto) {
PaintCostConfigEntity entity = paintCostConfigService.getCost(dto.getRawMaterialGroup());
if (Objects.nonNull(entity)) {
return NumberUtil.mul(dto.getNum(), entity.getCost());
} else {
return BigDecimal.ZERO;
}
return Optional.ofNullable(entity).map(PaintCostConfigEntity::getCost).orElse(BigDecimal.ZERO);
}
private BigDecimal calculateWorkshopOfficeExpenses(EBomDTO dto, BomCostCalculateConfig config, List<WorkingHourDTO> workHours) {
@ -297,7 +285,18 @@ public class BomCostCalculateService {
private BigDecimal calculateSteelsCost(EBomDTO dto) {
//是钢材
BigDecimal price = Optional.ofNullable(dto.getMaterialPrice()).orElse(BigDecimal.ZERO);
BigDecimal unitWeight = Optional.ofNullable(dto.getNum()).orElse(BigDecimal.ZERO);
if (StrUtil.isNotBlank(dto.getRawMaterialGroup())) {
SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getRawMaterialGroup());
if (Objects.nonNull(steelsCostConfigEntity)) {
price = Optional.ofNullable(steelsCostConfigEntity.getCost()).orElse(BigDecimal.ZERO);
}
}
return price;
}
private BigDecimal calculateWasteCost(EBomDTO dto) {
//是钢材
BigDecimal price = Optional.ofNullable(dto.getMaterialPrice()).orElse(BigDecimal.ZERO);
BigDecimal wastage = BigDecimal.ZERO;
if (StrUtil.isNotBlank(dto.getRawMaterialGroup())) {
SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getRawMaterialGroup());
@ -306,8 +305,7 @@ public class BomCostCalculateService {
wastage = Optional.ofNullable(steelsCostConfigEntity.getWastage()).orElse(BigDecimal.ZERO);
}
}
return price.multiply(BigDecimal.ONE.add(wastage.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP))
.multiply(unitWeight));
return price.multiply(wastage.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
}
private String buildKey(EBomDTO dto) {

View File

@ -47,53 +47,17 @@ public class ProductCostAnalysisService {
@Resource
private BomCostService bomCostService;
public List<BomCostSingleLayerVO> getBomCostSingleLayer(String materialNo) {
public List<BomCostMultilayerVO> getBomCostSingleLayer(String materialNo) {
List<EBomCostCacheDTO> datas = bomCostCalculateService.calculate(materialNo);
if (CollectionUtil.isEmpty(datas)) {
return Collections.emptyList();
}
List<EBomDTO> materials = materialMainService.getInfos(datas.stream().map(EBomCostCacheDTO::getMaterialNo).collect(Collectors.toSet()));
EBomParentEntity parent = ebomService.getParent(materialNo);
return buildSingleLayerChildren(parent.getRowId(), datas);
}
public List<BomCostSingleLayerVO> buildSingleLayerChildren(long parentRowId, List<EBomCostCacheDTO> datas) {
List<EBomChildEntity> children = ebomService.getChildren(parentRowId);
Set<String> materialNos = children.stream()
.filter(c -> !StrUtil.equals(c.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY))
.map(EBomChildEntity::getMaterialNo)
.collect(Collectors.toSet());
List<EBomParentEntity> parents = ebomService.getParents(materialNos);
List<BomCostSingleLayerVO> vos = new ArrayList<>(MapUtil.calculateInitialCapacity(children.size()));
List<EBomDTO> materials = materialMainService.getInfos(materialNos);
children.forEach(child -> {
BomCostSingleLayerVO cvo = new BomCostSingleLayerVO();
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());
}
EBomParentEntity parent = parents.stream().filter(p -> StrUtil.equals(p.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
cvo.setVersion(Objects.isNull(parent) ? "A00" : parent.getCurrentVersion());
EBomCostCacheDTO ccost = datas.stream().filter(d -> StrUtil.equals(d.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(ccost)) {
cvo.setPrice(ccost.getTotalCost());
cvo.setNum(child.getNum());
cvo.setTotalPrice(cvo.getPrice().multiply(cvo.getNum()));
cvo.setMaterialTotalPrice(ccost.getMaterialCost().multiply(cvo.getNum()));
cvo.setLaborCosts(ccost.getDirectManualProductionCost().multiply(cvo.getNum()));
cvo.setAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost().multiply(cvo.getNum()));
}
vos.add(cvo);
});
return vos;
BomCostMultilayerVO vo = new BomCostMultilayerVO();
vo.setTotalNum(BigDecimal.ONE);
buildMultilayerChildren(parent.getRowId(), vo, materials, datas, false);
return vo.getChildren();
}
public BomCostMultilayerVO getBomCostMultilayer(String materialNo) {
@ -119,20 +83,20 @@ public class ProductCostAnalysisService {
vo.setNum(BigDecimal.ONE);
vo.setTotalNum(BigDecimal.ONE);
vo.setTotalCost(vo.getPrice());
vo.setMaterialCost(cost.getMaterialCost());
vo.setTotalMaterialCost(cost.getMaterialCost());
vo.setPaintCost(cost.getPaintCost());
vo.setTotalPaintCost(cost.getPaintCost());
vo.setDirectManualProductionCost(cost.getDirectManualProductionCost());
vo.setTotalDirectManualProductionCost(cost.getDirectManualProductionCost());
vo.setAuxiliaryManufacturingCost(cost.getAuxiliaryManufacturingCost());
vo.setTotalAuxiliaryManufacturingCost(cost.getAuxiliaryManufacturingCost());
vo.setMaterialCost(cost.getMaterialCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setTotalMaterialCost(cost.getMaterialCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setPaintCost(cost.getPaintCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setTotalPaintCost(cost.getPaintCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setDirectManualProductionCost(cost.getDirectManualProductionCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setTotalDirectManualProductionCost(cost.getDirectManualProductionCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setAuxiliaryManufacturingCost(cost.getAuxiliaryManufacturingCost().setScale(2, RoundingMode.UP).toPlainString());
vo.setTotalAuxiliaryManufacturingCost(cost.getAuxiliaryManufacturingCost().setScale(2, RoundingMode.UP).toPlainString());
}
buildMultilayerChildren(parent.getRowId(), vo, materials, datas);
buildMultilayerChildren(parent.getRowId(), vo, materials, datas, true);
return vo;
}
private void buildMultilayerChildren(long parentRowId, BomCostMultilayerVO pvo, List<EBomDTO> materials, List<EBomCostCacheDTO> datas) {
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();
@ -151,23 +115,29 @@ public class ProductCostAnalysisService {
}
EBomCostCacheDTO ccost = datas.stream().filter(d -> StrUtil.equals(d.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(ccost)) {
cvo.setPrice(ccost.getTotalCost());
cvo.setNum(child.getNum());
cvo.setTotalNum(cvo.getNum().multiply(pvo.getTotalNum()));
cvo.setTotalCost(cvo.getPrice().multiply(cvo.getTotalNum()));
cvo.setMaterialCost(ccost.getMaterialCost());
cvo.setTotalMaterialCost(ccost.getMaterialCost().multiply(cvo.getTotalNum()));
cvo.setPaintCost(ccost.getPaintCost());
cvo.setTotalPaintCost(ccost.getPaintCost().multiply(cvo.getTotalNum()));
cvo.setDirectManualProductionCost(ccost.getDirectManualProductionCost().multiply(cvo.getTotalNum()));
cvo.setTotalDirectManualProductionCost(ccost.getDirectManualProductionCost());
cvo.setAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost());
cvo.setTotalAuxiliaryManufacturingCost(ccost.getAuxiliaryManufacturingCost().multiply(cvo.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());
}
}
pvo.getChildren().add(cvo);
EBomParentEntity cparent = ebomService.getParent(child.getMaterialNo());
if (Objects.nonNull(cparent)) {
buildMultilayerChildren(cparent.getRowId(), cvo, materials, datas);
if (recursion) {
EBomParentEntity cparent = ebomService.getParent(child.getMaterialNo());
if (Objects.nonNull(cparent)) {
buildMultilayerChildren(cparent.getRowId(), cvo, materials, datas, recursion);
}
}
});
}
@ -180,21 +150,31 @@ public class ProductCostAnalysisService {
EBomParentEntity parent = ebomService.getParent(materialNo);
HighValuePurchasedPartsVO vo = new HighValuePurchasedPartsVO();
buildHighValuePurchasedParts(parent.getRowId(), vo, BigDecimal.ONE, price, datas);
List<EBomDTO> materials = materialMainService.getInfos(vo.getCosts().stream().map(MaterialCostVO::getMaterialNo).collect(Collectors.toSet()));
vo.getCosts().parallelStream().forEach(v -> {
EBomDTO cpm = materials.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), v.getMaterialNo())).findFirst().orElse(null);
if (Objects.nonNull(cpm)) {
v.setMaterialDesc(cpm.getMaterialDesc());
v.setMaterialCategoryName(cpm.getCategoryName());
v.setMaterialUnit(cpm.getMaterialUnit());
v.setMaterialRowId(cpm.getMaterialRowId());
v.setRelCategoryCode(cpm.getRelCategoryCode());
v.setInventory(cpm.getInventory());
v.setLeadTime(cpm.getLeadTime());
Set<String> materialNos = vo.getCosts().stream().map(MaterialCostVO::getMaterialNo).collect(Collectors.toSet());
if (CollectionUtil.isNotEmpty(materialNos)) {
List<EBomDTO> materials = materialMainService.getInfos(materialNos);
Iterator<MaterialCostVO> iterator = vo.getCosts().iterator();
while (iterator.hasNext()) {
MaterialCostVO element = iterator.next();
EBomDTO cpm = materials.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), element.getMaterialNo()))
.findFirst()
.orElse(null);
if (Objects.nonNull(cpm) && cpm.getMaterialPrice().compareTo(price) > 0) {
element.setMaterialDesc(cpm.getMaterialDesc());
element.setMaterialCategoryName(cpm.getCategoryName());
element.setMaterialUnit(cpm.getMaterialUnit());
element.setMaterialRowId(cpm.getMaterialRowId());
element.setRelCategoryCode(cpm.getRelCategoryCode());
element.setInventory(cpm.getInventory());
element.setLeadTime(cpm.getLeadTime());
element.setPrice(cpm.getMaterialPrice());
} else {
iterator.remove();
}
}
});
vo.getCosts().sort(Comparator.comparing(MaterialCostVO::getPrice).reversed());
vo.setTotalCost(vo.getCosts().stream().map(MaterialCostVO::getTotalPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
vo.getCosts().sort(Comparator.comparing(MaterialCostVO::getPrice).reversed());
vo.setTotalCost(vo.getCosts().stream().map(MaterialCostVO::getTotalPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
}
return vo;
}
@ -206,13 +186,14 @@ public class ProductCostAnalysisService {
if (Objects.isNull(ccost)) {
log.error("没有找到{}的缓存数据", child.getMaterialNo());
} else {
if (ccost.isPurchasedParts() && ccost.getTotalCost().compareTo(price) >= 0) {
if (ccost.isPurchasedParts()) {
MaterialCostVO cvo;
cvo = pvo.getCosts().stream().filter(v -> StrUtil.equals(v.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
if (Objects.isNull(cvo)) {
cvo = new MaterialCostVO();
cvo.setMaterialNo(child.getMaterialNo());
cvo.setPrice(ccost.getTotalCost());
cvo.setTotalPrice(ccost.getTotalCost().multiply(tnum));
//cvo.setPrice(ccost.getTotalCost());
cvo.setNum(tnum);
pvo.getCosts().add(cvo);
} else {
@ -473,17 +454,20 @@ public class ProductCostAnalysisService {
ManufactureCostVO manufactureCostVO = new ManufactureCostVO();
List<NameCostInfoVO> nameCostInfoVOS = new ArrayList<>();
//油漆费用
BigDecimal manufactureCostTotal = cost.getProductionCosts().stream().map(ProductionCostDTO::getCost).reduce(BigDecimal.ZERO, BigDecimal::add)
.add(cost.getPaintCost());
NameCostInfoVO paintNameCostInfoVO = new NameCostInfoVO();
paintNameCostInfoVO.setName("油漆费用");
paintNameCostInfoVO.setCost(cost.getPaintCost());
BigDecimal manufactureCostTotal = paintNameCostInfoVO.getCost();
paintNameCostInfoVO.setRatio(calculateRatio(cost.getPaintCost(), manufactureCostTotal));
nameCostInfoVOS.add(paintNameCostInfoVO);
if (CollectionUtil.isNotEmpty(cost.getProductionCosts())) {
manufactureCostTotal = BigDecimalUtil.multiply(cost.getProductionCosts().stream().map(ProductionCostDTO::getCost).toArray(BigDecimal[]::new));
BigDecimal finalManufactureCostTotal = manufactureCostTotal;
nameCostInfoVOS.addAll(cost.getProductionCosts().stream().map(c -> new NameCostInfoVO().setName(c.getName()).setCost(c.getCost()).setRatio(calculateRatio(c.getCost(), finalManufactureCostTotal))).collect(Collectors.toList()));
}
paintNameCostInfoVO.setRatio(calculateRatio(paintNameCostInfoVO.getCost(), manufactureCostTotal));
cost.getProductionCosts().forEach(pc -> {
nameCostInfoVOS.add(new NameCostInfoVO()
.setName(pc.getName())
.setCost(pc.getCost())
.setRatio(calculateRatio(pc.getCost(), manufactureCostTotal))
);
});
manufactureCostVO.setTotalCost(manufactureCostTotal);
manufactureCostVO.setCosts(nameCostInfoVOS);
vo.setManufactureCost(manufactureCostVO);
@ -494,7 +478,7 @@ public class ProductCostAnalysisService {
if (BigDecimal.ZERO.compareTo(total) == 0) {
return "-%";
}
return BigDecimalUtil.divide(v1, total).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP)
return BigDecimalUtil.divide(v1, total).multiply(BigDecimal.valueOf(100)).setScale(3, RoundingMode.HALF_UP)
.stripTrailingZeros().toPlainString() + "%";
}
}

View File

@ -9,7 +9,8 @@
INNER JOIN t_process_workcenter w ON w.working_type = t.`code`
INNER JOIN t_process_route_task_processes r ON r.work_center = w.work_center
INNER JOIN t_process_route_task rt ON r.task_row_id = rt.row_id
WHERE rt.material_no = #{materialNo}
WHERE w.factory = '1010'
AND rt.material_no = #{materialNo}
GROUP BY rt.material_no, t.`name`
</select>
</mapper>