|
|
@@ -2,21 +2,45 @@ package com.zzsmart.qomo.kn.cost.manage.plugin.materialinput;
|
|
2
|
2
|
|
|
3
|
3
|
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostResultValue;
|
|
4
|
4
|
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
|
|
|
5
|
+import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
|
|
5
|
6
|
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
|
|
|
7
|
+import com.zzsmart.qomo.kn.cost.manage.service.CostMaterialProcessHoursService;
|
|
6
|
8
|
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
|
|
|
9
|
+import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
|
|
|
10
|
+import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext;
|
|
7
|
11
|
import lombok.extern.slf4j.Slf4j;
|
|
8
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
9
|
13
|
import org.springframework.stereotype.Service;
|
|
10
|
14
|
|
|
11
|
15
|
import javax.annotation.PostConstruct;
|
|
12
|
|
-import java.util.Date;
|
|
|
16
|
+import java.math.BigDecimal;
|
|
|
17
|
+import java.util.ArrayList;
|
|
13
|
18
|
import java.util.List;
|
|
|
19
|
+import java.util.Map;
|
|
|
20
|
+import java.util.stream.Collectors;
|
|
14
|
21
|
|
|
15
|
22
|
@Service
|
|
16
|
23
|
@Slf4j
|
|
17
|
24
|
public class StandardCostService {
|
|
|
25
|
+ /**
|
|
|
26
|
+ * 物料BOM信息
|
|
|
27
|
+ */
|
|
18
|
28
|
@Autowired
|
|
19
|
29
|
CostMaterialBomMapper costMaterialBomMapper;
|
|
|
30
|
+
|
|
|
31
|
+ /**
|
|
|
32
|
+ * 小时费率
|
|
|
33
|
+ */
|
|
|
34
|
+ @Autowired
|
|
|
35
|
+ IHourRateService iHourRateService;
|
|
|
36
|
+ /**
|
|
|
37
|
+ * 工序
|
|
|
38
|
+ */
|
|
|
39
|
+ @Autowired
|
|
|
40
|
+ CostMaterialProcessHoursService costMaterialProcessHoursService;
|
|
|
41
|
+ /**
|
|
|
42
|
+ * 标准成本计算结果
|
|
|
43
|
+ */
|
|
20
|
44
|
@Autowired
|
|
21
|
45
|
IAppSceneCostResultValueService iAppSceneCostResultValueService;
|
|
22
|
46
|
public static StandardCostService standardCostService;
|
|
|
@@ -25,6 +49,8 @@ public class StandardCostService {
|
|
25
|
49
|
public void init() {
|
|
26
|
50
|
standardCostService = this;
|
|
27
|
51
|
standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
|
|
|
52
|
+ standardCostService.iHourRateService = this.iHourRateService;
|
|
|
53
|
+ standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
|
|
28
|
54
|
standardCostService.iAppSceneCostResultValueService = this.iAppSceneCostResultValueService;
|
|
29
|
55
|
}
|
|
30
|
56
|
|
|
|
@@ -32,25 +58,35 @@ public class StandardCostService {
|
|
32
|
58
|
/**
|
|
33
|
59
|
* 物料编号输入任务
|
|
34
|
60
|
*/
|
|
35
|
|
- public static void materialInputTask(String materialCode) {
|
|
36
|
|
- //1.查询出所有满足物料编号的物料(BOM物料)
|
|
37
|
|
- String sql = "select * from app_scene_cost_material_bom ";
|
|
38
|
|
- List<CostMaterialBom> list = standardCostService.costMaterialBomMapper.customSelect(sql);
|
|
39
|
|
- log.info("Full EmptyTask list: {}", list);
|
|
40
|
|
- //2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
|
|
41
|
|
- AppSceneCostResultValue appSceneCostResultValue = new AppSceneCostResultValue();
|
|
42
|
|
-
|
|
43
|
|
- appSceneCostResultValue.setInstanceCode("11");
|
|
44
|
|
- appSceneCostResultValue.setCountValue("11");
|
|
45
|
|
- appSceneCostResultValue.setCreateTime(new Date());
|
|
46
|
|
- standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
|
|
47
|
|
-
|
|
|
61
|
+ public static void materialInputTask(TaskExecutionContext parameters) {
|
|
|
62
|
+ try {
|
|
|
63
|
+ //获取最上层的物料号
|
|
|
64
|
+ String materialCode = "";
|
|
|
65
|
+ //获取任务类型
|
|
|
66
|
+ String taskType = "";
|
|
|
67
|
+ //获取任务代码
|
|
|
68
|
+ String taskCode = "";
|
|
|
69
|
+ //获取流程id
|
|
|
70
|
+ String flowInstanceId = "1";
|
|
|
71
|
+ //1.查询出所有满足物料编号的物料(BOM物料)
|
|
|
72
|
+ String sql = "select * from app_scene_cost_material_bom ";
|
|
|
73
|
+ List<CostMaterialBom> list = standardCostService.costMaterialBomMapper.customSelect(sql);
|
|
|
74
|
+ log.info("Full EmptyTask list: {}", list);
|
|
|
75
|
+ //2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
|
|
|
76
|
+ for (int i = 0; list != null && i < list.size(); i++) {
|
|
|
77
|
+ CostMaterialBom material = list.get(i);
|
|
|
78
|
+ AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(materialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).build();
|
|
|
79
|
+ standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
|
|
|
80
|
+ }
|
|
|
81
|
+ } catch (Exception e) {
|
|
|
82
|
+ throw new RuntimeException(e);
|
|
|
83
|
+ }
|
|
48
|
84
|
}
|
|
49
|
85
|
|
|
50
|
86
|
/**
|
|
51
|
87
|
* 物料成本任务
|
|
52
|
88
|
*/
|
|
53
|
|
- public static void materialCostTask(String materialCode) {
|
|
|
89
|
+ public static void materialCostTask(TaskExecutionContext parameters) {
|
|
54
|
90
|
//1.查询出物料编号对应的下所有的BOM信息
|
|
55
|
91
|
//2.计算出所有的单个物料的物料成本
|
|
56
|
92
|
//2.1查询出物料的单价和采购数量
|
|
|
@@ -60,17 +96,59 @@ public class StandardCostService {
|
|
60
|
96
|
/**
|
|
61
|
97
|
* 人工成本任务
|
|
62
|
98
|
*/
|
|
63
|
|
- public static void laborCostTask(String materialCode) {
|
|
64
|
|
- //1.查询出物料编号对应的下所有的BOM信息
|
|
65
|
|
- //2.计算出所有的单个物料的人工成本
|
|
66
|
|
- //2.1查询出物料的人员工时和人工费率
|
|
67
|
|
- //2.2计算出人工成本并存储到成本结果数据表中
|
|
|
99
|
+ public static void laborCostTask(TaskExecutionContext parameters) {
|
|
|
100
|
+ try {
|
|
|
101
|
+ //获取最上层的物料号
|
|
|
102
|
+ String topMaterialCode = "";
|
|
|
103
|
+ //获取任务类型
|
|
|
104
|
+ String taskType = "";
|
|
|
105
|
+ //获取上一节点任务类型
|
|
|
106
|
+ String lastTaskType = "LaborCost";
|
|
|
107
|
+ //获取任务代码
|
|
|
108
|
+ String taskCode = "";
|
|
|
109
|
+ //获取流程id
|
|
|
110
|
+ String flowInstanceId = "1";
|
|
|
111
|
+ //人工费率
|
|
|
112
|
+ BigDecimal laborRate = new BigDecimal("0.0");
|
|
|
113
|
+ //1.查询出物料编号对应的下所有的BOM信息
|
|
|
114
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, lastTaskType, flowInstanceId);
|
|
|
115
|
+ //2.计算出所有的单个物料的人工成本
|
|
|
116
|
+ //2.1查询出物料的人员工时和人工小时费率(涉及:小时费率表和工序表)
|
|
|
117
|
+ List<String> MarterialNoList = new ArrayList<>();
|
|
|
118
|
+ if (list != null && list.size() > 0) {
|
|
|
119
|
+ MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
|
120
|
+ }
|
|
|
121
|
+ //查询工序工时
|
|
|
122
|
+ Map<String, List<CostMaterialProcessHours>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
|
|
|
123
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
124
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
125
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
126
|
+ if (marterialNo != null) {
|
|
|
127
|
+ BigDecimal totalLaborCost = new BigDecimal("0.0");
|
|
|
128
|
+ List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
|
129
|
+ if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
|
130
|
+ for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
|
131
|
+ CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
|
132
|
+ BigDecimal laborHours = processHours.getLaborHours();
|
|
|
133
|
+ //计算总人工成本
|
|
|
134
|
+ totalLaborCost.add(laborHours.multiply(laborRate));
|
|
|
135
|
+ }
|
|
|
136
|
+ }
|
|
|
137
|
+ //2.2计算出人工成本并存储到成本结果数据表中
|
|
|
138
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalLaborCost + "").build();
|
|
|
139
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
140
|
+ }
|
|
|
141
|
+ }
|
|
|
142
|
+ } catch (Exception e) {
|
|
|
143
|
+ throw new RuntimeException(e);
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
68
|
146
|
}
|
|
69
|
147
|
|
|
70
|
148
|
/**
|
|
71
|
149
|
* 制造费用成本任务
|
|
72
|
150
|
*/
|
|
73
|
|
- public static void manufacturingCostTask(String materialCode) {
|
|
|
151
|
+ public static void manufacturingCostTask(TaskExecutionContext parameters) {
|
|
74
|
152
|
//1.查询出物料编号对应的下所有的BOM信息
|
|
75
|
153
|
//2.根据费用类型进行不同的费用计算
|
|
76
|
154
|
//2.1机器折旧费(机器工时*费率)
|
|
|
@@ -83,7 +161,7 @@ public class StandardCostService {
|
|
83
|
161
|
/**
|
|
84
|
162
|
* 标准成本计算任务
|
|
85
|
163
|
*/
|
|
86
|
|
- public static void standardCostTask(String materialCode) {
|
|
|
164
|
+ public static void standardCostTask(TaskExecutionContext parameters) {
|
|
87
|
165
|
//1.查询出物料编号对应的下所有的BOM信息
|
|
88
|
166
|
//2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
|
|
89
|
167
|
//3.计算出所有的单个物料的累计标准成本
|