|
|
@@ -4,9 +4,12 @@ import com.alibaba.fastjson.JSON;
|
|
4
|
4
|
import com.alibaba.fastjson.JSONObject;
|
|
5
|
5
|
import com.zzsmart.qomo.kn.cost.manage.entity.*;
|
|
6
|
6
|
import com.zzsmart.qomo.kn.cost.manage.enums.FeeTypeEnum;
|
|
|
7
|
+import com.zzsmart.qomo.kn.cost.manage.enums.HourOrRateTypeEnum;
|
|
|
8
|
+import com.zzsmart.qomo.kn.cost.manage.enums.TotalCostEnum;
|
|
7
|
9
|
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
|
|
8
|
10
|
import com.zzsmart.qomo.kn.cost.manage.service.*;
|
|
9
|
11
|
import com.zzsmart.qomo.kn.cost.manage.vo.FlowTaskInfoVO;
|
|
|
12
|
+import com.zzsmart.qomo.kn.cost.manage.vo.TotalResultValue;
|
|
10
|
13
|
import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext;
|
|
11
|
14
|
import lombok.extern.slf4j.Slf4j;
|
|
12
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -50,10 +53,20 @@ public class StandardCostService {
|
|
50
|
53
|
*/
|
|
51
|
54
|
@Autowired
|
|
52
|
55
|
IAppSceneCostResultValueService iAppSceneCostResultValueService;
|
|
|
56
|
+ /**
|
|
|
57
|
+ * 标准成本服务
|
|
|
58
|
+ */
|
|
53
|
59
|
public static StandardCostService standardCostService;
|
|
|
60
|
+ /**
|
|
|
61
|
+ * 成本计算服务
|
|
|
62
|
+ */
|
|
54
|
63
|
@Autowired
|
|
55
|
64
|
IAppSceneCostCountService appSceneCostCountService;
|
|
56
|
|
-
|
|
|
65
|
+ /**
|
|
|
66
|
+ * 标准成本明细服务(单行查询服务)
|
|
|
67
|
+ */
|
|
|
68
|
+ @Autowired
|
|
|
69
|
+ private IAppSceneCostStandardDetailService iAppSceneCostStandardDetailService;
|
|
57
|
70
|
|
|
58
|
71
|
@PostConstruct
|
|
59
|
72
|
public void init() {
|
|
|
@@ -65,6 +78,7 @@ public class StandardCostService {
|
|
65
|
78
|
standardCostService.iHourRateService = this.iHourRateService;
|
|
66
|
79
|
standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
|
|
67
|
80
|
standardCostService.iAppSceneCostResultValueService = this.iAppSceneCostResultValueService;
|
|
|
81
|
+ standardCostService.iAppSceneCostStandardDetailService = this.iAppSceneCostStandardDetailService;
|
|
68
|
82
|
}
|
|
69
|
83
|
|
|
70
|
84
|
/**
|
|
|
@@ -93,6 +107,7 @@ public class StandardCostService {
|
|
93
|
107
|
//1.查询出所有满足物料编号的物料(BOM物料)
|
|
94
|
108
|
String sql = flowTaskInfoVO.getSqlString();
|
|
95
|
109
|
log.info("传递过来的SQL语句:" + sql);
|
|
|
110
|
+ //TODO 查询最顶部的BOM物料编号下所有的物料并进行层级排序
|
|
96
|
111
|
List<CostMaterialBom> list = standardCostService.costMaterialBomService.queryAllBomInfoBytopMaterialCode(topMaterialCode);
|
|
97
|
112
|
log.info("Full EmptyTask list: {}", list);
|
|
98
|
113
|
//2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
|
|
|
@@ -220,7 +235,7 @@ public class StandardCostService {
|
|
220
|
235
|
//单价乘以数量
|
|
221
|
236
|
BigDecimal totalCost = price.multiply(number);
|
|
222
|
237
|
//2.2计算出人工成本并存储到成本结果数据表中
|
|
223
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).costType(feeType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
|
|
|
238
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).costType(feeType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").priceOrRate(price).build();
|
|
224
|
239
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
225
|
240
|
}
|
|
226
|
241
|
}
|
|
|
@@ -271,17 +286,18 @@ public class StandardCostService {
|
|
271
|
286
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
272
|
287
|
if (marterialNo != null) {
|
|
273
|
288
|
BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
289
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
274
|
290
|
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
275
|
291
|
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
276
|
292
|
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
277
|
293
|
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
278
|
|
- BigDecimal laborHours = processHours.getLaborHours();
|
|
|
294
|
+ laborHours = laborHours.add(processHours.getLaborHours());
|
|
279
|
295
|
//计算总人工成本
|
|
280
|
|
- totalCost = totalCost.add(laborHours.multiply(hourRate));
|
|
|
296
|
+ totalCost = totalCost.add(processHours.getLaborHours().multiply(hourRate));
|
|
281
|
297
|
}
|
|
282
|
298
|
}
|
|
283
|
299
|
//2.2计算出人工成本并存储到成本结果数据表中
|
|
284
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
|
|
|
300
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
285
|
301
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
286
|
302
|
}
|
|
287
|
303
|
}
|
|
|
@@ -339,17 +355,18 @@ public class StandardCostService {
|
|
339
|
355
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
340
|
356
|
if (marterialNo != null) {
|
|
341
|
357
|
BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
358
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
342
|
359
|
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
343
|
360
|
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
344
|
361
|
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
345
|
362
|
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
346
|
|
- BigDecimal laborHours = processHours.getDeviceHours();
|
|
|
363
|
+ laborHours = laborHours.add(processHours.getDeviceHours());
|
|
347
|
364
|
//计算机器成本
|
|
348
|
|
- totalCost = totalCost.add(laborHours.multiply(hourRate));
|
|
|
365
|
+ totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
349
|
366
|
}
|
|
350
|
367
|
}
|
|
351
|
368
|
//2.2计算机器成本并存储到成本结果数据表中
|
|
352
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
|
|
|
369
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
353
|
370
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
354
|
371
|
}
|
|
355
|
372
|
}
|
|
|
@@ -360,18 +377,19 @@ public class StandardCostService {
|
|
360
|
377
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
361
|
378
|
if (marterialNo != null) {
|
|
362
|
379
|
BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
380
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
363
|
381
|
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
364
|
382
|
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
365
|
383
|
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
366
|
384
|
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
367
|
385
|
//TODO 辅料工时来源
|
|
368
|
|
- BigDecimal laborHours = processHours.getLaborHours();
|
|
|
386
|
+ laborHours = laborHours.add(processHours.getDeviceHours());
|
|
369
|
387
|
//机物料消耗
|
|
370
|
|
- totalCost = totalCost.add(laborHours.multiply(hourRate));
|
|
|
388
|
+ totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
371
|
389
|
}
|
|
372
|
390
|
}
|
|
373
|
391
|
//2.2计算机物料消耗存储到成本结果数据表中
|
|
374
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
|
|
|
392
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
375
|
393
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
376
|
394
|
}
|
|
377
|
395
|
}
|
|
|
@@ -382,18 +400,19 @@ public class StandardCostService {
|
|
382
|
400
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
383
|
401
|
if (marterialNo != null) {
|
|
384
|
402
|
BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
403
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
385
|
404
|
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
386
|
405
|
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
387
|
406
|
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
388
|
407
|
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
389
|
408
|
//TODO 燃动力工时来源
|
|
390
|
|
- BigDecimal laborHours = processHours.getLaborHours();
|
|
391
|
|
- //机物料消耗
|
|
392
|
|
- totalCost = totalCost.add(laborHours.multiply(hourRate));
|
|
|
409
|
+ laborHours = laborHours.add(processHours.getDeviceHours());
|
|
|
410
|
+ //水电费(燃动力工时*费率)成本
|
|
|
411
|
+ totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
393
|
412
|
}
|
|
394
|
413
|
}
|
|
395
|
414
|
//2.2计算机物料消耗存储到成本结果数据表中
|
|
396
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
|
|
|
415
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
397
|
416
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
398
|
417
|
}
|
|
399
|
418
|
}
|
|
|
@@ -404,18 +423,19 @@ public class StandardCostService {
|
|
404
|
423
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
405
|
424
|
if (marterialNo != null) {
|
|
406
|
425
|
BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
426
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
407
|
427
|
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
408
|
428
|
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
409
|
429
|
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
410
|
430
|
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
411
|
431
|
//TODO 其他工时来源
|
|
412
|
|
- BigDecimal laborHours = processHours.getLaborHours();
|
|
413
|
|
- //机物料消耗
|
|
414
|
|
- totalCost = totalCost.add(laborHours.multiply(hourRate));
|
|
|
432
|
+ laborHours = laborHours.add(processHours.getDeviceHours());
|
|
|
433
|
+ //其他制费成本
|
|
|
434
|
+ totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
415
|
435
|
}
|
|
416
|
436
|
}
|
|
417
|
437
|
//2.2计算机物料消耗存储到成本结果数据表中
|
|
418
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
|
|
|
438
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
419
|
439
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
420
|
440
|
}
|
|
421
|
441
|
}
|
|
|
@@ -465,6 +485,7 @@ public class StandardCostService {
|
|
465
|
485
|
//2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
|
|
466
|
486
|
//按照物料编号进行分组
|
|
467
|
487
|
Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
|
488
|
+ //遍历根物料下所有的物料进行该物料本阶成本和费用类别的统计
|
|
468
|
489
|
for (String key : materialNoMap.keySet()) {
|
|
469
|
490
|
List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
470
|
491
|
//按照费用类别进行分组
|
|
|
@@ -485,6 +506,23 @@ public class StandardCostService {
|
|
485
|
506
|
BigDecimal otherCost = new BigDecimal("0.0");
|
|
486
|
507
|
//7.本阶制造费(物流费)
|
|
487
|
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");
|
|
488
|
526
|
AppSceneCostResultValue currentMaterialCost = null;
|
|
489
|
527
|
//遍历所有费用类别计算本阶标准成本
|
|
490
|
528
|
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
|
@@ -497,36 +535,73 @@ public class StandardCostService {
|
|
497
|
535
|
currentCost = currentCost.add(new BigDecimal(countValue));
|
|
498
|
536
|
}
|
|
499
|
537
|
}
|
|
500
|
|
- //计算本阶各个费用类别费用
|
|
|
538
|
+ //计算本阶各个费用类别费用以及记录本阶物料的工时和小时费率
|
|
501
|
539
|
for (String feeType : costTypeMap.keySet()) {
|
|
502
|
540
|
List<AppSceneCostResultValue> appSceneCostResultValues1 = costTypeMap.get(feeType);
|
|
503
|
541
|
for (int m = 0; m < appSceneCostResultValues1.size(); m++) {
|
|
504
|
542
|
if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) {
|
|
|
543
|
+ //物料成本
|
|
505
|
544
|
materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
545
|
+ //物料单价
|
|
|
546
|
+ materialUnitPrice = appSceneCostResultValues1.get(m).getPriceOrRate();
|
|
506
|
547
|
} else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) {
|
|
|
548
|
+ //人工成本
|
|
507
|
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());
|
|
508
|
553
|
} else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
|
554
|
+ //设备费用
|
|
509
|
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());
|
|
510
|
559
|
} else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
|
560
|
+ //辅料费用
|
|
511
|
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());
|
|
512
|
565
|
} else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
|
566
|
+ //燃动费用
|
|
513
|
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());
|
|
514
|
571
|
} else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
|
572
|
+ //物流费用
|
|
515
|
573
|
logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
516
|
574
|
} else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
|
575
|
+ //其他费用
|
|
517
|
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());
|
|
518
|
580
|
}
|
|
519
|
581
|
}
|
|
520
|
582
|
}
|
|
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();
|
|
|
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();
|
|
530
|
605
|
standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
531
|
606
|
}
|
|
532
|
607
|
//3.计算出所有的单个物料的累计标准成本
|
|
|
@@ -545,6 +620,8 @@ public class StandardCostService {
|
|
545
|
620
|
* @param flowInstanceId
|
|
546
|
621
|
*/
|
|
547
|
622
|
private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
|
|
|
623
|
+
|
|
|
624
|
+ List<AppSceneCostStandardDetail> costStandardDetails = new ArrayList<>();
|
|
548
|
625
|
//父类对应的子节点(除了最上层节点)
|
|
549
|
626
|
Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
|
|
550
|
627
|
for (int i = 0; i < standardCostList.size(); i++) {
|
|
|
@@ -552,11 +629,45 @@ public class StandardCostService {
|
|
552
|
629
|
AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i);
|
|
553
|
630
|
BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue());
|
|
554
|
631
|
//循环计算出当前节点的累计成本
|
|
555
|
|
- totalCost = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
|
|
556
|
|
- oldAppSceneCostResultValue.setTotalValue(totalCost.toString());
|
|
|
632
|
+ String costDetail = oldAppSceneCostResultValue.getCostDetail();
|
|
|
633
|
+ //查询当前节点各个类型的成本
|
|
|
634
|
+ BigDecimal totalLabourCost = new BigDecimal(0);
|
|
|
635
|
+ BigDecimal totalEquipmentCost = new BigDecimal(0);
|
|
|
636
|
+ BigDecimal totalSupplyMaterialCost = new BigDecimal(0);
|
|
|
637
|
+ BigDecimal totalDriveCost = new BigDecimal(0);
|
|
|
638
|
+ BigDecimal totalLogisticsCost = new BigDecimal(0);
|
|
|
639
|
+ BigDecimal totalOtherCost = new BigDecimal(0);
|
|
|
640
|
+ JSONObject costDetailJson = JSON.parseObject(costDetail);
|
|
|
641
|
+ if (costDetailJson != null) {
|
|
|
642
|
+ totalLabourCost = costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode());
|
|
|
643
|
+ totalEquipmentCost = costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode());
|
|
|
644
|
+ totalSupplyMaterialCost = costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode());
|
|
|
645
|
+ totalDriveCost = costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode());
|
|
|
646
|
+ totalLogisticsCost = costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode());
|
|
|
647
|
+ totalOtherCost = costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode());
|
|
|
648
|
+ }
|
|
|
649
|
+ TotalResultValue hourOrRateResultValue = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, totalLabourCost, totalEquipmentCost, totalSupplyMaterialCost, totalDriveCost, totalLogisticsCost, totalOtherCost, totalCost);
|
|
|
650
|
+ costDetailJson.put(TotalCostEnum.TotalLaborCost.getCode(), hourOrRateResultValue.getTotalLabourCost());
|
|
|
651
|
+ costDetailJson.put(TotalCostEnum.TotalEquipmentFee.getCode(), hourOrRateResultValue.getTotalEquipmentCost());
|
|
|
652
|
+ costDetailJson.put(TotalCostEnum.TotalSupplyMaterialFee.getCode(), hourOrRateResultValue.getTotalSupplyMaterialCost());
|
|
|
653
|
+ costDetailJson.put(TotalCostEnum.TotalDriverFee.getCode(), hourOrRateResultValue.getTotalDriveCost());
|
|
|
654
|
+ costDetailJson.put(TotalCostEnum.TotalLogisticsFee.getCode(), hourOrRateResultValue.getTotalLogisticsCost());
|
|
|
655
|
+ costDetailJson.put(TotalCostEnum.TotalOtherFee.getCode(), hourOrRateResultValue.getTotalOtherCost());
|
|
|
656
|
+ costDetailJson.put(TotalCostEnum.TotalStandardCost.getCode(), hourOrRateResultValue.getTotalCost());
|
|
|
657
|
+ oldAppSceneCostResultValue.setCostDetail(costDetailJson.toJSONString());
|
|
|
658
|
+ oldAppSceneCostResultValue.setTotalValue(hourOrRateResultValue.getTotalCost().toString());
|
|
557
|
659
|
standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
|
|
558
|
|
- //TODO 更新结果集到标准成本单行查询中去
|
|
|
660
|
+ //构造单行成本查询记录
|
|
|
661
|
+ AppSceneCostStandardDetail costStandardDetail = AppSceneCostStandardDetail.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).materialName(oldAppSceneCostResultValue.getMarterialNo()).parentMaterialNumber(oldAppSceneCostResultValue.getParentMarterialNo())
|
|
|
662
|
+// .versionNumber()
|
|
|
663
|
+// .level()
|
|
|
664
|
+// .sort()
|
|
|
665
|
+// .figureNumber()
|
|
|
666
|
+ .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();
|
|
|
667
|
+ costStandardDetails.add(costStandardDetail);
|
|
559
|
668
|
}
|
|
|
669
|
+ //更新结果集到标准成本单行查询中去
|
|
|
670
|
+ standardCostService.iAppSceneCostStandardDetailService.saveBatch(costStandardDetails);
|
|
560
|
671
|
}
|
|
561
|
672
|
|
|
562
|
673
|
/**
|
|
|
@@ -565,12 +676,8 @@ public class StandardCostService {
|
|
565
|
676
|
*
|
|
566
|
677
|
* @param appSceneCostResultValue
|
|
567
|
678
|
* @param parentMaterialNoMap
|
|
568
|
|
- * @param topMaterialCode
|
|
569
|
|
- * @param taskType
|
|
570
|
|
- * @param taskCode
|
|
571
|
|
- * @param flowInstanceId
|
|
572
|
679
|
*/
|
|
573
|
|
- private static BigDecimal loopCount(AppSceneCostResultValue appSceneCostResultValue, Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap, String topMaterialCode, String taskType, String taskCode, String flowInstanceId, BigDecimal totalCost) {
|
|
|
680
|
+ private static TotalResultValue loopCount(AppSceneCostResultValue appSceneCostResultValue, Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap, BigDecimal totalLabourCost, BigDecimal totalEquipmentCost, BigDecimal totalSupplyMaterialCost, BigDecimal totalDriveCost, BigDecimal totalLogisticsCost, BigDecimal totalOtherCost, BigDecimal totalCost) {
|
|
574
|
681
|
String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
575
|
682
|
if (parentMaterialNoMap.containsKey(marterialNo)) {
|
|
576
|
683
|
//获取当前节点的子节点并遍历
|
|
|
@@ -578,16 +685,31 @@ public class StandardCostService {
|
|
578
|
685
|
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
579
|
686
|
AppSceneCostResultValue appSceneCostResultValue1 = appSceneCostResultValues.get(j);
|
|
580
|
687
|
String countValue = appSceneCostResultValue1.getCountValue();
|
|
|
688
|
+ //标准成本累计
|
|
581
|
689
|
if (countValue != null) {
|
|
582
|
690
|
totalCost = totalCost.add(new BigDecimal(countValue));
|
|
583
|
691
|
}
|
|
|
692
|
+ //各个费用类别成本累计
|
|
|
693
|
+ if (appSceneCostResultValue1.getCostDetail() != null) {
|
|
|
694
|
+ JSONObject costDetailJson = JSON.parseObject(appSceneCostResultValue1.getCostDetail());
|
|
|
695
|
+ if (costDetailJson != null) {
|
|
|
696
|
+ totalLabourCost = totalLabourCost.add(costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode()));
|
|
|
697
|
+ totalEquipmentCost = totalEquipmentCost.add(costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode()));
|
|
|
698
|
+ totalSupplyMaterialCost = totalSupplyMaterialCost.add(costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode()));
|
|
|
699
|
+ totalDriveCost = totalDriveCost.add(costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode()));
|
|
|
700
|
+ totalLogisticsCost = totalLogisticsCost.add(costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode()));
|
|
|
701
|
+ totalOtherCost = totalOtherCost.add(costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode()));
|
|
|
702
|
+ }
|
|
|
703
|
+ }
|
|
584
|
704
|
//判断当前子节点是否还有子节点
|
|
585
|
705
|
if (parentMaterialNoMap.containsKey(appSceneCostResultValue1.getMarterialNo())) {
|
|
586
|
706
|
//如果还有子节点则继续递归
|
|
587
|
|
- loopCount(appSceneCostResultValue1, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
|
|
|
707
|
+ loopCount(appSceneCostResultValue1, parentMaterialNoMap, totalLabourCost, totalEquipmentCost, totalSupplyMaterialCost, totalDriveCost, totalLogisticsCost, totalOtherCost, totalCost);
|
|
588
|
708
|
}
|
|
589
|
709
|
}
|
|
590
|
710
|
}
|
|
591
|
|
- return totalCost;
|
|
|
711
|
+ TotalResultValue hourOrRateResultValue = TotalResultValue.builder().totalLabourCost(totalLabourCost).totalEquipmentCost(totalEquipmentCost).totalSupplyMaterialCost(totalSupplyMaterialCost).totalDriveCost(totalDriveCost).totalLogisticsCost(totalLogisticsCost).totalOtherCost(totalOtherCost).totalCost(totalCost).build();
|
|
|
712
|
+ appSceneCostResultValue.setTotalValue(totalCost.toString());
|
|
|
713
|
+ return hourOrRateResultValue;
|
|
592
|
714
|
}
|
|
593
|
715
|
}
|