|
|
@@ -0,0 +1,64 @@
|
|
|
+package com.zksy.web.controller.base.environment;
|
|
|
+
|
|
|
+import com.zksy.base.environment.domain.ERealTimeData;
|
|
|
+import com.zksy.base.environment.service.ERealTimeDataService;
|
|
|
+import com.zksy.common.core.domain.AjaxResult;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/env")
|
|
|
+public class ERealTimeDataController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ERealTimeDataService dataService;
|
|
|
+
|
|
|
+ private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ private static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ @GetMapping("/latest")
|
|
|
+ @ApiOperation("查询最新数据")
|
|
|
+ public AjaxResult getLatest(@RequestParam Integer deviceId,
|
|
|
+ @RequestParam Integer nodeId) {
|
|
|
+ return AjaxResult.success(dataService.getLatestByDeviceNode(deviceId, nodeId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/daily-stats")
|
|
|
+ @ApiOperation("按天统计(均值、最大值、最小值)")
|
|
|
+ public AjaxResult getDailyStats(@RequestParam Integer deviceId,
|
|
|
+ @RequestParam Integer nodeId,
|
|
|
+ @RequestParam String date) {
|
|
|
+ LocalDate localDate = LocalDate.parse(date, DATE_FORMAT);
|
|
|
+ return AjaxResult.success(dataService.getDailyStats(deviceId, nodeId, localDate));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/trend")
|
|
|
+ @ApiOperation("设备趋势分析")
|
|
|
+ public AjaxResult getTrend(@RequestParam Integer deviceId,
|
|
|
+ @RequestParam Integer nodeId,
|
|
|
+ @RequestParam String start,
|
|
|
+ @RequestParam String end) {
|
|
|
+ LocalDateTime startTime = LocalDateTime.parse(start, DATETIME_FORMAT);
|
|
|
+ LocalDateTime endTime = LocalDateTime.parse(end, DATETIME_FORMAT);
|
|
|
+ return AjaxResult.success(dataService.getTrend(deviceId, nodeId, startTime, endTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/alarms")
|
|
|
+ @ApiOperation("查询报警数据")
|
|
|
+ public AjaxResult getAlarms(@RequestParam Integer deviceId,
|
|
|
+ @RequestParam Integer nodeId,
|
|
|
+ @RequestParam String start,
|
|
|
+ @RequestParam String end,
|
|
|
+ @RequestParam(required = false) Double threshold) {
|
|
|
+ LocalDateTime startTime = LocalDateTime.parse(start, DATETIME_FORMAT);
|
|
|
+ LocalDateTime endTime = LocalDateTime.parse(end, DATETIME_FORMAT);
|
|
|
+ return AjaxResult.success(dataService.getAlarms(deviceId, nodeId, startTime, endTime, threshold));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|