|
|
|
|
@ -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;
|
|
|
|
|
|