|
|
|
@ -124,19 +124,114 @@ public class QuoteDetailServiceImpl extends ServiceImpl<QuoteDetailMapper, Quote |
|
|
|
public Map<String, Object> queryQuoteDetailCost(QuoteDetail quoteDetail) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
// 1、工具成本 |
|
|
|
QuoteDetailTool tool = new QuoteDetailTool(); |
|
|
|
tool.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
List<QuoteDetailTool> toolList = quoteDetailToolService.queryQuoteDetailTool(tool); |
|
|
|
BigDecimal toolCost = new BigDecimal(0); |
|
|
|
for (QuoteDetailTool quoteDetailTool : toolList) { |
|
|
|
toolCost = toolCost.add(quoteDetailTool.getQuoteUnitCost()); |
|
|
|
} |
|
|
|
BigDecimal toolCost = computedToolCost(quoteDetail.getId()); |
|
|
|
// 2、其他成本 |
|
|
|
QuoteDetailAttribute attribute = new QuoteDetailAttribute(); |
|
|
|
attribute.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
List<QuoteDetailAttribute> attributeList = quoteDetailAttributeService.queryQuoteDetailAttribute(attribute); |
|
|
|
// 2-1、包装成本 |
|
|
|
BigDecimal packCost = new BigDecimal(0); |
|
|
|
BigDecimal packCost = computedPackCost(attributeList); |
|
|
|
// 2-2、运输成本 |
|
|
|
BigDecimal shippingCost = computedShippingCost(attributeList); |
|
|
|
QuoteDetailBomTree one = quoteDetailBomTreeService.lambdaQuery() |
|
|
|
.eq(QuoteDetailBomTree::getQuoteDetailId, quoteDetail.getId()) |
|
|
|
.eq(QuoteDetailBomTree::getParentId, 0L).one(); |
|
|
|
|
|
|
|
// 3、工艺成本 |
|
|
|
BigDecimal labourCost = BigDecimal.ZERO; |
|
|
|
BigDecimal machineCost = BigDecimal.ZERO; |
|
|
|
BigDecimal manufactureCost = BigDecimal.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
Map<Long, List<QuoteDetailRouting>> routingMap = new HashMap<>(); |
|
|
|
if (Objects.nonNull(one)){ |
|
|
|
// 工艺 |
|
|
|
QuoteDetailRouting routing = new QuoteDetailRouting(); |
|
|
|
routing.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
routing.setIsAllRouting(true); |
|
|
|
routing.setTreeId(one.getId()); |
|
|
|
List<QuoteDetailRouting> routingList = quoteDetailRoutingService.queryQuoteDetailRouting(routing); |
|
|
|
for (QuoteDetailRouting quoteDetailRouting : routingList) { |
|
|
|
// labourCost = labourCost.add(quoteDetailRouting.getTotalLaborCost()); |
|
|
|
machineCost = machineCost.add(quoteDetailRouting.getTotalMachCost()); |
|
|
|
manufactureCost = manufactureCost.add(quoteDetailRouting.getTotalManCost()); |
|
|
|
} |
|
|
|
|
|
|
|
routingMap = routingList.stream().collect(Collectors.groupingBy(QuoteDetailRouting::getTreeId)); |
|
|
|
} |
|
|
|
|
|
|
|
// 计算 tree 参数 |
|
|
|
List<QuoteDetailBomTree> list = quoteDetailBomTreeService.lambdaQuery() |
|
|
|
.eq(QuoteDetailBomTree::getQuoteDetailId,quoteDetail.getId()) |
|
|
|
.orderByDesc(QuoteDetailBomTree::getLevel) |
|
|
|
.list(); |
|
|
|
// 计算 |
|
|
|
updateQuoteDetailBomTree(list); |
|
|
|
// 开始计算 Routing |
|
|
|
for (QuoteDetailBomTree bomTree : list) { |
|
|
|
if (bomTree.getParentId().equals(0L)){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 计算具体人工成本 |
|
|
|
List<QuoteDetailRouting> routings = routingMap.get(bomTree.getId()); |
|
|
|
BigDecimal cost1 = BigDecimal.ZERO; |
|
|
|
for (QuoteDetailRouting routing : routings) { |
|
|
|
cost1 = cost1.add(routing.getTotalLaborCost()); |
|
|
|
} |
|
|
|
BigDecimal usage = BigDecimal.ONE; |
|
|
|
BigDecimal yield = BigDecimal.ONE; |
|
|
|
for (QuoteDetailBomTree tree : list) { |
|
|
|
if (tree.getLevel() >= bomTree.getLevel()){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
List<QuoteDetailBom> boms = quoteDetailBomService.lambdaQuery().eq(QuoteDetailBom::getTreeId, tree.getParentId()).eq(QuoteDetailBom::getComponentPart, tree.getPartNo()).list(); |
|
|
|
for (QuoteDetailBom bom : boms) { |
|
|
|
usage = usage.multiply(bom.getQtyPerAssembly()); |
|
|
|
} |
|
|
|
if (Objects.isNull(tree.getYield()) || tree.getYield().compareTo(BigDecimal.ZERO) == 0){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
yield = yield.divide(tree.getYield().divide(BigDecimal.valueOf(100),6,RoundingMode.HALF_UP),6,RoundingMode.HALF_UP); |
|
|
|
} |
|
|
|
cost1 = cost1.multiply(usage); |
|
|
|
cost1 = cost1.divide(yield,6,RoundingMode.HALF_UP); |
|
|
|
|
|
|
|
labourCost = labourCost.add(cost1); |
|
|
|
} |
|
|
|
|
|
|
|
// 4、材料成本 |
|
|
|
BigDecimal unitQuotePrice = computedPartCost(one).get("unitQuotePrice"); // 标准报价成本 |
|
|
|
BigDecimal actualQuotePrice = computedPartCost(one).get("actualQuotePrice"); // 实际报价成本 |
|
|
|
BigDecimal quotePrice = computedPartCost(one).get("quotePrice"); // 报价成本 |
|
|
|
|
|
|
|
|
|
|
|
// 传入map |
|
|
|
map.put("toolCost", toolCost); |
|
|
|
map.put("packCost", packCost); |
|
|
|
map.put("shippingCost", shippingCost); |
|
|
|
map.put("otherCost", packCost.add(shippingCost)); |
|
|
|
map.put("unitQuotePrice",unitQuotePrice); |
|
|
|
map.put("actualQuotePrice",actualQuotePrice); |
|
|
|
map.put("quoteCost",quotePrice); |
|
|
|
map.put("labourCost",labourCost); |
|
|
|
map.put("machineCost",machineCost); |
|
|
|
map.put("manufactureCost",manufactureCost); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
private BigDecimal computedToolCost(Long quoteDetailId){ |
|
|
|
BigDecimal toolCost = BigDecimal.ZERO; |
|
|
|
QuoteDetailTool tool = new QuoteDetailTool(); |
|
|
|
tool.setQuoteDetailId(quoteDetailId); |
|
|
|
List<QuoteDetailTool> toolList = quoteDetailToolService.queryQuoteDetailTool(tool); |
|
|
|
for (QuoteDetailTool quoteDetailTool : toolList) { |
|
|
|
toolCost = toolCost.add(quoteDetailTool.getQuoteUnitCost()); |
|
|
|
} |
|
|
|
return toolCost; |
|
|
|
} |
|
|
|
|
|
|
|
private BigDecimal computedPackCost(List<QuoteDetailAttribute> attributeList){ |
|
|
|
BigDecimal packCost = BigDecimal.ZERO; |
|
|
|
//每箱袋数 |
|
|
|
Optional<QuoteDetailAttribute> boxOfBags = attributeList.stream().filter(a -> "PACK-BAGS/BOX".equals(a.getItemNo())).findAny(); |
|
|
|
// 包装箱子成本 |
|
|
|
@ -163,36 +258,20 @@ public class QuoteDetailServiceImpl extends ServiceImpl<QuoteDetailMapper, Quote |
|
|
|
packCost = num1.add(num2); |
|
|
|
} |
|
|
|
} |
|
|
|
// 2-2、运输成本 |
|
|
|
BigDecimal shippingCost = BigDecimal.ZERO; |
|
|
|
//运输成本 |
|
|
|
Optional<QuoteDetailAttribute> shipCost = attributeList.stream().filter(a -> "SHIPPING-COST".equals(a.getItemNo())).findAny(); |
|
|
|
//交付数量 |
|
|
|
Optional<QuoteDetailAttribute> deliverQuantity = attributeList.stream().filter(a -> "SHIPPING-DELIVER-QUANTITY".equals(a.getItemNo())).findAny(); |
|
|
|
//运输其他成本 |
|
|
|
Optional<QuoteDetailAttribute> otherShipCost = attributeList.stream().filter(a -> "SHIPPING-OTHER-COST".equals(a.getItemNo())).findAny(); |
|
|
|
if (shipCost.isPresent() && deliverQuantity.isPresent()) { |
|
|
|
if (Objects.nonNull(shipCost.get().getNumValue()) && (Objects.nonNull(deliverQuantity.get().getNumValue()) && deliverQuantity.get().getNumValue().compareTo(new BigDecimal(0)) >= 1)) { |
|
|
|
shippingCost = shipCost.get().getNumValue().divide(deliverQuantity.get().getNumValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
// 3、材料成本 |
|
|
|
BigDecimal unitQuotePrice = BigDecimal.ZERO; // 标准报价成本 |
|
|
|
BigDecimal actualQuotePrice = BigDecimal.ZERO; // 实际报价成本 |
|
|
|
BigDecimal quotePrice = BigDecimal.ZERO; // 报价成本 |
|
|
|
QuoteDetailBomTree one = quoteDetailBomTreeService.lambdaQuery() |
|
|
|
.eq(QuoteDetailBomTree::getQuoteDetailId, quoteDetail.getId()) |
|
|
|
.eq(QuoteDetailBomTree::getParentId, 0L).one(); |
|
|
|
return packCost; |
|
|
|
} |
|
|
|
|
|
|
|
// 4 工艺成本 |
|
|
|
BigDecimal labourCost = BigDecimal.ZERO; |
|
|
|
BigDecimal machineCost = BigDecimal.ZERO; |
|
|
|
BigDecimal manufactureCost = BigDecimal.ZERO; |
|
|
|
|
|
|
|
private Map<String,BigDecimal> computedPartCost(QuoteDetailBomTree one){ |
|
|
|
Map<String,BigDecimal> map = new HashMap<>(); |
|
|
|
BigDecimal unitQuotePrice = BigDecimal.ZERO; |
|
|
|
BigDecimal actualQuotePrice = BigDecimal.ZERO; |
|
|
|
BigDecimal quotePrice = BigDecimal.ZERO; |
|
|
|
|
|
|
|
if (Objects.nonNull(one)){ |
|
|
|
// 材料 |
|
|
|
QuoteDetailBom bom = new QuoteDetailBom(); |
|
|
|
bom.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
bom.setQuoteDetailId(one.getQuoteDetailId()); |
|
|
|
bom.setAllTree(true); |
|
|
|
bom.setTreeId(one.getId()); |
|
|
|
List<QuoteDetailBom> list = quoteDetailBomService.queryQuoteDetailBom(bom); |
|
|
|
@ -201,25 +280,31 @@ public class QuoteDetailServiceImpl extends ServiceImpl<QuoteDetailMapper, Quote |
|
|
|
actualQuotePrice = actualQuotePrice.add(quoteDetailBom.getActualQuotePrice()); |
|
|
|
quotePrice = quotePrice.add(quoteDetailBom.getAllQuotePrice()); |
|
|
|
} |
|
|
|
// 工艺 |
|
|
|
QuoteDetailRouting routing = new QuoteDetailRouting(); |
|
|
|
routing.setQuoteDetailId(quoteDetail.getId()); |
|
|
|
routing.setIsAllRouting(true); |
|
|
|
routing.setTreeId(one.getId()); |
|
|
|
List<QuoteDetailRouting> routingList = quoteDetailRoutingService.queryQuoteDetailRouting(routing); |
|
|
|
for (QuoteDetailRouting quoteDetailRouting : routingList) { |
|
|
|
labourCost = labourCost.add(quoteDetailRouting.getTotalLaborCost()); |
|
|
|
machineCost = machineCost.add(quoteDetailRouting.getTotalMachCost()); |
|
|
|
manufactureCost = manufactureCost.add(quoteDetailRouting.getTotalManCost()); |
|
|
|
} |
|
|
|
map.put("unitQuotePrice",unitQuotePrice); |
|
|
|
map.put("actualQuotePrice",actualQuotePrice); |
|
|
|
map.put("quotePrice",quotePrice); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
private BigDecimal computedShippingCost(List<QuoteDetailAttribute> attributeList){ |
|
|
|
BigDecimal shippingCost = BigDecimal.ZERO; |
|
|
|
//运输成本 |
|
|
|
Optional<QuoteDetailAttribute> shipCost = attributeList.stream().filter(a -> "SHIPPING-COST".equals(a.getItemNo())).findAny(); |
|
|
|
//交付数量 |
|
|
|
Optional<QuoteDetailAttribute> deliverQuantity = attributeList.stream().filter(a -> "SHIPPING-DELIVER-QUANTITY".equals(a.getItemNo())).findAny(); |
|
|
|
//运输其他成本 |
|
|
|
Optional<QuoteDetailAttribute> otherShipCost = attributeList.stream().filter(a -> "SHIPPING-OTHER-COST".equals(a.getItemNo())).findAny(); |
|
|
|
if (shipCost.isPresent() && deliverQuantity.isPresent()) { |
|
|
|
if (Objects.nonNull(shipCost.get().getNumValue()) && (Objects.nonNull(deliverQuantity.get().getNumValue()) && deliverQuantity.get().getNumValue().compareTo(new BigDecimal(0)) >= 1)) { |
|
|
|
shippingCost = shipCost.get().getNumValue().divide(deliverQuantity.get().getNumValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
return shippingCost; |
|
|
|
} |
|
|
|
|
|
|
|
// 计算 tree 参数 |
|
|
|
// 1、获取当前 quoteDetail的 BOMTree |
|
|
|
List<QuoteDetailBomTree> list = quoteDetailBomTreeService.lambdaQuery() |
|
|
|
.eq(QuoteDetailBomTree::getQuoteDetailId, quoteDetail.getId()) |
|
|
|
.orderByDesc(QuoteDetailBomTree::getLevel) |
|
|
|
.list(); |
|
|
|
|
|
|
|
private void updateQuoteDetailBomTree(List<QuoteDetailBomTree> list){ |
|
|
|
for (QuoteDetailBomTree tree : list) { |
|
|
|
// 获取YieId |
|
|
|
BigDecimal yieldRate = quoteDetailBomTreeService.queryYieldRate(tree); |
|
|
|
@ -243,26 +328,18 @@ public class QuoteDetailServiceImpl extends ServiceImpl<QuoteDetailMapper, Quote |
|
|
|
for (QuoteDetailRouting quoteDetailRouting : routingList) { |
|
|
|
processTime = processTime.add(quoteDetailRouting.getLaborCycleTime()); |
|
|
|
} |
|
|
|
tree.setYield(yieldRate); |
|
|
|
tree.setBomUnYield(bomUnYield); |
|
|
|
tree.setBomYield(bomYield); |
|
|
|
tree.setProcessTime(processTime); |
|
|
|
quoteDetailBomTreeService.lambdaUpdate() |
|
|
|
.set(QuoteDetailBomTree::getYield,yieldRate) |
|
|
|
.set(QuoteDetailBomTree::getBomUnYield,bomUnYield) |
|
|
|
.set(QuoteDetailBomTree::getBomYield,bomYield) |
|
|
|
.set(QuoteDetailBomTree::getProcessTime, processTime.compareTo(BigDecimal.ZERO) == 0 ? null : processTime) |
|
|
|
.set(QuoteDetailBomTree::getYield,tree.getYield()) |
|
|
|
.set(QuoteDetailBomTree::getBomUnYield,tree.getBomUnYield()) |
|
|
|
.set(QuoteDetailBomTree::getBomYield,tree.getBomYield()) |
|
|
|
.set(QuoteDetailBomTree::getProcessTime, tree.getProcessTime().compareTo(BigDecimal.ZERO) == 0 ? null : tree.getProcessTime()) |
|
|
|
.eq(QuoteDetailBomTree::getId,tree.getId()) |
|
|
|
.update(); |
|
|
|
} |
|
|
|
// 传入map |
|
|
|
map.put("toolCost", toolCost); |
|
|
|
map.put("packCost", packCost); |
|
|
|
map.put("shippingCost", shippingCost); |
|
|
|
map.put("otherCost", packCost.add(shippingCost)); |
|
|
|
map.put("unitQuotePrice",unitQuotePrice); |
|
|
|
map.put("actualQuotePrice",actualQuotePrice); |
|
|
|
map.put("quoteCost",quotePrice); |
|
|
|
map.put("labourCost",labourCost); |
|
|
|
map.put("machineCost",machineCost); |
|
|
|
map.put("manufactureCost",manufactureCost); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|