EmergencyAnalysisController.java
10.5 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
package com.skua.modules.emergency.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.modules.emergency.entity.*;
import com.skua.modules.emergency.service.*;
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.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* 应急统计
*/
@Slf4j
@Api(tags = "应急模块统计分析")
@RestController
@RequestMapping("/emergency/analysis")
public class EmergencyAnalysisController {
@Autowired
private IEmergencyCartsService emergencyCartsService;
@Autowired
private IEmergencyGoodsService goodsService;
@Autowired
private IEmergencyMobileDangerReportService mobileDangerReportService;
@Autowired
private IEmergencyEventsCostService eventsCostService;
@Autowired
private IEmergencyEventsService emergencyEventsService;
@Autowired
private IEmergencyEventsGoodsService emergencyEventsGoodsService;
@Autowired
private IEmergencyEventsCartService emergencyEventsCartService;
@Autowired
private FlowBusinessService flowBusinessService;
/**
* @param req
* @return
*/
@AutoLog(value = "应急-移动险情数量统计")
@ApiOperation(value = "应急-移动险情数量统计", notes = "应急-移动险情数量统计")
@GetMapping(value = "/mobileDangerCount")
public Result mobileDangerCount(
HttpServletRequest req) {
Result result = new Result<>();
try {
List<Map<String, Object>> resultMap = mobileDangerReportService.mobileDangerCount();
result.setSuccess(true);
result.setResult(resultMap);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
result.error500("查询失败");
}
return result;
}
/**
* @param req
* @return
*/
@AutoLog(value = "应急-移动险情等级统计")
@ApiOperation(value = "应急-移动险情等级统计", notes = "应急-移动险情等级统计")
@GetMapping(value = "/mobileDangerLevelCount")
public Result mobileDangerLevelCount(
HttpServletRequest req) {
Result result = new Result<>();
try {
List<Map<String, Object>> resultMap = mobileDangerReportService.mobileDangerLevelCount();
result.setSuccess(true);
result.setResult(resultMap);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
result.error500("查询失败");
}
return result;
}
/**
* 应急资源统计
* @param departId
* @return
*/
@AutoLog(value = "应急-应急资源统计")
@ApiOperation(value = "应急-应急资源统计", notes = "应急-应急资源统计")
@GetMapping(value = "/resource")
public Result resource(String moduleType,String departId) {
Result result = new Result<>();
try {
ArrayList<Object> resultList = new ArrayList<>();
QueryWrapper<EmergencyGoods> emergencyGoodsQueryWrapper = new QueryWrapper<EmergencyGoods>()
.select("id,goods_type as goodsType,goods_name as goodsName,goods_unit as goodsUnit,sum(goods_num)as totalGoods")
.eq(StringUtils.isNotEmpty(moduleType),"module_type", moduleType)
.eq(StringUtils.isNotEmpty(departId),"depart_id", departId)
.eq("del_flag", 1)
.groupBy("goods_name");
List<Map<String, Object>> totalGoodsList = goodsService.listMaps(emergencyGoodsQueryWrapper);
QueryWrapper<EmergencyCarts> emergencyCartsQueryWrapper = new QueryWrapper<EmergencyCarts>().eq("del_flag", 1);
int totalCarts = emergencyCartsService.count(emergencyCartsQueryWrapper);
for (Map<String, Object> goodsMap : totalGoodsList) {
Double inUseNum = 0.0;
goodsMap.put("inUseNum", inUseNum);
goodsMap.put("freeNum", Double.parseDouble(String.valueOf(goodsMap.get("totalGoods"))) - inUseNum>0?Double.parseDouble(String.valueOf(goodsMap.get("totalGoods"))) - inUseNum:0);
}
int useCartNum = 0;
HashMap<String, Object> map = new HashMap<>();
map.put("goodsName", "应急车辆");
map.put("goodsUnit", "辆");
map.put("goodsType", "应急车辆");
map.put("totalGoods", totalCarts);
map.put("inUseNum", useCartNum);
map.put("freeNum", totalCarts - useCartNum>0?totalCarts - useCartNum:0);
resultList.addAll(totalGoodsList);
resultList.add(map);
result.setSuccess(true);
result.setResult(resultList);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
result.error500("查询失败");
}
return result;
}
/**
* @param req
* @return
*/
@AutoLog(value = "应急-年度应急事件统计")
@ApiOperation(value = "应急-年度应急事件统计", notes = "应急-年度应急事件统计")
@GetMapping(value = "/incident")
public Result incident(
HttpServletRequest req, String moduleType) {
Result result = new Result<>();
try {
//ArrayList<Object> resultList = new ArrayList<>();
//String moduleType = req.getParameter("moduleType");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy");
String thisYear = LocalDateTime.now().format(dateTimeFormatter);
HashMap<String, Object> map = new HashMap<>();
QueryWrapper<EmergencyEvents> emergencyEventsQueryWrapper = new QueryWrapper<>();
emergencyEventsQueryWrapper.eq("module_type", moduleType).eq("del_flag", 1).isNotNull("process_instance_id").like("create_time", thisYear);
List<EmergencyEvents> eventsList = emergencyEventsService.list(emergencyEventsQueryWrapper);
//待处理
List<EmergencyEvents> processEventsList = eventsList.stream().filter(events -> StringUtils.isNotBlank(events.getProcessInstanceId())).collect(Collectors.toList());
Set<String> processInstanceIdS = processEventsList.stream().map(events -> events.getProcessInstanceId()).collect(Collectors.toSet());
Map<String,Map<String, String>> processStateMap = flowBusinessService.getProcessState(processInstanceIdS);
for (EmergencyEvents events : eventsList) {
events.setProcessState(processStateMap.get(events.getProcessInstanceId()).getOrDefault("state", "pending"));
}
int processed = 0;
int inHand = 0;
int pending = 0;
for (EmergencyEvents emergencyEvents : eventsList) {
if ("finished".equals(emergencyEvents.getProcessState())) {
processed++;
} else if ("unfinished".equals(emergencyEvents.getProcessState())) {
inHand++;
} else {
pending++;
}
}
map.put("total", !CollectionUtils.isEmpty(eventsList) ? eventsList.size() : 0);
//已处理
map.put("processed", processed);
//处理中
map.put("inHand", inHand);
//待处理
map.put("pending", pending);
// resultList.add(map);
result.setSuccess(true);
result.setResult(map);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
result.error500("查询失败");
}
return result;
}
/**
* @param req
* @return
*/
@AutoLog(value = "应急-应急费用统计")
@ApiOperation(value = "应急-应急费用统计", notes = "应急-应急费用统计")
@GetMapping(value = "/cost")
public Result cost(
HttpServletRequest req, String time) {
Result result = new Result<>();
try {
//ArrayList<Object> resultList = new ArrayList<>();
DateTimeFormatter yearFormatter = DateTimeFormatter.ofPattern("yyyy");
String thisYear = LocalDateTime.now().format(yearFormatter);
String lastYear = LocalDateTime.now().minusYears(1).format(yearFormatter);
QueryWrapper<EmergencyEventsCost> eventsCostQueryWrapper = new QueryWrapper<>();
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
String lastMonth = LocalDateTime.now().minusMonths(1).format(monthFormatter);
String lastYearMonth = LocalDateTime.now().minusYears(1).format(monthFormatter);
Map<String, Object> thisYeardata = eventsCostService.costByYear(thisYear);
Map<String, Object> lastYeardata = eventsCostService.costByYear(lastYear);
Map<String, Object> lastMonthdata = eventsCostService.costByMonth(lastMonth);
Map<String, Object> lastYearMonthdata = eventsCostService.costByMonth(lastYearMonth);
HashMap<String, Object> map = new HashMap<>();
map.put("lastMonth", ObjectUtils.isEmpty(lastMonthdata)?0:lastMonthdata.getOrDefault("cost", ""));
//去年同期
map.put("samePeriod", ObjectUtils.isEmpty(lastYearMonthdata)?0:lastYearMonthdata.getOrDefault("cost", ""));
//今年
map.put("thisYear", ObjectUtils.isEmpty(thisYeardata)?0:thisYeardata.getOrDefault("cost", ""));
//去年
map.put("lastYear", ObjectUtils.isEmpty(lastYeardata)?0:lastYeardata.getOrDefault("cost", ""));
// resultList.add(map);
result.setSuccess(true);
result.setResult(map);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
result.error500("查询失败");
}
return result;
}
}