AlarmController.java
10.0 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.app.alarm;
import com.alibaba.fastjson.JSONObject;
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.google.common.collect.Lists;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.api.ISysBaseAPI;
import com.skua.core.query.QueryGenerator;
import com.skua.core.api.vo.DictModel;
import com.skua.core.util.DateUtils;
import com.skua.modules.alarm.entity.AlarmCheckRecordMastertable;
import com.skua.modules.alarm.entity.AlarmCheckRecordSubtable;
import com.skua.modules.alarm.service.IAlarmCheckRecordMastertableService;
import com.skua.modules.alarm.service.IAlarmCheckRecordSubtableService;
import com.skua.modules.alarm.vo.AlarmQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 异常报警APP接口
*/
@Slf4j
@Api(tags="异常报警APP接口")
@RestController
@RequestMapping("/v1/app/alarm")
public class AlarmController {
@Autowired
private IAlarmCheckRecordSubtableService alarmCheckRecordSubtableService;
@Autowired
private IAlarmCheckRecordMastertableService alarmCheckRecordMastertableService;
@Autowired
private ISysBaseAPI iSysBaseAPI;
/**
* 异常报警分页列表
* @param jsonObject
* @param req
* @return
*/
@AutoLog(value = "异常报警分页列表")
@ApiOperation(value="异常报警分页列表", notes="异常报警分页列表")
@PostMapping(value = "/list")
public Result<IPage<AlarmCheckRecordSubtable>> queryPageList(@RequestBody JSONObject jsonObject, HttpServletRequest req) {
int pageNo = 1;
int pageSize = 10;
Result<IPage<AlarmCheckRecordSubtable>> result = new Result<IPage<AlarmCheckRecordSubtable>>();
AlarmCheckRecordSubtable alarmCheckRecordSubtable = new AlarmCheckRecordSubtable();
pageNo = jsonObject.getInteger("pageNo");
pageSize = jsonObject.getInteger("pageSize");
String date = jsonObject.getString("date");
if(!date.equals("")){
alarmCheckRecordSubtable.setCheAlasTime(date);
}
QueryWrapper<AlarmCheckRecordSubtable> queryWrapper = QueryGenerator.initQueryWrapper(alarmCheckRecordSubtable, req.getParameterMap());
Page<AlarmCheckRecordSubtable> page = new Page<AlarmCheckRecordSubtable>(pageNo, pageSize);
IPage<AlarmCheckRecordSubtable> pageList = alarmCheckRecordSubtableService.page(page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
/**
* 上传异常报警处理详情
* @param jsonObject
* @return
*/
@AutoLog(value = "上传异常报警处理详情")
@ApiOperation(value="上传异常报警处理详情", notes="上传异常报警处理详情")
@PostMapping(value = "/edit")
public Result<AlarmCheckRecordMastertable> edit(@RequestBody JSONObject jsonObject) {
//设置日期格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String id = jsonObject.getString("id");
//解决办法
String cheAlamSolution = jsonObject.getString("cheAlamSolution");
//报警原因
String cheAlamReason = jsonObject.getString("cheAlamReason");
//解决人
String cheAlamSolveUserName = jsonObject.getString("cheAlamSolveUserName");
//备注
String cheAlamExtraInfo = jsonObject.getString("cheAlamExtraInfo");
Result<AlarmCheckRecordMastertable> result = new Result<AlarmCheckRecordMastertable>();
AlarmCheckRecordMastertable entity = alarmCheckRecordMastertableService.getById(id);
if(entity==null) {
result.error500("未找到对应实体");
}else {
entity.setCheAlamSolution(cheAlamSolution);
entity.setCheAlamReason(cheAlamReason);
entity.setCheAlamSolveUserId(cheAlamSolveUserName);
entity.setCheAlamExtraInfo(cheAlamExtraInfo);
entity.setCheAlamEndTime(sdf.format(new Date()));
entity.setCheAlamState("2");
boolean ok = alarmCheckRecordMastertableService.updateById(entity);
if(ok) {
result.success("上传异常报警处理成功!");
}else{
result.error500("上传异常报警处理失败!");
}
}
return result;
}
/**
* 异常报警不分页列表
* @param
* @param
* @return
*/
@AutoLog(value = "异常报警不分页列表")
@ApiOperation(value="异常报警不分页列表", notes="异常报警不分页列表")
@GetMapping(value = "/queryCustomerList")
public Result<Map<String,Object>> queryCustomerList(AlarmQueryVO alarmQueryVO) {
Result<Map<String,Object> > result = new Result<Map<String,Object>>();
Page<Map<String,Object>> records = alarmCheckRecordSubtableService.getAlarmListByTime(alarmQueryVO,null);
// HashMap<String, Object> map = new HashMap<>();
// //超标报警
// int overStandard = 0;
// //故障报警
// int fault = 0;
// List<Map<String, Object>> pageList = records.getRecords();
// for (int i = 0; i < pageList.size(); i++) {
// if("0".equals(pageList.get(i).get("type"))){
// overStandard ++;
// }else if("2".equals(pageList.get(i).get("type"))){
// fault ++;
// }
// }
Map<String, Object> map = new HashMap<>(4);
Map<String, Object> map1 = new HashMap<>(4);
List<Map<String, Object>> list = new ArrayList<>();
map1.put("standard_params_name","指标1");
map1.put("che_alas_time","2020-09-01");
map1.put("che_alas_desc","指标值超过标准值");
map1.put("che_alas_value",0);
map1.put("che_alas_type","超标报警");
map1.put("che_alam_state","未处理");
list.add(map1);
map.put("overStandard",0);
map.put("fault",0);
map.put("pageList",list);
result.setSuccess(true);
result.setResult(map);
return result;
}
/**
* 报警趋势app
* @param alarmQueryVO
* @return
*/
@AutoLog(value = "报警趋势app")
@ApiOperation(value="报警趋势app", notes="报警趋势app")
@GetMapping(value = "/queryCustomerListapp")
public Result<Map<String,Object>> queryCustomerListapp(AlarmQueryVO alarmQueryVO) {
Result<Map<String,Object> > result = new Result<Map<String,Object>>();
List<Map<String,Object>> qsList = alarmCheckRecordSubtableService.getAlarmListByTimeApp(alarmQueryVO);
HashMap<String, Object> map = new HashMap<>();
map.put("dateList",qsList);
result.setSuccess(true);
result.setResult(map);
return result;
}
/**
* 报警说明app
* @param alarmQueryVO
* @return
*/
@AutoLog(value = "报警说明app")
@ApiOperation(value="报警说明app", notes="报警说明app")
@GetMapping(value = "/bjsmapplist")
public Result<Page<Map<String, Object>>> bjsmapplist(AlarmQueryVO alarmQueryVO,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
Result<Page<Map<String, Object>>> result = new Result<Page<Map<String, Object>>>();
Page<Map<String, Object>> page=new Page();
page.setCurrent(pageNo);
page.setSize(pageSize);
alarmQueryVO.setStartTime(alarmQueryVO.getChosetime()+"-01 00:00:00");
alarmQueryVO.setEndTime(DateUtils.getLastDayOfMonth(alarmQueryVO.getChosetime())+" 23:59:59");
Page<Map<String,Object>> pageList = alarmCheckRecordSubtableService.getAlarmListByTime(alarmQueryVO,page);
result.setResult(pageList);
result.setSuccess(true);
return result;
}
/**
* 报警统计app
* @param alarmQueryVO
* @return
*/
@AutoLog(value = "报警统计app")
@ApiOperation(value="报警统计app", notes="报警统计app")
@GetMapping(value = "/bjcsapplist")
public Result<Map<String, Object>> bjcsapplist(AlarmQueryVO alarmQueryVO) {
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
int totalCount = alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO);
// 未处理的
alarmQueryVO.setAlarmState(1);
int untreatedCount =alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO);
// 已处理的
alarmQueryVO.setAlarmState(2);
int treatedCount=alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO);
Map<String, Object> resMap = new LinkedHashMap<>();
resMap.put("untreatedCount",untreatedCount);
resMap.put("treatedCount",treatedCount);
resMap.put("totalCount",totalCount);
List<JSONObject> jsonArray= Lists.newArrayList();
//异常报警检测类型字典查询
List<DictModel> alarmCheckType = iSysBaseAPI.queryDictItemsByCode("alarmCheckType");
JSONObject jsonObject;
//去除处理状态的条件
alarmQueryVO.setAlarmState(null);
for (DictModel a : alarmCheckType) {
jsonObject = new JSONObject();
jsonObject.put("name", a.getText());
alarmQueryVO.setAlarmType(Integer.parseInt(a.getValue()));
jsonObject.put("count", alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO));
jsonArray.add(jsonObject);
}
resMap.put("alarmDatas",jsonArray);
result.setSuccess(true);
result.setResult(resMap);
return result;
}
}