|
|
@@ -220,7 +220,7 @@ public class StandardCostService {
|
|
220
|
220
|
//单价乘以数量
|
|
221
|
221
|
BigDecimal totalCost = price.multiply(number);
|
|
222
|
222
|
//2.2计算出人工成本并存储到成本结果数据表中
|
|
223
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
|
|
|
223
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).costType(feeType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
|
|
224
|
224
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
225
|
225
|
}
|
|
226
|
226
|
}
|
|
|
@@ -459,23 +459,74 @@ public class StandardCostService {
|
|
459
|
459
|
String taskCode = flowTaskInfoVO.getTaskCode();
|
|
460
|
460
|
//获取流程id
|
|
461
|
461
|
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
|
|
462
|
|
- //1.查询出物料编号对应的下所有的BOM信息
|
|
463
|
|
- List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, null, flowInstanceId);
|
|
|
462
|
+ String costType = FeeTypeEnum.StandardCost.getCode();
|
|
|
463
|
+ //1.查询出根物料编号对应的下所有的BOM信息结果值
|
|
|
464
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getAllResultValueByTopMaterialNo(topMaterialCode, flowInstanceId);
|
|
464
|
465
|
//2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
|
|
465
|
466
|
//按照物料编号进行分组
|
|
466
|
467
|
Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
467
|
468
|
for (String key : materialNoMap.keySet()) {
|
|
468
|
469
|
List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
469
|
|
- //本阶成本
|
|
|
470
|
+ //按照费用类别进行分组
|
|
|
471
|
+ Map<String, List<AppSceneCostResultValue>> costTypeMap = appSceneCostResultValues.stream().filter(s -> s.getCostType() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getCostType));
|
|
|
472
|
+ //本阶标准成本
|
|
470
|
473
|
BigDecimal currentCost = new BigDecimal("0.0");
|
|
|
474
|
+ //1.本阶物料成本
|
|
|
475
|
+ BigDecimal materialCost = new BigDecimal("0.0");
|
|
|
476
|
+ //2.本阶人工成本
|
|
|
477
|
+ BigDecimal laborCost = new BigDecimal("0.0");
|
|
|
478
|
+ //3.本阶制造费(设备费)
|
|
|
479
|
+ BigDecimal equipmentCost = new BigDecimal("0.0");
|
|
|
480
|
+ //4.本阶制造费(辅料费用)
|
|
|
481
|
+ BigDecimal supplyMaterialCost = new BigDecimal("0.0");
|
|
|
482
|
+ //5.本阶制造费(水电费、燃动费)
|
|
|
483
|
+ BigDecimal driveCost = new BigDecimal("0.0");
|
|
|
484
|
+ //6.本阶制造费(其他制造费用)
|
|
|
485
|
+ BigDecimal otherCost = new BigDecimal("0.0");
|
|
|
486
|
+ //7.本阶制造费(物流费)
|
|
|
487
|
+ BigDecimal logisticsCost = new BigDecimal("0.0");
|
|
|
488
|
+ AppSceneCostResultValue currentMaterialCost = null;
|
|
|
489
|
+ //遍历所有费用类别计算本阶标准成本
|
|
471
|
490
|
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
|
491
|
+ if (j == 0) {
|
|
|
492
|
+ currentMaterialCost = appSceneCostResultValues.get(0);
|
|
|
493
|
+ }
|
|
472
|
494
|
AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
|
|
473
|
495
|
String countValue = appSceneCostResultValue.getCountValue();
|
|
474
|
496
|
if (countValue != null) {
|
|
475
|
497
|
currentCost = currentCost.add(new BigDecimal(countValue));
|
|
476
|
498
|
}
|
|
477
|
499
|
}
|
|
478
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(appSceneCostResultValues.get(0).getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).build();
|
|
|
500
|
+ //计算本阶各个费用类别费用
|
|
|
501
|
+ for (String feeType : costTypeMap.keySet()) {
|
|
|
502
|
+ List<AppSceneCostResultValue> appSceneCostResultValues1 = costTypeMap.get(feeType);
|
|
|
503
|
+ for (int m = 0; m < appSceneCostResultValues1.size(); m++) {
|
|
|
504
|
+ if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) {
|
|
|
505
|
+ materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
506
|
+ } else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) {
|
|
|
507
|
+ laborCost = laborCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
508
|
+ } else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
|
509
|
+ equipmentCost = equipmentCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
510
|
+ } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
|
511
|
+ supplyMaterialCost = supplyMaterialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
512
|
+ } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
|
513
|
+ driveCost = driveCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
514
|
+ } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
|
515
|
+ logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
516
|
+ } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
|
517
|
+ otherCost = otherCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
518
|
+ }
|
|
|
519
|
+ }
|
|
|
520
|
+ }
|
|
|
521
|
+ JSONObject costTypeDetail = new JSONObject();
|
|
|
522
|
+ costTypeDetail.put(FeeTypeEnum.MaterialCost.getCode(), materialCost.toString());
|
|
|
523
|
+ costTypeDetail.put(FeeTypeEnum.LaborCost.getCode(), laborCost.toString());
|
|
|
524
|
+ costTypeDetail.put(FeeTypeEnum.EquipmentFee.getCode(), equipmentCost.toString());
|
|
|
525
|
+ costTypeDetail.put(FeeTypeEnum.SupplyMaterialFee.getCode(), supplyMaterialCost.toString());
|
|
|
526
|
+ costTypeDetail.put(FeeTypeEnum.DriverFee.getCode(), driveCost.toString());
|
|
|
527
|
+ costTypeDetail.put(FeeTypeEnum.LogisticsFee.getCode(), logisticsCost.toString());
|
|
|
528
|
+ costTypeDetail.put(FeeTypeEnum.OtherFee.getCode(), otherCost.toString());
|
|
|
529
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(currentMaterialCost.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).costDetail(JSON.toJSONString(costTypeDetail)).costType(costType).build();
|
|
479
|
530
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
480
|
531
|
}
|
|
481
|
532
|
//3.计算出所有的单个物料的累计标准成本
|
|
|
@@ -494,10 +545,13 @@ public class StandardCostService {
|
|
494
|
545
|
* @param flowInstanceId
|
|
495
|
546
|
*/
|
|
496
|
547
|
private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
|
|
|
548
|
+ //父类对应的子节点(除了最上层节点)
|
|
497
|
549
|
Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
|
|
498
|
550
|
for (int i = 0; i < standardCostList.size(); i++) {
|
|
|
551
|
+ //当前节点及其对应的本阶成本
|
|
499
|
552
|
AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i);
|
|
500
|
553
|
BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue());
|
|
|
554
|
+ //循环计算出当前节点的累计成本
|
|
501
|
555
|
totalCost = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
|
|
502
|
556
|
oldAppSceneCostResultValue.setTotalValue(totalCost.toString());
|
|
503
|
557
|
standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
|
|
|
@@ -519,6 +573,7 @@ public class StandardCostService {
|
|
519
|
573
|
private static BigDecimal loopCount(AppSceneCostResultValue appSceneCostResultValue, Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap, String topMaterialCode, String taskType, String taskCode, String flowInstanceId, BigDecimal totalCost) {
|
|
520
|
574
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
521
|
575
|
if (parentMaterialNoMap.containsKey(marterialNo)) {
|
|
|
576
|
+ //获取当前节点的子节点并遍历
|
|
522
|
577
|
List<AppSceneCostResultValue> appSceneCostResultValues = parentMaterialNoMap.get(marterialNo);
|
|
523
|
578
|
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
524
|
579
|
AppSceneCostResultValue appSceneCostResultValue1 = appSceneCostResultValues.get(j);
|
|
|
@@ -526,7 +581,11 @@ public class StandardCostService {
|
|
526
|
581
|
if (countValue != null) {
|
|
527
|
582
|
totalCost = totalCost.add(new BigDecimal(countValue));
|
|
528
|
583
|
}
|
|
529
|
|
- loopCount(appSceneCostResultValue1, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
|
|
|
584
|
+ //判断当前子节点是否还有子节点
|
|
|
585
|
+ if (parentMaterialNoMap.containsKey(appSceneCostResultValue1.getMarterialNo())) {
|
|
|
586
|
+ //如果还有子节点则继续递归
|
|
|
587
|
+ loopCount(appSceneCostResultValue1, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
|
|
|
588
|
+ }
|
|
530
|
589
|
}
|
|
531
|
590
|
}
|
|
532
|
591
|
return totalCost;
|