DangerousOperationController.java
12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package com.skua.modules.emergency.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.query.QueryGenerator;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.emergency.entity.DangerousOperation;
import com.skua.modules.emergency.service.IDangerousOperationService;
import com.skua.modules.flow.business.service.FlowBusinessService;
import com.skua.modules.flow.core.entity.FlowAssemblyEntity;
import com.skua.modules.system.vo.UserCertificate;
import com.skua.tool.util.BeanExtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
/**
* 危险作业事件
*/
@Slf4j
@Api(tags="危险作业事件")
@RestController
@RequestMapping("/danger/dangerOperation")
public class DangerousOperationController {
@Autowired
private IDangerousOperationService dangerousOperationService;
@Autowired
private FlowBusinessService flowBusinessService;
/**
* <pre>
* 查询处理数量
* </pre>
* @param dangerousOperation
* @return
* @author xiechao, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "处理数量统计")
@ApiOperation(value="处理数量统计", notes="处理数量统计")
@GetMapping(value = "/getDefectHandleCount")
public Result<List<Map<String,Object>>> getDefectHandleCount(DangerousOperation dangerousOperation){
Result<List<Map<String,Object>>> result = new Result<>();
QueryWrapper<DangerousOperation> queryWrapper = new QueryWrapper<DangerousOperation>();
queryWrapper.select("count(id) count,operation_status operationStatus");
queryWrapper.ge(StringUtils.isNotEmpty(dangerousOperation.getStartTime()),"report_date",dangerousOperation.getStartTime());
queryWrapper.le(StringUtils.isNotEmpty(dangerousOperation.getEndTime()),"report_date",dangerousOperation.getEndTime());
queryWrapper.groupBy("operation_status");
List<Map<String,Object>> list = dangerousOperationService.listMaps(queryWrapper);
result.setSuccess(true);
result.setResult(list);
return result;
}
@AutoLog(value = "按时间类型统计处理数量")
@ApiOperation(value="按时间类型统计处理数量", notes="按时间类型统计处理数量")
@GetMapping(value = "/getDefectHandleCountByEventType")
public Result<List<Map<String,Object>>> getDefectHandleCountByEventType(DangerousOperation dangerousOperation){
Result<List<Map<String,Object>>> result = new Result<>();
//未处理应急事件
QueryWrapper<DangerousOperation> emergencyRiskEventQueryWrapper = new QueryWrapper<>();//QueryGenerator.initQueryWrapper(equipmentDefectManagement, req.getParameterMap());
emergencyRiskEventQueryWrapper.select("count(id) wclCount,event_type,(select item_text as event_type_dictText from sys_dict_item where dict_id =(select id from sys_dict where dict_code='emergency_risk_event_eventtype') and item_value=event_type) as event_type_dictText");
emergencyRiskEventQueryWrapper.eq("operation_status","1");
emergencyRiskEventQueryWrapper.ne("operation_type","");
emergencyRiskEventQueryWrapper.isNotNull("operation_type");
emergencyRiskEventQueryWrapper.ge(StringUtils.isNotEmpty(dangerousOperation.getStartTime()),"report_date",dangerousOperation.getStartTime());
emergencyRiskEventQueryWrapper.le(StringUtils.isNotEmpty(dangerousOperation.getEndTime()),"report_date",dangerousOperation.getEndTime());
emergencyRiskEventQueryWrapper.groupBy("operation_status","operation_type");
List<Map<String,Object>> list = dangerousOperationService.listMaps(emergencyRiskEventQueryWrapper);
//已处理应急事件
emergencyRiskEventQueryWrapper = new QueryWrapper<>();//QueryGenerator.initQueryWrapper(equipmentDefectManagement, req.getParameterMap());
emergencyRiskEventQueryWrapper.select("count(id) yclCount,event_type,(select item_text as event_type_dictText from sys_dict_item where dict_id =(select id from sys_dict where dict_code='emergency_risk_event_eventtype') and item_value=event_type) as event_type_dictText");
emergencyRiskEventQueryWrapper.eq("operation_status","2");
emergencyRiskEventQueryWrapper.ne("operation_type","");
emergencyRiskEventQueryWrapper.isNotNull("operation_type");
emergencyRiskEventQueryWrapper.ge(StringUtils.isNotEmpty(dangerousOperation.getStartTime()),"report_date",dangerousOperation.getStartTime());
emergencyRiskEventQueryWrapper.le(StringUtils.isNotEmpty(dangerousOperation.getEndTime()),"report_date",dangerousOperation.getEndTime());
emergencyRiskEventQueryWrapper.groupBy("operation_status","operation_type");
List<Map<String,Object>> yclList = dangerousOperationService.listMaps(emergencyRiskEventQueryWrapper);
//获取未处理、已处理中的应急事件类型
Map<String, Map<String,Object>> mapping = new HashMap<>();
list.forEach(map ->{
String eventType = ConvertUtils.getString(map.get("operation_type"));
Map<String,Object> eventMap = mapping.get(eventType);
if(eventMap==null){
eventMap = new HashMap<>();
mapping.put(eventType,eventMap);
}
eventMap.putAll(map);
});
yclList.forEach(map ->{
String eventType = ConvertUtils.getString(map.get("operation_type"));
Map<String,Object> eventMap = mapping.get(eventType);
if(eventMap==null){
eventMap = new HashMap<>();
mapping.put(eventType,eventMap);
}
eventMap.putAll(map);
});
//构造结果集合
List<Map<String,Object>> resultList = new ArrayList<>();
Set<String> keySet = mapping.keySet();
for(String key : keySet){
resultList.add(mapping.get(key));
}
result.setSuccess(true);
result.setResult(resultList);
return result;
}
@AutoLog(value = "危险作业事件-分页列表查询")
@ApiOperation(value="危险作业事件-分页列表查询", notes="危险作业事件-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<DangerousOperation>> queryPageList(DangerousOperation dangerousOperation,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
Result<IPage<DangerousOperation>> result = new Result<IPage<DangerousOperation>>();
QueryWrapper<DangerousOperation> queryWrapper = QueryGenerator.initQueryWrapper(dangerousOperation, req.getParameterMap());
Page<DangerousOperation> page = new Page<DangerousOperation>(pageNo, pageSize);
IPage<DangerousOperation> pageList = dangerousOperationService.page(page, queryWrapper);
//获取流程状态
List<DangerousOperation> records = pageList.getRecords();
Set<String> processInstanceIdSet = records.stream().filter(data-> StringUtils.isNotBlank(data.getProcessInstanceId()))
.map(DangerousOperation::getProcessInstanceId).collect(Collectors.toSet());
Map<String, Map<String, String>> processInstanceMap;
try {
processInstanceMap = flowBusinessService.getProcessState(processInstanceIdSet);
} catch (Exception e) {
e.printStackTrace();
processInstanceMap = new HashMap<>();
}
for (DangerousOperation record : records) {
record.getFlow().setProcessDefinitionKey(processInstanceMap.getOrDefault(record.getProcessInstanceId(), new HashMap<>()).get("processDefinitionKey"));
record.getFlow().setTaskDefinitionKey(processInstanceMap.getOrDefault(record.getProcessInstanceId(), new HashMap<>()).get("taskDefinitionKey"));
record.getFlow().setStatus(processInstanceMap.getOrDefault(record.getProcessInstanceId(), new HashMap<>()).get("state"));
record.getFlow().setTaskName(processInstanceMap.getOrDefault(record.getProcessInstanceId(), new HashMap<>()).get("processDefinitionName"));
}
result.setSuccess(true);
result.setResult(pageList);
return result;
}
/**
/**
* <pre>
* 添加
* </pre>
* @param dangerousOperation
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "危险作业事件-开始流程")
@ApiOperation(value="危险作业事件-开始流程", notes="危险作业事件-开始流程")
@PostMapping(value = "/start-process")
public Result<DangerousOperation> startProcess(@RequestBody DangerousOperation dangerousOperation) {
Result<DangerousOperation> result = new Result<>();
try {
dangerousOperation.setDelFlag(0);
DangerousOperation data = dangerousOperationService.startProcess(dangerousOperation);
result.setResult(data);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败");
}
return result;
}
/**
* <pre>
* 编辑
* </pre>
* @param dangerousOperation
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "危险作业事件-处理")
@ApiOperation(value="危险作业事件-处理", notes="危险作业事件-处理")
@PostMapping(value = "/handle")
public Result<DangerousOperation> handle(@Valid @RequestBody DangerousOperation dangerousOperation) {
Result<DangerousOperation> result = new Result<DangerousOperation>();
dangerousOperationService.handle(dangerousOperation);
result.success("处理成功!");
return result;
}
/**
* <pre>
* 通过id删除
* </pre>
* @param id
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "危险作业事件-通过id删除")
@ApiOperation(value="危险作业事件-通过id删除", notes="危险作业事件-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
try {
dangerousOperationService.removeById(id);
} catch (Exception e) {
log.error("删除失败",e.getMessage());
return Result.error("删除失败!");
}
return Result.ok("删除成功!");
}
@PostMapping(value = "/complete-task-choose-user-pass")
public Result<?> completeTaskChooseUserPass(@RequestBody DangerousOperation dangerousOperation) throws Exception {
Result<?> result = new Result();
FlowAssemblyEntity flowAssemblyEntity = BeanExtUtils.bean2Bean(dangerousOperation, FlowAssemblyEntity.class);
if (org.apache.commons.lang.StringUtils.isEmpty(flowAssemblyEntity.getAssemblyKey())) {
//AssemblyKey对应参数用户id
flowAssemblyEntity.setAssemblyKey("");
}
String activeResult = this.flowBusinessService.completeTaskChooseUserPass(flowAssemblyEntity);
if ("noChooseUser".equals(activeResult)) {
result.error500("未指定下一节点用户!");
} else if ("fail".equals(activeResult)) {
result.error500("程序异常,流程审批失败!");
} else {
DangerousOperation dangerOperation = BeanExtUtils.bean2Bean(dangerousOperation, DangerousOperation.class);
dangerousOperationService.updateById(dangerOperation);
result.success("成功");
}
return result;
}
@AutoLog(value = "危险作业事件-办结流程")
@ApiOperation(value = "危险作业事件-办结流程", notes = "危险作业事件-办结流程")
@PostMapping(value = "/complete-process")
public Result<DangerousOperation> completeProcess(@RequestBody DangerousOperation dangerousOperation) {
Result<DangerousOperation> result = new Result<>();
try {
dangerousOperation.setDelFlag(0);
boolean flag = dangerousOperationService.completeProcess(dangerousOperation);
if (flag) {
result.success("办结成功!");
} else {
result.error500("办结失败!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("办结失败");
}
return result;
}
@AutoLog(value = "危险作业事件-人员证书列表")
@ApiOperation(value="危险作业事件-人员证书列表", notes="危险作业事件-人员证书列表")
@GetMapping(value = "/getFileList")
public Result<List<UserCertificate>> getFileList(String userType, String userId) {
List<UserCertificate> list = new ArrayList<>();
Result<List<UserCertificate>> result = new Result<List<UserCertificate>>();
list = dangerousOperationService.getFileList(userType, userId);
result.setResult(list);
result.setSuccess(true);
return result;
}
}