From 147c5544f77087bca03e39abee8c586965d8867d Mon Sep 17 00:00:00 2001 From: wenjy Date: Fri, 18 Mar 2022 17:55:38 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E8=AE=BE=E5=A4=87=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E6=95=B0=E6=8D=AE=E5=AE=9E=E6=97=B6=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/DeviceMonitorController.java | 69 ++++++++++---- .../resources/static/img/sensor-block.png | Bin 2056 -> 1104 bytes .../static/js/Iot-ui/deviceMonitor.js | 85 ++++++++++++++++++ .../templates/section/transformer-detail.html | 15 ++-- 4 files changed, 144 insertions(+), 25 deletions(-) create mode 100644 ruoyi-admin/src/main/resources/static/js/Iot-ui/deviceMonitor.js 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 509cea0452ddac6858c79ac3371770323c1b61f6..95350bc8f2b44d6b69eaf8afd595d375bd630702 100644 GIT binary patch literal 1104 zcmeAS@N?(olHy`uVBq!ia0y~yVB7;_KjUBnlIt!R{9<5W5%+X)45^s&_Lg_nVFM9| zz@;hTk|qByC*na|NQA2Wj`L8GgO$(_N^`s zVGxli|MuhZm+#Tb+!&56IhJ#a`yNmET?K|7cGmY_8q%3Q)SUZXvv}`=PGN@4XEM&D zxx_{>Dm>h=%VpEQ{IejY4J-%ALoSyJN0zrgrk|OYS+{+dFUl>yzmW2e>Wo zS6qF6ZYD4@S-i{n6sGzA)D?~cGp@|=tv)#W;W}xShK~y#$jW{2VVHM*t+mSKH?011 p7-popC7UU~y2Qos|Gvay?$2tHjaD}{*a1rl22WQ%mvv4FO#lOkKyUy6 literal 2056 zcmeH|`7_&j7{|Z1AuX#`ZDUGHO@e7zJ)$K9J=jXEV|pWMJ5;cZmLTG;)@ZkJ^sAMG zIJ%wHcA8K}DG92F^jjgVD65XtCMXe+1Qk-*>_4!x*X&RG%V$0_pXYhzx!#}G^`L+w z#)cM#000={e7%nWfF4(OpImRCJ8SxOuK)mCfb%|hB84d%O}jRy26zfVG=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MYYg-brJv9qj&xK9VdVO#fEGjOi;w{^mLY`+p{l_bO5BaqqO>_3R7D@ TXM}~0@Bq#yz`N$q_c^}-#~F7W 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 @@
--->