From 53693529e1d06a417f7e1d8f9f68e0478cdb4fca Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 1 Mar 2025 23:30:47 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91IoT=EF=BC=9A=E9=A6=96=E9=A1=B5=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../statistics/IotStatisticsController.java | 31 +++++++------- ...tStatisticsDeviceMessageSummaryRespVO.java | 4 +- .../statistics/vo/IotStatisticsReqVO.java | 5 +-- .../vo/IotStatisticsSummaryRespVO.java | 40 +++++-------------- .../iot/dal/mysql/device/IotDeviceMapper.java | 9 +---- .../iot/dal/tdengine/IotDeviceLogMapper.java | 8 ++-- .../iot/service/device/IotDeviceService.java | 8 ---- .../service/device/IotDeviceServiceImpl.java | 8 +--- .../device/data/IotDeviceLogService.java | 9 ++--- .../device/data/IotDeviceLogServiceImpl.java | 4 +- .../product/IotProductCategoryService.java | 3 +- .../IotProductCategoryServiceImpl.java | 5 +-- 13 files changed, 46 insertions(+), 90 deletions(-) diff --git a/pom.xml b/pom.xml index a343309726..0b8e28284d 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ yudao-module-system yudao-module-infra - + yudao-module-bpm diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java index c4ef83a4ac..31cc5121ad 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java @@ -36,43 +36,42 @@ public class IotStatisticsController { @Resource private IotDeviceLogService deviceLogService; - // TODO @super:description 非必要,可以不写哈 @GetMapping("/get-summary") - @Operation(summary = "获取IOT数据统计") + @Operation(summary = "获取 IoT 数据统计") public CommonResult getIotStatisticsSummary(){ IotStatisticsSummaryRespVO respVO = new IotStatisticsSummaryRespVO(); - // 获取总数 + // 1.1 获取总数 respVO.setProductCategoryCount(productCategoryService.getProductCategoryCount(null)); respVO.setProductCount(productService.getProductCount(null)); respVO.setDeviceCount(deviceService.getDeviceCount(null)); respVO.setDeviceMessageCount(deviceLogService.getDeviceLogCount(null)); - - // 获取今日新增数量 + // 1.2 获取今日新增数量 + // TODO @super:使用 LocalDateTimeUtils.getToday() LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0); respVO.setProductCategoryTodayCount(productCategoryService.getProductCategoryCount(todayStart)); respVO.setProductTodayCount(productService.getProductCount(todayStart)); respVO.setDeviceTodayCount(deviceService.getDeviceCount(todayStart)); respVO.setDeviceMessageTodayCount(deviceLogService.getDeviceLogCount(todayStart)); - // 获取各个品类下设备数量统计 + // 2. 获取各个品类下设备数量统计 respVO.setProductCategoryDeviceCounts(productCategoryService.getProductCategoryDeviceCountMap()); - // 获取设备状态数量统计 + // 3. 获取设备状态数量统计 Map deviceCountMap = deviceService.getDeviceCountMapByState(); respVO.setDeviceOnlineCount(deviceCountMap.getOrDefault(IotDeviceStateEnum.ONLINE.getState(), 0L)); respVO.setDeviceOfflineCount(deviceCountMap.getOrDefault(IotDeviceStateEnum.OFFLINE.getState(), 0L)); respVO.setDeviceInactiveCount(deviceCountMap.getOrDefault(IotDeviceStateEnum.INACTIVE.getState(), 0L)); - return CommonResult.success(respVO); } - @GetMapping("/get-log-summary") - @Operation(summary = "获取IOT上下行消息数据统计") - public CommonResult getIotStatisticsDeviceMessageSummary(@Valid IotStatisticsReqVO reqVO){ - // 根据传入时间范围获取设备上下行消息数量统计 - IotStatisticsDeviceMessageSummaryRespVO iotStatisticsRespVO = new IotStatisticsDeviceMessageSummaryRespVO(); - iotStatisticsRespVO.setUpstreamCounts(deviceLogService.getDeviceLogUpCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())); - iotStatisticsRespVO.setDownstreamCounts(deviceLogService.getDeviceLogDownCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())); - return CommonResult.success(iotStatisticsRespVO); + // TODO @super:要不干掉 IotStatisticsReqVO 参数,直接使用 @RequestParam 接收,简单一些。 + @GetMapping("/get-log-summary") + @Operation(summary = "获取 IoT 设备上下行消息数据统计") + public CommonResult getIotStatisticsDeviceMessageSummary( + @Valid IotStatisticsReqVO reqVO) { + return CommonResult.success(new IotStatisticsDeviceMessageSummaryRespVO() + .setDownstreamCounts(deviceLogService.getDeviceLogUpCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())) + .setDownstreamCounts((deviceLogService.getDeviceLogDownCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())))); } + } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java index 250c63e2ab..15d2abccc6 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java @@ -6,14 +6,14 @@ import lombok.Data; import java.util.List; import java.util.Map; -@Schema(description = "管理后台 - Iot 上下行消息数量统计 Response VO") +@Schema(description = "管理后台 - IoT 设备上下行消息数量统计 Response VO") @Data public class IotStatisticsDeviceMessageSummaryRespVO { + @Schema(description = "每小时上行数据数量统计") private List> upstreamCounts; @Schema(description = "每小时下行数据数量统计") private List> downstreamCounts; - // TODO @super:如果只有这两个字段,使用 KeyValue 这个键值对 } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java index acffe1299f..741f77f3a4 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java @@ -4,12 +4,11 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Data; -@Schema(description = "管理后台 - Iot统计 Request VO") +@Schema(description = "管理后台 - IoT 统计 Request VO") @Data public class IotStatisticsReqVO { - // TODO @supper:times 直接传递哈; - // TODO 2super:private 不要丢了 + // TODO @super:前端传递的时候,还是通过 startTime 和 endTime 传递。后端转成 Long @Schema(description = "查询起始时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1658486600000") @NotNull(message = "查询起始时间不能为空") diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java index 0ad1f9ff4f..1b750f380b 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java @@ -5,8 +5,6 @@ import lombok.Data; import java.util.Map; -// TODO @super:Total 全部改成 Count -// TODO @super:IotStatisticsSummaryRespVO /** * 管理后台 - Iot 统计 Response VO */ @@ -14,56 +12,40 @@ import java.util.Map; @Data public class IotStatisticsSummaryRespVO { - // TODO @super:productCategory 哈 @Schema(description = "品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private long productCategoryCount; + private Long productCategoryCount; @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") - private long productCount; + private Long productCount; @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private long deviceCount; + private Long deviceCount; - // TODO @super:deviceMessageCount;设备消息数量 @Schema(description = "上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - private long deviceMessageCount; + private Long deviceMessageCount; - // TODO @super:productCategory 哈 @Schema(description = "今日新增品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private long productCategoryTodayCount; + private Long productCategoryTodayCount; @Schema(description = "今日新增产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") - private long productTodayCount; + private Long productTodayCount; @Schema(description = "今日新增设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private long deviceTodayCount; + private Long deviceTodayCount; - // TODO @super:deviceMessageCount;今日设备消息数量 @Schema(description = "今日新增上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - private long deviceMessageTodayCount; - - // TODO @super:deviceOnlineCount + private Long deviceMessageTodayCount; @Schema(description = "在线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") - private long deviceOnlineCount; - - // TODO @super:deviceOfflineCount + private Long deviceOnlineCount; @Schema(description = "离线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15") - private long deviceOfflineCount; - - // TODO @super:deviceInactivECount + private Long deviceOfflineCount; @Schema(description = "待激活设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - private long deviceInactiveCount; + private Long deviceInactiveCount; - // TODO @super:1)类型改成 Map,key 分类名、value 设备数量;2)deviceStatsOfCategory => productCategoryDeviceCounts @Schema(description = "按品类统计的设备数量") private Map productCategoryDeviceCounts; - // TODO @super:貌似界面里,用不到这个字段??? - - - // TODO @super:deviceUpMessageStats、deviceDownMessageStats 单独抽到 IotStatisticsDeviceMessageSummaryRespVO,然后里面属性就是 upstreamCounts、downstreamCounts - } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java index 128b026f50..babbf29e7d 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java @@ -8,13 +8,11 @@ import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePa import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import javax.annotation.Nullable; import java.time.LocalDateTime; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * IoT 设备 Mapper @@ -79,18 +77,15 @@ public interface IotDeviceMapper extends BaseMapperX { .geIfPresent(IotDeviceDO::getCreateTime, createTime)); } - default Long selectCountByState(@Nullable Integer state) { - return selectCount(new LambdaQueryWrapperX() - .eqIfPresent(IotDeviceDO::getState, state)); - } - /** * 查询指定产品下各状态的设备数量 * * @return 设备数量统计列表 */ + // TODO @super:通过 mybatis-plus 来写哈,然后返回 Map 貌似就行了?! List> selectDeviceCountMapByProductId(); + // TODO @super:通过 mybatis-plus 来写哈,然后返回 Map 貌似就行了?! /** * 查询各个状态下的设备数量 * diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java index 9efe2ec805..96741e6095 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java @@ -63,14 +63,14 @@ public interface IotDeviceLogMapper { * 查询每个小时设备上行消息数量 */ List> selectDeviceLogUpCountByHour(@Param("deviceKey") String deviceKey, - @Param("startTime") Long startTime, - @Param("endTime") Long endTime); + @Param("startTime") Long startTime, + @Param("endTime") Long endTime); /** * 查询每个小时设备下行消息数量 */ List> selectDeviceLogDownCountByHour(@Param("deviceKey") String deviceKey, - @Param("startTime") Long startTime, - @Param("endTime") Long endTime); + @Param("startTime") Long startTime, + @Param("endTime") Long endTime); } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java index 0e50f4a27a..1dda3f333c 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java @@ -196,14 +196,6 @@ public interface IotDeviceService { */ Long getDeviceCount(@Nullable LocalDateTime createTime); - - /** - * 获得所有设备列表 - * - * @return 设备列表 - */ - List getDeviceList(); - /** * 获取 MQTT 连接参数 * diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java index b6c0969d17..989f10a095 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java @@ -430,13 +430,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { return deviceMapper.selectCountByCreateTime(createTime); } - // TODO @super:是不是 groupby 查询,更高效;不过 controller,还是要考虑 null 的情况;不过可以直接枚举 foreach 处理下 - - @Override - public List getDeviceList() { - return deviceMapper.selectList(); - } - + // TODO @super:简化 @Override public Map getDeviceCountMapByProductId() { // 查询结果转换成Map diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java index e1a15aaa16..468599e1ce 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.iot.service.device.data; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsDeviceMessageSummaryRespVO; import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; @@ -57,8 +56,8 @@ public interface IotDeviceLogService { * @return key: 时间戳, value: 消息数量 */ List> getDeviceLogUpCountByHour(@Nullable String deviceKey, - @Nullable Long startTime, - @Nullable Long endTime); + @Nullable Long startTime, + @Nullable Long endTime); /** * 获得每个小时设备下行消息数量统计 @@ -69,7 +68,7 @@ public interface IotDeviceLogService { * @return key: 时间戳, value: 消息数量 */ List> getDeviceLogDownCountByHour(@Nullable String deviceKey, - @Nullable Long startTime, - @Nullable Long endTime); + @Nullable Long startTime, + @Nullable Long endTime); } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java index 29b57402b5..1df4d4cd44 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java @@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsDeviceMessageSummaryRespVO; import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogMapper; import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; @@ -73,13 +72,13 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService { @Override public Long getDeviceLogCount(LocalDateTime createTime) { - // todo @super:1)LocalDateTimeUtil.toEpochMilli(createTime);2)直接表达式,更简洁 time != null ? createTime.toInstant(ZoneOffset.UTC).toEpochMilli() : null; return deviceLogMapper.selectCountByCreateTime(createTime != null ? LocalDateTimeUtil.toEpochMilli(createTime) : null); } // TODO @super:加一个参数,Boolean upstream:true 上行,false 下行,null 不过滤 @Override public List> getDeviceLogUpCountByHour(String deviceKey, Long startTime, Long endTime) { + // TODO @super:不能只基于数据库统计。因为有一些小时,可能出现没数据的情况,导致前端展示的图是不全的。可以参考 CrmStatisticsCustomerService 来实现 List> list = deviceLogMapper.selectDeviceLogUpCountByHour(deviceKey, startTime, endTime); return list.stream() .map(map -> { @@ -93,6 +92,7 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService { .collect(Collectors.toList()); } + // TODO @super:getDeviceLogDownCountByHour 融合到 getDeviceLogUpCountByHour @Override public List> getDeviceLogDownCountByHour(String deviceKey, Long startTime, Long endTime) { List> list = deviceLogMapper.selectDeviceLogDownCountByHour(deviceKey, startTime, endTime); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java index 662d161c10..8cc640556b 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java @@ -93,9 +93,8 @@ public interface IotProductCategoryService { */ Long getProductCategoryCount(@Nullable LocalDateTime createTime); - // TODO @super:1)Map 虽然有点怪哈,然后 Controller 按需转换成 Map ;2)名字 getProductCategoryDeviceCountMap 方法 /** - * 获得各个品类下设备数量统计 + * 获得各个品类下设备数量统计,其中 key 是产品分类名 * * @return 品类设备统计列表 */ diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java index 5499937fde..f03186866d 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java @@ -106,11 +106,9 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService // 2. 统计每个分类下的设备数量 Map categoryDeviceCountMap = new HashMap<>(); - - // 2.1 初始化所有分类的计数为0 for (IotProductCategoryDO category : categoryList) { categoryDeviceCountMap.put(category.getName(), 0); - + // TODO @super:CollectionUtils.getSumValue(),看看能不能简化下 // 2.2 找到该分类下的所有产品,累加设备数量 for (IotProductDO product : productList) { if (Objects.equals(product.getCategoryId(), category.getId())) { @@ -119,7 +117,6 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService } } } - return categoryDeviceCountMap; }