feat(iot): 增加设备告警统计功能
- 在 DeviceStatusVo 中添加在线、离线、停用设备数量以及直连设备、网关设备和网关子设备数量字段 - 在 DataWarningVo 中添加一级、二级、三级告警数量字段 - 修改 DeviceServiceImpl 中的查询方法,增加各类设备数量的统计 - 修改 RecordDataRepository 接口,添加按位统计告警数量的方法 - 更新 RecordDataServiceImpl 中的数据统计逻辑,支持多级别告警统计
This commit is contained in:
parent
4ddf88b799
commit
153bd8cd40
@ -140,7 +140,7 @@ public class DeviceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 查询设备告警信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("/data/status")
|
@GetMapping("/data/status")
|
||||||
@PreAuthorize("hasAuthority('iot:device:query')")
|
@PreAuthorize("hasAuthority('iot:device:query')")
|
||||||
|
@ -200,6 +200,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
|||||||
vo.propertyCount = propertyRepo.selectCount(null);
|
vo.propertyCount = propertyRepo.selectCount(null);
|
||||||
vo.serveCount = serveRepo.selectCount(null);
|
vo.serveCount = serveRepo.selectCount(null);
|
||||||
vo.eventCount = eventRepo.selectCount(null);
|
vo.eventCount = eventRepo.selectCount(null);
|
||||||
|
vo.onlineCount = baseMapper.selectCount(new LambdaQueryWrapper<Device>().eq(Device::getOnline, true));
|
||||||
|
vo.offlineCount = baseMapper.selectCount(new LambdaQueryWrapper<Device>().eq(Device::getOnline, false));
|
||||||
|
vo.disabledCount = baseMapper.selectCount(new LambdaQueryWrapper<Device>().eq(Device::getState, Device.Status.UNACTIVATED));
|
||||||
|
vo.directCount = productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.HTTP));
|
||||||
|
vo.gatewayCount = productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.TCP));
|
||||||
|
vo.gatewaySubCount = productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.MQTT));
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,34 @@ public class DeviceStatusVo {
|
|||||||
*/
|
*/
|
||||||
public Long eventCount;
|
public Long eventCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线数量
|
||||||
|
*/
|
||||||
|
public Long onlineCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 离线数量
|
||||||
|
*/
|
||||||
|
public Long offlineCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停用数量
|
||||||
|
*/
|
||||||
|
public Long disabledCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直连设备
|
||||||
|
*/
|
||||||
|
public Long directCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网关设备
|
||||||
|
*/
|
||||||
|
public Long gatewayCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网关子设备
|
||||||
|
*/
|
||||||
|
public Long gatewaySubCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,19 @@ public class DataWarningVo {
|
|||||||
* 今日新增
|
* 今日新增
|
||||||
*/
|
*/
|
||||||
private Long todayWarningCount;
|
private Long todayWarningCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一级报警数
|
||||||
|
*/
|
||||||
|
private Long firstWarningCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二级报警数
|
||||||
|
*/
|
||||||
|
private Long secondWarningCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 三级报警数
|
||||||
|
*/
|
||||||
|
private Long thirdWarningCount;
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,12 @@ import java.util.List;
|
|||||||
* @author zhuang
|
* @author zhuang
|
||||||
*/
|
*/
|
||||||
public interface RecordDataRepository extends BaseMapper<RecordData> {
|
public interface RecordDataRepository extends BaseMapper<RecordData> {
|
||||||
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND (content->>'warning')::int & 1 = 1")
|
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND (content->>'warning')::int & 1 = 0 AND ((content->>'warning')::int & ~1) > 0")
|
||||||
long countWarnings();
|
long countWarnings();
|
||||||
|
|
||||||
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND (content->>'warning')::int & 1 = 1 AND record_time >= #{todayStart}")
|
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND ((content->>'warning')::int & 1 = 0) AND ((content->>'warning')::int & ~1) > 0 AND record_time >= #{todayStart}")
|
||||||
long countTodayWarnings(@Param("todayStart") LocalDateTime todayStart);
|
long countTodayWarnings(@Param("todayStart") LocalDateTime todayStart);
|
||||||
|
|
||||||
|
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND (content->>'warning')::int & #{bitPosition} = #{bitPosition}")
|
||||||
|
long countWarningsByBit(@Param("bitPosition") int bitPosition);
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,14 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
|
|||||||
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
|
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
|
||||||
long warningCount = baseMapper.countWarnings();
|
long warningCount = baseMapper.countWarnings();
|
||||||
long todayWarningCount = baseMapper.countTodayWarnings(todayStart);
|
long todayWarningCount = baseMapper.countTodayWarnings(todayStart);
|
||||||
|
long firstWarningCount = baseMapper.countWarningsByBit(1);
|
||||||
|
long secondWarningCount = baseMapper.countWarningsByBit(2);
|
||||||
|
long thirdWarningCount = baseMapper.countWarningsByBit(4);
|
||||||
dataWarningVo.setWarningCount(warningCount);
|
dataWarningVo.setWarningCount(warningCount);
|
||||||
dataWarningVo.setTodayWarningCount(todayWarningCount);
|
dataWarningVo.setTodayWarningCount(todayWarningCount);
|
||||||
|
dataWarningVo.setFirstWarningCount(firstWarningCount);
|
||||||
|
dataWarningVo.setSecondWarningCount(secondWarningCount);
|
||||||
|
dataWarningVo.setThirdWarningCount(thirdWarningCount);
|
||||||
return dataWarningVo;
|
return dataWarningVo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user