add - 传感器状态监控任务

main
wenjy 3 years ago
parent 56fbd35ddb
commit 49d145fab1

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

@ -267,7 +267,7 @@ public class IndexController {
List<Integer> data =
new ArrayList<Integer>() {
{
/*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);*/
}
};

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

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

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

Loading…
Cancel
Save