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") @GetMapping("getBomCostSingleLayer")
@ApiOperation("获取Bom组件成本(单层)") @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)); return ResultVO.success(productCostAnalysisService.getBomCostSingleLayer(materialNo));
} }

View File

@ -1,5 +1,15 @@
package com.nflg.product.technology.constant; package com.nflg.product.technology.constant;
import java.util.Arrays;
import java.util.List;
public class BomConstant { public class BomConstant {
public static final String PROJECT_TYPE_TEMPORARY = "T"; 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 steelsCost = BigDecimal.ZERO;
/**
* 损耗成本
*/
private BigDecimal wasteCost = BigDecimal.ZERO;
/** /**
* 外购件成本 * 外购件成本
*/ */
@ -82,14 +86,16 @@ public class EBomCostCacheDTO implements Serializable {
private String categoryCode; private String categoryCode;
private boolean hasChildren;
/** /**
* 材料成本 * 材料成本
*/ */
@JsonIgnore @JsonIgnore
private BigDecimal materialCost; private BigDecimal materialCost;
public BigDecimal getMaterialCost() { 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; private BigDecimal totalCost;
@ApiModelProperty("单件材料成本") @ApiModelProperty("单件材料成本")
@JsonFormat(pattern = "#.##") private String materialCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal materialCost;
@ApiModelProperty("材料成本") @ApiModelProperty("材料成本")
@JsonFormat(pattern = "#.##") private String totalMaterialCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalMaterialCost;
@ApiModelProperty("单件油漆成本") @ApiModelProperty("单件油漆成本")
@JsonFormat(pattern = "#.##") private String paintCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal paintCost;
@ApiModelProperty("油漆成本") @ApiModelProperty("油漆成本")
@JsonFormat(pattern = "#.##") private String totalPaintCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalPaintCost;
@ApiModelProperty("单件标准人工工资") @ApiModelProperty("单件标准人工工资")
@JsonFormat(pattern = "#.##") private String directManualProductionCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal directManualProductionCost;
@ApiModelProperty("标准人工工资") @ApiModelProperty("标准人工工资")
@JsonFormat(pattern = "#.##") private String totalDirectManualProductionCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalDirectManualProductionCost;
@ApiModelProperty("单件辅助费用") @ApiModelProperty("单件辅助费用")
@JsonFormat(pattern = "#.##") private String auxiliaryManufacturingCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal auxiliaryManufacturingCost;
@ApiModelProperty("辅助费用") @ApiModelProperty("辅助费用")
@JsonFormat(pattern = "#.##") private String totalAuxiliaryManufacturingCost = "-";
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal totalAuxiliaryManufacturingCost;
@ApiModelProperty("子物料列表") @ApiModelProperty("子物料列表")
private List<BomCostMultilayerVO> children = new ArrayList<>(); private List<BomCostMultilayerVO> children = new ArrayList<>();

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

View File

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

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

View File

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

View File

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

View File

@ -1,7 +1,6 @@
package com.nflg.product.technology.service; package com.nflg.product.technology.service;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.nflg.product.technology.constant.BomConstant; import com.nflg.product.technology.constant.BomConstant;
import com.nflg.product.technology.pojo.BomCostCalculateConfig; 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 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) { public List<EBomCostCacheDTO> calculate(String materialNo) {
VUtils.isTure(StrUtil.isBlank(materialNo)).throwMessage("物料编号不能为空"); VUtils.isTure(StrUtil.isBlank(materialNo)).throwMessage("物料编号不能为空");
List<EBomDTO> datas = new ArrayList<>(); List<EBomDTO> datas = new ArrayList<>();
@ -112,26 +106,30 @@ public class BomCostCalculateService {
cdto.setPaintCost(calculatePaintCost(dto)); cdto.setPaintCost(calculatePaintCost(dto));
cdto.setProductionCosts(calculateProductionCosts(dto, config, workingHours)); cdto.setProductionCosts(calculateProductionCosts(dto, config, workingHours));
if (CollectionUtil.isEmpty(children)) { 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()) { if (cdto.isPurchasedParts()) {
// 外购件只计算采购成本 // 外购件只计算采购成本
cdto.setPurchasedPartsCost(calculatePurchasedPartsCost(dto)); cdto.setPurchasedPartsCost(calculatePurchasedPartsCost(dto));
} else { } else {
// 非外购件计算材料成本和制作成本 // 非外购件计算材料成本和制作成本
// 计算制作成本 // 计算材料成本
cdto.setSteelsCost(calculateSteelsCost(dto)); cdto.setSteelsCost(calculateSteelsCost(dto));
// 计算损耗成本
cdto.setWasteCost(calculateWasteCost(dto));
} }
} else { } else {
cdto.setHasChildren(true);
cdto.setPurchasedParts(false); cdto.setPurchasedParts(false);
//计算子级成本 //计算子级成本
List<EBomCostCacheDTO> childrenCost = children.parallelStream() List<EBomCostCacheDTO> childrenCost = children.parallelStream()
.map(c -> calculateBom(c, datas, config, result)) .map(c -> calculateBom(c, datas, config, result))
.collect(Collectors.toList()); .collect(Collectors.toList());
List<ProductionCostDTO> productionCosts = new ArrayList<>();
for (EBomCostCacheDTO c : childrenCost) { for (EBomCostCacheDTO c : childrenCost) {
EBomDTO dto1 = children.stream().filter(cc -> StrUtil.equals(cc.getMaterialNo(), c.getMaterialNo())).findFirst().orElse(null); 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.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.setPurchasedPartsCost(cdto.getPurchasedPartsCost().add(c.getPurchasedPartsCost().multiply(dto1.getNum())));
cdto.setPieceRateSalary(cdto.getPieceRateSalary().add(c.getPieceRateSalary().multiply(dto1.getNum()))); cdto.setPieceRateSalary(cdto.getPieceRateSalary().add(c.getPieceRateSalary().multiply(dto1.getNum())));
cdto.setWelfareExpenses(cdto.getWelfareExpenses().add(c.getWelfareExpenses().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.setAuxiliaryDepartmentLaborCost(cdto.getAuxiliaryDepartmentLaborCost().add(c.getAuxiliaryDepartmentLaborCost().multiply(dto1.getNum())));
cdto.setAuxiliaryDepartmentExpenses(cdto.getAuxiliaryDepartmentExpenses().add(c.getAuxiliaryDepartmentExpenses().multiply(dto1.getNum()))); cdto.setAuxiliaryDepartmentExpenses(cdto.getAuxiliaryDepartmentExpenses().add(c.getAuxiliaryDepartmentExpenses().multiply(dto1.getNum())));
cdto.setPaintCost(cdto.getPaintCost().add(c.getPaintCost().multiply(dto1.getNum()))); cdto.setPaintCost(cdto.getPaintCost().add(c.getPaintCost().multiply(dto1.getNum())));
if (CollectionUtil.isNotEmpty(cdto.getProductionCosts())) { if (CollectionUtil.isNotEmpty(c.getProductionCosts())) {
cdto.getProductionCosts().forEach(pc -> { c.getProductionCosts().forEach(pc -> {
ProductionCostDTO pdto = productionCosts.parallelStream() ProductionCostDTO pdto = cdto.getProductionCosts().parallelStream()
.filter(p -> StrUtil.equals(p.getName(), pc.getName())) .filter(p -> StrUtil.equals(p.getName(), pc.getName()))
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (Objects.isNull(pdto)) { if (Objects.isNull(pdto)) {
pdto = new ProductionCostDTO(); pdto = new ProductionCostDTO();
pdto.setName(pc.getName()); pdto.setName(pc.getName());
productionCosts.add(pdto); cdto.getProductionCosts().add(pdto);
} }
pdto.setCost(pdto.getCost().add(pc.getCost().multiply(dto1.getNum()))); 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) { private List<ProductionCostDTO> calculateProductionCosts(EBomDTO d, BomCostCalculateConfig config, List<WorkingHourDTO> workHours) {
List<ProductionCostDTO> productionCosts = new ArrayList<>(); 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()) { for (VirtualWorkingItemVO vw : config.getVirtualWorkings()) {
ProductionCostDTO dto = new ProductionCostDTO(); ProductionCostDTO dto = new ProductionCostDTO();
dto.setName(vw.getWorkingTypeName()); dto.setName(vw.getWorkingTypeName());
hourlyWages = Optional.ofNullable(config.getManday().getHourlyWages()).orElse(BigDecimal.ZERO); BigDecimal hourlyWages = Optional.ofNullable(config.getManday().getHourlyWages()).orElse(BigDecimal.ZERO);
benefit = Optional.ofNullable(config.getManday().getBenefit()).orElse(BigDecimal.ZERO); BigDecimal benefit = Optional.ofNullable(config.getManday().getBenefit()).orElse(BigDecimal.ZERO);
auxiliaryMaterialsAndConsumables = Optional.ofNullable(vw.getConsumablesFee()).orElse(BigDecimal.ZERO); BigDecimal auxiliaryMaterialsAndConsumables = Optional.ofNullable(vw.getConsumablesFee()).orElse(BigDecimal.ZERO);
feeEquipmentDepreciation = Optional.ofNullable(vw.getEquipmentDepreciationFee()).orElse(BigDecimal.ZERO); BigDecimal feeEquipmentDepreciation = Optional.ofNullable(vw.getEquipmentDepreciationFee()).orElse(BigDecimal.ZERO);
feeWorkshopLaborCost = Optional.ofNullable(vw.getWorkshopLaborFee()).orElse(BigDecimal.ZERO); BigDecimal feeWorkshopLaborCost = Optional.ofNullable(vw.getWorkshopLaborFee()).orElse(BigDecimal.ZERO);
feeWorkshopOffice = Optional.ofNullable(vw.getWorkshopOfficeFee()).orElse(BigDecimal.ZERO); BigDecimal feeWorkshopOffice = Optional.ofNullable(vw.getWorkshopOfficeFee()).orElse(BigDecimal.ZERO);
auxiliaryDepartmentLaborCosts = Optional.ofNullable(vw.getAssistantLaborFee()).orElse(BigDecimal.ZERO); BigDecimal auxiliaryDepartmentLaborCosts = Optional.ofNullable(vw.getAssistantLaborFee()).orElse(BigDecimal.ZERO);
assistantFee = Optional.ofNullable(vw.getAssistantFee()).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) dto.setCost(hourlyWages.add(benefit).add(auxiliaryMaterialsAndConsumables).add(feeEquipmentDepreciation)
.add(feeEquipmentDepreciation).add(feeWorkshopLaborCost).add(feeWorkshopOffice) .add(feeWorkshopLaborCost).add(feeWorkshopOffice).add(auxiliaryDepartmentLaborCosts).add(assistantFee)
.add(auxiliaryDepartmentLaborCosts).add(assistantFee) .multiply(gs));
.multiply(getGsForWorkingType(d, workHours, vw)));
productionCosts.add(dto); productionCosts.add(dto);
if (dto.getCost().compareTo(BigDecimal.ZERO) > 0) { 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; return productionCosts;
@ -210,11 +202,7 @@ public class BomCostCalculateService {
private BigDecimal calculatePaintCost(EBomDTO dto) { private BigDecimal calculatePaintCost(EBomDTO dto) {
PaintCostConfigEntity entity = paintCostConfigService.getCost(dto.getRawMaterialGroup()); PaintCostConfigEntity entity = paintCostConfigService.getCost(dto.getRawMaterialGroup());
if (Objects.nonNull(entity)) { return Optional.ofNullable(entity).map(PaintCostConfigEntity::getCost).orElse(BigDecimal.ZERO);
return NumberUtil.mul(dto.getNum(), entity.getCost());
} else {
return BigDecimal.ZERO;
}
} }
private BigDecimal calculateWorkshopOfficeExpenses(EBomDTO dto, BomCostCalculateConfig config, List<WorkingHourDTO> workHours) { private BigDecimal calculateWorkshopOfficeExpenses(EBomDTO dto, BomCostCalculateConfig config, List<WorkingHourDTO> workHours) {
@ -297,7 +285,18 @@ public class BomCostCalculateService {
private BigDecimal calculateSteelsCost(EBomDTO dto) { private BigDecimal calculateSteelsCost(EBomDTO dto) {
//是钢材 //是钢材
BigDecimal price = Optional.ofNullable(dto.getMaterialPrice()).orElse(BigDecimal.ZERO); 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; BigDecimal wastage = BigDecimal.ZERO;
if (StrUtil.isNotBlank(dto.getRawMaterialGroup())) { if (StrUtil.isNotBlank(dto.getRawMaterialGroup())) {
SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getRawMaterialGroup()); SteelsCostConfigEntity steelsCostConfigEntity = steelsCostConfigService.getCost(dto.getRawMaterialGroup());
@ -306,8 +305,7 @@ public class BomCostCalculateService {
wastage = Optional.ofNullable(steelsCostConfigEntity.getWastage()).orElse(BigDecimal.ZERO); wastage = Optional.ofNullable(steelsCostConfigEntity.getWastage()).orElse(BigDecimal.ZERO);
} }
} }
return price.multiply(BigDecimal.ONE.add(wastage.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP)) return price.multiply(wastage.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
.multiply(unitWeight));
} }
private String buildKey(EBomDTO dto) { private String buildKey(EBomDTO dto) {

View File

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

View File

@ -9,7 +9,8 @@
INNER JOIN t_process_workcenter w ON w.working_type = t.`code` 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_processes r ON r.work_center = w.work_center
INNER JOIN t_process_route_task rt ON r.task_row_id = rt.row_id 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` GROUP BY rt.material_no, t.`name`
</select> </select>
</mapper> </mapper>