diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/record/RecordSensorDataController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/record/RecordSensorDataController.java index aa9a70f..110bc6b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/record/RecordSensorDataController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/record/RecordSensorDataController.java @@ -1,14 +1,23 @@ package com.ruoyi.web.controller.record; import com.alibaba.fastjson.JSONArray; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.domain.BaseSensorInfo; import com.ruoyi.system.domain.dto.BaseSensorInfoDto; +import com.ruoyi.system.service.IBaseSensorInfoService; import com.ruoyi.system.service.IRecordSensorDataService; +import lombok.Data; +import org.apache.commons.collections.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; /** * 传感器数据记录 @@ -22,14 +31,25 @@ public class RecordSensorDataController { @Autowired private IRecordSensorDataService iRecordSensorDataService; + @Autowired + private IBaseSensorInfoService baseSensorInfoService; + private String prefix = "record/recordSensorData"; + private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @GetMapping("/getPage") public String recordSensorData(@RequestParam("id") String id, ModelMap mmap) { mmap.put("sensorId", id); return prefix + "/recordSensorData"; } + @GetMapping("/getTemperatureTrend") + public String getTemperatureTrend(@RequestParam("id") String id, ModelMap mmap){ + mmap.put("sensorId", id); + return prefix + "/temperatureTrend"; + } + @PostMapping("/list") @ResponseBody public String _getList(BaseSensorInfoDto baseSensorInfoDto) { @@ -59,7 +79,115 @@ public class RecordSensorDataController { List> maps = iRecordSensorDataService.selectSensorDataList(baseSensorInfoDto); - return JSONArray.toJSONString(maps); } + + @PostMapping("/getTemperatureTrendJson") + @ResponseBody + public String getTemperatureTrendJson(BaseSensorInfoDto baseSensorInfoDto){ + + baseSensorInfoDto.setTableName("record_" + baseSensorInfoDto.getSensorType()); + + Date date = new Date(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.DATE, -3); + date = calendar.getTime(); + + Map paramMap = new HashMap(); + + if (baseSensorInfoDto.getBeginCollectTime() == null) { + paramMap.put("beginCollectTime", date); + } else { + paramMap.put("beginCollectTime", baseSensorInfoDto.getBeginCollectTime()); + } + + if (baseSensorInfoDto.getEndCollectTime() == null) { + paramMap.put("endCollectTime", new Date()); + } else { + paramMap.put("endCollectTime", baseSensorInfoDto.getEndCollectTime()); + } + + baseSensorInfoDto.setParams(paramMap); + + List baseSensorInfoDtos = baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(baseSensorInfoDto.getSensorId())); + + List baseSensorInfoDtos1 = baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(null,null,null,baseSensorInfoDtos.get(0).getMonitorunitId())); + + List> maps = new ArrayList<>(); + + for (BaseSensorInfoDto sensorInfoDto : baseSensorInfoDtos1) { + baseSensorInfoDto.setSensorId(sensorInfoDto.getSensorId()); + maps.addAll(maps.size(),iRecordSensorDataService.selectTemperatureList(baseSensorInfoDto)); + } + + Map>> sensorId = maps.stream().collect(Collectors.groupingBy(m -> (m.get("sensorName").toString()))); + + List legend = new ArrayList<>(); + List xAxis = new ArrayList<>(); + List series = new ArrayList<>(); + + for (Map.Entry>> entry : sensorId.entrySet()) { + String mapKey = entry.getKey(); + List> mapValue = entry.getValue(); + + legend.add(entry.getKey()); + List data = new ArrayList<>(); + for (Map map : entry.getValue()) { + xAxis.add(map.get("collectTime").toString()); + data.add(Convert.toBigDecimal(map.get("value"))); + } + series.add(new Series(entry.getKey(),"line","Total",data)); + + } + + List collect = xAxis.stream().distinct().collect(Collectors.toList()); + + String s = JSONArray.toJSONString(new Root(legend, collect, series)); + + System.out.println("曲线趋势数据格式打印:"+s); + + return s; + } +} + +@Data +class Root{ + + public Root() { + } + + public Root(List legend, List xAxis, List series) { + this.legend = legend; + this.xAxis = xAxis; + this.series = series; + } + + private List legend; + + private List xAxis; + + private List series; } + +@Data +class Series{ + + public Series() { + } + + public Series(String name, String type, String stack, List data) { + this.name = name; + this.type = type; + this.stack = stack; + this.data = data; + } + + private String name; + + private String type; + + private String stack; + + private List data; +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/static/js/Iot-ui/deviceMonitor.js b/ruoyi-admin/src/main/resources/static/js/Iot-ui/deviceMonitor.js index a7c2076..5d560d4 100644 --- a/ruoyi-admin/src/main/resources/static/js/Iot-ui/deviceMonitor.js +++ b/ruoyi-admin/src/main/resources/static/js/Iot-ui/deviceMonitor.js @@ -49,7 +49,7 @@ const createDeviceModule = function (sensor,params) { case "temperature": html += `
${sensor.sensorName}
`; - html += '
'; + html += '
'; for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}
`; } @@ -181,4 +181,17 @@ Date.prototype.format = function(fmt) { } } return fmt; +} + +//温度传感器折线图 +const temperatureTrend = function (sensorId) { + Dialog({ + title: "趋势分析", + width: 1100, + iframeContent: { + src: "/record/recordSensorData/getTemperatureTrend?id="+sensorId, + height: 600 + }, + showButton: false + }); } \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/record/recordSensorData/temperatureTrend.html b/ruoyi-admin/src/main/resources/templates/record/recordSensorData/temperatureTrend.html new file mode 100644 index 0000000..8bd97bf --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/record/recordSensorData/temperatureTrend.html @@ -0,0 +1,314 @@ + + + + + + +
+
+
+
+
+
    +
  • + +
  • +
  • + + + - + +
  • + +
  • + + +
  • + +
  • +  搜索 + +  重置 + + + 导出 + + +
  • +
+
+
+
+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordSensorDataMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordSensorDataMapper.java index ae6c8aa..e76f427 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordSensorDataMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RecordSensorDataMapper.java @@ -13,4 +13,6 @@ import java.util.Map; public interface RecordSensorDataMapper { List> selectSensorDataList(BaseSensorInfoDto baseSensorInfoDto); + + List> selectTemperatureList(BaseSensorInfoDto baseSensorInfoDto); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordSensorDataService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordSensorDataService.java index e0fc50d..6bee974 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordSensorDataService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IRecordSensorDataService.java @@ -13,4 +13,6 @@ public interface IRecordSensorDataService { List> selectSensorDataList(BaseSensorInfoDto baseSensorInfoDto); + List> selectTemperatureList(BaseSensorInfoDto baseSensorInfoDto); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordSensorDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordSensorDataServiceImpl.java index a3d45da..2fe4930 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordSensorDataServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RecordSensorDataServiceImpl.java @@ -24,4 +24,9 @@ public class RecordSensorDataServiceImpl implements IRecordSensorDataService { public List> selectSensorDataList(BaseSensorInfoDto baseSensorInfoDto) { return recordSensorDataMapper.selectSensorDataList(baseSensorInfoDto); } + + @Override + public List> selectTemperatureList(BaseSensorInfoDto baseSensorInfoDto) { + return recordSensorDataMapper.selectTemperatureList(baseSensorInfoDto); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/RecordSensorDataMapper.xml b/ruoyi-system/src/main/resources/mapper/system/RecordSensorDataMapper.xml index 94ad7a8..6c9aa8a 100644 --- a/ruoyi-system/src/main/resources/mapper/system/RecordSensorDataMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/RecordSensorDataMapper.xml @@ -36,5 +36,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by collectTime desc + + \ No newline at end of file