|
@@ -9,6 +9,9 @@ import java.util.Map;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import com.bz.smart_city.dto.DeviceDataQueryDTO;
|
|
|
+import com.bz.smart_city.service.DeviceDataService;
|
|
|
+import com.zcxk.zoniot.smartcity.common.model.DeviceData;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
@@ -16,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -67,8 +71,6 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
DeviceErrorMapper deviceErrorMapper;
|
|
|
@Autowired
|
|
|
DeviceMapper deviceMapper;
|
|
|
- @Autowired
|
|
|
- DeviceDataDimMapper deviceDataDimMapper;
|
|
|
@Resource
|
|
|
SnowflakeIdWorker idWorker;
|
|
|
@Resource
|
|
@@ -86,6 +88,9 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
@Autowired
|
|
|
KafkaTemplate<String, Object> kafkaTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ DeviceDataService deviceDataService;
|
|
|
+
|
|
|
static Map<String, AlarmType> alarmTypes = new HashMap<String, AlarmType>();
|
|
|
|
|
|
@Override
|
|
@@ -97,26 +102,28 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
Device param = new Device();
|
|
|
param.setDeviceType(deviceTypeId);
|
|
|
List<Integer> statusList = new ArrayList<Integer>();
|
|
|
- statusList.add(1); // 正常
|
|
|
- statusList.add(2); // 故障
|
|
|
+ // 正常 故障 预警
|
|
|
+ statusList.add(1);
|
|
|
+ statusList.add(2);
|
|
|
// statusList.add(3);
|
|
|
- statusList.add(4); // 预警
|
|
|
+ statusList.add(4);
|
|
|
param.setDeviceStatusList(statusList);
|
|
|
int total = deviceMapper.countDevice(param);
|
|
|
|
|
|
int pageSize = 1000;
|
|
|
|
|
|
int totalPage = total / pageSize;
|
|
|
- if (total % pageSize != 0)
|
|
|
+ if (total % pageSize != 0){
|
|
|
totalPage++;
|
|
|
+ }
|
|
|
List<DeviceError> errorList = new ArrayList<DeviceError>();
|
|
|
- for (int i = 1; i <= totalPage; i++) { // 测试修改
|
|
|
- int start = (i - 1) * pageSize; // 测试修改
|
|
|
- List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize); // 测试修改
|
|
|
+ for (int i = 1; i <= totalPage; i++) {
|
|
|
+ int start = (i - 1) * pageSize;
|
|
|
+ List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize);
|
|
|
|
|
|
for (DeviceDto device : deviceList) {
|
|
|
// 先从缓存中获取缓存数据
|
|
|
- Long deviceId = device.getId(); // 设备id
|
|
|
+ Long deviceId = device.getId();
|
|
|
// String deviceNo = device.getDeviceNo();
|
|
|
String deviceDataJSONStr = redisUtil.get(String.valueOf(deviceId));
|
|
|
Date date = DateTimeUtil.yesterdayLastDate();
|
|
@@ -125,80 +132,100 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
JSONObject dataObj = (JSONObject) JSON.parse(deviceDataJSONStr);
|
|
|
// 获取上报时间测点
|
|
|
JSONObject timeData = (JSONObject) dataObj.get("TIME");
|
|
|
- String timeStr = (String) timeData.get("measuringVaule"); // 格式 20181221100659
|
|
|
+ // 格式 20181221100659
|
|
|
+ String timeStr = (String) timeData.get("measuringData");
|
|
|
// 判断上报时间是否超时
|
|
|
Date cacheDate = DateTimeUtil.parseDate(timeStr, "yyyyMMddHHmmss");
|
|
|
// if ((date.getTime() - cacheDate.getTime()) > period * 3600 * 1000)
|
|
|
- if (cacheDate.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) { // 当设备为预警状态下,再进一步判断是否通讯中断
|
|
|
+ // 当设备为预警状态下,再进一步判断是否通讯中断
|
|
|
+ if (cacheDate.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) {
|
|
|
DeviceError alarm = createTimeOutDerviceError(device);
|
|
|
if (alarm != null) {
|
|
|
errorList.add(alarm);
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(2); // 设置设备为故障状态
|
|
|
+ // 设置设备为故障状态
|
|
|
+ obj.setDeviceStatus(2);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
result++;
|
|
|
}
|
|
|
- } else if (cacheDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) { // 超过24小时没有上报数据则将设备状态设置为预警 //(date.getTime() - cacheDate.getTime()) > 24 * 3600 * 1000
|
|
|
+ }
|
|
|
+ // 超过24小时没有上报数据则将设备状态设置为预警 //(date.getTime() - cacheDate.getTime()) > 24 * 3600 * 1000
|
|
|
+ else if (cacheDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) {
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(4); // 设置设备为预警状态
|
|
|
+ // 设置设备为预警状态
|
|
|
+ obj.setDeviceStatus(4);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
// 预警状态下的连续天数
|
|
|
- if (device.getDeviceStatus() == 2) { // 故障天数清零
|
|
|
+ if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障天数 清零
|
|
|
waterMeterErrorDaysMapper.reset(deviceId);
|
|
|
- } else if (device.getDeviceStatus() == 2) { // 故障连续天数+1
|
|
|
+ } else if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障连续天数+1
|
|
|
waterMeterErrorDaysMapper.addDays(deviceId);
|
|
|
}
|
|
|
}
|
|
|
} else { // 缓存中没有数据则从数据库中进行查询
|
|
|
- DeviceDataDim data = getLastDeviceData(deviceId);
|
|
|
+ DeviceData data = getLastDeviceData(deviceId);
|
|
|
if (data != null) {
|
|
|
- Date sendTime = data.getSendTime();
|
|
|
- if (sendTime.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) { //(date.getTime() - sendTime.getTime()) > period * 3600 * 1000
|
|
|
+ Date sendTime = data.getReceiveTime();
|
|
|
+ //(date.getTime() - sendTime.getTime()) > period * 3600 * 1000
|
|
|
+ if (sendTime.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) {
|
|
|
DeviceError alarm = createTimeOutDerviceError(device);
|
|
|
if (alarm != null) {
|
|
|
errorList.add(alarm);
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(2); // 设置设备为故障状态
|
|
|
+ // 设置设备为故障状态
|
|
|
+ obj.setDeviceStatus(2);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
result++;
|
|
|
}
|
|
|
- } else if (sendTime.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) { // 超过24小时没有上报数据则将设备状态设置为预警 (date.getTime() - sendTime.getTime()) > 24 * 3600 * 1000
|
|
|
+ }
|
|
|
+ // 超过24小时没有上报数据则将设备状态设置为预警 (date.getTime() - sendTime.getTime()) > 24 * 3600 * 1000
|
|
|
+ else if (sendTime.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) {
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(4); // 设置设备为预警状态
|
|
|
+ // 设置设备为预警状态
|
|
|
+ obj.setDeviceStatus(4);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
|
|
|
// 预警状态下的连续天数
|
|
|
- if (device.getDeviceStatus() == 2) { // 故障天数清零
|
|
|
+ if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障天数清零
|
|
|
waterMeterErrorDaysMapper.reset(deviceId);
|
|
|
- } else if (device.getDeviceStatus() == 2) { // 故障连续天数+1
|
|
|
+ } else if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障连续天数+1
|
|
|
waterMeterErrorDaysMapper.addDays(deviceId);
|
|
|
}
|
|
|
}
|
|
|
- } else { // 如果没上报数据则根据设备的创建时间进行对比
|
|
|
- if (deviceCreateDate.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) { // (date.getTime() - deviceCreateDate.getTime()) > period * 3600 * 1000
|
|
|
+ } else {
|
|
|
+ // 如果没上报数据则根据设备的创建时间进行对比
|
|
|
+ if (deviceCreateDate.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) {
|
|
|
DeviceError alarm = createTimeOutDerviceError(device);
|
|
|
if (alarm != null) {
|
|
|
errorList.add(alarm);
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(2); // 设置设备为故障状态
|
|
|
+ // 设置设备为故障状态
|
|
|
+ obj.setDeviceStatus(2);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
result++;
|
|
|
}
|
|
|
} else if (deviceCreateDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) { // 超过24小时没有上报数据则将设备状态设置为预警 (date.getTime() - deviceCreateDate.getTime()) > 24 * 3600 * 1000
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(4); // 设置设备为预警状态
|
|
|
+ // 设置设备为预警状态
|
|
|
+ obj.setDeviceStatus(4);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
|
|
|
// 预警状态下的连续天数
|
|
|
- if (device.getDeviceStatus() == 2) { // 故障天数清零
|
|
|
+ if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障天数清零
|
|
|
waterMeterErrorDaysMapper.reset(deviceId);
|
|
|
- } else if (device.getDeviceStatus() == 2) { // 故障连续天数+1
|
|
|
+ } else if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障连续天数+1
|
|
|
waterMeterErrorDaysMapper.addDays(deviceId);
|
|
|
}
|
|
|
}
|
|
@@ -215,7 +242,7 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- Thread.sleep(3000l);
|
|
|
+ Thread.sleep(3000L);
|
|
|
} catch (Exception e) {
|
|
|
log.error("runtime error", e);
|
|
|
}
|
|
@@ -229,7 +256,7 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
errorList.clear();
|
|
|
}
|
|
|
log.info("DeviceDataTimeOutService createTimeOutAlarm cost ="
|
|
|
- + (new Date().getTime() - startTime.getTime()) / 1000 + " seconds");
|
|
|
+ + (System.currentTimeMillis()- startTime.getTime()) / 1000 + " seconds");
|
|
|
log.info("end DeviceDataTimeOutService createTimeOutAlarm, result = " + result);
|
|
|
return result;
|
|
|
}
|
|
@@ -237,39 +264,50 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
/**
|
|
|
* 处理告警数据
|
|
|
*
|
|
|
- * @param device
|
|
|
- * @param errors
|
|
|
- * @param lastReceiveTime
|
|
|
+ * @param
|
|
|
+ * @param
|
|
|
+ * @param
|
|
|
*/
|
|
|
protected DeviceError processAlarm(DeviceError error) {
|
|
|
DeviceError rtnError = null;
|
|
|
// 1,查询最新告警记录
|
|
|
Long deviceId = error.getDeviceId();
|
|
|
List<DeviceError> lastErrorList = getDeviceLastErrorList(deviceId);
|
|
|
- if (lastErrorList == null || lastErrorList.size() == 0) { // 无最新告警记录,将告警记录直接入库
|
|
|
+ if (lastErrorList == null || lastErrorList.size() == 0) {
|
|
|
+ // 无最新告警记录,将告警记录直接入库
|
|
|
rtnError = saveNewDeviceError(error);
|
|
|
} else {
|
|
|
// 2,有最新告警记录,对比最新告警的告警类型是否同新生成告警记录的告警类型
|
|
|
boolean isSame = false;
|
|
|
DeviceError originalError = null;
|
|
|
for (DeviceError lde : lastErrorList) {
|
|
|
- if (2 == lde.getHandleStatus() && lde.getAlarmTypeId() == error.getAlarmTypeId()) { // 处理状态 1.已处理;2.未处理
|
|
|
+ // 处理状态 1.已处理;2.未处理
|
|
|
+ if (2 == lde.getHandleStatus() && lde.getAlarmTypeId().equals( error.getAlarmTypeId())) {
|
|
|
isSame = true;
|
|
|
originalError = lde;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if (!isSame) { // 告警类型与上次告警类型不同,则直接新增记录
|
|
|
+ if (!isSame) {
|
|
|
+ // 告警类型与上次告警类型不同,则直接新增记录
|
|
|
rtnError = saveNewDeviceError(error);
|
|
|
- } else { // 告警类型与上次告警类型相同
|
|
|
- // 3,查询上次告警时间至本次告警时间是否有上传数据
|
|
|
+ } else {
|
|
|
+ // 告警类型与上次告警类型相同
|
|
|
+ // 3,查询上次告警时间至本次告警时间是否有上传数据
|
|
|
Date lastAlarmTime = Jdk8DateUtils.getLocalDateTimeToDate(lastErrorList.get(0).getLastAlarmTime());
|
|
|
Date currentAlarmTime = Jdk8DateUtils.getLocalDateTimeToDate(error.getAlarmTime());
|
|
|
- List<DeviceDataDim> receiveDatas = deviceDataDimMapper.getDeviceDataBetweenDate(lastAlarmTime,
|
|
|
- currentAlarmTime, deviceId);
|
|
|
- if (receiveDatas != null && receiveDatas.size() != 0) { // 有新上报数据,记录为新告警
|
|
|
+ DeviceDataQueryDTO param = new DeviceDataQueryDTO();
|
|
|
+ param.setDeviceId(deviceId);
|
|
|
+ param.setEndDate(currentAlarmTime);
|
|
|
+ param.setStartDate(lastAlarmTime);
|
|
|
+ List<DeviceData> receiveDatas = deviceDataService.queryDeviceDataList(param);
|
|
|
+// List<DeviceDataDim> receiveDatas = deviceDataDimMapper.getDeviceDataBetweenDate(lastAlarmTime,
|
|
|
+// currentAlarmTime, deviceId);
|
|
|
+ if (receiveDatas != null && receiveDatas.size() != 0) {
|
|
|
+ // 有新上报数据,记录为新告警
|
|
|
rtnError = saveNewDeviceError(error);
|
|
|
- } else { // 无新上报数据,更新最后一次报警的次数与最后上报时间
|
|
|
+ } else {
|
|
|
+ // 无新上报数据,更新最后一次报警的次数与最后上报时间
|
|
|
rtnError = updateExistDeviceError(error, originalError);
|
|
|
}
|
|
|
}
|
|
@@ -304,7 +342,7 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
/**
|
|
|
* 查看最后一次上报的告警信息
|
|
|
*
|
|
|
- * @param device
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
protected List<DeviceError> getDeviceLastErrorList(Long deviceId) {
|
|
@@ -378,8 +416,9 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
target = alarmType;
|
|
|
}
|
|
|
}
|
|
|
- if (target != null)
|
|
|
+ if(target != null){
|
|
|
alarmTypes.put(key, target);
|
|
|
+ }
|
|
|
}
|
|
|
return target;
|
|
|
}
|
|
@@ -393,12 +432,18 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
return alarmTypeMapper.queryAlaramType(param);
|
|
|
}
|
|
|
|
|
|
- protected DeviceDataDim getLastDeviceData(Long deviceId) {
|
|
|
- DeviceDataDim result = null;
|
|
|
- DeviceDataDim p = new DeviceDataDim();
|
|
|
- p.setDeviceId(deviceId);
|
|
|
+ protected DeviceData getLastDeviceData(Long deviceId) {
|
|
|
+ DeviceData result = null;
|
|
|
+// DeviceDataDim p = new DeviceDataDim();
|
|
|
+// p.setDeviceId(deviceId);
|
|
|
// p.setDeviceNo(deviceNo);
|
|
|
- List<DeviceDataDim> datas = deviceDataDimMapper.queryDeviceDataDim(p, 1);
|
|
|
+ DeviceDataQueryDTO param = new DeviceDataQueryDTO();
|
|
|
+ param.setSort(new Sort(Sort.Direction.DESC, "receiveTime"));
|
|
|
+ param.setDeviceId(deviceId);
|
|
|
+ param.setPageIndex(0);
|
|
|
+ param.setPageSize(1);
|
|
|
+ List<DeviceData> datas = deviceDataService.queryDeviceDataList(param);
|
|
|
+// List<DeviceDataDim> datas = deviceDataDimMapper.queryDeviceDataDim(p, 1);
|
|
|
if (datas.size() > 0) {
|
|
|
result = datas.get(0);
|
|
|
}
|
|
@@ -442,51 +487,64 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
JSONObject dataObj = (JSONObject) JSON.parse(deviceDataJSONStr);
|
|
|
// 获取上报时间测点
|
|
|
JSONObject timeData = (JSONObject) dataObj.get("TIME");
|
|
|
- String timeStr = (String) timeData.get("measuringVaule"); // 格式 20181221100659
|
|
|
+ // 格式 20181221100659
|
|
|
+ String timeStr = (String) timeData.get("measuringVaule");
|
|
|
// 判断上报时间是否超时
|
|
|
Date cacheDate = DateTimeUtil.parseDate(timeStr, "yyyyMMddHHmmss");
|
|
|
- if (cacheDate.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) { // 当设备为预警状态下,再进一步判断是否通讯中断
|
|
|
+ // 当设备为预警状态下,再进一步判断是否通讯中断
|
|
|
+ if (cacheDate.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) {
|
|
|
alarm = createTimeOutDerviceError(device);
|
|
|
if (alarm != null) {
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(2); // 设置设备为故障状态
|
|
|
+ // 设置设备为故障状态
|
|
|
+ obj.setDeviceStatus(2);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
}
|
|
|
- } else if (cacheDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) { // 超过24小时没有上报数据则将设备状态设置为预警
|
|
|
+ } else if (cacheDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) {
|
|
|
+ // 超过24小时没有上报数据则将设备状态设置为预警
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(4); // 设置设备为预警状态
|
|
|
+ // 设置设备为预警状态
|
|
|
+ obj.setDeviceStatus(4);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
// 预警状态下的连续天数
|
|
|
- if (device.getDeviceStatus() == 2) { // 故障天数清零
|
|
|
+ if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障天数清零
|
|
|
waterMeterErrorDaysMapper.reset(deviceId);
|
|
|
- } else if (device.getDeviceStatus() == 2) { // 故障连续天数+1
|
|
|
+ } else if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障连续天数+1
|
|
|
waterMeterErrorDaysMapper.addDays(deviceId);
|
|
|
}
|
|
|
}
|
|
|
- } else { // 缓存中没有数据则从数据库中进行查询
|
|
|
- DeviceDataDim data = getLastDeviceData(deviceId);
|
|
|
+ } else {
|
|
|
+ // 缓存中没有数据则从数据库中进行查询
|
|
|
+ DeviceData data = getLastDeviceData(deviceId);
|
|
|
if (data != null) {
|
|
|
- Date sendTime = data.getSendTime();
|
|
|
+ Date sendTime = data.getReceiveTime();
|
|
|
if (sendTime.before(DateTimeUtil.before(date, new Double(period * 3600 * 1000).longValue()))) {
|
|
|
alarm = createTimeOutDerviceError(device);
|
|
|
if (alarm != null) {
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(2); // 设置设备为故障状态
|
|
|
+ obj.setDeviceStatus(2);
|
|
|
+ // 设置设备为故障状态
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
}
|
|
|
- } else if (sendTime.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) { // 超过24小时没有上报数据则将设备状态设置为预警
|
|
|
+ } else if (sendTime.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) {
|
|
|
+ // 超过24小时没有上报数据则将设备状态设置为预警
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(4); // 设置设备为预警状态
|
|
|
+ obj.setDeviceStatus(4);
|
|
|
+ // 设置设备为预警状态
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
|
|
|
// 预警状态下的连续天数
|
|
|
- if (device.getDeviceStatus() == 2) { // 故障天数清零
|
|
|
+ if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障天数清零
|
|
|
waterMeterErrorDaysMapper.reset(deviceId);
|
|
|
- } else if (device.getDeviceStatus() == 2) { // 故障连续天数+1
|
|
|
+ } else if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障连续天数+1
|
|
|
waterMeterErrorDaysMapper.addDays(deviceId);
|
|
|
}
|
|
|
}
|
|
@@ -496,19 +554,24 @@ public class DeviceDataTimeOutServiceImpl implements DeviceDataTimeOutService, I
|
|
|
if (alarm != null) {
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(2); // 设置设备为故障状态
|
|
|
+ // 设置设备为故障状态
|
|
|
+ obj.setDeviceStatus(2);
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
}
|
|
|
- } else if (deviceCreateDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) { // 超过24小时没有上报数据则将设备状态设置为预警
|
|
|
+ } else if (deviceCreateDate.before(DateTimeUtil.before(date, new Double(24 * 3600 * 1000).longValue()))) {
|
|
|
+ // 超过24小时没有上报数据则将设备状态设置为预警
|
|
|
Device obj = new Device();
|
|
|
obj.setId(device.getId());
|
|
|
- obj.setDeviceStatus(4); // 设置设备为预警状态
|
|
|
+ obj.setDeviceStatus(4);
|
|
|
+ // 设置设备为预警状态
|
|
|
deviceMapper.updateByPrimaryKeySelective(obj);
|
|
|
|
|
|
// 预警状态下的连续天数
|
|
|
- if (device.getDeviceStatus() == 2) { // 故障天数清零
|
|
|
+ if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障天数清零
|
|
|
waterMeterErrorDaysMapper.reset(deviceId);
|
|
|
- } else if (device.getDeviceStatus() == 2) { // 故障连续天数+1
|
|
|
+ } else if (device.getDeviceStatus() == 2) {
|
|
|
+ // 故障连续天数+1
|
|
|
waterMeterErrorDaysMapper.addDays(deviceId);
|
|
|
}
|
|
|
}
|