EmergencyRiskEventController.java
10.8 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
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.dto.EmergencyRiskEventAddDTO;
import com.skua.modules.emergency.dto.EmergencyRiskEventHandleDto;
import com.skua.modules.emergency.entity.EmergencyRiskEvent;
import com.skua.modules.emergency.service.IEmergencyRiskEventService;
import com.skua.modules.flow.business.service.FlowBusinessService;
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;
/**
* <pre>
* 应急风险事件
* </pre>
* @author 开发者姓名
* @version V0.1, 开发时间
*/
@Slf4j
@Api(tags="应急风险事件")
@RestController
@RequestMapping("/web/emergency/emergencyRiskEvent")
public class EmergencyRiskEventController {
@Autowired
private IEmergencyRiskEventService emergencyRiskEventService;
@Autowired
private FlowBusinessService flowBusinessService;
/**
* <pre>
* 查询处理数量
* </pre>
* @param equipmentDefectManagement
* @param req
* @return
* @author xiechao, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "处理数量统计")
@ApiOperation(value="处理数量统计", notes="处理数量统计")
@GetMapping(value = "/getDefectHandleCount")
public Result<List<Map<String,Object>>> getDefectHandleCount(EmergencyRiskEvent equipmentDefectManagement, HttpServletRequest req){
Result<List<Map<String,Object>>> result = new Result<>();
QueryWrapper<EmergencyRiskEvent> queryWrapper = new QueryWrapper<EmergencyRiskEvent>();//QueryGenerator.initQueryWrapper(equipmentDefectManagement, req.getParameterMap());
queryWrapper.select("count(id) count,handle_result handleResult");
queryWrapper.ge(StringUtils.isNotEmpty(equipmentDefectManagement.getStartTime()),"report_date",equipmentDefectManagement.getStartTime());
queryWrapper.le(StringUtils.isNotEmpty(equipmentDefectManagement.getEndTime()),"report_date",equipmentDefectManagement.getEndTime());
queryWrapper.groupBy("handle_result");
List<Map<String,Object>> list = emergencyRiskEventService.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(EmergencyRiskEvent equipmentDefectManagement, HttpServletRequest req){
Result<List<Map<String,Object>>> result = new Result<>();
//未处理应急事件
QueryWrapper<EmergencyRiskEvent> 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("handle_result","1");
emergencyRiskEventQueryWrapper.ne("event_type","");
emergencyRiskEventQueryWrapper.isNotNull("event_type");
emergencyRiskEventQueryWrapper.ge(StringUtils.isNotEmpty(equipmentDefectManagement.getStartTime()),"report_date",equipmentDefectManagement.getStartTime());
emergencyRiskEventQueryWrapper.le(StringUtils.isNotEmpty(equipmentDefectManagement.getEndTime()),"report_date",equipmentDefectManagement.getEndTime());
emergencyRiskEventQueryWrapper.groupBy("handle_result","event_type");
List<Map<String,Object>> list = emergencyRiskEventService.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("handle_result","3");
emergencyRiskEventQueryWrapper.ne("event_type","");
emergencyRiskEventQueryWrapper.isNotNull("event_type");
emergencyRiskEventQueryWrapper.ge(StringUtils.isNotEmpty(equipmentDefectManagement.getStartTime()),"report_date",equipmentDefectManagement.getStartTime());
emergencyRiskEventQueryWrapper.le(StringUtils.isNotEmpty(equipmentDefectManagement.getEndTime()),"report_date",equipmentDefectManagement.getEndTime());
emergencyRiskEventQueryWrapper.groupBy("handle_result","event_type");
List<Map<String,Object>> yclList = emergencyRiskEventService.listMaps(emergencyRiskEventQueryWrapper);
//获取未处理、已处理中的应急事件类型
Map<String, Map<String,Object>> mapping = new HashMap<>();
list.forEach(map ->{
String eventType = ConvertUtils.getString(map.get("event_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("event_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<EmergencyRiskEvent>> queryPageList(EmergencyRiskEvent emergencyRiskEvent,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
Result<IPage<EmergencyRiskEvent>> result = new Result<IPage<EmergencyRiskEvent>>();
QueryWrapper<EmergencyRiskEvent> queryWrapper = QueryGenerator.initQueryWrapper(emergencyRiskEvent, req.getParameterMap());
Page<EmergencyRiskEvent> page = new Page<EmergencyRiskEvent>(pageNo, pageSize);
if(StringUtils.isNotEmpty(emergencyRiskEvent.getStartTime())){
queryWrapper.ge("report_date",emergencyRiskEvent.getStartTime());
}
if(StringUtils.isNotEmpty(emergencyRiskEvent.getEndTime())){
queryWrapper.le("report_date",emergencyRiskEvent.getEndTime());
}
IPage<EmergencyRiskEvent> pageList = emergencyRiskEventService.page(page, queryWrapper);
//获取流程状态
List<EmergencyRiskEvent> records = pageList.getRecords();
Set<String> processInstanceIdSet = records.stream().filter(data-> StringUtils.isNotBlank(data.getProcessInstanceId()))
.map(EmergencyRiskEvent::getProcessInstanceId).collect(Collectors.toSet());
Map<String, Map<String, String>> processInstanceMap;
try {
processInstanceMap = flowBusinessService.getProcessState(processInstanceIdSet);
} catch (Exception e) {
e.printStackTrace();
processInstanceMap = new HashMap<>();
}
for (EmergencyRiskEvent 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 emergencyRiskEvent
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "应急风险事件-开始流程")
@ApiOperation(value="应急风险事件-开始流程", notes="应急风险事件-开始流程")
@PostMapping(value = "/startProcess")
public Result<EmergencyRiskEvent> startProcess(@Valid @RequestBody EmergencyRiskEventAddDTO emergencyRiskEvent) {
Result<EmergencyRiskEvent> result = new Result<EmergencyRiskEvent>();
try {
emergencyRiskEventService.startProcess(emergencyRiskEvent);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(),e);
result.error500("操作失败");
}
return result;
}
/**
* <pre>
* 编辑
* </pre>
* @param
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "应急风险事件-处理")
@ApiOperation(value="应急风险事件-处理", notes="应急风险事件-处理")
@PostMapping(value = "/handle")
public Result<EmergencyRiskEvent> handle(@Valid @RequestBody EmergencyRiskEventHandleDto dto) {
Result<EmergencyRiskEvent> result = new Result<EmergencyRiskEvent>();
emergencyRiskEventService.handle(dto);
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 {
emergencyRiskEventService.removeById(id);
} catch (Exception e) {
log.error("删除失败",e.getMessage());
return Result.error("删除失败!");
}
return Result.ok("删除成功!");
}
}