diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java index 71e4a7b..0496ea8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/DeviceMonitorController.java @@ -1,6 +1,9 @@ package com.ruoyi.web.controller.iot; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.json.JsonUtils; import com.ruoyi.system.domain.BaseMonitorunitInfo; import com.ruoyi.system.domain.BaseSensorInfo; import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto; @@ -9,13 +12,16 @@ import com.ruoyi.system.service.IBaseMonitorunitInfoService; import com.ruoyi.system.service.IBaseSensorInfoService; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -32,6 +38,8 @@ public class DeviceMonitorController { @Autowired private IBaseSensorInfoService baseSensorInfoService; + @Autowired private StringRedisTemplate redisTemplate; + /** * 获取监控单元列表 * @@ -107,7 +115,8 @@ public class DeviceMonitorController { @GetMapping("/getSensorInfo") @ResponseBody public String getSensorInfo(String monitorunitId) { - List baseSensorInfoDtos = new ArrayList<>(); + List> result = new ArrayList<>(); + //List baseSensorInfoDtos = new ArrayList<>(); List baseMonitorunitInfoDtos = baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList( @@ -115,26 +124,48 @@ public class DeviceMonitorController { baseMonitorunitInfoDtos.forEach( x -> { - /*if(x.getParentId().isEmpty()){ - BaseMonitorunitInfo baseMonitorunitInfo = new BaseMonitorunitInfo(); - baseMonitorunitInfo.setParentId(x.getMonitorunitId()); - List baseMonitorunitInfoDtos1 = baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo); - baseMonitorunitInfoDtos1.forEach(y->{ - List baseSensorInfoDtos1 = baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(null, null, null, y.getMonitorunitId())); - baseSensorInfoDtos.addAll(baseSensorInfoDtos1); - }); - }else{ - List baseSensorInfoDtos1 = baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(null, null, null, x.getMonitorunitId())); - baseSensorInfoDtos.addAll(baseSensorInfoDtos1); - }*/ - - List baseSensorInfoDtos1 = - baseSensorInfoService.selectBaseSensorInfoList( - new BaseSensorInfo(null, null, null, x.getMonitorunitId())); - baseSensorInfoDtos.addAll(baseSensorInfoDtos1); + List baseSensorInfoDtos = + baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(null, null, null, x.getMonitorunitId())); + + baseSensorInfoDtos.forEach(y -> { + Map info = new HashMap<>(); + + Object jrm = redisTemplate.opsForHash().get(y.getSensorType(), y.getSensorId()); + + if (jrm != null) { + JSONObject jsonObject = JSON.parseObject(jrm.toString()); + + Object param = jsonObject.get("param"); + + JSONObject data = JSON.parseObject(param.toString()); + + JSONObject datavalue = JSON.parseObject(data.get("datavalue").toString()); + + info = JsonUtils.JSONObjectToMap(datavalue); + + info.put("datatype", data.get("datatype")); + } + + info.put("datatype",y.getSensorType()); + + info.put("id", 1); + + info.put("sensorId", y.getSensorId()); + + info.put("edgeId", y.getEdgeId()); + + info.put("sensorLocation", y.getSensorLocation()); + + result.add(info); + }); }); - return JSONArray.toJSONString(baseSensorInfoDtos); + + + String s = JSONArray.toJSONString(result); + System.out.println("传感器数据展示" + s); + + return s; } } diff --git a/ruoyi-admin/src/main/resources/static/img/sensor-block.png b/ruoyi-admin/src/main/resources/static/img/sensor-block.png index 509cea0..95350bc 100644 Binary files a/ruoyi-admin/src/main/resources/static/img/sensor-block.png and b/ruoyi-admin/src/main/resources/static/img/sensor-block.png differ 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 new file mode 100644 index 0000000..de61696 --- /dev/null +++ b/ruoyi-admin/src/main/resources/static/js/Iot-ui/deviceMonitor.js @@ -0,0 +1,85 @@ +const getParameter = function (dataType){ + var returnData; + let formData = new FormData(); + formData.append("sensorTypeId", dataType); + $.ajax({ + type: "post", + url: "/base/sysParamConfig/getParameter", + data: formData, + contentType: "application/json;charset=utf-8", + dataType: "json", + json: 'callback', + processData: false, + contentType: false, + async: false, + success: function (json) { + returnData = json; + }, + error: function () { + alert("错误"); + } + }); + return returnData; +} + +const sensorCollectionRefresh = function (monitorUnitId) { + setInterval(function() { + $.ajax({ + url: "/iot/deviceMonitor/getSensorInfo?monitorunitId=" + monitorUnitId, + type: "get", + dataType: 'JSON', + success: (res) => { + $("#sensor-card-group").html(""); + res.map(x=>{ + let params = getParameter(x.datatype); + createDeviceModule(x,params); + }) + }, + error: () => { + console.log("失败"); + } + }) + }, 5000); +} + +const createDeviceModule = function (sensor,params) { + + let html = '
'; + switch (sensor.datatype) { + case "temperature": + html += `
${sensor.sensorId}
`; + for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}
`; + } + html += ''; + $("#sensor-card-group").append(html); + break; + + case "image": + html += `
${sensor.sensorId}
`; + html += ''; + $("#sensor-card-group").append(html); + break; + + case "smoke": + html += `
${sensor.sensorId}
`; + for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}`; + } + html += ''; + $("#sensor-card-group").append(html); + break; + + case "platen": + html += `
${sensor.sensorId}
`; + for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}`; + } + html += ''; + $("#sensor-card-group").append(html); + break; + + default: + break; + } +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/section/transformer-detail.html b/ruoyi-admin/src/main/resources/templates/section/transformer-detail.html index cc78964..8c10f9a 100644 --- a/ruoyi-admin/src/main/resources/templates/section/transformer-detail.html +++ b/ruoyi-admin/src/main/resources/templates/section/transformer-detail.html @@ -245,6 +245,8 @@ left: 49%; top: 13%; overflow-y: scroll; + display: flex; + flex-wrap: wrap; } #sensor-card-group > * { @@ -257,7 +259,7 @@ .sensor-card { background: url("/img/sensor-block.png") no-repeat #00000000; - background-size: 100% auto; + background-size: 100% 100%; width: 27rem; height: 14.6rem; border-radius: 0; @@ -265,8 +267,8 @@ } .sensor-card:hover, .sensor-card.active { - background: url("/img/sensor-block-active.png") no-repeat #00000000; - background-size: 100% auto; + background: url("/img/sensor-block.png") no-repeat #00000000; + background-size: 100% 100%; } .card-title { @@ -387,6 +389,7 @@ +
@@ -438,7 +441,7 @@
--->