|
|
@@ -14,16 +14,19 @@ import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext;
|
|
14
|
14
|
import lombok.extern.slf4j.Slf4j;
|
|
15
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
16
|
16
|
import org.springframework.stereotype.Service;
|
|
|
17
|
+import org.springframework.transaction.annotation.Transactional;
|
|
17
|
18
|
|
|
18
|
19
|
import javax.annotation.PostConstruct;
|
|
19
|
20
|
import java.math.BigDecimal;
|
|
20
|
21
|
import java.util.ArrayList;
|
|
|
22
|
+import java.util.Date;
|
|
21
|
23
|
import java.util.List;
|
|
22
|
24
|
import java.util.Map;
|
|
23
|
25
|
import java.util.stream.Collectors;
|
|
24
|
26
|
|
|
25
|
27
|
@Service
|
|
26
|
28
|
@Slf4j
|
|
|
29
|
+@Transactional
|
|
27
|
30
|
public class StandardCostService {
|
|
28
|
31
|
/**
|
|
29
|
32
|
* 物料BOM信息
|
|
|
@@ -469,145 +472,150 @@ public class StandardCostService {
|
|
469
|
472
|
* 5.标准成本计算任务
|
|
470
|
473
|
*/
|
|
471
|
474
|
public static void standardCostTask(TaskExecutionContext parameters) {
|
|
472
|
|
- //获取任务流程相关信息
|
|
473
|
|
- FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
|
|
474
|
|
- //获取最上层的物料号
|
|
475
|
|
- String topMaterialCode = flowTaskInfoVO.getTopMaterialCode();
|
|
476
|
|
- //获取任务类型
|
|
477
|
|
- String taskType = parameters.getTaskType();
|
|
478
|
|
- //获取任务代码
|
|
479
|
|
- String taskCode = flowTaskInfoVO.getTaskCode();
|
|
480
|
|
- //获取流程id
|
|
481
|
|
- String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
|
|
482
|
|
- String costType = FeeTypeEnum.StandardCost.getCode();
|
|
483
|
|
- //1.查询出根物料编号对应的下所有的BOM信息结果值
|
|
484
|
|
- List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getAllResultValueByTopMaterialNo(topMaterialCode, flowInstanceId);
|
|
485
|
|
- //2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
|
|
486
|
|
- //按照物料编号进行分组
|
|
487
|
|
- Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
488
|
|
- //遍历根物料下所有的物料进行该物料本阶成本和费用类别的统计
|
|
489
|
|
- for (String key : materialNoMap.keySet()) {
|
|
490
|
|
- List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
491
|
|
- //按照费用类别进行分组
|
|
492
|
|
- Map<String, List<AppSceneCostResultValue>> costTypeMap = appSceneCostResultValues.stream().filter(s -> s.getCostType() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getCostType));
|
|
493
|
|
- //【本阶标准成本】
|
|
494
|
|
- BigDecimal currentCost = new BigDecimal("0.0");
|
|
495
|
|
- //1.本阶物料成本
|
|
496
|
|
- BigDecimal materialCost = new BigDecimal("0.0");
|
|
497
|
|
- //2.本阶人工成本
|
|
498
|
|
- BigDecimal laborCost = new BigDecimal("0.0");
|
|
499
|
|
- //3.本阶制造费(设备费)
|
|
500
|
|
- BigDecimal equipmentCost = new BigDecimal("0.0");
|
|
501
|
|
- //4.本阶制造费(辅料费用)
|
|
502
|
|
- BigDecimal supplyMaterialCost = new BigDecimal("0.0");
|
|
503
|
|
- //5.本阶制造费(水电费、燃动费)
|
|
504
|
|
- BigDecimal driveCost = new BigDecimal("0.0");
|
|
505
|
|
- //6.本阶制造费(其他制造费用)
|
|
506
|
|
- BigDecimal otherCost = new BigDecimal("0.0");
|
|
507
|
|
- //7.本阶制造费(物流费)
|
|
508
|
|
- BigDecimal logisticsCost = new BigDecimal("0.0");
|
|
509
|
|
- //物料单价
|
|
510
|
|
- BigDecimal materialUnitPrice = new BigDecimal("0.0");
|
|
511
|
|
- //人员工时、小时费率
|
|
512
|
|
- BigDecimal laborHour = new BigDecimal("0.0");
|
|
513
|
|
- BigDecimal laborHourRate = new BigDecimal("0.0");
|
|
514
|
|
- //设备工时、小时费率
|
|
515
|
|
- BigDecimal equipmentHour = new BigDecimal("0.0");
|
|
516
|
|
- BigDecimal equipmentHourRate = new BigDecimal("0.0");
|
|
517
|
|
- //辅料工时、小时费率
|
|
518
|
|
- BigDecimal supplyMaterialHour = new BigDecimal("0.0");
|
|
519
|
|
- BigDecimal supplyMaterialHourRate = new BigDecimal("0.0");
|
|
520
|
|
- //燃动工时、小时费率
|
|
521
|
|
- BigDecimal driveHour = new BigDecimal("0.0");
|
|
522
|
|
- BigDecimal driveHourRate = new BigDecimal("0.0");
|
|
523
|
|
- //其他工时、小时费率
|
|
524
|
|
- BigDecimal otherHour = new BigDecimal("0.0");
|
|
525
|
|
- BigDecimal otherHourRate = new BigDecimal("0.0");
|
|
526
|
|
- AppSceneCostResultValue currentMaterialCost = null;
|
|
527
|
|
- //遍历所有费用类别计算本阶标准成本
|
|
528
|
|
- for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
529
|
|
- if (j == 0) {
|
|
530
|
|
- currentMaterialCost = appSceneCostResultValues.get(0);
|
|
531
|
|
- }
|
|
532
|
|
- AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
|
|
533
|
|
- String countValue = appSceneCostResultValue.getCountValue();
|
|
534
|
|
- if (countValue != null) {
|
|
535
|
|
- currentCost = currentCost.add(new BigDecimal(countValue));
|
|
|
475
|
+ try {
|
|
|
476
|
+ //获取任务流程相关信息
|
|
|
477
|
+ FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
|
|
|
478
|
+ //获取最上层的物料号
|
|
|
479
|
+ String topMaterialCode = flowTaskInfoVO.getTopMaterialCode();
|
|
|
480
|
+ //获取任务类型
|
|
|
481
|
+ String taskType = parameters.getTaskType();
|
|
|
482
|
+ //获取任务代码
|
|
|
483
|
+ String taskCode = flowTaskInfoVO.getTaskCode();
|
|
|
484
|
+ //获取流程id
|
|
|
485
|
+ String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
|
|
|
486
|
+ String costType = FeeTypeEnum.StandardCost.getCode();
|
|
|
487
|
+ //1.查询出根物料编号对应的下所有的BOM信息结果值
|
|
|
488
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getAllResultValueByTopMaterialNo(topMaterialCode, flowInstanceId);
|
|
|
489
|
+ //2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
|
|
|
490
|
+ //按照物料编号进行分组
|
|
|
491
|
+ Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
|
492
|
+ //遍历根物料下所有的物料进行该物料本阶成本和费用类别的统计
|
|
|
493
|
+ for (String key : materialNoMap.keySet()) {
|
|
|
494
|
+ List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
|
495
|
+ //按照费用类别进行分组
|
|
|
496
|
+ Map<String, List<AppSceneCostResultValue>> costTypeMap = appSceneCostResultValues.stream().filter(s -> s.getCostType() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getCostType));
|
|
|
497
|
+ //【本阶标准成本】
|
|
|
498
|
+ BigDecimal currentCost = new BigDecimal("0.0");
|
|
|
499
|
+ //1.本阶物料成本
|
|
|
500
|
+ BigDecimal materialCost = new BigDecimal("0.0");
|
|
|
501
|
+ //2.本阶人工成本
|
|
|
502
|
+ BigDecimal laborCost = new BigDecimal("0.0");
|
|
|
503
|
+ //3.本阶制造费(设备费)
|
|
|
504
|
+ BigDecimal equipmentCost = new BigDecimal("0.0");
|
|
|
505
|
+ //4.本阶制造费(辅料费用)
|
|
|
506
|
+ BigDecimal supplyMaterialCost = new BigDecimal("0.0");
|
|
|
507
|
+ //5.本阶制造费(水电费、燃动费)
|
|
|
508
|
+ BigDecimal driveCost = new BigDecimal("0.0");
|
|
|
509
|
+ //6.本阶制造费(其他制造费用)
|
|
|
510
|
+ BigDecimal otherCost = new BigDecimal("0.0");
|
|
|
511
|
+ //7.本阶制造费(物流费)
|
|
|
512
|
+ BigDecimal logisticsCost = new BigDecimal("0.0");
|
|
|
513
|
+ //物料单价
|
|
|
514
|
+ BigDecimal materialUnitPrice = new BigDecimal("0.0");
|
|
|
515
|
+ //人员工时、小时费率
|
|
|
516
|
+ BigDecimal laborHour = new BigDecimal("0.0");
|
|
|
517
|
+ BigDecimal laborHourRate = new BigDecimal("0.0");
|
|
|
518
|
+ //设备工时、小时费率
|
|
|
519
|
+ BigDecimal equipmentHour = new BigDecimal("0.0");
|
|
|
520
|
+ BigDecimal equipmentHourRate = new BigDecimal("0.0");
|
|
|
521
|
+ //辅料工时、小时费率
|
|
|
522
|
+ BigDecimal supplyMaterialHour = new BigDecimal("0.0");
|
|
|
523
|
+ BigDecimal supplyMaterialHourRate = new BigDecimal("0.0");
|
|
|
524
|
+ //燃动工时、小时费率
|
|
|
525
|
+ BigDecimal driveHour = new BigDecimal("0.0");
|
|
|
526
|
+ BigDecimal driveHourRate = new BigDecimal("0.0");
|
|
|
527
|
+ //其他工时、小时费率
|
|
|
528
|
+ BigDecimal otherHour = new BigDecimal("0.0");
|
|
|
529
|
+ BigDecimal otherHourRate = new BigDecimal("0.0");
|
|
|
530
|
+ AppSceneCostResultValue currentMaterialCost = null;
|
|
|
531
|
+ //遍历所有费用类别计算本阶标准成本
|
|
|
532
|
+ for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
|
533
|
+ if (j == 0) {
|
|
|
534
|
+ currentMaterialCost = appSceneCostResultValues.get(0);
|
|
|
535
|
+ }
|
|
|
536
|
+ AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
|
|
|
537
|
+ String countValue = appSceneCostResultValue.getCountValue();
|
|
|
538
|
+ if (countValue != null) {
|
|
|
539
|
+ currentCost = currentCost.add(new BigDecimal(countValue));
|
|
|
540
|
+ }
|
|
536
|
541
|
}
|
|
537
|
|
- }
|
|
538
|
|
- //计算本阶各个费用类别费用以及记录本阶物料的工时和小时费率
|
|
539
|
|
- for (String feeType : costTypeMap.keySet()) {
|
|
540
|
|
- List<AppSceneCostResultValue> appSceneCostResultValues1 = costTypeMap.get(feeType);
|
|
541
|
|
- for (int m = 0; m < appSceneCostResultValues1.size(); m++) {
|
|
542
|
|
- if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) {
|
|
543
|
|
- //物料成本
|
|
544
|
|
- materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
545
|
|
- //物料单价
|
|
546
|
|
- materialUnitPrice = appSceneCostResultValues1.get(m).getPriceOrRate();
|
|
547
|
|
- } else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) {
|
|
548
|
|
- //人工成本
|
|
549
|
|
- laborCost = laborCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
550
|
|
- //人工工时、小时费率
|
|
551
|
|
- laborHour = laborHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
552
|
|
- laborHourRate = laborHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
553
|
|
- } else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
554
|
|
- //设备费用
|
|
555
|
|
- equipmentCost = equipmentCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
556
|
|
- //设备工时、小时费率
|
|
557
|
|
- equipmentHour = equipmentHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
558
|
|
- equipmentHourRate = equipmentHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
559
|
|
- } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
560
|
|
- //辅料费用
|
|
561
|
|
- supplyMaterialCost = supplyMaterialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
562
|
|
- //辅料工时、小时费率
|
|
563
|
|
- supplyMaterialHour = supplyMaterialHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
564
|
|
- supplyMaterialHourRate = supplyMaterialHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
565
|
|
- } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
566
|
|
- //燃动费用
|
|
567
|
|
- driveCost = driveCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
568
|
|
- //燃动工时、小时费率
|
|
569
|
|
- driveHour = driveHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
570
|
|
- driveHourRate = driveHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
571
|
|
- } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
572
|
|
- //物流费用
|
|
573
|
|
- logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
574
|
|
- } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
575
|
|
- //其他费用
|
|
576
|
|
- otherCost = otherCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
577
|
|
- //其他工时、小时费率
|
|
578
|
|
- otherHour = otherHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
579
|
|
- otherHourRate = otherHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
542
|
+ //计算本阶各个费用类别费用以及记录本阶物料的工时和小时费率
|
|
|
543
|
+ for (String feeType : costTypeMap.keySet()) {
|
|
|
544
|
+ List<AppSceneCostResultValue> appSceneCostResultValues1 = costTypeMap.get(feeType);
|
|
|
545
|
+ for (int m = 0; m < appSceneCostResultValues1.size(); m++) {
|
|
|
546
|
+ if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) {
|
|
|
547
|
+ //物料成本
|
|
|
548
|
+ materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
549
|
+ //物料单价
|
|
|
550
|
+ materialUnitPrice = appSceneCostResultValues1.get(m).getPriceOrRate();
|
|
|
551
|
+ } else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) {
|
|
|
552
|
+ //人工成本
|
|
|
553
|
+ laborCost = laborCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
554
|
+ //人工工时、小时费率
|
|
|
555
|
+ laborHour = laborHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
556
|
+ laborHourRate = laborHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
557
|
+ } else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
|
558
|
+ //设备费用
|
|
|
559
|
+ equipmentCost = equipmentCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
560
|
+ //设备工时、小时费率
|
|
|
561
|
+ equipmentHour = equipmentHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
562
|
+ equipmentHourRate = equipmentHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
563
|
+ } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
|
564
|
+ //辅料费用
|
|
|
565
|
+ supplyMaterialCost = supplyMaterialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
566
|
+ //辅料工时、小时费率
|
|
|
567
|
+ supplyMaterialHour = supplyMaterialHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
568
|
+ supplyMaterialHourRate = supplyMaterialHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
569
|
+ } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
|
570
|
+ //燃动费用
|
|
|
571
|
+ driveCost = driveCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
572
|
+ //燃动工时、小时费率
|
|
|
573
|
+ driveHour = driveHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
574
|
+ driveHourRate = driveHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
575
|
+ } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
|
576
|
+ //物流费用
|
|
|
577
|
+ logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
578
|
+ } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
|
579
|
+ //其他费用
|
|
|
580
|
+ otherCost = otherCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
581
|
+ //其他工时、小时费率
|
|
|
582
|
+ otherHour = otherHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
583
|
+ otherHourRate = otherHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
584
|
+ }
|
|
580
|
585
|
}
|
|
581
|
586
|
}
|
|
|
587
|
+ //本阶不同费用类别成本统计
|
|
|
588
|
+ JSONObject currentLevelCostTypeDetail = new JSONObject();
|
|
|
589
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.MaterialCost.getCode(), materialCost);
|
|
|
590
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.LaborCost.getCode(), laborCost);
|
|
|
591
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.EquipmentFee.getCode(), equipmentCost);
|
|
|
592
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.SupplyMaterialFee.getCode(), supplyMaterialCost);
|
|
|
593
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.DriverFee.getCode(), driveCost);
|
|
|
594
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.LogisticsFee.getCode(), logisticsCost);
|
|
|
595
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.OtherFee.getCode(), otherCost);
|
|
|
596
|
+ //统计本阶不同费用类别工时、小时费率
|
|
|
597
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.MaterialUnitPrice.getCode(), materialUnitPrice);
|
|
|
598
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHour.getCode(), laborHour);
|
|
|
599
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHourRate.getCode(), laborHourRate);
|
|
|
600
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHour.getCode(), equipmentHour);
|
|
|
601
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHourRate.getCode(), equipmentHourRate);
|
|
|
602
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHour.getCode(), supplyMaterialHour);
|
|
|
603
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHourRate.getCode(), supplyMaterialHourRate);
|
|
|
604
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHour.getCode(), driveHour);
|
|
|
605
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHourRate.getCode(), driveHourRate);
|
|
|
606
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHour.getCode(), otherHour);
|
|
|
607
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHourRate.getCode(), otherHourRate);
|
|
|
608
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(currentMaterialCost.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).costDetail(JSON.toJSONString(currentLevelCostTypeDetail)).costType(costType).build();
|
|
|
609
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
582
|
610
|
}
|
|
583
|
|
- //本阶不同费用类别成本统计
|
|
584
|
|
- JSONObject currentLevelCostTypeDetail = new JSONObject();
|
|
585
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.MaterialCost.getCode(), materialCost);
|
|
586
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.LaborCost.getCode(), laborCost);
|
|
587
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.EquipmentFee.getCode(), equipmentCost);
|
|
588
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.SupplyMaterialFee.getCode(), supplyMaterialCost);
|
|
589
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.DriverFee.getCode(), driveCost);
|
|
590
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.LogisticsFee.getCode(), logisticsCost);
|
|
591
|
|
- currentLevelCostTypeDetail.put(FeeTypeEnum.OtherFee.getCode(), otherCost);
|
|
592
|
|
- //统计本阶不同费用类别工时、小时费率
|
|
593
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.MaterialUnitPrice.getCode(), materialUnitPrice);
|
|
594
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHour.getCode(), laborHour);
|
|
595
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHourRate.getCode(), laborHourRate);
|
|
596
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHour.getCode(), equipmentHour);
|
|
597
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHourRate.getCode(), equipmentHourRate);
|
|
598
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHour.getCode(), supplyMaterialHour);
|
|
599
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHourRate.getCode(), supplyMaterialHourRate);
|
|
600
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHour.getCode(), driveHour);
|
|
601
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHourRate.getCode(), driveHourRate);
|
|
602
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHour.getCode(), otherHour);
|
|
603
|
|
- currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHourRate.getCode(), otherHourRate);
|
|
604
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(currentMaterialCost.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).costDetail(JSON.toJSONString(currentLevelCostTypeDetail)).costType(costType).build();
|
|
605
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
611
|
+ //3.计算出所有的单个物料的累计标准成本
|
|
|
612
|
+ List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
|
|
|
613
|
+ //【累计成本】的计算
|
|
|
614
|
+ totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
|
|
|
615
|
+ } catch (Exception e) {
|
|
|
616
|
+ e.printStackTrace();
|
|
|
617
|
+ throw new RuntimeException("计算成本失败");
|
|
606
|
618
|
}
|
|
607
|
|
- //3.计算出所有的单个物料的累计标准成本
|
|
608
|
|
- List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
|
|
609
|
|
- //【累计成本】的计算
|
|
610
|
|
- totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
|
|
611
|
619
|
}
|
|
612
|
620
|
|
|
613
|
621
|
/**
|
|
|
@@ -620,48 +628,51 @@ public class StandardCostService {
|
|
620
|
628
|
* @param flowInstanceId
|
|
621
|
629
|
*/
|
|
622
|
630
|
private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
|
|
623
|
|
-
|
|
624
|
|
- List<AppSceneCostStandardDetail> costStandardDetails = new ArrayList<>();
|
|
625
|
|
- //父类对应的子节点(除了最上层节点)
|
|
626
|
|
- Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
|
|
627
|
|
- for (int i = 0; i < standardCostList.size(); i++) {
|
|
628
|
|
- //当前节点及其对应的本阶成本
|
|
629
|
|
- AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i);
|
|
630
|
|
- BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue());
|
|
631
|
|
- //循环计算出当前节点的累计成本
|
|
632
|
|
- String costDetail = oldAppSceneCostResultValue.getCostDetail();
|
|
633
|
|
- //查询当前节点各个类型的成本
|
|
634
|
|
- BigDecimal totalMaterialCost = new BigDecimal(0);
|
|
635
|
|
- BigDecimal totalLabourCost = new BigDecimal(0);
|
|
636
|
|
- BigDecimal totalEquipmentCost = new BigDecimal(0);
|
|
637
|
|
- BigDecimal totalSupplyMaterialCost = new BigDecimal(0);
|
|
638
|
|
- BigDecimal totalDriveCost = new BigDecimal(0);
|
|
639
|
|
- BigDecimal totalLogisticsCost = new BigDecimal(0);
|
|
640
|
|
- BigDecimal totalOtherCost = new BigDecimal(0);
|
|
641
|
|
- JSONObject costDetailJson = JSON.parseObject(costDetail);
|
|
642
|
|
- TotalResultValue hourOrRateResultValue = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, totalMaterialCost, totalLabourCost, totalEquipmentCost, totalSupplyMaterialCost, totalDriveCost, totalLogisticsCost, totalOtherCost, totalCost);
|
|
643
|
|
- costDetailJson.put(TotalCostEnum.TotalMaterialCost.getCode(), hourOrRateResultValue.getTotalMaterialCost());
|
|
644
|
|
- costDetailJson.put(TotalCostEnum.TotalLaborCost.getCode(), hourOrRateResultValue.getTotalLabourCost());
|
|
645
|
|
- costDetailJson.put(TotalCostEnum.TotalEquipmentFee.getCode(), hourOrRateResultValue.getTotalEquipmentCost());
|
|
646
|
|
- costDetailJson.put(TotalCostEnum.TotalSupplyMaterialFee.getCode(), hourOrRateResultValue.getTotalSupplyMaterialCost());
|
|
647
|
|
- costDetailJson.put(TotalCostEnum.TotalDriverFee.getCode(), hourOrRateResultValue.getTotalDriveCost());
|
|
648
|
|
- costDetailJson.put(TotalCostEnum.TotalLogisticsFee.getCode(), hourOrRateResultValue.getTotalLogisticsCost());
|
|
649
|
|
- costDetailJson.put(TotalCostEnum.TotalOtherFee.getCode(), hourOrRateResultValue.getTotalOtherCost());
|
|
650
|
|
- costDetailJson.put(TotalCostEnum.TotalStandardCost.getCode(), hourOrRateResultValue.getTotalCost());
|
|
651
|
|
- oldAppSceneCostResultValue.setCostDetail(costDetailJson.toJSONString());
|
|
652
|
|
- oldAppSceneCostResultValue.setTotalValue(hourOrRateResultValue.getTotalCost().toString());
|
|
653
|
|
- standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
|
|
654
|
|
- //构造单行成本查询记录
|
|
655
|
|
- AppSceneCostStandardDetail costStandardDetail = AppSceneCostStandardDetail.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).materialName(oldAppSceneCostResultValue.getMarterialNo()).parentMaterialNumber(oldAppSceneCostResultValue.getParentMarterialNo())
|
|
|
631
|
+ try {
|
|
|
632
|
+ List<AppSceneCostStandardDetail> costStandardDetails = new ArrayList<>();
|
|
|
633
|
+ //父类对应的子节点(除了最上层节点)
|
|
|
634
|
+ Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
|
|
|
635
|
+ for (int i = 0; i < standardCostList.size(); i++) {
|
|
|
636
|
+ //当前节点及其对应的本阶成本
|
|
|
637
|
+ AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i);
|
|
|
638
|
+ BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue());
|
|
|
639
|
+ //循环计算出当前节点的累计成本
|
|
|
640
|
+ String costDetail = oldAppSceneCostResultValue.getCostDetail();
|
|
|
641
|
+ //查询当前节点各个类型的成本
|
|
|
642
|
+ BigDecimal totalMaterialCost = new BigDecimal(0);
|
|
|
643
|
+ BigDecimal totalLabourCost = new BigDecimal(0);
|
|
|
644
|
+ BigDecimal totalEquipmentCost = new BigDecimal(0);
|
|
|
645
|
+ BigDecimal totalSupplyMaterialCost = new BigDecimal(0);
|
|
|
646
|
+ BigDecimal totalDriveCost = new BigDecimal(0);
|
|
|
647
|
+ BigDecimal totalLogisticsCost = new BigDecimal(0);
|
|
|
648
|
+ BigDecimal totalOtherCost = new BigDecimal(0);
|
|
|
649
|
+ JSONObject costDetailJson = JSON.parseObject(costDetail);
|
|
|
650
|
+ TotalResultValue hourOrRateResultValue = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, totalMaterialCost, totalLabourCost, totalEquipmentCost, totalSupplyMaterialCost, totalDriveCost, totalLogisticsCost, totalOtherCost, totalCost);
|
|
|
651
|
+ costDetailJson.put(TotalCostEnum.TotalMaterialCost.getCode(), hourOrRateResultValue.getTotalMaterialCost());
|
|
|
652
|
+ costDetailJson.put(TotalCostEnum.TotalLaborCost.getCode(), hourOrRateResultValue.getTotalLabourCost());
|
|
|
653
|
+ costDetailJson.put(TotalCostEnum.TotalEquipmentFee.getCode(), hourOrRateResultValue.getTotalEquipmentCost());
|
|
|
654
|
+ costDetailJson.put(TotalCostEnum.TotalSupplyMaterialFee.getCode(), hourOrRateResultValue.getTotalSupplyMaterialCost());
|
|
|
655
|
+ costDetailJson.put(TotalCostEnum.TotalDriverFee.getCode(), hourOrRateResultValue.getTotalDriveCost());
|
|
|
656
|
+ costDetailJson.put(TotalCostEnum.TotalLogisticsFee.getCode(), hourOrRateResultValue.getTotalLogisticsCost());
|
|
|
657
|
+ costDetailJson.put(TotalCostEnum.TotalOtherFee.getCode(), hourOrRateResultValue.getTotalOtherCost());
|
|
|
658
|
+ costDetailJson.put(TotalCostEnum.TotalStandardCost.getCode(), hourOrRateResultValue.getTotalCost());
|
|
|
659
|
+ oldAppSceneCostResultValue.setCostDetail(costDetailJson.toJSONString());
|
|
|
660
|
+ oldAppSceneCostResultValue.setTotalValue(hourOrRateResultValue.getTotalCost().toString());
|
|
|
661
|
+ standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
|
|
|
662
|
+ //构造单行成本查询记录
|
|
|
663
|
+ AppSceneCostStandardDetail costStandardDetail = AppSceneCostStandardDetail.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).materialName(oldAppSceneCostResultValue.getMarterialNo()).parentMaterialNumber(oldAppSceneCostResultValue.getParentMarterialNo())
|
|
656
|
664
|
// .versionNumber()
|
|
657
|
665
|
// .level()
|
|
658
|
666
|
// .sort()
|
|
659
|
667
|
// .figureNumber()
|
|
660
|
|
- .dosage(oldAppSceneCostResultValue.getNum() != null ? new Double(oldAppSceneCostResultValue.getNum()) : 0).unit(oldAppSceneCostResultValue.getUnit()).materialCost(costDetailJson.getBigDecimal(FeeTypeEnum.MaterialCost.getCode())).laborCost(costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode())).equipmentCost(costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode())).supplyMaterialCost(costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode())).driveCost(costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode())).logisticsCost(costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode())).otherCost(costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode())).currentStandardCost(new BigDecimal(oldAppSceneCostResultValue.getCountValue())).totalMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalMaterialCost.getCode())).totalLaborCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLaborCost.getCode())).totalEquipmentCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalEquipmentFee.getCode())).totalSupplyMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalSupplyMaterialFee.getCode())).totalDriveCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalDriverFee.getCode())).totalLogisticsCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLogisticsFee.getCode())).totalOtherCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalOtherFee.getCode())).totalStandardCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalStandardCost.getCode())).build();
|
|
661
|
|
- costStandardDetails.add(costStandardDetail);
|
|
|
668
|
+ .dosage(oldAppSceneCostResultValue.getNum() != null ? new Double(oldAppSceneCostResultValue.getNum()) : 0).unit(oldAppSceneCostResultValue.getUnit()).materialCost(costDetailJson.getBigDecimal(FeeTypeEnum.MaterialCost.getCode())).laborCost(costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode())).equipmentCost(costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode())).supplyMaterialCost(costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode())).driveCost(costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode())).logisticsCost(costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode())).otherCost(costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode())).currentStandardCost(new BigDecimal(oldAppSceneCostResultValue.getCountValue())).totalMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalMaterialCost.getCode())).totalLaborCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLaborCost.getCode())).totalEquipmentCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalEquipmentFee.getCode())).totalSupplyMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalSupplyMaterialFee.getCode())).totalDriveCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalDriverFee.getCode())).totalLogisticsCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLogisticsFee.getCode())).totalOtherCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalOtherFee.getCode())).totalStandardCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalStandardCost.getCode())).createTime(new Date()).build();
|
|
|
669
|
+ costStandardDetails.add(costStandardDetail);
|
|
|
670
|
+ }
|
|
|
671
|
+ //更新结果集到标准成本单行查询中去
|
|
|
672
|
+ standardCostService.iAppSceneCostStandardDetailService.saveBatch(costStandardDetails);
|
|
|
673
|
+ } catch (Exception e) {
|
|
|
674
|
+ e.printStackTrace();
|
|
662
|
675
|
}
|
|
663
|
|
- //更新结果集到标准成本单行查询中去
|
|
664
|
|
- standardCostService.iAppSceneCostStandardDetailService.saveBatch(costStandardDetails);
|
|
665
|
676
|
}
|
|
666
|
677
|
|
|
667
|
678
|
/**
|