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 0496ea8..14afa12 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 @@ -18,10 +18,9 @@ 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.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.stream.Collectors; /** @@ -40,6 +39,8 @@ public class DeviceMonitorController { @Autowired private StringRedisTemplate redisTemplate; + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + /** * 获取监控单元列表 * @@ -143,6 +144,8 @@ public class DeviceMonitorController { info = JsonUtils.JSONObjectToMap(datavalue); + info.put("collectTime",jsonObject.get("collectTime").toString()); + info.put("datatype", data.get("datatype")); } @@ -156,6 +159,8 @@ public class DeviceMonitorController { info.put("sensorLocation", y.getSensorLocation()); + info.put("sensorStatus",y.getSensorStatus()); + result.add(info); }); }); 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 de61696..47a585e 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 @@ -23,63 +23,147 @@ const getParameter = function (dataType){ } 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); + /*setInterval(function() { + + }, 5000);*/ + + $.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("失败"); + } + }) } const createDeviceModule = function (sensor,params) { - let html = '
'; + let html = '
'; switch (sensor.datatype) { case "temperature": html += `
${sensor.sensorId}
`; + + html += '
'; for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}
`; } html += '
'; + html += '
'; + html+=`

${sensor['sensorStatus'] == null ? "-" : sensorStatus(sensor['sensorStatus'])}

`; + html+=`

${sensor['collectTime'] == null ? "-" : collectTime(sensor['collectTime'])}

`; + html += '
'; + $("#sensor-card-group").append(html); break; case "image": - html += `
${sensor.sensorId}
`; - html += '
'; + html += `
${sensor.sensorId}  ${sensor['sensorStatus'] == null ? "-" : sensorStatus(sensor['sensorStatus'])}
` + html += '
'; + let imgurl = sensor.imgstr.replace("D:/ruoyi/uploadPath","/profile"); + html += '' + html += '
' + html += '
'; + html += `

${sensor['collectTime'] == null ? "-" : collectTime(sensor['collectTime'])}

`; + for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}

`; + } + } + html += '
'; + html += ``; + $("#sensor-card-group").append(html); break; case "smoke": html += `
${sensor.sensorId}
`; + + html += '
'; for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}
`; } html += ''; + html += '
'; + html+=`

${sensor['sensorStatus'] == null ? "-" : sensorStatus(sensor['sensorStatus'])}

`; + html+=`

${sensor['collectTime'] == null ? "-" : collectTime(sensor['collectTime'])}

`; + html += '
'; + $("#sensor-card-group").append(html); break; + break; case "platen": html += `
${sensor.sensorId}
`; + + html += '
'; for (let i=0; i${params[i].paramText+":"+(sensor[params[i].paramTitle] == null ? "-" : sensor[params[i].paramTitle])}
`; } html += ''; + html += '
'; + html+=`

${sensor['sensorStatus'] == null ? "-" : sensorStatus(sensor['sensorStatus'])}

`; + html+=`

${sensor['collectTime'] == null ? "-" : collectTime(sensor['collectTime'])}

`; + html += '
'; + $("#sensor-card-group").append(html); break; + break; default: break; } +} + +const collectTime = function (time){ + let oldTime = (new Date(time)).getTime(); + let curTime = new Date(oldTime).format("yyyy-MM-dd hh:mm:ss"); + return curTime; +} + +const sensorStatus = function (status) { + let result = "-"; + switch (status) { + case 0: + result = `在线`; + break; + case 1: + result = `离线`; + break; + case 2: + result = `告警`; + break; + default: + result = `异常`; + break; + } + return result; +} + +Date.prototype.format = function(fmt) { + var o = { + "M+" : this.getMonth()+1, //月份 + "d+" : this.getDate(), //日 + "h+" : this.getHours(), //小时 + "m+" : this.getMinutes(), //分 + "s+" : this.getSeconds(), //秒 + "q+" : Math.floor((this.getMonth()+3)/3), //季度 + "S" : this.getMilliseconds() //毫秒 + }; + if(/(y+)/.test(fmt)) { + fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); + } + for(var k in o) { + if(new RegExp("("+ k +")").test(fmt)){ + fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); + } + } + return fmt; } \ 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 8c10f9a..5acace9 100644 --- a/ruoyi-admin/src/main/resources/templates/section/transformer-detail.html +++ b/ruoyi-admin/src/main/resources/templates/section/transformer-detail.html @@ -17,8 +17,6 @@ -