|
|
@@ -5,12 +5,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
5
|
5
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
6
|
6
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
7
|
7
|
import com.zzsmart.qomo.dao.entity.FlowDefinition;
|
|
|
8
|
+import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostCount;
|
|
|
9
|
+import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostModel;
|
|
|
10
|
+import com.zzsmart.qomo.kn.cost.manage.enums.CostModelStatusEnum;
|
|
|
11
|
+import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostCountMapper;
|
|
|
12
|
+import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostModelMapper;
|
|
8
|
13
|
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostModelService;
|
|
|
14
|
+import com.zzsmart.qomo.kn.cost.manage.vo.CostModelDefinitionVO;
|
|
9
|
15
|
import com.zzsmart.qomo.service.IDataFlowDefinitionService;
|
|
10
|
16
|
import io.swagger.annotations.Api;
|
|
11
|
17
|
import io.swagger.annotations.ApiOperation;
|
|
12
|
18
|
import lombok.extern.slf4j.Slf4j;
|
|
13
|
|
-import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
14
|
19
|
import org.jeecg.common.api.vo.Result;
|
|
15
|
20
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
16
|
21
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
@@ -20,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
|
|
20
|
25
|
import javax.servlet.http.HttpServletRequest;
|
|
21
|
26
|
import java.util.Date;
|
|
22
|
27
|
import java.util.List;
|
|
|
28
|
+import java.util.Random;
|
|
23
|
29
|
|
|
24
|
30
|
/**
|
|
25
|
31
|
* @Description: app_scene_cost_model
|
|
|
@@ -36,7 +42,10 @@ public class AppSceneCostModelController {
|
|
36
|
42
|
private IAppSceneCostModelService appSceneCostModelService;
|
|
37
|
43
|
@Autowired
|
|
38
|
44
|
private IDataFlowDefinitionService flowDefinitionService;
|
|
39
|
|
-
|
|
|
45
|
+ @Autowired
|
|
|
46
|
+ private AppSceneCostCountMapper appSceneCostCountMapper;
|
|
|
47
|
+ @Autowired
|
|
|
48
|
+ private AppSceneCostModelMapper costModelMapper;
|
|
40
|
49
|
/**
|
|
41
|
50
|
* 标准成本模型分页列表查询
|
|
42
|
51
|
*
|
|
|
@@ -71,17 +80,41 @@ public class AppSceneCostModelController {
|
|
71
|
80
|
/**
|
|
72
|
81
|
* 添加标准成本模型
|
|
73
|
82
|
*
|
|
74
|
|
- * @param flowDefinition
|
|
|
83
|
+ * @param modelDefinitionVO
|
|
75
|
84
|
* @return
|
|
76
|
85
|
*/
|
|
77
|
86
|
@AutoLog(value = "app_scene_cost_model-添加")
|
|
78
|
87
|
@ApiOperation(value = "app_scene_cost_model-添加", notes = "app_scene_cost_model-添加")
|
|
79
|
88
|
@PostMapping(value = "/add")
|
|
80
|
|
- public Result<FlowDefinition> add(@RequestBody FlowDefinition flowDefinition) {
|
|
81
|
|
- flowDefinition.setCreateTime(new Date());
|
|
82
|
|
- flowDefinition.setUpdateTime(new Date());
|
|
83
|
|
- FlowDefinition definition = flowDefinitionService.add(flowDefinition);
|
|
84
|
|
- return Result.OK(definition);
|
|
|
89
|
+ public Result<FlowDefinition> add(@RequestBody CostModelDefinitionVO modelDefinitionVO) {
|
|
|
90
|
+ try {
|
|
|
91
|
+ FlowDefinition flowDefinition = new FlowDefinition();
|
|
|
92
|
+ //TODO 新增平台层模型定义记录
|
|
|
93
|
+ String flowCode = "FLOW_" + System.currentTimeMillis() + new Random(10000).nextInt();
|
|
|
94
|
+ flowDefinition.setUpdateTime(new Date());
|
|
|
95
|
+ flowDefinition.setCreateTime(new Date());
|
|
|
96
|
+ flowDefinition.setCode(flowCode);
|
|
|
97
|
+ flowDefinition.setProjectId(modelDefinitionVO.getProjectId());
|
|
|
98
|
+ flowDefinition.setUserId("1744546658109349889");
|
|
|
99
|
+ flowDefinition.setUserName("系统管理员");
|
|
|
100
|
+ flowDefinition.setTenantId(-1);
|
|
|
101
|
+ flowDefinition.setEnvironmentId(1);
|
|
|
102
|
+ flowDefinition.setName(modelDefinitionVO.getModelName());
|
|
|
103
|
+ FlowDefinition definition = flowDefinitionService.add(flowDefinition);
|
|
|
104
|
+ AppSceneCostModel forecastModel = new AppSceneCostModel();
|
|
|
105
|
+ forecastModel.setModelType(modelDefinitionVO.getModelType());
|
|
|
106
|
+ forecastModel.setModelName(modelDefinitionVO.getModelName());
|
|
|
107
|
+ forecastModel.setStatus(CostModelStatusEnum.Draft.getCode());
|
|
|
108
|
+ //2.新模型记录
|
|
|
109
|
+ forecastModel.setFlowDefinitionId(definition.getId());
|
|
|
110
|
+ forecastModel.setUpdateTime(new Date());
|
|
|
111
|
+ forecastModel.setCreateTime(new Date());
|
|
|
112
|
+ costModelMapper.insert(forecastModel);
|
|
|
113
|
+
|
|
|
114
|
+ } catch (Exception e) {
|
|
|
115
|
+ return Result.error("新增失败");
|
|
|
116
|
+ }
|
|
|
117
|
+ return Result.OK("新增成功");
|
|
85
|
118
|
}
|
|
86
|
119
|
|
|
87
|
120
|
/**
|
|
|
@@ -108,6 +141,19 @@ public class AppSceneCostModelController {
|
|
108
|
141
|
@ApiOperation(value = "app_scene_cost_model-通过id删除", notes = "app_scene_cost_model-通过id删除")
|
|
109
|
142
|
@DeleteMapping(value = "/delete")
|
|
110
|
143
|
public Result<String> delete(@RequestParam(name = "id", required = true) Integer id) {
|
|
|
144
|
+ //检查模型是否被引用或挂载
|
|
|
145
|
+ if (id != null) {
|
|
|
146
|
+ FlowDefinition flowDefinition = flowDefinitionService.getById(id);
|
|
|
147
|
+ if (flowDefinition != null) {
|
|
|
148
|
+ Integer id1 = flowDefinition.getId();
|
|
|
149
|
+ QueryWrapper<AppSceneCostCount> queryWrapper = new QueryWrapper<>();
|
|
|
150
|
+ queryWrapper.eq("flow_definition_id", id1);
|
|
|
151
|
+ Long aLong = appSceneCostCountMapper.selectCount(queryWrapper);
|
|
|
152
|
+ if (aLong > 0) {
|
|
|
153
|
+ return Result.error("该模型正在被引用,无法删除!");
|
|
|
154
|
+ }
|
|
|
155
|
+ }
|
|
|
156
|
+ }
|
|
111
|
157
|
flowDefinitionService.delete(id);
|
|
112
|
158
|
return Result.OK("删除成功!");
|
|
113
|
159
|
}
|