|
|
@@ -6,7 +6,7 @@ import com.zzsmart.qomo.kn.cost.manage.entity.*;
|
|
6
|
6
|
import com.zzsmart.qomo.kn.cost.manage.enums.FeeTypeEnum;
|
|
7
|
7
|
import com.zzsmart.qomo.kn.cost.manage.enums.HourOrRateTypeEnum;
|
|
8
|
8
|
import com.zzsmart.qomo.kn.cost.manage.enums.TotalCostEnum;
|
|
9
|
|
-import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostMaterialBomMapper;
|
|
|
9
|
+import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostBomRelevancyMapper;
|
|
10
|
10
|
import com.zzsmart.qomo.kn.cost.manage.service.*;
|
|
11
|
11
|
import com.zzsmart.qomo.kn.cost.manage.vo.FlowTaskInfoVO;
|
|
12
|
12
|
import com.zzsmart.qomo.kn.cost.manage.vo.TotalResultValue;
|
|
|
@@ -32,9 +32,9 @@ public class StandardCostService {
|
|
32
|
32
|
* 物料BOM信息
|
|
33
|
33
|
*/
|
|
34
|
34
|
@Autowired
|
|
35
|
|
- AppSceneCostMaterialBomMapper costMaterialBomMapper;
|
|
|
35
|
+ AppSceneCostBomRelevancyMapper appSceneCostBomRelevancyMapper;
|
|
36
|
36
|
@Autowired
|
|
37
|
|
- IAppSceneCostMaterialBomService costMaterialBomService;
|
|
|
37
|
+ IAppSceneCostBomRelevancyService costMaterialBomService;
|
|
38
|
38
|
|
|
39
|
39
|
/**
|
|
40
|
40
|
* 小时费率
|
|
|
@@ -45,12 +45,12 @@ public class StandardCostService {
|
|
45
|
45
|
* 采购单价
|
|
46
|
46
|
*/
|
|
47
|
47
|
@Autowired
|
|
48
|
|
- IAppSceneCostPurchasePriceService costPurchasePriceService;
|
|
|
48
|
+ IAppSceneCostPurchaseRecordService costPurchaseRecordService;
|
|
49
|
49
|
/**
|
|
50
|
50
|
* 工序
|
|
51
|
51
|
*/
|
|
52
|
52
|
@Autowired
|
|
53
|
|
- IAppSceneCostMaterialProcessHoursService costMaterialProcessHoursService;
|
|
|
53
|
+ IAppSceneCostProductProcessMaintenanceService costMaterialProcessHoursService;
|
|
54
|
54
|
/**
|
|
55
|
55
|
* 标准成本计算结果
|
|
56
|
56
|
*/
|
|
|
@@ -69,19 +69,19 @@ public class StandardCostService {
|
|
69
|
69
|
* 标准成本明细服务(单行查询服务)
|
|
70
|
70
|
*/
|
|
71
|
71
|
@Autowired
|
|
72
|
|
- private IAppSceneCostStandardDetailService iAppSceneCostStandardDetailService;
|
|
|
72
|
+ private IAppSceneCostStandardResultService iAppSceneCostStandardResultService;
|
|
73
|
73
|
|
|
74
|
74
|
@PostConstruct
|
|
75
|
75
|
public void init() {
|
|
76
|
76
|
standardCostService = this;
|
|
77
|
|
- standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
|
|
|
77
|
+ standardCostService.appSceneCostBomRelevancyMapper = this.appSceneCostBomRelevancyMapper;
|
|
78
|
78
|
standardCostService.appSceneCostCountService = this.appSceneCostCountService;
|
|
79
|
79
|
standardCostService.costMaterialBomService = this.costMaterialBomService;
|
|
80
|
|
- standardCostService.costPurchasePriceService = this.costPurchasePriceService;
|
|
|
80
|
+ standardCostService.costPurchaseRecordService = this.costPurchaseRecordService;
|
|
81
|
81
|
standardCostService.iHourRateService = this.iHourRateService;
|
|
82
|
82
|
standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
|
|
83
|
83
|
standardCostService.iAppSceneCostResultValueService = this.iAppSceneCostResultValueService;
|
|
84
|
|
- standardCostService.iAppSceneCostStandardDetailService = this.iAppSceneCostStandardDetailService;
|
|
|
84
|
+ standardCostService.iAppSceneCostStandardResultService = this.iAppSceneCostStandardResultService;
|
|
85
|
85
|
}
|
|
86
|
86
|
|
|
87
|
87
|
/**
|
|
|
@@ -110,20 +110,400 @@ public class StandardCostService {
|
|
110
|
110
|
//1.查询出所有满足物料编号的物料(BOM物料)
|
|
111
|
111
|
String sql = flowTaskInfoVO.getSqlString();
|
|
112
|
112
|
log.info("传递过来的SQL语句:" + sql);
|
|
113
|
|
- //TODO 查询最顶部的BOM物料编号下所有的物料并进行层级排序
|
|
114
|
|
- List<AppSceneCostMaterialBom> list = standardCostService.costMaterialBomService.queryAllBomInfoBytopMaterialCode(topMaterialCode);
|
|
115
|
|
- log.info("Full EmptyTask list: {}", list);
|
|
116
|
|
- //2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
|
|
117
|
|
- for (int i = 0; list != null && i < list.size(); i++) {
|
|
118
|
|
- AppSceneCostMaterialBom material = list.get(i);
|
|
119
|
|
- AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).num(material.getNumber()).build();
|
|
120
|
|
- standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
|
|
121
|
|
- }
|
|
|
113
|
+ //获取顶部物料下所有的物料信息并存储到新的表中
|
|
|
114
|
+ getAllMaterialBomInfoByTopMaterialCode(topMaterialCode, taskType, taskCode, flowInstanceId != null ? Integer.valueOf(flowInstanceId) : null);
|
|
122
|
115
|
} catch (Exception e) {
|
|
123
|
116
|
throw new RuntimeException(e);
|
|
124
|
117
|
}
|
|
125
|
118
|
}
|
|
126
|
119
|
|
|
|
120
|
+ /**
|
|
|
121
|
+ * 【1.成本参数查询】查询最顶部的BOM物料编号下所有的物料并进行层级排序
|
|
|
122
|
+ * * 获取顶部物料下所有的物料信息并存储到新的表中
|
|
|
123
|
+ *
|
|
|
124
|
+ * @param topMaterialCode 顶部物料编号
|
|
|
125
|
+ * @param taskType 任务类型
|
|
|
126
|
+ * @param taskCode 任务编号
|
|
|
127
|
+ * @param flowInstanceId 流程实例id
|
|
|
128
|
+ */
|
|
|
129
|
+ public static void getAllMaterialBomInfoByTopMaterialCode(String topMaterialCode, String taskType, String taskCode, Integer flowInstanceId) {
|
|
|
130
|
+ List<AppSceneCostBomRelevancy> list = standardCostService.costMaterialBomService.queryAllBomInfoByTopMaterialCode(topMaterialCode);
|
|
|
131
|
+ log.info("Full ParamTask list: {}", list);
|
|
|
132
|
+ //TODO material.getMeins()领用量??为什么是ST字母
|
|
|
133
|
+ for (int i = 0; list != null && i < list.size(); i++) {
|
|
|
134
|
+ AppSceneCostBomRelevancy material = list.get(i);
|
|
|
135
|
+ //TODO 物料领用数据
|
|
|
136
|
+ BigDecimal num1 = BigDecimal.ONE;
|
|
|
137
|
+ AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(material.getIdnrk()).parentMarterialNo(material.getMatnr()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).num(num1).build();
|
|
|
138
|
+ standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
|
|
|
139
|
+ }
|
|
|
140
|
+ }
|
|
|
141
|
+
|
|
|
142
|
+ /**
|
|
|
143
|
+ * 【2.物料成本计算】计算物料成本
|
|
|
144
|
+ *
|
|
|
145
|
+ * @param topMaterialCode 顶部物料编号
|
|
|
146
|
+ * @param taskType 任务类型
|
|
|
147
|
+ * @param taskCode 任务编号
|
|
|
148
|
+ * @param flowInstanceId 流程实例id
|
|
|
149
|
+ */
|
|
|
150
|
+ public static void countMaterialCostByTopMaterialCode(String topMaterialCode, String taskType, String taskCode, Integer flowInstanceId, String feeType) {
|
|
|
151
|
+ //1.查询出物料编号对应的下所有的BOM信息
|
|
|
152
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", String.valueOf(flowInstanceId));
|
|
|
153
|
+ //2.计算出所有的单个物料的物料成本
|
|
|
154
|
+ //2.1查询出物料的单价和采购数量
|
|
|
155
|
+ List<String> MarterialNoList = new ArrayList<>();
|
|
|
156
|
+ if (list != null && list.size() > 0) {
|
|
|
157
|
+ MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
|
158
|
+ }
|
|
|
159
|
+ //查询物料的采购价
|
|
|
160
|
+ Map<String, BigDecimal> purchasePriceMap = standardCostService.costPurchaseRecordService.getMinCostPurchasePriceByMaterialNo(MarterialNoList);
|
|
|
161
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
162
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
163
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
164
|
+ BigDecimal num = appSceneCostResultValue.getNum();
|
|
|
165
|
+ if (marterialNo != null && num != null && (new BigDecimal(num.toString()).compareTo(BigDecimal.ZERO)) != 0) {
|
|
|
166
|
+ BigDecimal price = purchasePriceMap.get(marterialNo);
|
|
|
167
|
+ if (price == null) {
|
|
|
168
|
+ price = BigDecimal.ZERO;
|
|
|
169
|
+ }
|
|
|
170
|
+ BigDecimal number = new BigDecimal(num.toString());
|
|
|
171
|
+ //单价乘以数量
|
|
|
172
|
+ BigDecimal totalCost = price.multiply(number);
|
|
|
173
|
+ //2.2计算出人工成本并存储到成本结果数据表中
|
|
|
174
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).costType(feeType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").priceOrRate(price).num(num).build();
|
|
|
175
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
176
|
+ }
|
|
|
177
|
+ }
|
|
|
178
|
+ }
|
|
|
179
|
+
|
|
|
180
|
+ /**
|
|
|
181
|
+ * 【3.人工成本计算】
|
|
|
182
|
+ *
|
|
|
183
|
+ * @param topMaterialCode 顶部物料编号
|
|
|
184
|
+ * @param taskType 任务类型
|
|
|
185
|
+ * @param taskCode 任务编号
|
|
|
186
|
+ * @param flowInstanceId 流程实例id
|
|
|
187
|
+ */
|
|
|
188
|
+ public static void countLaborCostByTopMaterialCode(String topMaterialCode, String taskType, String taskCode, Integer flowInstanceId, String feeType, AppSceneCostHourRate appSceneCostHourRate) {
|
|
|
189
|
+ //1.查询出人员工时费率
|
|
|
190
|
+ AppSceneCostHourRate hourRateInfo = standardCostService.iHourRateService.getOneHourRateInfo(appSceneCostHourRate);
|
|
|
191
|
+ BigDecimal hourRate = new BigDecimal("0");
|
|
|
192
|
+ if (hourRateInfo != null) {
|
|
|
193
|
+ hourRate = hourRateInfo.getLaborHourRate();
|
|
|
194
|
+ }
|
|
|
195
|
+ //1.查询出物料编号对应的下所有的BOM信息
|
|
|
196
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", String.valueOf(flowInstanceId));
|
|
|
197
|
+ //2.计算出所有的单个物料的人工成本
|
|
|
198
|
+ //2.1查询出物料的人员工时和人工小时费率(涉及:小时费率表和工序表)
|
|
|
199
|
+ List<String> MarterialNoList = new ArrayList<>();
|
|
|
200
|
+ if (list != null && list.size() > 0) {
|
|
|
201
|
+ MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
|
202
|
+ }
|
|
|
203
|
+ //查询工序工时
|
|
|
204
|
+ Map<String, List<AppSceneCostProductProcessMaintenance>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
|
|
|
205
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
206
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
207
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
208
|
+ if (marterialNo != null) {
|
|
|
209
|
+ BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
210
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
|
211
|
+ List<AppSceneCostProductProcessMaintenance> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
|
212
|
+ if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
|
213
|
+ for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
|
214
|
+ AppSceneCostProductProcessMaintenance processHours = costMaterialProcessHours.get(j);
|
|
|
215
|
+ laborHours = laborHours.add(processHours.getLaborHour());
|
|
|
216
|
+ //计算总人工成本
|
|
|
217
|
+ totalCost = totalCost.add(processHours.getLaborHour().multiply(hourRate));
|
|
|
218
|
+ }
|
|
|
219
|
+ }
|
|
|
220
|
+ //2.2计算出人工成本并存储到成本结果数据表中
|
|
|
221
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
|
222
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
223
|
+ }
|
|
|
224
|
+ }
|
|
|
225
|
+ }
|
|
|
226
|
+
|
|
|
227
|
+ /**
|
|
|
228
|
+ * 【4.制造费用】
|
|
|
229
|
+ *
|
|
|
230
|
+ * @param topMaterialCode 顶部物料编号
|
|
|
231
|
+ * @param taskType 任务类型
|
|
|
232
|
+ * @param taskCode 任务编号
|
|
|
233
|
+ * @param flowInstanceId 流程实例id
|
|
|
234
|
+ */
|
|
|
235
|
+ public static void countManufacturingCostByTopMaterialCode(String topMaterialCode, String taskType, String taskCode, Integer flowInstanceId, String feeType, AppSceneCostHourRate appSceneCostHourRate) {
|
|
|
236
|
+ //1.查询出人员工时费率
|
|
|
237
|
+ AppSceneCostHourRate hourRateInfo = standardCostService.iHourRateService.getOneHourRateInfo(appSceneCostHourRate);
|
|
|
238
|
+ BigDecimal hourRate = new BigDecimal("0");
|
|
|
239
|
+ if (hourRateInfo != null) {
|
|
|
240
|
+ hourRate = hourRateInfo.getLaborHourRate();
|
|
|
241
|
+ }
|
|
|
242
|
+ //1.查询出物料编号对应的下所有的BOM信息
|
|
|
243
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", String.valueOf(flowInstanceId));
|
|
|
244
|
+ //2.根据费用类型进行不同的费用计算
|
|
|
245
|
+ //查询工序工时
|
|
|
246
|
+ List<String> MarterialNoList = new ArrayList<>();
|
|
|
247
|
+ if (list != null && list.size() > 0) {
|
|
|
248
|
+ MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
|
249
|
+ }
|
|
|
250
|
+ Map<String, List<AppSceneCostProductProcessMaintenance>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
|
|
|
251
|
+ //2.1机器折旧费(机器工时*费率)
|
|
|
252
|
+ if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
|
253
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
254
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
255
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
256
|
+ if (marterialNo != null) {
|
|
|
257
|
+ BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
258
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
|
259
|
+ List<AppSceneCostProductProcessMaintenance> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
|
260
|
+ if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
|
261
|
+ for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
|
262
|
+ AppSceneCostProductProcessMaintenance processHours = costMaterialProcessHours.get(j);
|
|
|
263
|
+ laborHours = laborHours.add(processHours.getMachineHour());
|
|
|
264
|
+ //计算机器成本
|
|
|
265
|
+ totalCost = totalCost.add(processHours.getMachineHour().multiply(hourRate));
|
|
|
266
|
+ }
|
|
|
267
|
+ }
|
|
|
268
|
+ //2.2计算机器成本并存储到成本结果数据表中
|
|
|
269
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
|
270
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
271
|
+ }
|
|
|
272
|
+ }
|
|
|
273
|
+ } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
|
274
|
+ //机物料消耗(辅料工时*费率)
|
|
|
275
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
276
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
277
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
278
|
+ if (marterialNo != null) {
|
|
|
279
|
+ BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
280
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
|
281
|
+ List<AppSceneCostProductProcessMaintenance> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
|
282
|
+ if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
|
283
|
+ for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
|
284
|
+ AppSceneCostProductProcessMaintenance processHours = costMaterialProcessHours.get(j);
|
|
|
285
|
+ //辅料工时
|
|
|
286
|
+ laborHours = laborHours.add(processHours.getAuxiliaryHour());
|
|
|
287
|
+ //机物料消耗
|
|
|
288
|
+ totalCost = totalCost.add(processHours.getAuxiliaryHour().multiply(hourRate));
|
|
|
289
|
+ }
|
|
|
290
|
+ }
|
|
|
291
|
+ //2.2计算机物料消耗存储到成本结果数据表中
|
|
|
292
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
|
293
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
294
|
+ }
|
|
|
295
|
+ }
|
|
|
296
|
+ } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
|
297
|
+ //2.3水电费(燃动力工时*费率)
|
|
|
298
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
299
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
300
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
301
|
+ if (marterialNo != null) {
|
|
|
302
|
+ BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
303
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
|
304
|
+ List<AppSceneCostProductProcessMaintenance> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
|
305
|
+ if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
|
306
|
+ for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
|
307
|
+ AppSceneCostProductProcessMaintenance processHours = costMaterialProcessHours.get(j);
|
|
|
308
|
+ //燃动力工时来源
|
|
|
309
|
+ laborHours = laborHours.add(processHours.getBurningHour());
|
|
|
310
|
+ //水电费(燃动力工时*费率)成本
|
|
|
311
|
+ totalCost = totalCost.add(processHours.getBurningHour().multiply(hourRate));
|
|
|
312
|
+ }
|
|
|
313
|
+ }
|
|
|
314
|
+ //2.2计算机物料消耗存储到成本结果数据表中
|
|
|
315
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
|
316
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
317
|
+ }
|
|
|
318
|
+ }
|
|
|
319
|
+ } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
|
320
|
+ //2.4其他制费(其他工时*费率)
|
|
|
321
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
322
|
+ AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
|
323
|
+ String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
|
324
|
+ if (marterialNo != null) {
|
|
|
325
|
+ BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
326
|
+ BigDecimal laborHours = new BigDecimal("0.0");
|
|
|
327
|
+ List<AppSceneCostProductProcessMaintenance> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
|
328
|
+ if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
|
329
|
+ for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
|
330
|
+ AppSceneCostProductProcessMaintenance processHours = costMaterialProcessHours.get(j);
|
|
|
331
|
+ //其他工时来源
|
|
|
332
|
+ laborHours = laborHours.add(processHours.getOtherHour());
|
|
|
333
|
+ //其他制费成本
|
|
|
334
|
+ totalCost = totalCost.add(processHours.getOtherHour().multiply(hourRate));
|
|
|
335
|
+ }
|
|
|
336
|
+ }
|
|
|
337
|
+ //2.2计算机物料消耗存储到成本结果数据表中
|
|
|
338
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(totalCost + "").costType(feeType).priceOrRate(hourRate).hour(laborHours).build();
|
|
|
339
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
340
|
+ }
|
|
|
341
|
+ }
|
|
|
342
|
+ } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
|
343
|
+ //查出所有的机器折旧费、机物料消耗、水电费、其他制费
|
|
|
344
|
+ list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "ManufacturingCost", String.valueOf(flowInstanceId));
|
|
|
345
|
+ //2.5物流费((机器折旧+机物料消耗+水电费+其他制费)*10.16%)
|
|
|
346
|
+ //按照物料编号进行分组
|
|
|
347
|
+ Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
|
348
|
+ for (String key : materialNoMap.keySet()) {
|
|
|
349
|
+ List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
|
350
|
+ BigDecimal totalCost = new BigDecimal("0.0");
|
|
|
351
|
+ for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
|
352
|
+ AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
|
|
|
353
|
+ String countValue = appSceneCostResultValue.getCountValue();
|
|
|
354
|
+ if (countValue != null) {
|
|
|
355
|
+ totalCost = totalCost.add(new BigDecimal(countValue));
|
|
|
356
|
+ }
|
|
|
357
|
+ }
|
|
|
358
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(appSceneCostResultValues.get(0).getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(totalCost.multiply(new BigDecimal("0.1016")).toString()).costType(feeType).build();
|
|
|
359
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
360
|
+ }
|
|
|
361
|
+ }
|
|
|
362
|
+ }
|
|
|
363
|
+
|
|
|
364
|
+ /**
|
|
|
365
|
+ * 【5.制造费用】
|
|
|
366
|
+ *
|
|
|
367
|
+ * @param topMaterialCode 顶部物料编号
|
|
|
368
|
+ * @param taskType 任务类型
|
|
|
369
|
+ * @param taskCode 任务编号
|
|
|
370
|
+ * @param flowInstanceId 流程实例id
|
|
|
371
|
+ * @param costType 流程实例id
|
|
|
372
|
+ */
|
|
|
373
|
+ public static void countStandardCostByTopMaterialCode(String topMaterialCode, String taskType, String taskCode, Integer flowInstanceId, String costType, String versionNumber) {
|
|
|
374
|
+ //1.查询出根物料编号对应的下所有的BOM信息结果值
|
|
|
375
|
+ List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getAllResultValueByTopMaterialNo(topMaterialCode, String.valueOf(flowInstanceId));
|
|
|
376
|
+ //2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
|
|
|
377
|
+ //按照物料编号进行分组
|
|
|
378
|
+ Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
|
379
|
+ //遍历根物料下所有的物料进行该物料本阶成本和费用类别的统计
|
|
|
380
|
+ for (String key : materialNoMap.keySet()) {
|
|
|
381
|
+ List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
|
382
|
+ //按照费用类别进行分组
|
|
|
383
|
+ Map<String, List<AppSceneCostResultValue>> costTypeMap = appSceneCostResultValues.stream().filter(s -> s.getCostType() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getCostType));
|
|
|
384
|
+ //【本阶标准成本】
|
|
|
385
|
+ BigDecimal currentCost = new BigDecimal("0.0");
|
|
|
386
|
+ //1.本阶物料成本
|
|
|
387
|
+ BigDecimal materialCost = new BigDecimal("0.0");
|
|
|
388
|
+ //2.本阶人工成本
|
|
|
389
|
+ BigDecimal laborCost = new BigDecimal("0.0");
|
|
|
390
|
+ //3.本阶制造费(设备费)
|
|
|
391
|
+ BigDecimal equipmentCost = new BigDecimal("0.0");
|
|
|
392
|
+ //4.本阶制造费(辅料费用)
|
|
|
393
|
+ BigDecimal supplyMaterialCost = new BigDecimal("0.0");
|
|
|
394
|
+ //5.本阶制造费(水电费、燃动费)
|
|
|
395
|
+ BigDecimal driveCost = new BigDecimal("0.0");
|
|
|
396
|
+ //6.本阶制造费(其他制造费用)
|
|
|
397
|
+ BigDecimal otherCost = new BigDecimal("0.0");
|
|
|
398
|
+ //7.本阶制造费(物流费)
|
|
|
399
|
+ BigDecimal logisticsCost = new BigDecimal("0.0");
|
|
|
400
|
+ //物料单价
|
|
|
401
|
+ BigDecimal materialUnitPrice = new BigDecimal("0.0");
|
|
|
402
|
+ //人员工时、小时费率
|
|
|
403
|
+ BigDecimal laborHour = new BigDecimal("0.0");
|
|
|
404
|
+ BigDecimal laborHourRate = new BigDecimal("0.0");
|
|
|
405
|
+ //设备工时、小时费率
|
|
|
406
|
+ BigDecimal equipmentHour = new BigDecimal("0.0");
|
|
|
407
|
+ BigDecimal equipmentHourRate = new BigDecimal("0.0");
|
|
|
408
|
+ //辅料工时、小时费率
|
|
|
409
|
+ BigDecimal supplyMaterialHour = new BigDecimal("0.0");
|
|
|
410
|
+ BigDecimal supplyMaterialHourRate = new BigDecimal("0.0");
|
|
|
411
|
+ //燃动工时、小时费率
|
|
|
412
|
+ BigDecimal driveHour = new BigDecimal("0.0");
|
|
|
413
|
+ BigDecimal driveHourRate = new BigDecimal("0.0");
|
|
|
414
|
+ //其他工时、小时费率
|
|
|
415
|
+ BigDecimal otherHour = new BigDecimal("0.0");
|
|
|
416
|
+ BigDecimal otherHourRate = new BigDecimal("0.0");
|
|
|
417
|
+ AppSceneCostResultValue currentMaterialCost = null;
|
|
|
418
|
+ //遍历所有费用类别计算本阶标准成本
|
|
|
419
|
+ for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
|
420
|
+ if (j == 0) {
|
|
|
421
|
+ //初始化当前物料成本信息
|
|
|
422
|
+ currentMaterialCost = appSceneCostResultValues.get(0);
|
|
|
423
|
+ }
|
|
|
424
|
+ AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
|
|
|
425
|
+ String countValue = appSceneCostResultValue.getCountValue();
|
|
|
426
|
+ if (countValue != null) {
|
|
|
427
|
+ currentCost = currentCost.add(new BigDecimal(countValue));
|
|
|
428
|
+ }
|
|
|
429
|
+ }
|
|
|
430
|
+ //计算本阶各个费用类别费用以及记录本阶物料的工时和小时费率
|
|
|
431
|
+ for (String feeType : costTypeMap.keySet()) {
|
|
|
432
|
+ List<AppSceneCostResultValue> appSceneCostResultValues1 = costTypeMap.get(feeType);
|
|
|
433
|
+ for (int m = 0; m < appSceneCostResultValues1.size(); m++) {
|
|
|
434
|
+ if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) {
|
|
|
435
|
+ //物料成本
|
|
|
436
|
+ materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
437
|
+ //物料单价
|
|
|
438
|
+ materialUnitPrice = appSceneCostResultValues1.get(m).getPriceOrRate();
|
|
|
439
|
+ //TODO 数量
|
|
|
440
|
+ currentMaterialCost.setNum(appSceneCostResultValues1.get(m).getNum());
|
|
|
441
|
+ } else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) {
|
|
|
442
|
+ //人工成本
|
|
|
443
|
+ laborCost = laborCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
444
|
+ //人工工时、小时费率
|
|
|
445
|
+ laborHour = laborHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
446
|
+ laborHourRate = laborHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
447
|
+ } else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
|
448
|
+ //设备费用
|
|
|
449
|
+ equipmentCost = equipmentCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
450
|
+ //设备工时、小时费率
|
|
|
451
|
+ equipmentHour = equipmentHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
452
|
+ equipmentHourRate = equipmentHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
453
|
+ } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
|
454
|
+ //辅料费用
|
|
|
455
|
+ supplyMaterialCost = supplyMaterialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
456
|
+ //辅料工时、小时费率
|
|
|
457
|
+ supplyMaterialHour = supplyMaterialHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
458
|
+ supplyMaterialHourRate = supplyMaterialHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
459
|
+ } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
|
460
|
+ //燃动费用
|
|
|
461
|
+ driveCost = driveCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
462
|
+ //燃动工时、小时费率
|
|
|
463
|
+ driveHour = driveHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
464
|
+ driveHourRate = driveHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
465
|
+ } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
|
466
|
+ //物流费用
|
|
|
467
|
+ logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
468
|
+ } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
|
469
|
+ //其他费用
|
|
|
470
|
+ otherCost = otherCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue()));
|
|
|
471
|
+ //其他工时、小时费率
|
|
|
472
|
+ otherHour = otherHour.add(appSceneCostResultValues1.get(m).getHour());
|
|
|
473
|
+ otherHourRate = otherHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate());
|
|
|
474
|
+ }
|
|
|
475
|
+ }
|
|
|
476
|
+ }
|
|
|
477
|
+ //本阶不同费用类别成本统计
|
|
|
478
|
+ JSONObject currentLevelCostTypeDetail = new JSONObject();
|
|
|
479
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.MaterialCost.getCode(), materialCost);
|
|
|
480
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.LaborCost.getCode(), laborCost);
|
|
|
481
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.EquipmentFee.getCode(), equipmentCost);
|
|
|
482
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.SupplyMaterialFee.getCode(), supplyMaterialCost);
|
|
|
483
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.DriverFee.getCode(), driveCost);
|
|
|
484
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.LogisticsFee.getCode(), logisticsCost);
|
|
|
485
|
+ currentLevelCostTypeDetail.put(FeeTypeEnum.OtherFee.getCode(), otherCost);
|
|
|
486
|
+ //统计本阶不同费用类别工时、小时费率
|
|
|
487
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.MaterialUnitPrice.getCode(), materialUnitPrice);
|
|
|
488
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHour.getCode(), laborHour);
|
|
|
489
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHourRate.getCode(), laborHourRate);
|
|
|
490
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHour.getCode(), equipmentHour);
|
|
|
491
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHourRate.getCode(), equipmentHourRate);
|
|
|
492
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHour.getCode(), supplyMaterialHour);
|
|
|
493
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHourRate.getCode(), supplyMaterialHourRate);
|
|
|
494
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHour.getCode(), driveHour);
|
|
|
495
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHourRate.getCode(), driveHourRate);
|
|
|
496
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHour.getCode(), otherHour);
|
|
|
497
|
+ currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHourRate.getCode(), otherHourRate);
|
|
|
498
|
+ AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(currentMaterialCost.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(Integer.valueOf(flowInstanceId)).countValue(currentCost.toString()).costDetail(JSON.toJSONString(currentLevelCostTypeDetail)).costType(costType).num(currentMaterialCost.getNum()).build();
|
|
|
499
|
+ standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
|
500
|
+ }
|
|
|
501
|
+ //3.计算出所有的单个物料的累计标准成本
|
|
|
502
|
+ List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, String.valueOf(flowInstanceId));
|
|
|
503
|
+ //【累计成本】的计算
|
|
|
504
|
+ totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, String.valueOf(flowInstanceId), versionNumber);
|
|
|
505
|
+ }
|
|
|
506
|
+
|
|
127
|
507
|
/**
|
|
128
|
508
|
* 获取任务流程相关信息
|
|
129
|
509
|
*
|
|
|
@@ -190,7 +570,7 @@ public class StandardCostService {
|
|
190
|
570
|
*/
|
|
191
|
571
|
private static FlowTaskInfoVO queryFlowDefinitionByFlowInstanceId(FlowTaskInfoVO flowTaskInfoVO) {
|
|
192
|
572
|
String sql = "SELECT A.model_json from qomo_flow_definition as A LEFT JOIN qomo_flow_instance AS B ON A.`code`=B.flow_definition_code WHERE B.id=" + flowTaskInfoVO.getFlowInstanceId() + " limit 1";
|
|
193
|
|
- String blob = standardCostService.costMaterialBomMapper.customSelectBlobModelJson(sql);
|
|
|
573
|
+ String blob = standardCostService.appSceneCostBomRelevancyMapper.customSelectBlobModelJson(sql);
|
|
194
|
574
|
if (blob != null) {
|
|
195
|
575
|
if (blob != null && blob.contains("topMaterialCode")) {
|
|
196
|
576
|
JSONObject jsonObject1 = JSON.parseObject(blob);
|
|
|
@@ -218,30 +598,7 @@ public class StandardCostService {
|
|
218
|
598
|
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
|
|
219
|
599
|
//成本类型
|
|
220
|
600
|
String feeType = FeeTypeEnum.MaterialCost.getCode();
|
|
221
|
|
- //1.查询出物料编号对应的下所有的BOM信息
|
|
222
|
|
- List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
|
|
223
|
|
- //2.计算出所有的单个物料的物料成本
|
|
224
|
|
- //2.1查询出物料的单价和采购数量
|
|
225
|
|
- List<String> MarterialNoList = new ArrayList<>();
|
|
226
|
|
- if (list != null && list.size() > 0) {
|
|
227
|
|
- MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
228
|
|
- }
|
|
229
|
|
- //查询物料的采购价
|
|
230
|
|
- Map<String, BigDecimal> purchasePriceMap = standardCostService.costPurchasePriceService.getMinCostPurchasePriceByMaterialNo(MarterialNoList);
|
|
231
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
232
|
|
- AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
233
|
|
- String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
234
|
|
- Integer num = appSceneCostResultValue.getNum();
|
|
235
|
|
- if (marterialNo != null && num != null) {
|
|
236
|
|
- BigDecimal price = purchasePriceMap.get(marterialNo);
|
|
237
|
|
- BigDecimal number = new BigDecimal(num.toString());
|
|
238
|
|
- //单价乘以数量
|
|
239
|
|
- BigDecimal totalCost = price.multiply(number);
|
|
240
|
|
- //2.2计算出人工成本并存储到成本结果数据表中
|
|
241
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).costType(feeType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").priceOrRate(price).build();
|
|
242
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
243
|
|
- }
|
|
244
|
|
- }
|
|
|
601
|
+
|
|
245
|
602
|
} catch (Exception e) {
|
|
246
|
603
|
throw new RuntimeException(e);
|
|
247
|
604
|
}
|
|
|
@@ -268,42 +625,7 @@ public class StandardCostService {
|
|
268
|
625
|
log.info("sql1:" + sql1);
|
|
269
|
626
|
String sql = sql1.replaceAll("^\"|\"$", ""); // 去除首尾引号
|
|
270
|
627
|
log.info("sql:" + sql);
|
|
271
|
|
- JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
|
|
272
|
|
- BigDecimal hourRate = new BigDecimal("0");
|
|
273
|
|
- if (jsonObject != null) {
|
|
274
|
|
- AppSceneCostHourRate rate = JSON.toJavaObject(jsonObject, AppSceneCostHourRate.class);
|
|
275
|
|
- hourRate = rate.getLaborHourRate();
|
|
276
|
|
- }
|
|
277
|
|
- //1.查询出物料编号对应的下所有的BOM信息
|
|
278
|
|
- List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
|
|
279
|
|
- //2.计算出所有的单个物料的人工成本
|
|
280
|
|
- //2.1查询出物料的人员工时和人工小时费率(涉及:小时费率表和工序表)
|
|
281
|
|
- List<String> MarterialNoList = new ArrayList<>();
|
|
282
|
|
- if (list != null && list.size() > 0) {
|
|
283
|
|
- MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
284
|
|
- }
|
|
285
|
|
- //查询工序工时
|
|
286
|
|
- Map<String, List<AppSceneCostMaterialProcessHours>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
|
|
287
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
288
|
|
- AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
289
|
|
- String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
290
|
|
- if (marterialNo != null) {
|
|
291
|
|
- BigDecimal totalCost = new BigDecimal("0.0");
|
|
292
|
|
- BigDecimal laborHours = new BigDecimal("0.0");
|
|
293
|
|
- List<AppSceneCostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
294
|
|
- if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
295
|
|
- for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
296
|
|
- AppSceneCostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
297
|
|
- laborHours = laborHours.add(processHours.getLaborHours());
|
|
298
|
|
- //计算总人工成本
|
|
299
|
|
- totalCost = totalCost.add(processHours.getLaborHours().multiply(hourRate));
|
|
300
|
|
- }
|
|
301
|
|
- }
|
|
302
|
|
- //2.2计算出人工成本并存储到成本结果数据表中
|
|
303
|
|
- 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();
|
|
304
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
305
|
|
- }
|
|
306
|
|
- }
|
|
|
628
|
+
|
|
307
|
629
|
} catch (Exception e) {
|
|
308
|
630
|
throw new RuntimeException(e);
|
|
309
|
631
|
}
|
|
|
@@ -336,132 +658,7 @@ public class StandardCostService {
|
|
336
|
658
|
log.info("sql1:" + sql1);
|
|
337
|
659
|
String sql = sql1.replaceAll("^\"|\"$", ""); // 去除首尾引号
|
|
338
|
660
|
log.info("sql:" + sql);
|
|
339
|
|
- JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
|
|
340
|
|
- BigDecimal hourRate = new BigDecimal("0");
|
|
341
|
|
- if (jsonObject != null) {
|
|
342
|
|
- AppSceneCostHourRate rate = JSON.toJavaObject(jsonObject, AppSceneCostHourRate.class);
|
|
343
|
|
- hourRate = rate.getLaborHourRate();
|
|
344
|
|
- }
|
|
345
|
|
- //1.查询出物料编号对应的下所有的BOM信息
|
|
346
|
|
- List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
|
|
347
|
|
- //2.根据费用类型进行不同的费用计算
|
|
348
|
|
- //查询工序工时
|
|
349
|
|
- List<String> MarterialNoList = new ArrayList<>();
|
|
350
|
|
- if (list != null && list.size() > 0) {
|
|
351
|
|
- MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
|
|
352
|
|
- }
|
|
353
|
|
- Map<String, List<AppSceneCostMaterialProcessHours>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
|
|
354
|
|
- //2.1机器折旧费(机器工时*费率)
|
|
355
|
|
- if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
|
|
356
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
357
|
|
- AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
358
|
|
- String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
359
|
|
- if (marterialNo != null) {
|
|
360
|
|
- BigDecimal totalCost = new BigDecimal("0.0");
|
|
361
|
|
- BigDecimal laborHours = new BigDecimal("0.0");
|
|
362
|
|
- List<AppSceneCostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
363
|
|
- if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
364
|
|
- for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
365
|
|
- AppSceneCostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
366
|
|
- laborHours = laborHours.add(processHours.getDeviceHours());
|
|
367
|
|
- //计算机器成本
|
|
368
|
|
- totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
369
|
|
- }
|
|
370
|
|
- }
|
|
371
|
|
- //2.2计算机器成本并存储到成本结果数据表中
|
|
372
|
|
- 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();
|
|
373
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
374
|
|
- }
|
|
375
|
|
- }
|
|
376
|
|
- } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
|
|
377
|
|
- //机物料消耗(辅料工时*费率)
|
|
378
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
379
|
|
- AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
380
|
|
- String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
381
|
|
- if (marterialNo != null) {
|
|
382
|
|
- BigDecimal totalCost = new BigDecimal("0.0");
|
|
383
|
|
- BigDecimal laborHours = new BigDecimal("0.0");
|
|
384
|
|
- List<AppSceneCostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
385
|
|
- if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
386
|
|
- for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
387
|
|
- AppSceneCostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
388
|
|
- //TODO 辅料工时来源
|
|
389
|
|
- laborHours = laborHours.add(processHours.getDeviceHours());
|
|
390
|
|
- //机物料消耗
|
|
391
|
|
- totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
392
|
|
- }
|
|
393
|
|
- }
|
|
394
|
|
- //2.2计算机物料消耗存储到成本结果数据表中
|
|
395
|
|
- 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();
|
|
396
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
397
|
|
- }
|
|
398
|
|
- }
|
|
399
|
|
- } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
|
|
400
|
|
- //2.3水电费(燃动力工时*费率)
|
|
401
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
402
|
|
- AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
403
|
|
- String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
404
|
|
- if (marterialNo != null) {
|
|
405
|
|
- BigDecimal totalCost = new BigDecimal("0.0");
|
|
406
|
|
- BigDecimal laborHours = new BigDecimal("0.0");
|
|
407
|
|
- List<AppSceneCostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
408
|
|
- if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
409
|
|
- for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
410
|
|
- AppSceneCostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
411
|
|
- //TODO 燃动力工时来源
|
|
412
|
|
- laborHours = laborHours.add(processHours.getDeviceHours());
|
|
413
|
|
- //水电费(燃动力工时*费率)成本
|
|
414
|
|
- totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
415
|
|
- }
|
|
416
|
|
- }
|
|
417
|
|
- //2.2计算机物料消耗存储到成本结果数据表中
|
|
418
|
|
- 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
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
420
|
|
- }
|
|
421
|
|
- }
|
|
422
|
|
- } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
|
|
423
|
|
- //2.4其他制费(其他工时*费率)
|
|
424
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
425
|
|
- AppSceneCostResultValue appSceneCostResultValue = list.get(i);
|
|
426
|
|
- String marterialNo = appSceneCostResultValue.getMarterialNo();
|
|
427
|
|
- if (marterialNo != null) {
|
|
428
|
|
- BigDecimal totalCost = new BigDecimal("0.0");
|
|
429
|
|
- BigDecimal laborHours = new BigDecimal("0.0");
|
|
430
|
|
- List<AppSceneCostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
|
|
431
|
|
- if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
|
|
432
|
|
- for (int j = 0; j < costMaterialProcessHours.size(); j++) {
|
|
433
|
|
- AppSceneCostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
|
|
434
|
|
- //TODO 其他工时来源
|
|
435
|
|
- laborHours = laborHours.add(processHours.getDeviceHours());
|
|
436
|
|
- //其他制费成本
|
|
437
|
|
- totalCost = totalCost.add(processHours.getDeviceHours().multiply(hourRate));
|
|
438
|
|
- }
|
|
439
|
|
- }
|
|
440
|
|
- //2.2计算机物料消耗存储到成本结果数据表中
|
|
441
|
|
- 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();
|
|
442
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
443
|
|
- }
|
|
444
|
|
- }
|
|
445
|
|
- } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
|
|
446
|
|
- //查出所有的机器折旧费、机物料消耗、水电费、其他制费
|
|
447
|
|
- list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "ManufacturingCost", flowInstanceId);
|
|
448
|
|
- //2.5物流费((机器折旧+机物料消耗+水电费+其他制费)*10.16%)
|
|
449
|
|
- //按照物料编号进行分组
|
|
450
|
|
- Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
|
|
451
|
|
- for (String key : materialNoMap.keySet()) {
|
|
452
|
|
- List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
|
|
453
|
|
- BigDecimal totalCost = new BigDecimal("0.0");
|
|
454
|
|
- for (int j = 0; j < appSceneCostResultValues.size(); j++) {
|
|
455
|
|
- AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
|
|
456
|
|
- String countValue = appSceneCostResultValue.getCountValue();
|
|
457
|
|
- if (countValue != null) {
|
|
458
|
|
- totalCost = totalCost.add(new BigDecimal(countValue));
|
|
459
|
|
- }
|
|
460
|
|
- }
|
|
461
|
|
- AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(appSceneCostResultValues.get(0).getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost.multiply(new BigDecimal("0.1016")).toString()).costType(feeType).build();
|
|
462
|
|
- standardCostService.iAppSceneCostResultValueService.save(resultValue);
|
|
463
|
|
- }
|
|
464
|
|
- }
|
|
|
661
|
+
|
|
465
|
662
|
} catch (Exception e) {
|
|
466
|
663
|
throw new RuntimeException(e);
|
|
467
|
664
|
}
|
|
|
@@ -484,134 +681,6 @@ public class StandardCostService {
|
|
484
|
681
|
//获取流程id
|
|
485
|
682
|
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
|
|
486
|
683
|
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
|
|
- }
|
|
541
|
|
- }
|
|
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
|
|
- }
|
|
585
|
|
- }
|
|
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);
|
|
610
|
|
- }
|
|
611
|
|
- //3.计算出所有的单个物料的累计标准成本
|
|
612
|
|
- List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
|
|
613
|
|
- //【累计成本】的计算
|
|
614
|
|
- totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
|
|
615
|
684
|
} catch (Exception e) {
|
|
616
|
685
|
e.printStackTrace();
|
|
617
|
686
|
throw new RuntimeException("计算成本失败");
|
|
|
@@ -627,9 +696,9 @@ public class StandardCostService {
|
|
627
|
696
|
* @param taskCode
|
|
628
|
697
|
* @param flowInstanceId
|
|
629
|
698
|
*/
|
|
630
|
|
- private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
|
|
|
699
|
+ private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId, String versionNumber) {
|
|
631
|
700
|
try {
|
|
632
|
|
- List<AppSceneCostStandardDetail> costStandardDetails = new ArrayList<>();
|
|
|
701
|
+ List<AppSceneCostStandardResult> costStandardResults = new ArrayList<>();
|
|
633
|
702
|
//父类对应的子节点(除了最上层节点)
|
|
634
|
703
|
Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
|
|
635
|
704
|
for (int i = 0; i < standardCostList.size(); i++) {
|
|
|
@@ -660,16 +729,16 @@ public class StandardCostService {
|
|
660
|
729
|
oldAppSceneCostResultValue.setTotalValue(hourOrRateResultValue.getTotalCost().toString());
|
|
661
|
730
|
standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
|
|
662
|
731
|
//构造单行成本查询记录
|
|
663
|
|
- AppSceneCostStandardDetail costStandardDetail = AppSceneCostStandardDetail.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).materialName(oldAppSceneCostResultValue.getMarterialNo()).parentMaterialNumber(oldAppSceneCostResultValue.getParentMarterialNo())
|
|
664
|
|
-// .versionNumber()
|
|
|
732
|
+ AppSceneCostStandardResult costStandardResultValue = AppSceneCostStandardResult.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).parentMatnr(oldAppSceneCostResultValue.getParentMarterialNo()).versionNumber(versionNumber)
|
|
665
|
733
|
// .level()
|
|
666
|
734
|
// .sort()
|
|
667
|
735
|
// .figureNumber()
|
|
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);
|
|
|
736
|
+// .dosage(oldAppSceneCostResultValue.getNum() != null ? oldAppSceneCostResultValue.getNum().doubleValue() : 0).unit(oldAppSceneCostResultValue.getUnit())
|
|
|
737
|
+ .materialCostStageInter(costDetailJson.getBigDecimal(FeeTypeEnum.MaterialCost.getCode())).laborCostStage(costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode())).equipCostStage(costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode())).auxiliaryCostStage(costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode())).burningCostStage(costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode())).stageLogisticsCost(costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode())).otherCostStage(costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode())).totalStandardCostInter(new BigDecimal(oldAppSceneCostResultValue.getCountValue())).materialCostAccumulated(costDetailJson.getBigDecimal(TotalCostEnum.TotalMaterialCost.getCode())).laborCostAccumulated(costDetailJson.getBigDecimal(TotalCostEnum.TotalLaborCost.getCode())).equipCostAccumulated(costDetailJson.getBigDecimal(TotalCostEnum.TotalEquipmentFee.getCode())).auxiliaryCostAccumulated(costDetailJson.getBigDecimal(TotalCostEnum.TotalSupplyMaterialFee.getCode())).burningCostAccumulated(costDetailJson.getBigDecimal(TotalCostEnum.TotalDriverFee.getCode())).totalLogisticsCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLogisticsFee.getCode())).otherCostAccumulated(costDetailJson.getBigDecimal(TotalCostEnum.TotalOtherFee.getCode())).totalStandardCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalStandardCost.getCode())).createdTime(new Date()).build();
|
|
|
738
|
+ costStandardResults.add(costStandardResultValue);
|
|
670
|
739
|
}
|
|
671
|
740
|
//更新结果集到标准成本单行查询中去
|
|
672
|
|
- standardCostService.iAppSceneCostStandardDetailService.saveBatch(costStandardDetails);
|
|
|
741
|
+ standardCostService.iAppSceneCostStandardResultService.saveBatch(costStandardResults);
|
|
673
|
742
|
} catch (Exception e) {
|
|
674
|
743
|
e.printStackTrace();
|
|
675
|
744
|
}
|