|
@@ -36,19 +36,20 @@ public class IotWarnBussinessService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public Long selectIotWarnCountByDevAndConfig(String devId, String configId) {
|
|
public Long selectIotWarnCountByDevAndConfig(String devId, String configId) {
|
|
|
-
|
|
|
|
|
Long count = redisCacheManager.getCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
|
|
Long count = redisCacheManager.getCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
|
|
|
-// if (false) {
|
|
|
|
|
-// redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, 0);
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (count != null) {
|
|
|
|
|
+ return count;
|
|
|
|
|
+ }
|
|
|
|
|
+ // count==null说明什么?1. 缓存手动清空了,但是数据库还有,2. 不存在他的数据(数据库+缓存都没有)
|
|
|
IotWarncount iotWarncount = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
|
|
IotWarncount iotWarncount = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
|
|
|
- // 如果为Null,说明还没触发过
|
|
|
|
|
|
|
+ // 缓存没有,数据库也没有
|
|
|
if (iotWarncount == null) {
|
|
if (iotWarncount == null) {
|
|
|
return null;
|
|
return null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 缓存有,数据库有放缓存
|
|
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, iotWarncount.getWctCount());
|
|
|
|
|
+ return iotWarncount.getWctCount();
|
|
|
}
|
|
}
|
|
|
- return iotWarncount.getWctCount();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -69,9 +70,13 @@ public class IotWarnBussinessService {
|
|
|
iotWarncount.setLastUpdateTime(DateUtils.dateTimeNow());
|
|
iotWarncount.setLastUpdateTime(DateUtils.dateTimeNow());
|
|
|
iotWarncount.setWctCount(1L);
|
|
iotWarncount.setWctCount(1L);
|
|
|
iotWarncount.setTid(tid);
|
|
iotWarncount.setTid(tid);
|
|
|
- return iotWarncountMapper.insertIncrementReCount(iotWarncount);
|
|
|
|
|
|
|
+ int re = iotWarncountMapper.insertIncrementReCount(iotWarncount);
|
|
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, iotWarncount.getWctCount());
|
|
|
|
|
+ return re;
|
|
|
} else {
|
|
} else {
|
|
|
- return iotWarncountMapper.updateIncrementReCount(devId, configId);
|
|
|
|
|
|
|
+ int re = iotWarncountMapper.updateIncrementReCount(devId, configId);
|
|
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, reCount + 1);
|
|
|
|
|
+ return re;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -85,7 +90,11 @@ public class IotWarnBussinessService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public int resetReCount() {
|
|
public int resetReCount() {
|
|
|
- return iotWarncountMapper.resetReCount();
|
|
|
|
|
|
|
+ // 清空缓存
|
|
|
|
|
+ redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, "*");
|
|
|
|
|
+ // 清除表
|
|
|
|
|
+ int result = iotWarncountMapper.resetReCount();
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -94,6 +103,8 @@ public class IotWarnBussinessService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public int resetReCountByDevIdAndConfigId(String devId, String configId) {
|
|
public int resetReCountByDevIdAndConfigId(String devId, String configId) {
|
|
|
|
|
+ // 清空缓存
|
|
|
|
|
+ redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
|
|
|
return iotWarncountMapper.resetReCountByDevIdAndConfigId(devId, configId);
|
|
return iotWarncountMapper.resetReCountByDevIdAndConfigId(devId, configId);
|
|
|
}
|
|
}
|
|
|
|
|
|