add - 传感器状态监控任务

main
wenjy 3 years ago
parent 56fbd35ddb
commit 49d145fab1

@ -155,6 +155,7 @@ public class BaseSensorInfoController extends BaseController {
public AjaxResult addSave(BaseSensorInfo baseSensorInfo) { public AjaxResult addSave(BaseSensorInfo baseSensorInfo) {
baseSensorInfo.setCreateBy(ShiroUtils.getLoginName()); baseSensorInfo.setCreateBy(ShiroUtils.getLoginName());
baseSensorInfo.setCreateTime(new Date()); baseSensorInfo.setCreateTime(new Date());
baseSensorInfo.setSensorStatus(1L);
return toAjax(baseSensorInfoService.insertBaseSensorInfo(baseSensorInfo)); return toAjax(baseSensorInfoService.insertBaseSensorInfo(baseSensorInfo));
} }

@ -267,7 +267,7 @@ public class IndexController {
List<Integer> data = List<Integer> data =
new ArrayList<Integer>() { new ArrayList<Integer>() {
{ {
/*this.add( this.add(
baseSensorInfoDtos.stream() baseSensorInfoDtos.stream()
.filter(x -> x.getSensorStatus() == 0) .filter(x -> x.getSensorStatus() == 0)
.collect(Collectors.toList()) .collect(Collectors.toList())
@ -281,10 +281,10 @@ public class IndexController {
baseSensorInfoDtos.stream() baseSensorInfoDtos.stream()
.filter(x -> x.getSensorStatus() == 2) .filter(x -> x.getSensorStatus() == 2)
.collect(Collectors.toList()) .collect(Collectors.toList())
.size()); // 告警*/ .size()); // 告警
this.add(0); /*this.add(0);
this.add(baseSensorInfoDtos.size()); this.add(baseSensorInfoDtos.size());
this.add(0); this.add(0);*/
} }
}; };

@ -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 20220529 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<BaseSensorInfoDto> 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);
}
}
}
}
}
}

@ -50,14 +50,14 @@
th:value="${dict.sensortypeId}"></option> th:value="${dict.sensortypeId}"></option>
</select> </select>
</li> </li>
<!--<li> <li>
<label>状态:</label> <label>传感器状态:</label>
<select name="sensorStatus" th:with="type=${@dict.getType('base_sensor_status')}"> <select name="sensorStatus" th:with="type=${@dict.getType('base_sensor_status')}">
<option value="">所有</option> <option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
th:value="${dict.dictValue}"></option> th:value="${dict.dictValue}"></option>
</select> </select>
</li>--> </li>
<li> <li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
class="fa fa-search"></i>&nbsp;搜索</a> class="fa fa-search"></i>&nbsp;搜索</a>
@ -193,7 +193,7 @@
formatter: function (value, row, index) { formatter: function (value, row, index) {
return $.table.selectDictLabel(sensorStatusDatas, value); return $.table.selectDictLabel(sensorStatusDatas, value);
}, },
visible: false visible: true
}, },
{ {
field: 'monitorunitName', field: 'monitorunitName',

@ -31,6 +31,8 @@ public interface IBaseSensorInfoService
*/ */
public List<BaseSensorInfoDto> selectBaseSensorInfoList(BaseSensorInfo baseSensorInfo); public List<BaseSensorInfoDto> selectBaseSensorInfoList(BaseSensorInfo baseSensorInfo);
public List<BaseSensorInfoDto> getSensorInfoList(BaseSensorInfo baseSensorInfo);
/** /**
* *
* @author WenJY * @author WenJY

@ -81,6 +81,11 @@ public class BaseSensorInfoServiceImpl implements IBaseSensorInfoService
} }
} }
@Override
public List<BaseSensorInfoDto> getSensorInfoList(BaseSensorInfo baseSensorInfo) {
return baseSensorInfoMapper.selectBaseSensorInfoList(baseSensorInfo);
}
/** /**
* *
* @author WenJY * @author WenJY

Loading…
Cancel
Save