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