|
@@ -36,42 +36,42 @@ public class IotWarnBussinessService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
- public Long selectIotWarnCountByDevAndConfig(String devId, String configId) {
|
|
|
|
|
- log.info("查询设备ID: {}, 配置ID: {} 的重复次数", devId, configId);
|
|
|
|
|
- Long count = redisCacheManager.getCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
|
|
|
|
|
|
|
+ public Long selectIotWarnCountByDevAndConfig(String devBid, String configId) {
|
|
|
|
|
+ log.info("查询设备ID: {}, 配置ID: {} 的重复次数", devBid, configId);
|
|
|
|
|
+ Long count = redisCacheManager.getCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devBid);
|
|
|
if (count != null) {
|
|
if (count != null) {
|
|
|
log.info("从缓存中获取到重复次数: {}", count);
|
|
log.info("从缓存中获取到重复次数: {}", count);
|
|
|
return count;
|
|
return count;
|
|
|
}
|
|
}
|
|
|
- IotWarncount iotWarncount = iotWarnBussinessMapper.selectIotWarnCountByDevAndConfig(devId, configId);
|
|
|
|
|
|
|
+ IotWarncount iotWarncount = iotWarnBussinessMapper.selectIotWarnCountByDevAndConfig(devBid, configId);
|
|
|
if (iotWarncount == null) {
|
|
if (iotWarncount == null) {
|
|
|
- log.warn("数据库中未找到设备ID: {}, 配置ID: {} 的重复次数数据", devId, configId);
|
|
|
|
|
|
|
+ log.warn("数据库中未找到设备ID: {}, 配置ID: {} 的重复次数数据", devBid, configId);
|
|
|
return null;
|
|
return null;
|
|
|
} else {
|
|
} else {
|
|
|
log.info("从数据库中获取到重复次数: {}, 并将其加入缓存", iotWarncount.getWctCount());
|
|
log.info("从数据库中获取到重复次数: {}, 并将其加入缓存", iotWarncount.getWctCount());
|
|
|
- redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, iotWarncount.getWctCount());
|
|
|
|
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devBid, iotWarncount.getWctCount());
|
|
|
return iotWarncount.getWctCount();
|
|
return iotWarncount.getWctCount();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int incrementReCount(Long reCount, String devId, String configId, String tid) {
|
|
|
|
|
- log.info("增加设备ID: {}, 配置ID: {} 的重复次数", devId, configId);
|
|
|
|
|
|
|
+ public int incrementReCount(Long reCount, String devBid, String configId, String tid) {
|
|
|
|
|
+ log.info("增加设备ID: {}, 配置ID: {} 的重复次数", devBid, configId);
|
|
|
if (reCount == null) {
|
|
if (reCount == null) {
|
|
|
log.info("初始化重复次数为1");
|
|
log.info("初始化重复次数为1");
|
|
|
IotWarncount iotWarncount = new IotWarncount();
|
|
IotWarncount iotWarncount = new IotWarncount();
|
|
|
iotWarncount.setWctBid(IdUtils.fastUUID());
|
|
iotWarncount.setWctBid(IdUtils.fastUUID());
|
|
|
- iotWarncount.setDevBid(devId);
|
|
|
|
|
|
|
+ iotWarncount.setDevBid(devBid);
|
|
|
iotWarncount.setWcBid(configId);
|
|
iotWarncount.setWcBid(configId);
|
|
|
iotWarncount.setLastUpdateTime(DateUtils.dateTimeNow());
|
|
iotWarncount.setLastUpdateTime(DateUtils.dateTimeNow());
|
|
|
iotWarncount.setWctCount(1L);
|
|
iotWarncount.setWctCount(1L);
|
|
|
iotWarncount.setTid(tid);
|
|
iotWarncount.setTid(tid);
|
|
|
int result = iotWarnBussinessMapper.insertIncrementReCount(iotWarncount);
|
|
int result = iotWarnBussinessMapper.insertIncrementReCount(iotWarncount);
|
|
|
- redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, iotWarncount.getWctCount());
|
|
|
|
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devBid, iotWarncount.getWctCount());
|
|
|
log.info("初始化重复次数成功, 结果: {}", result);
|
|
log.info("初始化重复次数成功, 结果: {}", result);
|
|
|
return result;
|
|
return result;
|
|
|
} else {
|
|
} else {
|
|
|
- int result = iotWarnBussinessMapper.updateIncrementReCount(devId, configId);
|
|
|
|
|
- redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId, reCount + 1);
|
|
|
|
|
|
|
+ int result = iotWarnBussinessMapper.updateIncrementReCount(devBid, configId);
|
|
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devBid, reCount + 1);
|
|
|
log.info("更新重复次数成功, 新的重复次数: {}", reCount + 1);
|
|
log.info("更新重复次数成功, 新的重复次数: {}", reCount + 1);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -97,10 +97,10 @@ public class IotWarnBussinessService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int resetReCountByDevIdAndConfigId(String devId, String configId) {
|
|
|
|
|
- log.info("重置设备ID: {}, 配置ID: {} 的重复次数", devId, configId);
|
|
|
|
|
- redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devId);
|
|
|
|
|
- int result = iotWarnBussinessMapper.resetReCountByDevIdAndConfigId(devId, configId);
|
|
|
|
|
|
|
+ public int resetReCountByDevBidAndConfigId(String devBid, String configId) {
|
|
|
|
|
+ log.info("重置设备ID: {}, 配置ID: {} 的重复次数", devBid, configId);
|
|
|
|
|
+ redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, configId + ":" + devBid);
|
|
|
|
|
+ int result = iotWarnBussinessMapper.resetReCountByDevBidAndConfigId(devBid, configId);
|
|
|
log.info("重置结果: {}", result);
|
|
log.info("重置结果: {}", result);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -167,11 +167,11 @@ public class IotWarnBussinessService {
|
|
|
/**
|
|
/**
|
|
|
* 设备若正常上报数据后,则离线告警自动处理
|
|
* 设备若正常上报数据后,则离线告警自动处理
|
|
|
*
|
|
*
|
|
|
- * @param devId
|
|
|
|
|
|
|
+ * @param devBid
|
|
|
*/
|
|
*/
|
|
|
- public void autoDealWarnOfflineLog(String devId) {
|
|
|
|
|
|
|
+ public void autoDealWarnOfflineLog(String devBid) {
|
|
|
IotWarnlog iotWarnlog = new IotWarnlog();
|
|
IotWarnlog iotWarnlog = new IotWarnlog();
|
|
|
- iotWarnlog.setDevBid(devId);
|
|
|
|
|
|
|
+ iotWarnlog.setDevBid(devBid);
|
|
|
iotWarnlog.setWlDealtime(DateUtils.dateTimeNow());
|
|
iotWarnlog.setWlDealtime(DateUtils.dateTimeNow());
|
|
|
iotWarnlog.setWlDealresult("该设备已于" + DateUtils.dateTimeNow() + "上报数据,离线告警自动恢复。");
|
|
iotWarnlog.setWlDealresult("该设备已于" + DateUtils.dateTimeNow() + "上报数据,离线告警自动恢复。");
|
|
|
iotWarnlog.setStatus("1");
|
|
iotWarnlog.setStatus("1");
|
|
@@ -194,16 +194,16 @@ public class IotWarnBussinessService {
|
|
|
/**
|
|
/**
|
|
|
* 统计设备的虫子种类数量
|
|
* 统计设备的虫子种类数量
|
|
|
*
|
|
*
|
|
|
- * @param devId 设备业务标识
|
|
|
|
|
|
|
+ * @param devBid 设备业务标识
|
|
|
* @param startTime 开始时间
|
|
* @param startTime 开始时间
|
|
|
* @param endTime 结束时间
|
|
* @param endTime 结束时间
|
|
|
* @return 虫子种类数量
|
|
* @return 虫子种类数量
|
|
|
*/
|
|
*/
|
|
|
- public int statPestTypeCountByDevId(String devId, String startTime, String endTime) {
|
|
|
|
|
|
|
+ public int statPestTypeCountByDevBid(String devBid, String startTime, String endTime) {
|
|
|
Query query = new Query();
|
|
Query query = new Query();
|
|
|
|
|
|
|
|
// 添加条件:设备业务标识
|
|
// 添加条件:设备业务标识
|
|
|
- query.addCriteria(Criteria.where("devBid").is(devId));
|
|
|
|
|
|
|
+ query.addCriteria(Criteria.where("devBid").is(devBid));
|
|
|
|
|
|
|
|
// 添加条件:创建时间在指定范围内
|
|
// 添加条件:创建时间在指定范围内
|
|
|
query.addCriteria(Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime));
|
|
query.addCriteria(Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime));
|
|
@@ -221,23 +221,47 @@ public class IotWarnBussinessService {
|
|
|
/**
|
|
/**
|
|
|
* 统计设备的虫子总数量
|
|
* 统计设备的虫子总数量
|
|
|
*
|
|
*
|
|
|
- * @param devId 设备业务标识
|
|
|
|
|
|
|
+ * @param devBid 设备业务标识
|
|
|
* @param startTime 开始时间
|
|
* @param startTime 开始时间
|
|
|
* @param endTime 结束时间
|
|
* @param endTime 结束时间
|
|
|
* @return 虫子总数量
|
|
* @return 虫子总数量
|
|
|
*/
|
|
*/
|
|
|
- public int statPestCountByDevId(String devId, String startTime, String endTime) {
|
|
|
|
|
|
|
+ public int statPestCountByDevBid(String devBid, String startTime, String endTime) {
|
|
|
Query query = new Query();
|
|
Query query = new Query();
|
|
|
|
|
|
|
|
// 添加条件:设备业务标识
|
|
// 添加条件:设备业务标识
|
|
|
- query.addCriteria(Criteria.where("devBid").is(devId));
|
|
|
|
|
|
|
+ query.addCriteria(Criteria.where("devBid").is(devBid));
|
|
|
|
|
|
|
|
// 添加条件:创建时间在指定范围内
|
|
// 添加条件:创建时间在指定范围内
|
|
|
query.addCriteria(Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime));
|
|
query.addCriteria(Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime));
|
|
|
|
|
|
|
|
// 使用聚合查询统计害虫数量
|
|
// 使用聚合查询统计害虫数量
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
- Aggregation.match(Criteria.where("devBid").is(devId)
|
|
|
|
|
|
|
+ Aggregation.match(Criteria.where("devBid").is(devBid)
|
|
|
|
|
+ .and("pestrecogCreatedDate").gte(startTime).lte(endTime)),
|
|
|
|
|
+ Aggregation.group().sum("pestrecogNum").as("totalPestCount")
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 执行聚合查询
|
|
|
|
|
+ AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "IotPestrecog", Map.class);
|
|
|
|
|
+ Map<String, Object> result = results.getUniqueMappedResult();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取统计结果,默认为0
|
|
|
|
|
+ return result != null ? ((Number) result.get("totalPestCount")).intValue() : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int statPestDetailByDevBid(String devBid, String startTime, String endTime) {
|
|
|
|
|
+ Query query = new Query();
|
|
|
|
|
+
|
|
|
|
|
+ // 添加条件:设备业务标识
|
|
|
|
|
+ query.addCriteria(Criteria.where("devBid").is(devBid));
|
|
|
|
|
+
|
|
|
|
|
+ // 添加条件:创建时间在指定范围内
|
|
|
|
|
+ query.addCriteria(Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime));
|
|
|
|
|
+
|
|
|
|
|
+ // 使用聚合查询统计害虫数量
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ Aggregation.match(Criteria.where("devBid").is(devBid)
|
|
|
.and("pestrecogCreatedDate").gte(startTime).lte(endTime)),
|
|
.and("pestrecogCreatedDate").gte(startTime).lte(endTime)),
|
|
|
Aggregation.group().sum("pestrecogNum").as("totalPestCount")
|
|
Aggregation.group().sum("pestrecogNum").as("totalPestCount")
|
|
|
);
|
|
);
|