Ver código fonte

优化标准成本计算功能

wangqiong 1 ano atrás
pai
commit
2872719a68

+ 26
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/FlowDefinitionController.java Ver arquivo

1
+package com.zzsmart.qomo.kn.cost.manage.controller;
2
+
3
+import com.zzsmart.qomo.controller.DataFlowDefinitionController;
4
+import org.slf4j.Logger;
5
+import org.slf4j.LoggerFactory;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RestController;
8
+
9
+@RestController
10
+@RequestMapping
11
+public class FlowDefinitionController {
12
+
13
+    private static final Logger log = LoggerFactory.getLogger(DataFlowDefinitionController.class);
14
+//    @Autowired
15
+//    FlowDefinitionService definitionService;
16
+
17
+//    @GetMapping({"/list"})
18
+//    public Result<IPage<FlowDefinition>> queryPageList(FlowDefinition flowDefinition, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
19
+//        QueryWrapper<FlowDefinition> queryWrapper = QueryGenerator.initQueryWrapper(flowDefinition, req.getParameterMap());
20
+//        Page<FlowDefinition> page = new Page((long) pageNo, (long) pageSize);
21
+//        LambdaQueryWrapper<FlowDefinition> wrapper = queryWrapper.lambda();
22
+//        wrapper.orderByDesc(FlowDefinition::getCreateTime);
23
+//        IPage<FlowDefinition> pageList = definitionService.queryPageList(page, wrapper);
24
+//        return Result.OK(pageList);
25
+//    }
26
+}

+ 4
- 1
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/FeeTypeEnum.java Ver arquivo

8
  * @Created wangqiong
8
  * @Created wangqiong
9
  */
9
  */
10
 public enum FeeTypeEnum {
10
 public enum FeeTypeEnum {
11
-    EquipmentFee("EquipmentFee", "机器折旧费"), SupplyMaterialFee("SupplyMaterialFee", "辅料费"), DriverFee("DriverFee", "水电费"), OtherFee("OtherFee", "其他费用"), LogisticsFee("LogisticsFee", "物流费");
11
+
12
+    LaborCost("LaborCost", "人工成本"),
13
+    MaterialCost("MaterialCost", "物料成本"),
14
+    EquipmentFee("EquipmentFee", "设备费"), SupplyMaterialFee("SupplyMaterialFee", "辅料费"), DriverFee("DriverFee", "水电费"), OtherFee("OtherFee", "其他费用"), LogisticsFee("LogisticsFee", "物流费");
12
 
15
 
13
     private final String code;
16
     private final String code;
14
     private final String text;
17
     private final String text;

+ 3
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/mapper/CostMaterialBomMapper.java Ver arquivo

7
 import org.apache.ibatis.annotations.Param;
7
 import org.apache.ibatis.annotations.Param;
8
 import org.apache.ibatis.annotations.Select;
8
 import org.apache.ibatis.annotations.Select;
9
 
9
 
10
+import java.sql.Blob;
10
 import java.util.List;
11
 import java.util.List;
11
 
12
 
12
 /**
13
 /**
31
 
32
 
32
     @Select("${selectSql}")
33
     @Select("${selectSql}")
33
     JSONObject customSelectOne(@Param("selectSql") String selectSql);
34
     JSONObject customSelectOne(@Param("selectSql") String selectSql);
35
+    @Select("${SelectBlobModel}")
36
+    String customSelectBlobModelJson(@Param("SelectBlobModel") String SelectBlobModel);
34
 }
37
 }

+ 71
- 34
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java Ver arquivo

2
 
2
 
3
 import com.alibaba.fastjson.JSON;
3
 import com.alibaba.fastjson.JSON;
4
 import com.alibaba.fastjson.JSONObject;
4
 import com.alibaba.fastjson.JSONObject;
5
-import com.zzsmart.qomo.dao.entity.FlowDefinition;
6
 import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostResultValue;
5
 import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostResultValue;
7
 import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
6
 import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
8
 import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
7
 import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
9
 import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
8
 import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
10
 import com.zzsmart.qomo.kn.cost.manage.enums.FeeTypeEnum;
9
 import com.zzsmart.qomo.kn.cost.manage.enums.FeeTypeEnum;
11
 import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
10
 import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
12
-import com.zzsmart.qomo.kn.cost.manage.service.CostMaterialProcessHoursService;
13
-import com.zzsmart.qomo.kn.cost.manage.service.CostPurchasePriceService;
14
-import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
15
-import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
11
+import com.zzsmart.qomo.kn.cost.manage.service.*;
16
 import com.zzsmart.qomo.kn.cost.manage.vo.FlowTaskInfoVO;
12
 import com.zzsmart.qomo.kn.cost.manage.vo.FlowTaskInfoVO;
17
 import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext;
13
 import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext;
18
 import lombok.extern.slf4j.Slf4j;
14
 import lombok.extern.slf4j.Slf4j;
34
      */
30
      */
35
     @Autowired
31
     @Autowired
36
     CostMaterialBomMapper costMaterialBomMapper;
32
     CostMaterialBomMapper costMaterialBomMapper;
33
+    @Autowired
34
+    CostMaterialBomService costMaterialBomService;
37
 
35
 
38
     /**
36
     /**
39
      * 小时费率
37
      * 小时费率
61
     public void init() {
59
     public void init() {
62
         standardCostService = this;
60
         standardCostService = this;
63
         standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
61
         standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
62
+        standardCostService.costMaterialBomService = this.costMaterialBomService;
64
         standardCostService.costPurchasePriceService = this.costPurchasePriceService;
63
         standardCostService.costPurchasePriceService = this.costPurchasePriceService;
65
         standardCostService.iHourRateService = this.iHourRateService;
64
         standardCostService.iHourRateService = this.iHourRateService;
66
         standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
65
         standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
85
             String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
84
             String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
86
             //1.查询出所有满足物料编号的物料(BOM物料)
85
             //1.查询出所有满足物料编号的物料(BOM物料)
87
             String sql = flowTaskInfoVO.getSqlString();
86
             String sql = flowTaskInfoVO.getSqlString();
88
-            List<CostMaterialBom> list = standardCostService.costMaterialBomMapper.customSelect(sql);
87
+            log.info("传递过来的SQL语句:" + sql);
88
+            List<CostMaterialBom> list = standardCostService.costMaterialBomService.queryAllBomInfoBytopMaterialCode(topMaterialCode);
89
             log.info("Full EmptyTask list: {}", list);
89
             log.info("Full EmptyTask list: {}", list);
90
             //2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
90
             //2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
91
             for (int i = 0; list != null && i < list.size(); i++) {
91
             for (int i = 0; list != null && i < list.size(); i++) {
92
                 CostMaterialBom material = list.get(i);
92
                 CostMaterialBom material = list.get(i);
93
-                AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).build();
93
+                AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).num(material.getNumber()).build();
94
                 standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
94
                 standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
95
             }
95
             }
96
         } catch (Exception e) {
96
         } catch (Exception e) {
113
                 String s1 = split[i];
113
                 String s1 = split[i];
114
                 if (s1.contains("taskType")) {
114
                 if (s1.contains("taskType")) {
115
                     String[] split1 = s1.split("=");
115
                     String[] split1 = s1.split("=");
116
-                    flowTaskInfoVO.setTaskType(split1[1]);
116
+                    if (split1[1].contains("\"")) {
117
+                        split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
118
+                        flowTaskInfoVO.setTaskType(split1[1]);
119
+                    } else {
120
+                        flowTaskInfoVO.setTaskType(split1[1]);
121
+                    }
117
                 } else if (s1.contains("taskCode")) {
122
                 } else if (s1.contains("taskCode")) {
118
                     String[] split1 = s1.split(":");
123
                     String[] split1 = s1.split(":");
119
-                    flowTaskInfoVO.setTaskCode(split1[1]);
124
+                    if (split1[1].contains("\"")) {
125
+                        split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
126
+                        flowTaskInfoVO.setTaskCode(split1[1]);
127
+                    } else {
128
+                        flowTaskInfoVO.setTaskCode(split1[1]);
129
+                    }
120
                 } else if (s1.contains("flowInstanceId")) {
130
                 } else if (s1.contains("flowInstanceId")) {
121
                     String[] split1 = s1.split("=");
131
                     String[] split1 = s1.split("=");
122
-                    flowTaskInfoVO.setFlowInstanceId(split1[1]);
132
+                    if (split1[1].contains("\"")) {
133
+                        split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
134
+                        flowTaskInfoVO.setFlowInstanceId(split1[1]);
135
+                    } else {
136
+                        flowTaskInfoVO.setFlowInstanceId(split1[1]);
137
+                    }
123
                 } else if (s1.contains("sqlString")) {
138
                 } else if (s1.contains("sqlString")) {
124
                     String[] split1 = s1.split(":");
139
                     String[] split1 = s1.split(":");
125
-                    flowTaskInfoVO.setSqlString(split1[1]);
140
+                    if (split1[1].contains("\"")) {
141
+                        split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
142
+                        flowTaskInfoVO.setSqlString(split1[1]);
143
+                    } else {
144
+                        flowTaskInfoVO.setSqlString(split1[1]);
145
+                    }
146
+                } else if (s.contains("feeType") && s1.contains("feeType")) {
147
+                    String[] split1 = s1.split(":");
148
+                    if (split1[1].contains("\"")) {
149
+                        split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
150
+                        flowTaskInfoVO.setFeeType(split1[1]);
151
+                    } else {
152
+                        flowTaskInfoVO.setFeeType(split1[1]);
153
+                    }
126
                 }
154
                 }
127
             }
155
             }
128
         }
156
         }
135
      * @param flowTaskInfoVO
163
      * @param flowTaskInfoVO
136
      */
164
      */
137
     private static FlowTaskInfoVO queryFlowDefinitionByFlowInstanceId(FlowTaskInfoVO flowTaskInfoVO) {
165
     private static FlowTaskInfoVO queryFlowDefinitionByFlowInstanceId(FlowTaskInfoVO flowTaskInfoVO) {
138
-        String sql = "SELECT A.id,A.`code`,A.`name`,A.version,A.release_state,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";
139
-        JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
140
-        FlowDefinition flowDefinition = JSON.toJavaObject(jsonObject, FlowDefinition.class);
141
-        if (flowDefinition != null) {
142
-            log.info("flowDefinition: {}", flowDefinition);
143
-            String modelJson = flowDefinition.getModelJson();
144
-            JSONObject jsonObject1 = JSON.parseObject(modelJson);
145
-            if (jsonObject1 != null) {
166
+        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";
167
+        String blob = standardCostService.costMaterialBomMapper.customSelectBlobModelJson(sql);
168
+        if (blob != null) {
169
+            if (blob != null && blob.contains("topMaterialCode")) {
170
+                JSONObject jsonObject1 = JSON.parseObject(blob);
146
                 String topMaterialCode = jsonObject1.getString("topMaterialCode");
171
                 String topMaterialCode = jsonObject1.getString("topMaterialCode");
147
                 flowTaskInfoVO.setTopMaterialCode(topMaterialCode);
172
                 flowTaskInfoVO.setTopMaterialCode(topMaterialCode);
148
             }
173
             }
165
             String taskCode = flowTaskInfoVO.getTaskCode();
190
             String taskCode = flowTaskInfoVO.getTaskCode();
166
             //获取流程id
191
             //获取流程id
167
             String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
192
             String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
193
+            //成本类型
194
+            String feeType = FeeTypeEnum.MaterialCost.getCode();
168
             //1.查询出物料编号对应的下所有的BOM信息
195
             //1.查询出物料编号对应的下所有的BOM信息
169
             List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
196
             List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
170
             //2.计算出所有的单个物料的物料成本
197
             //2.计算出所有的单个物料的物料成本
179
                 AppSceneCostResultValue appSceneCostResultValue = list.get(i);
206
                 AppSceneCostResultValue appSceneCostResultValue = list.get(i);
180
                 String marterialNo = appSceneCostResultValue.getMarterialNo();
207
                 String marterialNo = appSceneCostResultValue.getMarterialNo();
181
                 Integer num = appSceneCostResultValue.getNum();
208
                 Integer num = appSceneCostResultValue.getNum();
182
-                if (marterialNo != null) {
209
+                if (marterialNo != null && num != null) {
183
                     BigDecimal price = purchasePriceMap.get(marterialNo);
210
                     BigDecimal price = purchasePriceMap.get(marterialNo);
184
                     BigDecimal number = new BigDecimal(num.toString());
211
                     BigDecimal number = new BigDecimal(num.toString());
185
                     //单价乘以数量
212
                     //单价乘以数量
209
             String taskCode = flowTaskInfoVO.getTaskCode();
236
             String taskCode = flowTaskInfoVO.getTaskCode();
210
             //获取流程id
237
             //获取流程id
211
             String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
238
             String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
212
-            String sql = flowTaskInfoVO.getSqlString();
239
+            //成本类型
240
+            String feeType = FeeTypeEnum.LaborCost.getCode();
241
+            String sql1 = flowTaskInfoVO.getSqlString();
242
+            log.info("sql1:" + sql1);
243
+            String sql = sql1.replaceAll("^\"|\"$", ""); // 去除首尾引号
244
+            log.info("sql:" + sql);
213
             JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
245
             JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
214
             BigDecimal hourRate = new BigDecimal("0");
246
             BigDecimal hourRate = new BigDecimal("0");
215
             if (jsonObject != null) {
247
             if (jsonObject != null) {
241
                         }
273
                         }
242
                     }
274
                     }
243
                     //2.2计算出人工成本并存储到成本结果数据表中
275
                     //2.2计算出人工成本并存储到成本结果数据表中
244
-                    AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
276
+                    AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
245
                     standardCostService.iAppSceneCostResultValueService.save(resultValue);
277
                     standardCostService.iAppSceneCostResultValueService.save(resultValue);
246
                 }
278
                 }
247
             }
279
             }
273
             /**
305
             /**
274
              * 小时费率
306
              * 小时费率
275
              */
307
              */
276
-            String sql = flowTaskInfoVO.getSqlString();
308
+            String sql1 = flowTaskInfoVO.getSqlString();
309
+            log.info("sql1:" + sql1);
310
+            String sql = sql1.replaceAll("^\"|\"$", ""); // 去除首尾引号
311
+            log.info("sql:" + sql);
277
             JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
312
             JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
278
             BigDecimal hourRate = new BigDecimal("0");
313
             BigDecimal hourRate = new BigDecimal("0");
279
             if (jsonObject != null) {
314
             if (jsonObject != null) {
306
                             }
341
                             }
307
                         }
342
                         }
308
                         //2.2计算机器成本并存储到成本结果数据表中
343
                         //2.2计算机器成本并存储到成本结果数据表中
309
-                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
344
+                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
310
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
345
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
311
                     }
346
                     }
312
                 }
347
                 }
328
                             }
363
                             }
329
                         }
364
                         }
330
                         //2.2计算机物料消耗存储到成本结果数据表中
365
                         //2.2计算机物料消耗存储到成本结果数据表中
331
-                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
366
+                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
332
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
367
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
333
                     }
368
                     }
334
                 }
369
                 }
350
                             }
385
                             }
351
                         }
386
                         }
352
                         //2.2计算机物料消耗存储到成本结果数据表中
387
                         //2.2计算机物料消耗存储到成本结果数据表中
353
-                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
388
+                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
354
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
389
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
355
                     }
390
                     }
356
                 }
391
                 }
372
                             }
407
                             }
373
                         }
408
                         }
374
                         //2.2计算机物料消耗存储到成本结果数据表中
409
                         //2.2计算机物料消耗存储到成本结果数据表中
375
-                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
410
+                        AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
376
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
411
                         standardCostService.iAppSceneCostResultValueService.save(resultValue);
377
                     }
412
                     }
378
                 }
413
                 }
392
                             totalCost = totalCost.add(new BigDecimal(countValue));
427
                             totalCost = totalCost.add(new BigDecimal(countValue));
393
                         }
428
                         }
394
                     }
429
                     }
395
-                    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()).build();
430
+                    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();
396
                     standardCostService.iAppSceneCostResultValueService.save(resultValue);
431
                     standardCostService.iAppSceneCostResultValueService.save(resultValue);
397
                 }
432
                 }
398
             }
433
             }
437
         }
472
         }
438
         //3.计算出所有的单个物料的累计标准成本
473
         //3.计算出所有的单个物料的累计标准成本
439
         List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
474
         List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
440
-        //循环算出各个物料的累计成本
475
+      //TODO 优化累计成本的计算
441
         totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
476
         totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
442
     }
477
     }
443
 
478
 
453
     private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
488
     private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
454
         Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
489
         Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
455
         for (int i = 0; i < standardCostList.size(); i++) {
490
         for (int i = 0; i < standardCostList.size(); i++) {
456
-            AppSceneCostResultValue appSceneCostResultValue = standardCostList.get(i);
457
-            BigDecimal totalCost = new BigDecimal("0.0");
458
-            totalCost = loopCount(appSceneCostResultValue, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
459
-            appSceneCostResultValue.setTotalValue(totalCost.toString());
460
-            standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
491
+            AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i);
492
+            BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue());
493
+            totalCost = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
494
+            oldAppSceneCostResultValue.setTotalValue(totalCost.toString());
495
+            standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
496
+            //TODO 更新结果集到标准成本单行查询中去
461
         }
497
         }
462
     }
498
     }
463
 
499
 
464
     /**
500
     /**
501
+     * //循环算出各个物料的累计成本
465
      * 递归计算出累计成本
502
      * 递归计算出累计成本
466
      *
503
      *
467
      * @param appSceneCostResultValue
504
      * @param appSceneCostResultValue

+ 7
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/service/CostMaterialBomService.java Ver arquivo

20
      * @return
20
      * @return
21
      */
21
      */
22
     List<CostMaterialBom> queryListResult(String materialNumber);
22
     List<CostMaterialBom> queryListResult(String materialNumber);
23
+
24
+    /**
25
+     * 查询最顶层物料编号下所有的物料
26
+     * @param topMaterialCode
27
+     * @return
28
+     */
29
+    List<CostMaterialBom> queryAllBomInfoBytopMaterialCode(String topMaterialCode);
23
 }
30
 }

+ 1
- 1
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/service/impl/AppSceneCostResultValueServiceImpl.java Ver arquivo

40
             queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("task_type", lastTaskType).eq("flow_instance_id", flowInstanceId);
40
             queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("task_type", lastTaskType).eq("flow_instance_id", flowInstanceId);
41
             result = appSceneCostResultValueMapper.selectList(queryWrapper);
41
             result = appSceneCostResultValueMapper.selectList(queryWrapper);
42
         } else if (topMaterialCode != null && !topMaterialCode.equals("") && flowInstanceId != null && !flowInstanceId.equals("")) {
42
         } else if (topMaterialCode != null && !topMaterialCode.equals("") && flowInstanceId != null && !flowInstanceId.equals("")) {
43
-            queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("task_type", lastTaskType).eq("flow_instance_id", flowInstanceId);
43
+            queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("flow_instance_id", flowInstanceId);
44
             result = appSceneCostResultValueMapper.selectList(queryWrapper);
44
             result = appSceneCostResultValueMapper.selectList(queryWrapper);
45
         }
45
         }
46
         return result;
46
         return result;

+ 18
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/service/impl/CostMaterialBomServiceImpl.java Ver arquivo

40
         List list = costMaterialBomMapper.selectList(queryWrapper);
40
         List list = costMaterialBomMapper.selectList(queryWrapper);
41
         return list;
41
         return list;
42
     }
42
     }
43
+
44
+    /**
45
+     * 查询最顶层物料编号下所有的物料
46
+     *
47
+     * @param topMaterialCode
48
+     * @return
49
+     */
50
+    @Override
51
+    public List<CostMaterialBom> queryAllBomInfoBytopMaterialCode(String topMaterialCode) {
52
+        QueryWrapper queryWrapper = new QueryWrapper();
53
+        //TODO 循环遍历查出所有的物料下的物料(包含最上层的物料)
54
+//        if (StrUtil.isNotEmpty(topMaterialCode)) {
55
+//            // 物料号
56
+//            queryWrapper.like("material_code", topMaterialCode);
57
+//        }
58
+        List list = costMaterialBomMapper.selectList(queryWrapper);
59
+        return list;
60
+    }
43
 }
61
 }