diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/SensorSummaryController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/SensorSummaryController.java index 01ad3b5..9fda671 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/SensorSummaryController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/SensorSummaryController.java @@ -64,38 +64,31 @@ public class SensorSummaryController extends BaseController { List> result = new ArrayList<>(); List baseSensorInfoDtos = - baseSensorInfoService.selectBaseSensorInfoList(new BaseSensorInfo(sensorTypeId, 0L)); + baseSensorInfoService.selectSensorDataListBySensorType(sensorTypeId); - baseSensorInfoDtos.forEach( - x -> { - Map info = new HashMap<>(); + for (BaseSensorInfoDto baseSensorInfoDto : baseSensorInfoDtos) { + Map info = new HashMap<>(); + if (baseSensorInfoDto.getReportParam() != null) { + JSONObject jsonObject = JSON.parseObject(baseSensorInfoDto.getReportParam()); - Object jrm = redisTemplate.opsForHash().get(x.getSensorType(), x.getSensorId()); + JSONObject datavalue = JSON.parseObject(jsonObject.get("datavalue").toString()); - if (jrm != null) { - JSONObject jsonObject = JSON.parseObject(jrm.toString()); + info = JsonUtils.JSONObjectToMap(datavalue); - Object param = jsonObject.get("param"); + info.put("datatype", jsonObject.get("datatype")); + } + info.put("id", 1); - JSONObject data = JSON.parseObject(param.toString()); + info.put("sensorId", baseSensorInfoDto.getSensorId()); - JSONObject datavalue = JSON.parseObject(data.get("datavalue").toString()); + info.put("edgeId", baseSensorInfoDto.getEdgeId()); - info = JsonUtils.JSONObjectToMap(datavalue); + info.put("sensorLocation", baseSensorInfoDto.getSensorLocation()); - info.put("datatype", data.get("datatype")); - } + info.put("collectTime", baseSensorInfoDto.getCollectTime()); - info.put("id", 1); - - info.put("sensorId", x.getSensorId()); - - info.put("edgeId", x.getEdgeId()); - - info.put("sensorLocation", x.getSensorLocation()); - - result.add(info); - }); + result.add(info); + } String s = JSONArray.toJSONString(result); System.out.println("传感器数据展示" + s); @@ -128,86 +121,4 @@ public class SensorSummaryController extends BaseController { System.out.println("key为:" + item + "值为:" + children.get(item)); } } -} - -class sensorTableModel { - private int id; - - private String edgeId; - - private String sensorId; - - private BigDecimal sensorData; - - private BigDecimal rssi; - - private BigDecimal voltage; - - private String collectTime; - - private String monitorLocation; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getEdgeId() { - return edgeId; - } - - public void setEdgeId(String edgeId) { - this.edgeId = edgeId; - } - - public String getSensorId() { - return sensorId; - } - - public void setSensorId(String sensorId) { - this.sensorId = sensorId; - } - - public BigDecimal getSensorData() { - return sensorData; - } - - public void setSensorData(BigDecimal sensorData) { - this.sensorData = sensorData; - } - - public BigDecimal getRssi() { - return rssi; - } - - public void setRssi(BigDecimal rssi) { - this.rssi = rssi; - } - - public BigDecimal getVoltage() { - return voltage; - } - - public void setVoltage(BigDecimal voltage) { - this.voltage = voltage; - } - - public String getCollectTime() { - return collectTime; - } - - public void setCollectTime(String collectTime) { - this.collectTime = collectTime; - } - - public String getMonitorLocation() { - return monitorLocation; - } - - public void setMonitorLocation(String monitorLocation) { - this.monitorLocation = monitorLocation; - } -} +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/static/js/Iot-ui/sensorTableList.js b/ruoyi-admin/src/main/resources/static/js/Iot-ui/sensorTableList.js index 5d1e44e..ebe8276 100644 --- a/ruoyi-admin/src/main/resources/static/js/Iot-ui/sensorTableList.js +++ b/ruoyi-admin/src/main/resources/static/js/Iot-ui/sensorTableList.js @@ -2,26 +2,6 @@ const sensorInfoList = function (sensorTypeId) { let formData = new FormData(); formData.append("sensorTypeId", sensorTypeId); - - let sensorTypeArray = []; - - $.ajax({ - type: "post", - url: "/base/sysParamConfig/getParameter", - data: formData, - contentType: "application/json;charset=utf-8", - dataType: "json", - json: 'callback', - processData: false, - contentType: false, - success: function (json) { - sensorTypeArray = json; - }, - error: function () { - alert("错误"); - } - }); - $.ajax({ type: "post", url: "/iot/sensorSummary/getSensorInfo", @@ -32,10 +12,13 @@ const sensorInfoList = function (sensorTypeId) { processData: false, contentType: false, success: function (json) { + + let sensorTypeArray = getparamsFunction(sensorTypeId); + const columnsArray = []; columnsArray.push({field: "id", title: "序号", width: 60, colspan: 1, rowspan: 1, align: "center"}); - columnsArray.push({field: "edgeId", title: "边设备ID", width: 145, colspan: 1, rowspan: 1, align: "center"}); - columnsArray.push({field: "sensorId", title: "传感器ID", width: 145, colspan: 1, rowspan: 1, align: "center"}); + columnsArray.push({field: "edgeId", title: "边设备ID", width: 160, colspan: 1, rowspan: 1, align: "center"}); + columnsArray.push({field: "sensorId", title: "传感器ID", width: 160, colspan: 1, rowspan: 1, align: "center"}); columnsArray.push({ field: "sensorLocation", title: "监测位置", @@ -45,10 +28,19 @@ const sensorInfoList = function (sensorTypeId) { align: "center" }); + columnsArray.push({ + field: "collectTime", + title: "时间", + width: 160, + colspan: 1, + rowspan: 1, + align: "center" + }); + if (json.length > 0) { for (let i = 0; i < (Object.keys(json[0])).length; i++) {//Object.keys(obj) 获取key名称 let property = (Object.keys(json[0]))[i]; - if (property != "id" && property != "edgeId" && property != "sensorId" && property != 'sensorLocation' && property != 'datatype') { + if (property != "id" && property != "edgeId" && property != "sensorId" && property != 'sensorLocation' && property != 'datatype' && property != 'collectTime') { columnsArray.push({ field: property, title: sensorTypeArray.length == 0 ? property : sensorTypeArray.find(array => array.paramTitle === property).paramText, @@ -81,6 +73,30 @@ const sensorInfoList = function (sensorTypeId) { }) } +const getparamsFunction = function (sensorTypeId) { + var returnData; + let formData = new FormData(); + formData.append("sensorTypeId", sensorTypeId); + $.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 onSearchByMonitorLocation = function (obj) { setTimeout(function () { var storeId = document.getElementById('table'); @@ -113,4 +129,21 @@ const onSearchBySensorId = function (obj) { } } }, 500); +} + +const onSearchByCollectTime = function (obj) { + setTimeout(function () { + var storeId = document.getElementById('table'); + var rowsLength = storeId.rows.length; + var key = obj.value; + var searchCol = 4; + for (var i = 1; i < rowsLength; i++) { + var searchText = storeId.rows[i].cells[searchCol].innerHTML; + if (searchText.match(key)) { + storeId.rows[i].style.display = ''; + } else { + storeId.rows[i].style.display = 'none'; + } + } + }, 500); } \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/iot-ui/sensorSummary.html b/ruoyi-admin/src/main/resources/templates/iot-ui/sensorSummary.html index 32b5497..df8e048 100644 --- a/ruoyi-admin/src/main/resources/templates/iot-ui/sensorSummary.html +++ b/ruoyi-admin/src/main/resources/templates/iot-ui/sensorSummary.html @@ -9,29 +9,6 @@ - - @@ -53,8 +30,8 @@ - + + diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/BaseSensorInfoDto.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/BaseSensorInfoDto.java index 44a69aa..c71e5b5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/BaseSensorInfoDto.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/BaseSensorInfoDto.java @@ -18,4 +18,9 @@ public class BaseSensorInfoDto extends BaseSensorInfo { private BigDecimal[] maxValue; private BigDecimal[] minValue; + + /** 传感器实时上传数据 */ + private String reportParam; + /** 数据采集时间 */ + private String collectTime; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java index 938f108..025de90 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/BaseSensorInfoMapper.java @@ -59,4 +59,13 @@ public interface BaseSensorInfoMapper * @return 结果 */ public int deleteBaseSensorInfoByObjIds(String[] objIds); + + /** + * 通过传感器类型查询历史数据 + * @author WenJY + * @date 2022/3/25 9:27 + * @param sensorType + * @return java.util.List + */ + public List selectSensorDataListBySensorType(String sensorType); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseSensorInfoService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseSensorInfoService.java index ed90b3a..4f5757e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseSensorInfoService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IBaseSensorInfoService.java @@ -69,4 +69,13 @@ public interface IBaseSensorInfoService * @return 结果 */ public int deleteBaseSensorInfoByObjId(Long objId); + + /** + * 通过传感器类型查询历史数据 + * @author WenJY + * @date 2022/3/25 9:27 + * @param sensorType + * @return java.util.List + */ + public List selectSensorDataListBySensorType(String sensorType); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java index f1cd90c..e2403c8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BaseSensorInfoServiceImpl.java @@ -157,4 +157,16 @@ public class BaseSensorInfoServiceImpl implements IBaseSensorInfoService { return baseSensorInfoMapper.deleteBaseSensorInfoByObjId(objId); } + + /** + * 通过传感器类型查询历史数据 + * @author WenJY + * @date 2022/3/25 9:37 + * @param sensorType + * @return java.util.List + */ + @Override + public List selectSensorDataListBySensorType(String sensorType) { + return baseSensorInfoMapper.selectSensorDataListBySensorType(sensorType); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml index 812d83e..f6ee4a3 100644 --- a/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/BaseSensorInfoMapper.xml @@ -1,48 +1,65 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - select ObjId, EdgeId, Sensor_Id, Sensor_Name, Sensor_Type, Sensor_Status, MonitorUnit_Id, Sensor_Location, Sensor_Address, Order_Num, Enable_Flag, Create_By, Create_Time, Update_By, Update_Time from base_sensor_info + select ObjId, + EdgeId, + Sensor_Id, + Sensor_Name, + Sensor_Type, + Sensor_Status, + MonitorUnit_Id, + Sensor_Location, + Sensor_Address, + Order_Num, + Enable_Flag, + Create_By, + Create_Time, + Update_By, + Update_Time + from base_sensor_info - + - + + + insert into base_sensor_info @@ -117,7 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" Create_Time, Update_By, Update_Time, - + #{EdgeId}, #{sensorId}, @@ -133,7 +162,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createTime}, #{updateBy}, #{updateTime}, - + @@ -158,11 +187,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from base_sensor_info where ObjId = #{objId} + delete + from base_sensor_info + where ObjId = #{objId} - delete from base_sensor_info where ObjId in + delete from base_sensor_info where ObjId in #{objId}