diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/device/controller/DeviceController.java b/src/main/java/com/zsc/edu/gateway/modules/iot/device/controller/DeviceController.java index 0ff3aba..5ccf2cf 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/device/controller/DeviceController.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/device/controller/DeviceController.java @@ -140,7 +140,7 @@ public class DeviceController { } /** - * + * 查询设备告警信息 */ @GetMapping("/data/status") @PreAuthorize("hasAuthority('iot:device:query')") diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/device/service/impl/DeviceServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/iot/device/service/impl/DeviceServiceImpl.java index c6e7c27..43dc42d 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/device/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/device/service/impl/DeviceServiceImpl.java @@ -200,6 +200,12 @@ public class DeviceServiceImpl extends ServiceImpl imp vo.propertyCount = propertyRepo.selectCount(null); vo.serveCount = serveRepo.selectCount(null); vo.eventCount = eventRepo.selectCount(null); + vo.onlineCount = baseMapper.selectCount(new LambdaQueryWrapper().eq(Device::getOnline, true)); + vo.offlineCount = baseMapper.selectCount(new LambdaQueryWrapper().eq(Device::getOnline, false)); + vo.disabledCount = baseMapper.selectCount(new LambdaQueryWrapper().eq(Device::getState, Device.Status.UNACTIVATED)); + vo.directCount = productRepo.selectCount(new LambdaQueryWrapper().eq(Product::getLink, Product.LinkType.HTTP)); + vo.gatewayCount = productRepo.selectCount(new LambdaQueryWrapper().eq(Product::getLink, Product.LinkType.TCP)); + vo.gatewaySubCount = productRepo.selectCount(new LambdaQueryWrapper().eq(Product::getLink, Product.LinkType.MQTT)); return vo; } } diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/device/vo/DeviceStatusVo.java b/src/main/java/com/zsc/edu/gateway/modules/iot/device/vo/DeviceStatusVo.java index dde8f9f..c30a71e 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/device/vo/DeviceStatusVo.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/device/vo/DeviceStatusVo.java @@ -27,4 +27,34 @@ public class DeviceStatusVo { */ public Long eventCount; + /** + * 在线数量 + */ + public Long onlineCount; + + /** + * 离线数量 + */ + public Long offlineCount; + + /** + * 停用数量 + */ + public Long disabledCount; + + /** + * 直连设备 + */ + public Long directCount; + + /** + * 网关设备 + */ + public Long gatewayCount; + + /** + * 网关子设备 + */ + public Long gatewaySubCount; + } diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/record/entity/DataWarningVo.java b/src/main/java/com/zsc/edu/gateway/modules/iot/record/entity/DataWarningVo.java index a3e0173..e4c160a 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/record/entity/DataWarningVo.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/record/entity/DataWarningVo.java @@ -16,4 +16,19 @@ public class DataWarningVo { * 今日新增 */ private Long todayWarningCount; + + /** + * 一级报警数 + */ + private Long firstWarningCount; + + /** + * 二级报警数 + */ + private Long secondWarningCount; + + /** + * 三级报警数 + */ + private Long thirdWarningCount; } diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/record/repo/RecordDataRepository.java b/src/main/java/com/zsc/edu/gateway/modules/iot/record/repo/RecordDataRepository.java index 0943a53..52d57b3 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/record/repo/RecordDataRepository.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/record/repo/RecordDataRepository.java @@ -12,9 +12,12 @@ import java.util.List; * @author zhuang */ public interface RecordDataRepository extends BaseMapper { - @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(); - @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); + + @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); } diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordDataServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordDataServiceImpl.java index 53a3395..d886d24 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordDataServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordDataServiceImpl.java @@ -45,8 +45,14 @@ public class RecordDataServiceImpl extends ServiceImpl