|
|
|
@ -17,7 +17,9 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@ -211,20 +213,60 @@ public class QuoteDetailServiceImpl extends ServiceImpl<QuoteDetailMapper, Quote |
|
|
|
// 4、材料成本 |
|
|
|
BigDecimal actualQuotePrice = BigDecimal.ZERO; |
|
|
|
BigDecimal unitQuotePrice = BigDecimal.ZERO; |
|
|
|
// BigDecimal unitQuotePrice = Objects.isNull(tree.getBomYield()) ? tree.getBomUnYield() : tree.getBomYield(); // 标准报价成本 |
|
|
|
// BigDecimal actualQuotePrice = Objects.isNull(tree.getBomActualYield()) ? tree.getBomActualUnYield() : tree.getBomActualYield(); // 实际报价成本 |
|
|
|
|
|
|
|
// 获取BomTree 根据层级倒序 |
|
|
|
List<QuoteDetailBomTree> list = quoteDetailBomTreeService.lambdaQuery() |
|
|
|
.eq(QuoteDetailBomTree::getQuoteDetailId, quoteDetail.getId()) |
|
|
|
.orderByDesc(QuoteDetailBomTree::getLevel) |
|
|
|
.orderByDesc(QuoteDetailBomTree::getId) |
|
|
|
.list(); |
|
|
|
|
|
|
|
// 判断 报价BomTree是否存在 |
|
|
|
if (Objects.nonNull(one)) { |
|
|
|
Map<Long,List<QuoteDetailRouting>> routingMap = new HashMap<>(); |
|
|
|
//工艺 |
|
|
|
QuoteDetailRouting routing = new QuoteDetailRouting(); |
|
|
|
routing.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
routing.setIsAllRouting(true); |
|
|
|
routing.setTreeId(one.getId()); |
|
|
|
List<QuoteDetailRouting> routingList = quoteDetailRoutingService.queryQuoteDetailRouting(routing); |
|
|
|
// routingMap = routingList.stream().collect(Collectors.groupingBy(QuoteDetailRouting::getTreeId)); |
|
|
|
for (QuoteDetailRouting detailRouting : routingList) { |
|
|
|
labourCost = labourCost.add(detailRouting.getTotalLaborCost()); |
|
|
|
machineCost = machineCost.add(detailRouting.getTotalMachCost()); |
|
|
|
QuoteDetailRouting queryRouting = new QuoteDetailRouting(); |
|
|
|
queryRouting.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
queryRouting.setIsAllRouting(true); |
|
|
|
queryRouting.setTreeId(one.getId()); |
|
|
|
List<QuoteDetailRouting> routingList = quoteDetailRoutingService.queryQuoteDetailRouting(queryRouting); |
|
|
|
routingMap = routingList.stream().collect(Collectors.groupingBy(QuoteDetailRouting::getTreeId)); |
|
|
|
// 第一层BOM |
|
|
|
for (QuoteDetailBomTree bomTree : list) { |
|
|
|
// 计算具体人工成本 |
|
|
|
List<QuoteDetailRouting> routings = routingMap.get(bomTree.getId()); |
|
|
|
if (Objects.isNull(routings) || routings.isEmpty()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
BigDecimal bomLabourCost = BigDecimal.ZERO; |
|
|
|
BigDecimal bomMachineCost = BigDecimal.ZERO; |
|
|
|
// 获得 BomTree的 人工和制造成本 |
|
|
|
for (QuoteDetailRouting routing : routings) { |
|
|
|
bomLabourCost = bomLabourCost.add(routing.getTotalLaborCost()); |
|
|
|
bomMachineCost = bomMachineCost.add(routing.getTotalMachCost()); |
|
|
|
} |
|
|
|
log.info("当前BOM:{}", bomTree.getPartNo()); |
|
|
|
// 第二层BOM 目的是遍历所有的 BOM中 的 Part用量 |
|
|
|
long parentId = bomTree.getParentId(); |
|
|
|
for (QuoteDetailBomTree tree : list) { |
|
|
|
if (tree.getLevel() > bomTree.getLevel() || tree.getId() != parentId) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
parentId = tree.getParentId(); |
|
|
|
// 获取 层级比自己高的Bom 来获得BOM信息 用量和损耗 |
|
|
|
List<QuoteDetailBom> bomList = quoteDetailBomService.lambdaQuery().eq(QuoteDetailBom::getTreeId, tree.getParentId()).eq(QuoteDetailBom::getComponentPart, tree.getPartNo()).list(); |
|
|
|
BigDecimal qtyPerAssembly = BigDecimal.ONE; |
|
|
|
for (QuoteDetailBom bom : bomList) { |
|
|
|
BigDecimal yield = BigDecimal.ONE.subtract(bom.getShrinkageFactor().divide( BigDecimal.valueOf(100),16,RoundingMode.HALF_UP)); |
|
|
|
BigDecimal decimal = bom.getQtyPerAssembly().divide(yield, 16, RoundingMode.HALF_UP); |
|
|
|
qtyPerAssembly = qtyPerAssembly.multiply(decimal); |
|
|
|
} |
|
|
|
// 计算 损耗和用量得到的差异 |
|
|
|
bomLabourCost = bomLabourCost.multiply(qtyPerAssembly); |
|
|
|
bomMachineCost = bomMachineCost.multiply(qtyPerAssembly); |
|
|
|
} |
|
|
|
labourCost = labourCost.add(bomLabourCost); |
|
|
|
machineCost = machineCost.add(bomMachineCost); |
|
|
|
} |
|
|
|
// Bom计算 |
|
|
|
QuoteDetailBom bom = new QuoteDetailBom(); |
|
|
|
|