feat(device): 添加设备告警统计功能

- 在 DeviceServiceImpl 类中的 overview 方法中增加了设备告警相关的统计信息
- 新增 warningCount 字段用于统计当前所有处于告警状态的设备数量
- 新增 todayWarningCount 字段用于统计今日内处于告警状态的设备数量
This commit is contained in:
zhuangtianxiang 2025-03-27 19:52:06 +08:00
parent be5c66378d
commit 7908eba135

View File

@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -203,6 +204,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
.directCount(productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.HTTP))) .directCount(productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.HTTP)))
.gatewayCount(productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.TCP))) .gatewayCount(productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.TCP)))
.gatewaySubCount(productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.MQTT))) .gatewaySubCount(productRepo.selectCount(new LambdaQueryWrapper<Product>().eq(Product::getLink, Product.LinkType.MQTT)))
.warningCount(baseMapper.selectCount(new LambdaQueryWrapper<Device>().eq(Device::getDeviceState, false)))
.todayWarningCount(baseMapper.selectCount(new LambdaQueryWrapper<Device>().eq(Device::getDeviceState, false).between(Device::getCreateTime, LocalDateTime.now().withHour(0).withMinute(0).withSecond(0), LocalDateTime.now())))
.build(); .build();
} }