From 49d145fab1817be1ca4b68a5b68bca78bc670b41 Mon Sep 17 00:00:00 2001 From: wenjy Date: Sun, 29 May 2022 12:32:10 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E4=BC=A0=E6=84=9F=E5=99=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9B=91=E6=8E=A7=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/BaseSensorInfoController.java | 1 + .../web/controller/iot/IndexController.java | 8 +- .../timedTask/SensorStateConroller.java | 74 +++++++++++++++++++ .../templates/base/sensorInfo/sensorInfo.html | 8 +- .../service/IBaseSensorInfoService.java | 2 + .../impl/BaseSensorInfoServiceImpl.java | 5 ++ 6 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/timedTask/SensorStateConroller.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseSensorInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseSensorInfoController.java index 48fef65..fceedcc 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseSensorInfoController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/base/BaseSensorInfoController.java @@ -155,6 +155,7 @@ public class BaseSensorInfoController extends BaseController { public AjaxResult addSave(BaseSensorInfo baseSensorInfo) { baseSensorInfo.setCreateBy(ShiroUtils.getLoginName()); baseSensorInfo.setCreateTime(new Date()); + baseSensorInfo.setSensorStatus(1L); return toAjax(baseSensorInfoService.insertBaseSensorInfo(baseSensorInfo)); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java index 0113660..f2b4a68 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/iot/IndexController.java @@ -267,7 +267,7 @@ public class IndexController { List data = new ArrayList() { { - /*this.add( + this.add( baseSensorInfoDtos.stream() .filter(x -> x.getSensorStatus() == 0) .collect(Collectors.toList()) @@ -281,10 +281,10 @@ public class IndexController { baseSensorInfoDtos.stream() .filter(x -> x.getSensorStatus() == 2) .collect(Collectors.toList()) - .size()); // 告警*/ - this.add(0); + .size()); // 告警 + /*this.add(0); this.add(baseSensorInfoDtos.size()); - this.add(0); + this.add(0);*/ } }; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/timedTask/SensorStateConroller.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/timedTask/SensorStateConroller.java new file mode 100644 index 0000000..5ceb500 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/timedTask/SensorStateConroller.java @@ -0,0 +1,74 @@ +package com.ruoyi.web.controller.timedTask; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.controller.BaseController; +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.ISysParamConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * 传感器状态统计 + * @author WenJY + * + * @date 2022年05月29日 11:14 + */ +@Component("sensorState") +@Controller +@RequestMapping("/sensorState") +public class SensorStateConroller extends BaseController { + + @Autowired + private IBaseSensorInfoService baseSensorInfoService; + + @Autowired private StringRedisTemplate redisTemplate; + + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + public void task() throws ParseException { + BaseSensorInfo baseSensorInfo = new BaseSensorInfo(); + baseSensorInfo.setEnableFlag(0L); + List baseSensorInfoDtos =baseSensorInfoService.getSensorInfoList(baseSensorInfo); + for (BaseSensorInfoDto baseSensorInfoDto : baseSensorInfoDtos) { + Object jrm = redisTemplate.opsForHash().get(baseSensorInfoDto.getSensorType(), baseSensorInfoDto.getSensorId()); + + if (jrm != null) { + JSONObject jsonObject = JSON.parseObject(jrm.toString()); + String param = jsonObject.get("collectTime").toString(); + if(!StringUtils.isEmpty(param)){ + Date collectTime = dateFormat.parse(param); + Date nowTime = new Date(); + long diff = nowTime.getTime() - collectTime.getTime(); + long diffMinutes = diff / (60 * 1000) % 60; + + long sensorState = 0L; + + if(diffMinutes > 20){ + sensorState = 1L; + //System.out.println("传感器:"+baseSensorInfoDto.getSensorName() + ";时间间隔:"+diffMinutes); + } + + if(baseSensorInfoDto.getSensorStatus() != sensorState){ + baseSensorInfoDto.setSensorStatus(sensorState); + baseSensorInfoDto.setUpdateBy("定时任务"); + baseSensorInfoService.updateBaseSensorInfo(baseSensorInfoDto); + } + } + } + } + } + +} diff --git a/ruoyi-admin/src/main/resources/templates/base/sensorInfo/sensorInfo.html b/ruoyi-admin/src/main/resources/templates/base/sensorInfo/sensorInfo.html index 49d6264..9ecb246 100644 --- a/ruoyi-admin/src/main/resources/templates/base/sensorInfo/sensorInfo.html +++ b/ruoyi-admin/src/main/resources/templates/base/sensorInfo/sensorInfo.html @@ -50,14 +50,14 @@ th:value="${dict.sensortypeId}"> - +
  •  搜索 @@ -193,7 +193,7 @@ formatter: function (value, row, index) { return $.table.selectDictLabel(sensorStatusDatas, value); }, - visible: false + visible: true }, { field: 'monitorunitName', 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 a9f2f3d..963d199 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 @@ -31,6 +31,8 @@ public interface IBaseSensorInfoService */ public List selectBaseSensorInfoList(BaseSensorInfo baseSensorInfo); + public List getSensorInfoList(BaseSensorInfo baseSensorInfo); + /** * 导入传感器信息 * @author WenJY 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 35d00d6..4ad04d3 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 @@ -81,6 +81,11 @@ public class BaseSensorInfoServiceImpl implements IBaseSensorInfoService } } + @Override + public List getSensorInfoList(BaseSensorInfo baseSensorInfo) { + return baseSensorInfoMapper.selectBaseSensorInfoList(baseSensorInfo); + } + /** * 导入传感器信息 * @author WenJY