ThreeDController.java
22.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
package com.skua.modules.threedimensional.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.service.IPgQueryService;
import com.skua.core.util.DateUtils;
import com.skua.modules.alarmtmp.service.AlarmRecordHistoryService;
import com.skua.modules.alarmtmp.vo.AlarmRecordHistoryVO;
import com.skua.modules.common.service.ICommonSqlService;
import com.skua.modules.flow.utils.StringUtil;
import com.skua.modules.system.entity.SysDepart;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.modules.system.service.ISysDictService;
import com.skua.modules.system.service.ISysFactoryInfoService;
import com.skua.modules.system.vo.SysFactoryInfo.SysFactoryInfoVO;
import com.skua.modules.threedimensional.dto.RealTimeDataDTO;
import com.skua.modules.threedimensional.entity.RealTimeData;
import com.skua.modules.threedimensional.enums.PgEnums;
import com.skua.modules.threedimensional.service.IPgService;
import com.skua.modules.threedimensional.vo.EquipmentStateVO;
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.jdbc.core.JdbcTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author sonin
* @date 2021/9/15 9:34
* 曹县三维接口
*/
@Slf4j
@Api(tags = "曹县三维接口")
@RestController
@RequestMapping("/3d")
public class ThreeDController {
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private ISysFactoryInfoService sysFactoryInfoService;
@Autowired
private ICommonSqlService iCommonSqlService;
@Autowired
private IPgQueryService pgQueryService;
@Autowired
private ISysDictService sysDictService;
@Autowired
private AlarmRecordHistoryService alarmRecordHistoryService;
@CustomExceptionAnno(description = "三维-园区介绍")
@AutoLog(value = "三维-园区介绍")
@ApiOperation(value = "三维-园区介绍", notes = "三维-园区介绍")
@GetMapping(value = "/introduce")
public Result<SysFactoryInfoVO> introduceCtrl(@RequestParam(name = "departId", defaultValue = "f2df9193c8bc4e7a9cef0e4b98dd9e95") String departId) {
Result<SysFactoryInfoVO> result = new Result<>();
SysFactoryInfoVO sysFactoryInfo = sysFactoryInfoService.getByDepartId(departId);
if (sysFactoryInfo == null) {
result.error500("未找到对应实体");
} else {
result.setResult(sysFactoryInfo);
result.setSuccess(true);
}
return result;
}
@CustomExceptionAnno(description = "三维-设备运行时长")
@AutoLog(value = "三维-设备运行时长")
@ApiOperation(value = "三维-园区介绍", notes = "三维-设备运行时长")
@GetMapping(value = "/equipRunTime")
public Result<SysFactoryInfoVO> equipRunTime(@RequestParam(name = "departId", defaultValue = "f2df9193c8bc4e7a9cef0e4b98dd9e95") String departId) {
Result<SysFactoryInfoVO> result = new Result<>();
SysFactoryInfoVO sysFactoryInfo = sysFactoryInfoService.getByDepartId(departId);
if (sysFactoryInfo == null) {
result.error500("未找到对应实体");
} else {
result.setResult(sysFactoryInfo);
result.setSuccess(true);
}
return result;
}
@CustomExceptionAnno(description = "厂区在线状态")
@AutoLog(value = "厂区在线状态")
@ApiOperation(value = "厂区在线状态", notes = "厂区在线状态")
@GetMapping(value = "/factoryOnLine")
public Result<SysFactoryInfoVO> factoryOnLine(@RequestParam(name = "departId", defaultValue = "f2df9193c8bc4e7a9cef0e4b98dd9e95") String departId, @RequestParam(name = "departType", defaultValue = "1", required = false) String departType) {
Result result = new Result<>();
result.setSuccess(true);
result.setResult(new HashMap<>());
QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
sysDepartQueryWrapper.eq("depart_type", departType).eq("del_flag", 1);
List<Map<String, Object>> deviceList = sysDepartService.queryFactoryDevice(sysDepartQueryWrapper);
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
int onlineCount = 0;
if (!CollectionUtils.isEmpty(deviceList)) {
List<Object> list = new ArrayList<>();
for (Map<String, Object> deviceMap : deviceList) {
String status = "offline";
String departName = String.valueOf(deviceMap.get("departName"));
String deviceId = String.valueOf(deviceMap.get("deviceId"));
String sql = "SELECT count(1) FROM realtimedata WHERE factoryname ='" + deviceId + "' AND nm like'" + "%IoStatus%'" + " AND v = '" + "1'";
Map<String, Object> countMap = pgDb.queryForMap(sql);
Integer count = Integer.parseInt(String.valueOf(countMap.get("count")));
if (count > 0) {
status = "online";
onlineCount++;
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("departId", departId);
resultMap.put("departName", departName);
resultMap.put("status", status);
list.add(resultMap);
}
Map<String, Object> resultMaps = new HashMap<>();
resultMaps.put("depart", list);
resultMaps.put("onlineCount", onlineCount);
resultMaps.put("totalCount", deviceList.size());
resultMaps.put("offlineCount", deviceList.size() - onlineCount > 0 ? deviceList.size() - onlineCount : 0);
result.setSuccess(true);
result.setResult(resultMaps);
}
return result;
}
@CustomExceptionAnno(description = "三维-实时数据查询")
@AutoLog(value = "三维-实时数据查询")
@ApiOperation(value = "三维-实时数据查询", notes = "三维-实时数据查询")
@GetMapping(value = "/realTimeData")
public Result<Object> realTimeDataCtrl(RealTimeDataDTO realTimeDataDTO) throws Exception {
Result<Object> result = new Result<>();
String departIds = realTimeDataDTO.getDepartIds();
String dictIds = realTimeDataDTO.getDictIds();
String groupType = realTimeDataDTO.getGroupType();
StringBuilder departIdStrBuilder = new StringBuilder("(");
for (String item : departIds.split(",")) {
departIdStrBuilder.append(", '").append(item).append("'");
}
departIdStrBuilder.append(")");
String sql;
if (StringUtils.isNotEmpty(groupType)) {
sql = "select smdg_smd.*, smmi.id as pgId, smmi.depart_id as departId, ifnull(sort_num, 1000) as sortNum from (select smd.id as dictId, smd.metricd_name as metricdName, smd.metric_unit as metricUnit from (select dict_id as dictId from sys_metric_dict_group where group_type = '" + groupType + "') as smdg inner join sys_metric_dict as smd on smdg.dictId = smd.id) as smdg_smd inner join sys_monitor_metric_info as smmi on smdg_smd.dictId = smmi.metric_uid_tag and smmi.depart_id in " + departIdStrBuilder.toString().replaceFirst(", ", "") + " order by sort_num";
} else {
StringBuilder dictIdStrBuilder = new StringBuilder("(");
for (String item : dictIds.split(",")) {
dictIdStrBuilder.append(", '").append(item).append("'");
}
dictIdStrBuilder.append(")");
sql = "select smd.id as dictId, smd.metricd_name as metricdName, smd.metric_unit as metricUnit, smmi.id as pgId, smmi.depart_id as departId from sys_metric_dict as smd inner join sys_monitor_metric_info as smmi on smd.id = smmi.metric_uid_tag and smd.id in " + dictIdStrBuilder.toString().replaceFirst(", ", "") + " and smmi.depart_id in " + departIdStrBuilder.toString().replaceFirst(", ", "");
}
// dictId, metricdName, metricUnit, pgId
List<Map<String, Object>> mapList = iCommonSqlService.queryForList(sql);
if (mapList == null || mapList.isEmpty() || mapList.get(0) == null) {
return result.error500("数据为空");
}
List<RealTimeData> realTimeDataList = BeanExtUtils.maps2Beans(mapList, RealTimeData.class);
Class<? extends IPgService> clazz = PgEnums.getClazz(groupType, dictIds);
IPgService iPgService = SpringContextUtils.getBean(clazz);
Object res = iPgService.doService(realTimeDataDTO, realTimeDataList);
result.setResult(res);
return result;
}
@AutoLog(value = "三维-药耗统计")
@ApiOperation(value = "三维-药耗统计", notes = "三维-药耗统计")
@GetMapping(value = "/drugConsumption")
public Result<Object> drugConsumptionCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("药耗统计error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-能耗情况")
@ApiOperation(value = "三维-能耗情况", notes = "三维-能耗情况")
@GetMapping(value = "/energyConsumption")
public Result<Object> energyConsumptionCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("能耗情况error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-报警统计")
@ApiOperation(value = "三维-报警统计", notes = "三维-报警统计")
@GetMapping(value = "/policeStatistics")
public Result<Object> policeStatisticsCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("报警统计error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@CustomExceptionAnno(description = "三维-设备运行时长统计")
@AutoLog(value = "三维-设备运行时长统计")
@ApiOperation(value = "三维-设备运行时长统计", notes = "三维-设备运行时长统计")
@GetMapping(value = "/equipRuntimeStatistics")
public Result<Object> deviceRuntimeStatisticsCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("设备运行时长统计error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-设备状态")
@ApiOperation(value = "三维-设备状态", notes = "三维-设备状态")
@GetMapping(value = "/equipmentState")
public Result<List<EquipmentStateVO>> equipmentStateCtrl(@RequestParam(name = "departId", defaultValue = "") String departId, @RequestParam(name = "structCode", defaultValue = "") String structCode) {
Result<List<EquipmentStateVO>> result = new Result<>();
String departs = BaseContextHandler.getDeparts();
QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
sysDepartQueryWrapper.eq("del_flag", 1).eq("depart_type", 1).in("id", Lists.newArrayList(departs.split(",")))
.select("id,depart_name");
List<Map<String, Object>> departMapList = sysDepartService.listMaps(sysDepartQueryWrapper);
departId = departMapList.stream().map(map ->
String.valueOf(map.get("id"))
).collect(Collectors.joining(","));
String sql = "select ei.id ,ssd.struct_name as structName,smmi.depart_id as departId,sd.depart_name as departName, ei.equipment_name as metricName, smmi.metric_express1 as metricExpress1, smmi.metric_express2 as metricExpress2, smmi.metric_express3 as metricExpress3 from sys_monitor_metric_info smmi inner join equipment_info ei on smmi.equipment_code = ei.id inner join sys_depart sd on sd.id = smmi.depart_id left join sys_struct_dict ssd on ssd.id = smmi.struct_code where smmi.equipment_code is not null";
if (StringUtil.isNotBlank(departId)) {
String[] factory = departId.split(",");
StringBuilder sb = new StringBuilder();
for (String tempDepartId : factory) {
sb.append(",'").append(tempDepartId).append("'");
}
if (StringUtil.isNotBlank(sb.toString())) {
sql += " and ei.depart_id in (" + sb.substring(1) + ")";
}
}
if (StringUtils.isNotEmpty(structCode)) {
sql += " and smmi.struct_code = '" + structCode + "'";
}
List<Map<String, Object>> mapList = iCommonSqlService.queryForList(sql);
StringBuilder pgIds = new StringBuilder();
Map<String, Map<String, Object>> pgId2ItemMap = new HashMap<>();
for (Map<String, Object> map : mapList) {
pgId2ItemMap.put(map.getOrDefault("metricExpress1", "") + "", map);
pgId2ItemMap.put(map.getOrDefault("metricExpress2", "") + "", map);
pgId2ItemMap.put(map.getOrDefault("metricExpress3", "") + "", map);
pgIds.append(",").append(map.get("metricExpress1")).append(",").append(map.get("metricExpress2")).append(",").append(map.get("metricExpress3"));
}
List<Map<String, Object>> pgMapList = pgQueryService.queryFactoryInfosForMonitor(departId, pgIds.toString().replaceFirst(",", ""));
if (pgMapList.isEmpty()) {
result.setResult(new ArrayList<>());
return result;
}
List<EquipmentStateVO> equipmentStateVOList = new ArrayList<>();
for (Map<String, Object> item : mapList) {
EquipmentStateVO equipmentStateVO = new EquipmentStateVO();
equipmentStateVO.setId(item.get("id") + "");
equipmentStateVO.setStructName(item.get("structName") + "");
equipmentStateVO.setMetricName(item.get("metricName").toString());
equipmentStateVO.setFactory(item.get("departName").toString());
String time = String.valueOf(Math.abs(item.get("metricName").toString().hashCode()) / 1000000);
equipmentStateVO.setRunDuration(time);
equipmentStateVO.setRunTotalDuration(time);
Map<String, Object> pgMap = pgMapList.get(0);
if (pgMap.get("" + item.get("metricExpress1")) != null && "1".equals(pgMap.get("" + item.get("metricExpress1")))) {
equipmentStateVO.setStatus("2");
} else if (pgMap.get("" + item.get("metricExpress2")) != null && "1".equals(pgMap.get("" + item.get("metricExpress2")))) {
equipmentStateVO.setStatus("1");
} else {
equipmentStateVO.setStatus("0");
}
equipmentStateVOList.add(equipmentStateVO);
}
result.setResult(equipmentStateVOList);
return result;
}
@AutoLog(value = "三维-工艺状态")
@ApiOperation(value = "三维-工艺状态", notes = "三维-工艺状态")
@GetMapping(value = "/processState")
public Result<Object> processStateCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("工艺状态error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-监测数据")
@ApiOperation(value = "三维-监测数据", notes = "三维-监测数据")
@GetMapping(value = "/monitorData")
public Result<Object> monitorDataCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("监测数据error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-告警标准")
@ApiOperation(value = "三维-告警标准", notes = "三维-告警标准")
@GetMapping(value = "/alarmStandard")
public Result<Object> alarmStandardCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("告警标准error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-以往告警记录")
@ApiOperation(value = "三维-以往告警记录", notes = "三维-以往告警记录")
@GetMapping(value = "/alarmRecord")
public Result<Object> alarmRecordCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("以往告警记录error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
@AutoLog(value = "三维-巡检内容")
@ApiOperation(value = "三维-巡检内容", notes = "三维-巡检内容")
@GetMapping(value = "/inspectionContent")
public Result<Object> inspectionContentCtrl() {
Result<Object> result = new Result<>();
try {
result.setResult("todo...");
} catch (Exception e) {
log.error("巡检内容error: {}", e.getMessage());
result.error500(e.getMessage());
}
return result;
}
/**
* (type outside|inside)
* outside 对外 只预警
* inside 对内 默认
*
* @return com.skua.core.api.vo.Result<java.lang.Object>
* @Description
* @Date 2021-10-22 17:04
* @Param [type]
**/
@AutoLog(value = "三维-报警等级统计数量")
@ApiOperation(value = "三维-报警等级统计数量", notes = "三维-报警等级统计数量")
@GetMapping(value = "/getAlarmStatisticsCount")
public Result<List<Map<String, Object>>> getAlarmStatisticsCount(@RequestParam(defaultValue = "inside") String type, String departId) {
Result<List<Map<String, Object>>> result = new Result<>();
String condition = "";
String conditionFac = "";
if ("outside".equals(type)) {
condition = "AND ( alarm_rule_level_name !='重要报警' ) ";
}
if (StringUtils.isNotBlank(departId)) {
String[] split = departId.split(",");
String facs = "";
for (String factor : split) {
facs = facs + ",'" + factor + "'";
}
conditionFac = " AND depart_id in (" + facs.substring(1) + ")";
}
String sql = "SELECT tt.item_text levelName,ifnull( t.cou, 0 ) count FROM( " +
"SELECT item_text, item_value FROM sys_dict_item b LEFT JOIN sys_dict a ON a.id = b.dict_id WHERE a.dict_code = 'alarm_level' ) tt " +
"LEFT JOIN (SELECT alarm_rule_level_name,count( 1 ) cou FROM alarm_record_history " +
"WHERE DATE_FORMAT( record_time, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ), '%Y-%m-%d' ) " +
"AND ( alarm_rule_type = 'A001A001' OR " +
" alarm_rule_type = 'A001A002' OR " +
" alarm_rule_type = 'A001A003' OR " +
" alarm_rule_type = 'B001B001' OR " +
" alarm_rule_type = 'C001C002' )"
+ condition + conditionFac +
" GROUP BY alarm_rule_level_name ) t " +
"ON t.alarm_rule_level_name = tt.item_value";
List<Map<String, Object>> mapList = iCommonSqlService.queryForList(sql);
result.setResult(mapList);
return result;
}
/**
* (type outside|inside)
* outside 对外 只预警
* inside 对内 默认
* <p>
* departId 没传查询全部
*
* @return com.skua.core.api.vo.Result<java.lang.Object>
* @Description
* @Date 2021-10-22 17:04
* @Param [type]
**/
@AutoLog(value = "三维-根据报警等级查询当天的报警信息")
@ApiOperation(value = "三维-根据报警等级查询当天的报警信息", notes = "三维-根据报警等级查询当天的报警信息")
@GetMapping(value = "/getAlarmInfoByLevelName")
public Result<List<JSONObject>> getAlarmInfoByLevelName(@RequestParam(defaultValue = "inside") String type, String departId, String levelName) {
Result<List<JSONObject>> result = new Result<>();
AlarmRecordHistoryVO alarmRecordHistoryVO = new AlarmRecordHistoryVO();
alarmRecordHistoryVO.setAlarmRuleType("A001A001,A001A002,A001A003,B001B001,C001C002");
String date = DateUtils.getDate("yyyy-MM-dd");
alarmRecordHistoryVO.setStartTime(date + " 00:00:00");
alarmRecordHistoryVO.setEndTime(date + " 23:59:59");
if ("outside".equals(type)) {
if ("重要报警".equals(levelName)) {
return result;
}
alarmRecordHistoryVO.setAlarmRuleLevelName("一般报警,提醒报警");
}
if (StringUtils.isNotBlank(levelName)) {
alarmRecordHistoryVO.setAlarmRuleLevelName(levelName);
}
if (StringUtils.isNotBlank(departId)) {
alarmRecordHistoryVO.setDepartId(departId);
}
Page<AlarmRecordHistoryVO> pageList = new Page<>(1, 500);
Page<AlarmRecordHistoryVO> alarmRecordHistoryVOPage = alarmRecordHistoryService.queryPageAllList(pageList, alarmRecordHistoryVO);
List<AlarmRecordHistoryVO> records = alarmRecordHistoryVOPage.getRecords();
List<JSONObject> data = Lists.newArrayList();
if (records != null && records.size() > 0) {
for (AlarmRecordHistoryVO record : records) {
JSONObject jsonObject = sysDictService.translateTDictValue(record);
data.add(jsonObject);
}
}
result.setResult(data);
return result;
}
}