add - 传感器状态监控任务
parent
56fbd35ddb
commit
49d145fab1
@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue