Compare commits

..

2 Commits

Author SHA1 Message Date
7908eba135 feat(device): 添加设备告警统计功能
- 在 DeviceServiceImpl 类中的 overview 方法中增加了设备告警相关的统计信息
- 新增 warningCount 字段用于统计当前所有处于告警状态的设备数量
- 新增 todayWarningCount 字段用于统计今日内处于告警状态的设备数量
2025-03-27 19:52:06 +08:00
be5c66378d refactor(iot): 重构设备和记录相关代码
- 移除 Attachment 类的冗余导入- 删除 DeviceMapper.xml 中的冗余关联映射
- 更新 DeviceStatusVo 和 DeviceVo 中的字段
- 移除 RecordDataRepository 中的告警统计相关方法- 更新 RecordDataServiceImpl 中的 recordDataStatus 方法
- 删除 RecordDataStatusVo 中的告警统计字段
2025-03-27 19:50:07 +08:00
8 changed files with 13 additions and 43 deletions

View File

@ -10,6 +10,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects;
/** /**
* 附件 * 附件

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();
} }

View File

@ -59,4 +59,13 @@ public class DeviceStatusVo {
*/ */
public Long gatewaySubCount; public Long gatewaySubCount;
/**
* 报警数
*/
public Long warningCount;
/**
* 今日新增
*/
public Long todayWarningCount;
} }

View File

@ -110,22 +110,12 @@ public class DeviceVo {
*/ */
public String iconId; public String iconId;
/**
* 设备图标附件
*/
public Attachment icon;
/** /**
* 设备预览图附件ID * 设备预览图附件ID
*/ */
public String previewId; public String previewId;
/**
* 设备预览图附件
*/
public Attachment preview;
/** /**
* 所属产品ID * 所属产品ID
*/ */

View File

@ -19,13 +19,4 @@ public class RecordDataStatusVo {
*/ */
public Long dataCount; public Long dataCount;
/**
* 告警总数
*/
private Long warningCount;
/**
* 今日新增
*/
private Long todayWarningCount;
} }

View File

@ -12,14 +12,6 @@ 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::jsonb->>'warning' IS NOT NULL AND (content::jsonb->>'warning')::int & 1 = 0 AND ((content::jsonb->>'warning')::int & ~1) > 0")
long countWarnings();
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content::jsonb->>'warning' IS NOT NULL AND ((content::jsonb->>'warning')::int & 1 = 0) AND ((content::jsonb->>'warning')::int & ~1) > 0 AND record_time >= #{todayStart}")
long countTodayWarnings(@Param("todayStart") LocalDateTime todayStart);
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content::jsonb->>'warning' IS NOT NULL AND (content::jsonb->>'warning')::int & #{bitPosition} = #{bitPosition}")
long countWarningsByBit(@Param("bitPosition") int bitPosition);
List<RecordData> selectByClientId(@Param("clientId") String clientId); List<RecordData> selectByClientId(@Param("clientId") String clientId);
} }

View File

@ -72,11 +72,7 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
*/ */
@Override @Override
public RecordDataStatusVo recordDataStatus() { public RecordDataStatusVo recordDataStatus() {
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
return RecordDataStatusVo.builder() return RecordDataStatusVo.builder()
.warningCount(baseMapper.countWarnings())
.todayWarningCount(baseMapper.countTodayWarnings(todayStart))
.recordCount(baseMapper.selectCount(new LambdaQueryWrapper<>())) .recordCount(baseMapper.selectCount(new LambdaQueryWrapper<>()))
.dataCount(baseMapper.selectCount(new LambdaQueryWrapper<RecordData>().isNotNull(RecordData::getContent))) .dataCount(baseMapper.selectCount(new LambdaQueryWrapper<RecordData>().isNotNull(RecordData::getContent)))
.build(); .build();

View File

@ -36,18 +36,6 @@
<result column="update_time" jdbcType="DATE" property="updateTime"/> <result column="update_time" jdbcType="DATE" property="updateTime"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/> <result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="enabled" jdbcType="BOOLEAN" property="enabled"/> <result column="enabled" jdbcType="BOOLEAN" property="enabled"/>
<association property="icon" javaType="com.zsc.edu.gateway.modules.attachment.entity.Attachment"
autoMapping="true"
columnPrefix="icon_">
<id column="id" property="id"/>
<result column="file_name" property="fileName"/>
</association>
<association property="preview" javaType="com.zsc.edu.gateway.modules.attachment.entity.Attachment"
autoMapping="true"
columnPrefix="preview_">
<id column="id" property="id"/>
<result column="file_name" property="fileName"/>
</association>
<collection property="params" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param" autoMapping="true" <collection property="params" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param" autoMapping="true"
columnPrefix="param_"> columnPrefix="param_">
<id column="id" property="id"/> <id column="id" property="id"/>