Commit 6e1ec8b3eb7ee3261a58126c86ff2c516a1b78cd

Authored by YunaiV
1 parent 2a65e3bd

【代码评审】IoT:首页统计

Showing 17 changed files with 90 additions and 75 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java
@@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.RestController; @@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.RestController;
19 19
20 import java.time.LocalDateTime; 20 import java.time.LocalDateTime;
21 21
22 -  
23 @Tag(name = "管理后台 - IoT 数据统计") 22 @Tag(name = "管理后台 - IoT 数据统计")
24 @RestController 23 @RestController
25 @RequestMapping("/iot/statistics") 24 @RequestMapping("/iot/statistics")
@@ -27,48 +26,47 @@ import java.time.LocalDateTime; @@ -27,48 +26,47 @@ import java.time.LocalDateTime;
27 public class IotStatisticsController { 26 public class IotStatisticsController {
28 27
29 @Resource 28 @Resource
30 - private IotDeviceService iotDeviceService;  
31 - 29 + private IotDeviceService deviceService;
32 @Resource 30 @Resource
33 - private IotProductCategoryService iotProductCategoryService;  
34 - 31 + private IotProductCategoryService productCategoryService;
35 @Resource 32 @Resource
36 - private IotProductService iotProductService;  
37 - 33 + private IotProductService productService;
38 @Resource 34 @Resource
39 - private IotDeviceLogService iotDeviceLogService;  
40 - 35 + private IotDeviceLogService deviceLogService;
41 36
  37 + // TODO @super:description 非必要,可以不写哈
42 @GetMapping("/main") 38 @GetMapping("/main")
43 - @Operation(summary = "获取IOT首页的数据统计", description = "用于IOT首页的数据统计") 39 + @Operation(summary = "获取首页的数据统计", description = "用于IOT首页的数据统计")
44 public CommonResult<IotStatisticsRespVO> getIotMainStats(@Valid IotStatisticsReqVO reqVO){ 40 public CommonResult<IotStatisticsRespVO> getIotMainStats(@Valid IotStatisticsReqVO reqVO){
  41 + // TODO @super:新增 get-summary 接口,返回:总数、今日新增、数量、状态
45 IotStatisticsRespVO iotStatisticsRespVO = new IotStatisticsRespVO(); 42 IotStatisticsRespVO iotStatisticsRespVO = new IotStatisticsRespVO();
46 // 获取总数 43 // 获取总数
47 - iotStatisticsRespVO.setCategoryTotal(iotProductCategoryService.getProductCategoryCount(null));  
48 - iotStatisticsRespVO.setProductTotal(iotProductService.getProductCount(null));  
49 - iotStatisticsRespVO.setDeviceTotal(iotDeviceService.getDeviceCount(null));  
50 - iotStatisticsRespVO.setReportTotal(iotDeviceLogService.getDeviceLogCount(null)); 44 + iotStatisticsRespVO.setCategoryTotal(productCategoryService.getProductCategoryCount(null));
  45 + iotStatisticsRespVO.setProductTotal(productService.getProductCount(null));
  46 + iotStatisticsRespVO.setDeviceTotal(deviceService.getDeviceCount(null));
  47 + iotStatisticsRespVO.setReportTotal(deviceLogService.getDeviceLogCount(null));
51 48
52 // 获取今日新增数量 49 // 获取今日新增数量
53 LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0); 50 LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
54 - iotStatisticsRespVO.setCategoryTodayTotal(iotProductCategoryService.getProductCategoryCount(todayStart));  
55 - iotStatisticsRespVO.setProductTodayTotal(iotProductService.getProductCount(todayStart));  
56 - iotStatisticsRespVO.setDeviceTodayTotal(iotDeviceService.getDeviceCount(todayStart));  
57 - iotStatisticsRespVO.setReportTodayTotal(iotDeviceLogService.getDeviceLogCount(todayStart)); 51 + iotStatisticsRespVO.setCategoryTodayTotal(productCategoryService.getProductCategoryCount(todayStart));
  52 + iotStatisticsRespVO.setProductTodayTotal(productService.getProductCount(todayStart));
  53 + iotStatisticsRespVO.setDeviceTodayTotal(deviceService.getDeviceCount(todayStart));
  54 + iotStatisticsRespVO.setReportTodayTotal(deviceLogService.getDeviceLogCount(todayStart));
58 55
59 // 获取各个品类下设备数量统计 56 // 获取各个品类下设备数量统计
60 iotStatisticsRespVO.setDeviceStatsOfCategory( 57 iotStatisticsRespVO.setDeviceStatsOfCategory(
61 - iotProductCategoryService.getDeviceCountsOfProductCategory() 58 + productCategoryService.getDeviceCountsOfProductCategory()
62 ); 59 );
63 60
64 // 获取设备状态数量统计 61 // 获取设备状态数量统计
65 - iotStatisticsRespVO.setOnlineTotal(iotDeviceService.getDeviceCountByState(IotDeviceStateEnum.ONLINE.getState()));  
66 - iotStatisticsRespVO.setOfflineTotal(iotDeviceService.getDeviceCountByState(IotDeviceStateEnum.OFFLINE.getState()));  
67 - iotStatisticsRespVO.setNeverOnlineTotal(iotDeviceService.getDeviceCountByState(IotDeviceStateEnum.INACTIVE.getState())); 62 + iotStatisticsRespVO.setOnlineTotal(deviceService.getDeviceCountByState(IotDeviceStateEnum.ONLINE.getState()));
  63 + iotStatisticsRespVO.setOfflineTotal(deviceService.getDeviceCountByState(IotDeviceStateEnum.OFFLINE.getState()));
  64 + iotStatisticsRespVO.setNeverOnlineTotal(deviceService.getDeviceCountByState(IotDeviceStateEnum.INACTIVE.getState()));
68 65
  66 + // TODO @super:新增 get-log-summary 接口,返回
69 // 根据传入时间范围获取设备上下行消息数量统计 67 // 根据传入时间范围获取设备上下行消息数量统计
70 - iotStatisticsRespVO.setDeviceUpMessageStats(iotDeviceLogService.getDeviceLogUpCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime()));  
71 - iotStatisticsRespVO.setDeviceDownMessageStats(iotDeviceLogService.getDeviceLogDownCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())); 68 + iotStatisticsRespVO.setDeviceUpMessageStats(deviceLogService.getDeviceLogUpCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime()));
  69 + iotStatisticsRespVO.setDeviceDownMessageStats(deviceLogService.getDeviceLogDownCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime()));
72 70
73 return CommonResult.success(iotStatisticsRespVO); 71 return CommonResult.success(iotStatisticsRespVO);
74 } 72 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java
@@ -7,10 +7,16 @@ import lombok.Data; @@ -7,10 +7,16 @@ import lombok.Data;
7 @Schema(description = "管理后台 - Iot统计 Request VO") 7 @Schema(description = "管理后台 - Iot统计 Request VO")
8 @Data 8 @Data
9 public class IotStatisticsReqVO { 9 public class IotStatisticsReqVO {
  10 +
  11 + // TODO @supper:times 直接传递哈;
  12 + // TODO 2super:private 不要丢了
  13 +
10 @Schema(description = "查询起始时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") 14 @Schema(description = "查询起始时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "177")
11 @NotNull(message = "查询起始时间不能为空") 15 @NotNull(message = "查询起始时间不能为空")
12 Long startTime; 16 Long startTime;
  17 +
13 @Schema(description = "查询结束时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") 18 @Schema(description = "查询结束时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "177")
14 @NotNull(message = "查询结束时间不能为空") 19 @NotNull(message = "查询结束时间不能为空")
15 Long endTime; 20 Long endTime;
  21 +
16 } 22 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsRespVO.java
@@ -5,10 +5,16 @@ import lombok.Data; @@ -5,10 +5,16 @@ import lombok.Data;
5 5
6 import java.util.List; 6 import java.util.List;
7 7
8 -@Schema(description = "管理后台 - Iot统计 Response VO") 8 +// TODO @super:Total 全部改成 Count
  9 +// TODO @super:IotStatisticsSummaryRespVO
  10 +/**
  11 + * 管理后台 - Iot 统计 Response VO
  12 + */
  13 +@Schema(description = "管理后台 - Iot 统计 Response VO")
9 @Data 14 @Data
10 public class IotStatisticsRespVO { 15 public class IotStatisticsRespVO {
11 16
  17 + // TODO @super:productCategory 哈
12 @Schema(description = "品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") 18 @Schema(description = "品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
13 private long categoryTotal; 19 private long categoryTotal;
14 20
@@ -18,9 +24,11 @@ public class IotStatisticsRespVO { @@ -18,9 +24,11 @@ public class IotStatisticsRespVO {
18 @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") 24 @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
19 private long deviceTotal; 25 private long deviceTotal;
20 26
  27 + // TODO @super:deviceMessageCount;设备消息数量
21 @Schema(description = "上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") 28 @Schema(description = "上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
22 private long reportTotal; 29 private long reportTotal;
23 30
  31 + // TODO @super:productCategory 哈
24 @Schema(description = "今日新增品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") 32 @Schema(description = "今日新增品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
25 private long categoryTodayTotal; 33 private long categoryTodayTotal;
26 34
@@ -30,30 +38,42 @@ public class IotStatisticsRespVO { @@ -30,30 +38,42 @@ public class IotStatisticsRespVO {
30 @Schema(description = "今日新增设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") 38 @Schema(description = "今日新增设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
31 private long deviceTodayTotal; 39 private long deviceTodayTotal;
32 40
  41 + // TODO @super:deviceMessageCount;今日设备消息数量
33 @Schema(description = "今日新增上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") 42 @Schema(description = "今日新增上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
34 private long reportTodayTotal; 43 private long reportTodayTotal;
35 44
  45 + // TODO @super:deviceOnlineCount
  46 +
36 @Schema(description = "在线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") 47 @Schema(description = "在线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
37 private long onlineTotal; 48 private long onlineTotal;
38 49
  50 + // TODO @super:deviceOfflineCount
  51 +
39 @Schema(description = "离线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15") 52 @Schema(description = "离线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15")
40 private long offlineTotal; 53 private long offlineTotal;
41 54
  55 + // TODO @super:deviceInactivECount
  56 +
42 @Schema(description = "待激活设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") 57 @Schema(description = "待激活设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
43 private long neverOnlineTotal; 58 private long neverOnlineTotal;
44 59
  60 + // TODO @super:1)类型改成 Map,key 分类名、value 设备数量;2)deviceStatsOfCategory => productCategoryDeviceCounts
  61 + @Schema(description = "按品类统计的设备数量")
  62 + private List<DataItem> deviceStatsOfCategory;
  63 +
  64 + // TODO @super:貌似界面里,用不到这个字段???
45 @Schema(description = "上报数据数量统计") 65 @Schema(description = "上报数据数量统计")
46 private List<TimeData> reportDataStats; 66 private List<TimeData> reportDataStats;
47 67
  68 + // TODO @super:deviceUpMessageStats、deviceDownMessageStats 单独抽到 IotStatisticsDeviceMessageSummaryRespVO,然后里面属性就是 upstreamCounts、downstreamCounts
  69 +
48 @Schema(description = "上行数据数量统计") 70 @Schema(description = "上行数据数量统计")
49 private List<TimeData> deviceUpMessageStats; 71 private List<TimeData> deviceUpMessageStats;
50 72
51 @Schema(description = "下行数据数量统计") 73 @Schema(description = "下行数据数量统计")
52 private List<TimeData> deviceDownMessageStats; 74 private List<TimeData> deviceDownMessageStats;
53 75
54 - @Schema(description = "按品类统计的设备数量")  
55 - private List<DataItem> deviceStatsOfCategory;  
56 - 76 + // TODO @super:如果只有这两个字段,使用 KeyValue 这个键值对
57 @Schema(description = "时间数据") 77 @Schema(description = "时间数据")
58 @Data 78 @Data
59 public static class TimeData { 79 public static class TimeData {
@@ -63,6 +83,7 @@ public class IotStatisticsRespVO { @@ -63,6 +83,7 @@ public class IotStatisticsRespVO {
63 83
64 @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") 84 @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
65 private Object data; 85 private Object data;
  86 +
66 } 87 }
67 88
68 @Schema(description = "数据项") 89 @Schema(description = "数据项")
@@ -74,5 +95,7 @@ public class IotStatisticsRespVO { @@ -74,5 +95,7 @@ public class IotStatisticsRespVO {
74 95
75 @Schema(description = "数据项值", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") 96 @Schema(description = "数据项值", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
76 private Object value; 97 private Object value;
  98 +
77 } 99 }
  100 +
78 } 101 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java
@@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
10 import org.apache.ibatis.annotations.Mapper; 10 import org.apache.ibatis.annotations.Mapper;
11 11
  12 +import javax.annotation.Nullable;
12 import java.time.LocalDateTime; 13 import java.time.LocalDateTime;
13 import java.util.List; 14 import java.util.List;
14 15
@@ -70,24 +71,12 @@ public interface IotDeviceMapper extends BaseMapperX&lt;IotDeviceDO&gt; { @@ -70,24 +71,12 @@ public interface IotDeviceMapper extends BaseMapperX&lt;IotDeviceDO&gt; {
70 .apply("FIND_IN_SET(" + groupId + ",group_ids) > 0")); 71 .apply("FIND_IN_SET(" + groupId + ",group_ids) > 0"));
71 } 72 }
72 73
73 - /**  
74 - * 统计设备数量  
75 - *  
76 - * @param createTime 创建时间,如果为空,则统计所有设备数量  
77 - * @return 设备数量  
78 - */  
79 - default Long selectCountByCreateTime(LocalDateTime createTime) { 74 + default Long selectCountByCreateTime(@Nullable LocalDateTime createTime) {
80 return selectCount(new LambdaQueryWrapperX<IotDeviceDO>() 75 return selectCount(new LambdaQueryWrapperX<IotDeviceDO>()
81 .geIfPresent(IotDeviceDO::getCreateTime, createTime)); 76 .geIfPresent(IotDeviceDO::getCreateTime, createTime));
82 } 77 }
83 78
84 - /**  
85 - * 统计指定状态的设备数量  
86 - *  
87 - * @param state 状态  
88 - * @return 设备数量  
89 - */  
90 - default Long selectCountByState(Integer state) { 79 + default Long selectCountByState(@Nullable Integer state) {
91 return selectCount(new LambdaQueryWrapperX<IotDeviceDO>() 80 return selectCount(new LambdaQueryWrapperX<IotDeviceDO>()
92 .eqIfPresent(IotDeviceDO::getState, state)); 81 .eqIfPresent(IotDeviceDO::getState, state));
93 } 82 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java
@@ -6,8 +6,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -6,8 +6,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; 6 import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO;
7 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; 7 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
8 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
9 -import org.apache.ibatis.annotations.Param;  
10 9
  10 +import javax.annotation.Nullable;
11 import java.time.LocalDateTime; 11 import java.time.LocalDateTime;
12 import java.util.List; 12 import java.util.List;
13 13
@@ -30,13 +30,7 @@ public interface IotProductCategoryMapper extends BaseMapperX&lt;IotProductCategory @@ -30,13 +30,7 @@ public interface IotProductCategoryMapper extends BaseMapperX&lt;IotProductCategory
30 return selectList(IotProductCategoryDO::getStatus, status); 30 return selectList(IotProductCategoryDO::getStatus, status);
31 } 31 }
32 32
33 - /**  
34 - * 统计产品分类数量  
35 - *  
36 - * @param createTime 创建时间,如果为空,则统计所有分类数量  
37 - * @return 产品分类数量  
38 - */  
39 - default Long selectCountByCreateTime(LocalDateTime createTime) { 33 + default Long selectCountByCreateTime(@Nullable LocalDateTime createTime) {
40 return selectCount(new LambdaQueryWrapperX<IotProductCategoryDO>() 34 return selectCount(new LambdaQueryWrapperX<IotProductCategoryDO>()
41 .geIfPresent(IotProductCategoryDO::getCreateTime, createTime)); 35 .geIfPresent(IotProductCategoryDO::getCreateTime, createTime));
42 } 36 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductMapper.java
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
8 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 8 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
9 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
10 10
  11 +import javax.annotation.Nullable;
11 import java.time.LocalDateTime; 12 import java.time.LocalDateTime;
12 import java.util.List; 13 import java.util.List;
13 14
@@ -31,23 +32,11 @@ public interface IotProductMapper extends BaseMapperX&lt;IotProductDO&gt; { @@ -31,23 +32,11 @@ public interface IotProductMapper extends BaseMapperX&lt;IotProductDO&gt; {
31 .apply("LOWER(product_key) = {0}", productKey.toLowerCase())); 32 .apply("LOWER(product_key) = {0}", productKey.toLowerCase()));
32 } 33 }
33 34
34 - /**  
35 - * 统计产品数量  
36 - *  
37 - * @param createTime 创建时间,如果为空,则统计所有产品数量  
38 - * @return 产品数量  
39 - */  
40 - default Long selectCountByCreateTime(LocalDateTime createTime) { 35 + default Long selectCountByCreateTime(@Nullable LocalDateTime createTime) {
41 return selectCount(new LambdaQueryWrapperX<IotProductDO>() 36 return selectCount(new LambdaQueryWrapperX<IotProductDO>()
42 .geIfPresent(IotProductDO::getCreateTime, createTime)); 37 .geIfPresent(IotProductDO::getCreateTime, createTime));
43 } 38 }
44 39
45 - /**  
46 - * 获得产品列表,基于分类编号  
47 - *  
48 - * @param categoryId 分类编号  
49 - * @return 产品列表  
50 - */  
51 default List<IotProductDO> selectListByCategoryId(Long categoryId) { 40 default List<IotProductDO> selectListByCategoryId(Long categoryId) {
52 return selectList(new LambdaQueryWrapperX<IotProductDO>() 41 return selectList(new LambdaQueryWrapperX<IotProductDO>()
53 .eq(IotProductDO::getCategoryId, categoryId) 42 .eq(IotProductDO::getCategoryId, categoryId)
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java
@@ -73,6 +73,7 @@ public interface IotThingModelMapper extends BaseMapperX&lt;IotThingModelDO&gt; { @@ -73,6 +73,7 @@ public interface IotThingModelMapper extends BaseMapperX&lt;IotThingModelDO&gt; {
73 IotThingModelDO::getName, name); 73 IotThingModelDO::getName, name);
74 } 74 }
75 75
  76 + // TODO @super:用不到,删除下;
76 /** 77 /**
77 * 统计物模型数量 78 * 统计物模型数量
78 * 79 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java
@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; @@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
9 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
10 import org.apache.ibatis.annotations.Param; 10 import org.apache.ibatis.annotations.Param;
11 11
12 -import java.time.LocalDateTime;  
13 import java.util.List; 12 import java.util.List;
14 13
15 /** 14 /**
@@ -58,6 +57,8 @@ public interface IotDeviceLogMapper { @@ -58,6 +57,8 @@ public interface IotDeviceLogMapper {
58 */ 57 */
59 Long selectCountByCreateTime(@Param("createTime") Long createTime); 58 Long selectCountByCreateTime(@Param("createTime") Long createTime);
60 59
  60 + // TODO @super:1)上行、下行,不写在 mapper 里,而是通过参数传递,这样,selectDeviceLogUpCountByHour、selectDeviceLogDownCountByHour 可以合并;
  61 + // TODO @super:2)不能只基于 identifier 来计算,而是要 type + identifier 成对
61 /** 62 /**
62 * 获得每个小时设备上行消息数量统计 63 * 获得每个小时设备上行消息数量统计
63 * 64 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
@@ -192,7 +192,7 @@ public interface IotDeviceService { @@ -192,7 +192,7 @@ public interface IotDeviceService {
192 * @param createTime 创建时间,如果为空,则统计所有设备数量 192 * @param createTime 创建时间,如果为空,则统计所有设备数量
193 * @return 设备数量 193 * @return 设备数量
194 */ 194 */
195 - Long getDeviceCount(LocalDateTime createTime); 195 + Long getDeviceCount(@Nullable LocalDateTime createTime);
196 196
197 /** 197 /**
198 * 获得设备数量,基于状态 198 * 获得设备数量,基于状态
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
@@ -429,6 +429,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { @@ -429,6 +429,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
429 return deviceMapper.selectCountByCreateTime(createTime); 429 return deviceMapper.selectCountByCreateTime(createTime);
430 } 430 }
431 431
  432 + // TODO @super:是不是 groupby 查询,更高效;不过 controller,还是要考虑 null 的情况;不过可以直接枚举 foreach 处理下
432 @Override 433 @Override
433 public Long getDeviceCountByState(Integer state) { 434 public Long getDeviceCountByState(Integer state) {
434 return deviceMapper.selectCountByState(state); 435 return deviceMapper.selectCountByState(state);
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java
@@ -5,8 +5,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogP @@ -5,8 +5,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogP
5 import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsRespVO; 5 import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsRespVO;
6 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; 6 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
7 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; 7 import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
8 -import org.apache.ibatis.annotations.Param;  
9 8
  9 +import javax.annotation.Nullable;
10 import java.time.LocalDateTime; 10 import java.time.LocalDateTime;
11 import java.util.List; 11 import java.util.List;
12 12
@@ -45,7 +45,7 @@ public interface IotDeviceLogService { @@ -45,7 +45,7 @@ public interface IotDeviceLogService {
45 * @param createTime 创建时间,如果为空,则统计所有日志数量 45 * @param createTime 创建时间,如果为空,则统计所有日志数量
46 * @return 日志数量 46 * @return 日志数量
47 */ 47 */
48 - Long getDeviceLogCount(LocalDateTime createTime); 48 + Long getDeviceLogCount(@Nullable LocalDateTime createTime);
49 49
50 /** 50 /**
51 * 获得每个小时设备上行消息数量统计 51 * 获得每个小时设备上行消息数量统计
@@ -55,7 +55,9 @@ public interface IotDeviceLogService { @@ -55,7 +55,9 @@ public interface IotDeviceLogService {
55 * @param endTime 结束时间,如果为空,则不限制结束时间 55 * @param endTime 结束时间,如果为空,则不限制结束时间
56 * @return 每小时消息数量统计列表 56 * @return 每小时消息数量统计列表
57 */ 57 */
58 - List<IotStatisticsRespVO.TimeData> getDeviceLogUpCountByHour(String deviceKey, Long startTime, Long endTime); 58 + List<IotStatisticsRespVO.TimeData> getDeviceLogUpCountByHour(@Nullable String deviceKey,
  59 + @Nullable Long startTime,
  60 + @Nullable Long endTime);
59 61
60 /** 62 /**
61 * 获得每个小时设备下行消息数量统计 63 * 获得每个小时设备下行消息数量统计
@@ -65,6 +67,8 @@ public interface IotDeviceLogService { @@ -65,6 +67,8 @@ public interface IotDeviceLogService {
65 * @param endTime 结束时间,如果为空,则不限制结束时间 67 * @param endTime 结束时间,如果为空,则不限制结束时间
66 * @return 每小时消息数量统计列表 68 * @return 每小时消息数量统计列表
67 */ 69 */
68 - List<IotStatisticsRespVO.TimeData> getDeviceLogDownCountByHour( String deviceKey, Long startTime, Long endTime); 70 + List<IotStatisticsRespVO.TimeData> getDeviceLogDownCountByHour(@Nullable String deviceKey,
  71 + @Nullable Long startTime,
  72 + @Nullable Long endTime);
69 73
70 } 74 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java
@@ -73,11 +73,13 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService { @@ -73,11 +73,13 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService {
73 public Long getDeviceLogCount(LocalDateTime createTime) { 73 public Long getDeviceLogCount(LocalDateTime createTime) {
74 Long time = null; 74 Long time = null;
75 if (createTime != null) { 75 if (createTime != null) {
  76 + // todo @super:1)LocalDateTimeUtil.toEpochMilli(createTime);2)直接表达式,更简洁 time != null ? createTime.toInstant(ZoneOffset.UTC).toEpochMilli() : null;
76 time = createTime.toInstant(ZoneOffset.UTC).toEpochMilli(); 77 time = createTime.toInstant(ZoneOffset.UTC).toEpochMilli();
77 } 78 }
78 return deviceLogMapper.selectCountByCreateTime(time); 79 return deviceLogMapper.selectCountByCreateTime(time);
79 } 80 }
80 81
  82 + // TODO @super:加一个参数,Boolean upstream:true 上行,false 下行,null 不过滤
81 @Override 83 @Override
82 public List<IotStatisticsRespVO.TimeData> getDeviceLogUpCountByHour(String deviceKey, Long startTime, Long endTime) { 84 public List<IotStatisticsRespVO.TimeData> getDeviceLogUpCountByHour(String deviceKey, Long startTime, Long endTime) {
83 try { 85 try {
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsR @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsR
7 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; 7 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
8 import jakarta.validation.Valid; 8 import jakarta.validation.Valid;
9 9
  10 +import javax.annotation.Nullable;
10 import java.time.LocalDateTime; 11 import java.time.LocalDateTime;
11 import java.util.Collection; 12 import java.util.Collection;
12 import java.util.List; 13 import java.util.List;
@@ -91,8 +92,9 @@ public interface IotProductCategoryService { @@ -91,8 +92,9 @@ public interface IotProductCategoryService {
91 * @param createTime 创建时间,如果为空,则统计所有分类数量 92 * @param createTime 创建时间,如果为空,则统计所有分类数量
92 * @return 产品分类数量 93 * @return 产品分类数量
93 */ 94 */
94 - Long getProductCategoryCount(LocalDateTime createTime); 95 + Long getProductCategoryCount(@Nullable LocalDateTime createTime);
95 96
  97 + // TODO @super:1)Map<ProductCategory, Count> 虽然有点怪哈,然后 Controller 按需转换成 Map<String, Integer> ;2)名字 getProductCategoryDeviceCountMap 方法
96 /** 98 /**
97 * 获得各个品类下设备数量统计 99 * 获得各个品类下设备数量统计
98 * 100 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java
@@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
11 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; 11 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
12 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductCategoryMapper; 12 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductCategoryMapper;
13 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; 13 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
14 -import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService;  
15 import jakarta.annotation.Resource; 14 import jakarta.annotation.Resource;
16 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
17 import org.springframework.validation.annotation.Validated; 16 import org.springframework.validation.annotation.Validated;
@@ -108,16 +107,18 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService @@ -108,16 +107,18 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService
108 // 1. 获取所有数据 107 // 1. 获取所有数据
109 List<IotProductCategoryDO> categoryList = productCategoryMapper.selectList(); 108 List<IotProductCategoryDO> categoryList = productCategoryMapper.selectList();
110 List<IotProductDO> productList = productService.getProductList(); 109 List<IotProductDO> productList = productService.getProductList();
  110 + // TODO @super:不要 list 查询,返回内存,而是查询一个 Map<productId, count>
111 List<IotDeviceDO> deviceList = deviceService.getDeviceList(); 111 List<IotDeviceDO> deviceList = deviceService.getDeviceList();
112 112
113 // 2. 统计每个分类下的设备数量 113 // 2. 统计每个分类下的设备数量
114 Map<String, Integer> categoryDeviceCountMap = new HashMap<>(); 114 Map<String, Integer> categoryDeviceCountMap = new HashMap<>();
115 - 115 +
116 // 2.1 初始化所有分类的计数为0 116 // 2.1 初始化所有分类的计数为0
117 for (IotProductCategoryDO category : categoryList) { 117 for (IotProductCategoryDO category : categoryList) {
118 categoryDeviceCountMap.put(category.getName(), 0); 118 categoryDeviceCountMap.put(category.getName(), 0);
  119 + // TODO @super:直接这里面计算,不用多个循环。产品本身也不多,不用构建 Map,直接 filter 就好了
119 } 120 }
120 - 121 +
121 // 2.2 构建产品ID到分类的映射 122 // 2.2 构建产品ID到分类的映射
122 Map<Long, IotProductCategoryDO> productCategoryMap = new HashMap<>(); 123 Map<Long, IotProductCategoryDO> productCategoryMap = new HashMap<>();
123 for (IotProductDO product : productList) { 124 for (IotProductDO product : productList) {
@@ -130,7 +131,7 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService @@ -130,7 +131,7 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService
130 productCategoryMap.put(product.getId(), category); 131 productCategoryMap.put(product.getId(), category);
131 } 132 }
132 } 133 }
133 - 134 +
134 // 2.3 统计每个分类下的设备数量 135 // 2.3 统计每个分类下的设备数量
135 for (IotDeviceDO device : deviceList) { 136 for (IotDeviceDO device : deviceList) {
136 Long productId = device.getProductId(); 137 Long productId = device.getProductId();
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductService.java
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProduc @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProduc
6 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; 6 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
7 import jakarta.validation.Valid; 7 import jakarta.validation.Valid;
8 8
  9 +import javax.annotation.Nullable;
9 import java.time.LocalDateTime; 10 import java.time.LocalDateTime;
10 import java.util.List; 11 import java.util.List;
11 12
@@ -99,8 +100,9 @@ public interface IotProductService { @@ -99,8 +100,9 @@ public interface IotProductService {
99 * @param createTime 创建时间,如果为空,则统计所有产品数量 100 * @param createTime 创建时间,如果为空,则统计所有产品数量
100 * @return 产品数量 101 * @return 产品数量
101 */ 102 */
102 - Long getProductCount(LocalDateTime createTime); 103 + Long getProductCount(@Nullable LocalDateTime createTime);
103 104
  105 + // TODO @super:用不到的,删除下哈
104 /** 106 /**
105 * 获得产品列表,基于分类编号 107 * 获得产品列表,基于分类编号
106 * 108 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java
@@ -81,6 +81,7 @@ public interface IotThingModelService { @@ -81,6 +81,7 @@ public interface IotThingModelService {
81 */ 81 */
82 List<IotThingModelDO> getThingModelList(IotThingModelListReqVO reqVO); 82 List<IotThingModelDO> getThingModelList(IotThingModelListReqVO reqVO);
83 83
  84 + // TODO @super:用不到,删除下哈。
84 /** 85 /**
85 * 获得物模型数量 86 * 获得物模型数量
86 * 87 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
@@ -364,6 +364,7 @@ public class IotThingModelServiceImpl implements IotThingModelService { @@ -364,6 +364,7 @@ public class IotThingModelServiceImpl implements IotThingModelService {
364 return SpringUtil.getBean(getClass()); 364 return SpringUtil.getBean(getClass());
365 } 365 }
366 366
  367 + // TODO @super:用不到,删除下;
367 @Override 368 @Override
368 public Long getThingModelCount(LocalDateTime createTime) { 369 public Long getThingModelCount(LocalDateTime createTime) {
369 return thingModelMapper.selectCountByCreateTime(createTime); 370 return thingModelMapper.selectCountByCreateTime(createTime);