Commit 6d059eae61f1ff74ea43dd45aabd5a55de01a7f0

Authored by alwayssuper
1 parent 8e7bbfe0

[fix]:statistics

Showing 15 changed files with 368 additions and 5 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.statistics;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductRespVO;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsRespVO;
  6 +import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
  7 +import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService;
  8 +import cn.iocoder.yudao.module.iot.service.product.IotProductService;
  9 +import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService;
  10 +import io.swagger.v3.oas.annotations.Operation;
  11 +import io.swagger.v3.oas.annotations.tags.Tag;
  12 +import jakarta.annotation.Resource;
  13 +import org.springframework.validation.annotation.Validated;
  14 +import org.springframework.web.bind.annotation.GetMapping;
  15 +import org.springframework.web.bind.annotation.RequestMapping;
  16 +import org.springframework.web.bind.annotation.RestController;
  17 +
  18 +import java.time.LocalDateTime;
  19 +import java.util.List;
  20 +
  21 +
  22 +@Tag(name = "管理后台 - IoT 数据统计")
  23 +@RestController
  24 +@RequestMapping("/iot/statistics")
  25 +@Validated
  26 +public class IotStatisticsController {
  27 +
  28 + @Resource
  29 + private IotDeviceService iotDeviceService;
  30 +
  31 + @Resource
  32 + private IotProductCategoryService iotProductCategoryService;
  33 +
  34 + @Resource
  35 + private IotProductService iotProductService;
  36 +
  37 +
  38 + @GetMapping("/count")
  39 + @Operation(summary = "获取IOT首页的数据统计", description = "主要用于IOT首页的数据统计")
  40 + public CommonResult<IotStatisticsRespVO> getSimpleProductList(){
  41 + IotStatisticsRespVO iotStatisticsRespVO = new IotStatisticsRespVO();
  42 + // 获取总数
  43 + iotStatisticsRespVO.setCategoryTotal(iotProductCategoryService.getProductCategoryCount(null));
  44 + iotStatisticsRespVO.setProductTotal(iotProductService.getProductCount(null));
  45 + iotStatisticsRespVO.setDeviceTotal(iotDeviceService.getDeviceCount(null));
  46 +
  47 + // 获取今日新增数量
  48 + LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
  49 + iotStatisticsRespVO.setCategoryTodayTotal(iotProductCategoryService.getProductCategoryCount(todayStart));
  50 + iotStatisticsRespVO.setProductTodayTotal(iotProductService.getProductCount(todayStart));
  51 + iotStatisticsRespVO.setDeviceTodayTotal(iotDeviceService.getDeviceCount(todayStart));
  52 +
  53 + return CommonResult.success(iotStatisticsRespVO);
  54 + }
  55 +}
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.statistics.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import java.util.List;
  7 +
  8 +@Schema(description = "管理后台 - Iot统计 Response VO")
  9 +@Data
  10 +public class IotStatisticsRespVO {
  11 +
  12 + @Schema(description = "品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  13 + private long categoryTotal;
  14 +
  15 + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
  16 + private long productTotal;
  17 +
  18 + @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  19 + private long deviceTotal;
  20 +
  21 + @Schema(description = "上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
  22 + private long reportTotal;
  23 +
  24 + @Schema(description = "今日新增品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  25 + private long categoryTodayTotal;
  26 +
  27 + @Schema(description = "今日新增产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
  28 + private long productTodayTotal;
  29 +
  30 + @Schema(description = "今日新增设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  31 + private long deviceTodayTotal;
  32 +
  33 + @Schema(description = "今日新增上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
  34 + private long reportTodayTotal;
  35 +
  36 + @Schema(description = "在线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
  37 + private long onlineTotal;
  38 +
  39 + @Schema(description = "离线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15")
  40 + private long offlineTotal;
  41 +
  42 + @Schema(description = "待激活设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  43 + private long neverOnlineTotal;
  44 +
  45 + @Schema(description = "上报数据数量统计")
  46 + private List<TimeData> reportDataStats;
  47 +
  48 + @Schema(description = "上行数据数量统计")
  49 + private List<TimeData> deviceUpMessageStats;
  50 +
  51 + @Schema(description = "下行数据数量统计")
  52 + private List<TimeData> deviceDownMessageStats;
  53 +
  54 + @Schema(description = "按品类统计的设备数量")
  55 + private List<DataItem> deviceStatsOfCategory;
  56 +
  57 + @Schema(description = "时间数据")
  58 + @Data
  59 + public static class TimeData {
  60 +
  61 + @Schema(description = "时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1646092800000")
  62 + private long time;
  63 +
  64 + @Schema(description = "数据值", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  65 + private Object data;
  66 + }
  67 +
  68 + @Schema(description = "数据项")
  69 + @Data
  70 + public static class DataItem {
  71 +
  72 + @Schema(description = "数据项名", requiredMode = Schema.RequiredMode.REQUIRED, example = "智能家居")
  73 + private String name;
  74 +
  75 + @Schema(description = "数据项值", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
  76 + private Object value;
  77 + }
  78 +}
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 java.time.LocalDateTime;
12 import java.util.List; 13 import java.util.List;
13 14
14 /** 15 /**
@@ -66,4 +67,26 @@ public interface IotDeviceMapper extends BaseMapperX&lt;IotDeviceDO&gt; { @@ -66,4 +67,26 @@ public interface IotDeviceMapper extends BaseMapperX&lt;IotDeviceDO&gt; {
66 .orderByDesc(IotDeviceDO::getId)); 67 .orderByDesc(IotDeviceDO::getId));
67 } 68 }
68 69
  70 + /**
  71 + * 统计设备数量
  72 + *
  73 + * @param createTime 创建时间,如果为空,则统计所有设备数量
  74 + * @return 设备数量
  75 + */
  76 + default Long selectCountByCreateTime(LocalDateTime createTime) {
  77 + return selectCount(new LambdaQueryWrapperX<IotDeviceDO>()
  78 + .geIfPresent(IotDeviceDO::getCreateTime, createTime));
  79 + }
  80 +
  81 + /**
  82 + * 统计指定状态的设备数量
  83 + *
  84 + * @param state 状态
  85 + * @return 设备数量
  86 + */
  87 + default Long selectCountByState(Integer state) {
  88 + return selectCount(new LambdaQueryWrapperX<IotDeviceDO>()
  89 + .eqIfPresent(IotDeviceDO::getState, state));
  90 + }
  91 +
69 } 92 }
70 \ No newline at end of file 93 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java
@@ -6,7 +6,9 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -6,7 +6,9 @@ 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;
9 10
  11 +import java.time.LocalDateTime;
10 import java.util.List; 12 import java.util.List;
11 13
12 /** 14 /**
@@ -28,4 +30,15 @@ public interface IotProductCategoryMapper extends BaseMapperX&lt;IotProductCategory @@ -28,4 +30,15 @@ public interface IotProductCategoryMapper extends BaseMapperX&lt;IotProductCategory
28 return selectList(IotProductCategoryDO::getStatus, status); 30 return selectList(IotProductCategoryDO::getStatus, status);
29 } 31 }
30 32
  33 + /**
  34 + * 统计产品分类数量
  35 + *
  36 + * @param createTime 创建时间,如果为空,则统计所有分类数量
  37 + * @return 产品分类数量
  38 + */
  39 + default Long selectCountByCreateTime(LocalDateTime createTime) {
  40 + return selectCount(new LambdaQueryWrapperX<IotProductCategoryDO>()
  41 + .geIfPresent(IotProductCategoryDO::getCreateTime, createTime));
  42 + }
  43 +
31 } 44 }
32 \ No newline at end of file 45 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductMapper.java
@@ -8,6 +8,9 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; @@ -8,6 +8,9 @@ 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 java.time.LocalDateTime;
  12 +import java.util.List;
  13 +
11 /** 14 /**
12 * IoT 产品 Mapper 15 * IoT 产品 Mapper
13 * 16 *
@@ -28,4 +31,27 @@ public interface IotProductMapper extends BaseMapperX&lt;IotProductDO&gt; { @@ -28,4 +31,27 @@ public interface IotProductMapper extends BaseMapperX&lt;IotProductDO&gt; {
28 .apply("LOWER(product_key) = {0}", productKey.toLowerCase())); 31 .apply("LOWER(product_key) = {0}", productKey.toLowerCase()));
29 } 32 }
30 33
  34 + /**
  35 + * 统计产品数量
  36 + *
  37 + * @param createTime 创建时间,如果为空,则统计所有产品数量
  38 + * @return 产品数量
  39 + */
  40 + default Long selectCountByCreateTime(LocalDateTime createTime) {
  41 + return selectCount(new LambdaQueryWrapperX<IotProductDO>()
  42 + .geIfPresent(IotProductDO::getCreateTime, createTime));
  43 + }
  44 +
  45 + /**
  46 + * 获得产品列表,基于分类编号
  47 + *
  48 + * @param categoryId 分类编号
  49 + * @return 产品列表
  50 + */
  51 + default List<IotProductDO> selectListByCategoryId(Long categoryId) {
  52 + return selectList(new LambdaQueryWrapperX<IotProductDO>()
  53 + .eq(IotProductDO::getCategoryId, categoryId)
  54 + .orderByDesc(IotProductDO::getId));
  55 + }
  56 +
31 } 57 }
32 \ No newline at end of file 58 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelP @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelP
8 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; 8 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
9 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
10 10
  11 +import java.time.LocalDateTime;
11 import java.util.List; 12 import java.util.List;
12 13
13 /** 14 /**
@@ -72,4 +73,15 @@ public interface IotThingModelMapper extends BaseMapperX&lt;IotThingModelDO&gt; { @@ -72,4 +73,15 @@ public interface IotThingModelMapper extends BaseMapperX&lt;IotThingModelDO&gt; {
72 IotThingModelDO::getName, name); 73 IotThingModelDO::getName, name);
73 } 74 }
74 75
  76 + /**
  77 + * 统计物模型数量
  78 + *
  79 + * @param createTime 创建时间,如果为空,则统计所有物模型数量
  80 + * @return 物模型数量
  81 + */
  82 + default Long selectCountByCreateTime(LocalDateTime createTime) {
  83 + return selectCount(new LambdaQueryWrapperX<IotThingModelDO>()
  84 + .geIfPresent(IotThingModelDO::getCreateTime, createTime));
  85 + }
  86 +
75 } 87 }
76 \ No newline at end of file 88 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
@@ -7,6 +7,7 @@ import jakarta.validation.Valid; @@ -7,6 +7,7 @@ import jakarta.validation.Valid;
7 import jakarta.validation.constraints.NotEmpty; 7 import jakarta.validation.constraints.NotEmpty;
8 8
9 import javax.annotation.Nullable; 9 import javax.annotation.Nullable;
  10 +import java.time.LocalDateTime;
10 import java.util.Collection; 11 import java.util.Collection;
11 import java.util.List; 12 import java.util.List;
12 13
@@ -109,7 +110,7 @@ public interface IotDeviceService { @@ -109,7 +110,7 @@ public interface IotDeviceService {
109 IotDeviceDO getDeviceByDeviceKey(String deviceKey); 110 IotDeviceDO getDeviceByDeviceKey(String deviceKey);
110 111
111 /** 112 /**
112 - * ��得设备分页 113 + * 获得设备分页
113 * 114 *
114 * @param pageReqVO 分页查询 115 * @param pageReqVO 分页查询
115 * @return IoT 设备分页 116 * @return IoT 设备分页
@@ -168,4 +169,27 @@ public interface IotDeviceService { @@ -168,4 +169,27 @@ public interface IotDeviceService {
168 */ 169 */
169 IotDeviceImportRespVO importDevice(List<IotDeviceImportExcelVO> importDevices, boolean updateSupport); 170 IotDeviceImportRespVO importDevice(List<IotDeviceImportExcelVO> importDevices, boolean updateSupport);
170 171
  172 + /**
  173 + * 获得设备数量
  174 + *
  175 + * @param createTime 创建时间,如果为空,则统计所有设备数量
  176 + * @return 设备数量
  177 + */
  178 + Long getDeviceCount(LocalDateTime createTime);
  179 +
  180 + /**
  181 + * 获得设备数量,基于状态
  182 + *
  183 + * @param state 状态
  184 + * @return 设备数量
  185 + */
  186 + Long getDeviceCountByState(Integer state);
  187 +
  188 + /**
  189 + * 获得所有设备列表
  190 + *
  191 + * @return 设备列表
  192 + */
  193 + List<IotDeviceDO> getDeviceList();
  194 +
171 } 195 }
172 \ No newline at end of file 196 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
@@ -434,4 +434,19 @@ public class IotDeviceServiceImpl implements IotDeviceService { @@ -434,4 +434,19 @@ public class IotDeviceServiceImpl implements IotDeviceService {
434 return SpringUtil.getBean(getClass()); 434 return SpringUtil.getBean(getClass());
435 } 435 }
436 436
  437 + @Override
  438 + public Long getDeviceCount(LocalDateTime createTime) {
  439 + return deviceMapper.selectCountByCreateTime(createTime);
  440 + }
  441 +
  442 + @Override
  443 + public Long getDeviceCountByState(Integer state) {
  444 + return deviceMapper.selectCountByState(state);
  445 + }
  446 +
  447 + @Override
  448 + public List<IotDeviceDO> getDeviceList() {
  449 + return deviceMapper.selectList();
  450 + }
  451 +
437 } 452 }
438 \ No newline at end of file 453 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProdu @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProdu
6 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; 6 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
7 import jakarta.validation.Valid; 7 import jakarta.validation.Valid;
8 8
  9 +import java.time.LocalDateTime;
9 import java.util.Collection; 10 import java.util.Collection;
10 import java.util.List; 11 import java.util.List;
11 import java.util.Map; 12 import java.util.Map;
@@ -83,4 +84,20 @@ public interface IotProductCategoryService { @@ -83,4 +84,20 @@ public interface IotProductCategoryService {
83 */ 84 */
84 List<IotProductCategoryDO> getProductCategoryListByStatus(Integer status); 85 List<IotProductCategoryDO> getProductCategoryListByStatus(Integer status);
85 86
  87 + /**
  88 + * 获得产品分类数量
  89 + *
  90 + * @param createTime 创建时间,如果为空,则统计所有分类数量
  91 + * @return 产品分类数量
  92 + */
  93 + Long getProductCategoryCount(LocalDateTime createTime);
  94 +
  95 +
  96 + /**
  97 + * 获得各产品分类下属的设备总数
  98 + *
  99 + * @return 产品分类名称和各产品分类下属的设备总数
  100 + */
  101 + Map<String,Integer> getDeviceCountsOfProductCategoryMap();
  102 +
86 } 103 }
87 \ No newline at end of file 104 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java
@@ -5,14 +5,20 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -5,14 +5,20 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
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.controller.admin.product.vo.category.IotProductCategorySaveReqVO; 7 import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO;
  8 +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
8 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; 9 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
  10 +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
9 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductCategoryMapper; 11 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductCategoryMapper;
  12 +import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
10 import jakarta.annotation.Resource; 13 import jakarta.annotation.Resource;
11 import org.springframework.stereotype.Service; 14 import org.springframework.stereotype.Service;
12 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
13 16
  17 +import java.time.LocalDateTime;
14 import java.util.Collection; 18 import java.util.Collection;
  19 +import java.util.HashMap;
15 import java.util.List; 20 import java.util.List;
  21 +import java.util.Map;
16 22
17 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 23 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
18 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_CATEGORY_NOT_EXISTS; 24 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_CATEGORY_NOT_EXISTS;
@@ -29,7 +35,12 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService @@ -29,7 +35,12 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService
29 @Resource 35 @Resource
30 private IotProductCategoryMapper productCategoryMapper; 36 private IotProductCategoryMapper productCategoryMapper;
31 37
32 - @Override 38 + @Resource
  39 + private IotProductService productService;
  40 +
  41 + @Resource
  42 + private IotDeviceService deviceService;
  43 +
33 public Long createProductCategory(IotProductCategorySaveReqVO createReqVO) { 44 public Long createProductCategory(IotProductCategorySaveReqVO createReqVO) {
34 // 插入 45 // 插入
35 IotProductCategoryDO productCategory = BeanUtils.toBean(createReqVO, IotProductCategoryDO.class); 46 IotProductCategoryDO productCategory = BeanUtils.toBean(createReqVO, IotProductCategoryDO.class);
@@ -84,4 +95,50 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService @@ -84,4 +95,50 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService
84 return productCategoryMapper.selectListByStatus(status); 95 return productCategoryMapper.selectListByStatus(status);
85 } 96 }
86 97
  98 + @Override
  99 + public Long getProductCategoryCount(LocalDateTime createTime) {
  100 + return productCategoryMapper.selectCountByCreateTime(createTime);
  101 + }
  102 +
  103 + @Override
  104 + public Map<String, Integer> getDeviceCountsOfProductCategoryMap() {
  105 + // 1. 获取所有数据
  106 + List<IotProductCategoryDO> categoryList = productCategoryMapper.selectList();
  107 + List<IotProductDO> productList = productService.getProductList();
  108 + List<IotDeviceDO> deviceList = deviceService.getDeviceList();
  109 +
  110 + // 2. 统计每个分类下的设备数量
  111 + Map<String, Integer> categoryDeviceCountMap = new HashMap<>();
  112 +
  113 + // 2.1 初始化所有分类的计数为0
  114 + for (IotProductCategoryDO category : categoryList) {
  115 + categoryDeviceCountMap.put(category.getName(), 0);
  116 + }
  117 +
  118 + // 2.2 构建产品ID到分类的映射
  119 + Map<Long, IotProductCategoryDO> productCategoryMap = new HashMap<>();
  120 + for (IotProductDO product : productList) {
  121 + Long categoryId = product.getCategoryId();
  122 + IotProductCategoryDO category = categoryList.stream()
  123 + .filter(c -> c.getId().equals(categoryId))
  124 + .findFirst()
  125 + .orElse(null);
  126 + if (category != null) {
  127 + productCategoryMap.put(product.getId(), category);
  128 + }
  129 + }
  130 +
  131 + // 2.3 统计每个分类下的设备数量
  132 + for (IotDeviceDO device : deviceList) {
  133 + Long productId = device.getProductId();
  134 + IotProductCategoryDO category = productCategoryMap.get(productId);
  135 + if (category != null) {
  136 + String categoryName = category.getName();
  137 + categoryDeviceCountMap.merge(categoryName, 1, Integer::sum);
  138 + }
  139 + }
  140 +
  141 + return categoryDeviceCountMap;
  142 + }
  143 +
87 } 144 }
88 \ No newline at end of file 145 \ No newline at end of file
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 java.time.LocalDateTime;
9 import java.util.List; 10 import java.util.List;
10 11
11 /** 12 /**
@@ -92,4 +93,20 @@ public interface IotProductService { @@ -92,4 +93,20 @@ public interface IotProductService {
92 */ 93 */
93 List<IotProductDO> getProductList(); 94 List<IotProductDO> getProductList();
94 95
  96 + /**
  97 + * 获得产品数量
  98 + *
  99 + * @param createTime 创建时间,如果为空,则统计所有产品数量
  100 + * @return 产品数量
  101 + */
  102 + Long getProductCount(LocalDateTime createTime);
  103 +
  104 + /**
  105 + * 获得产品列表,基于分类编号
  106 + *
  107 + * @param categoryId 分类编号
  108 + * @return 产品列表
  109 + */
  110 + List<IotProductDO> getProductListByCategoryId(Long categoryId);
  111 +
95 } 112 }
96 \ No newline at end of file 113 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
@@ -15,6 +15,7 @@ import org.springframework.context.annotation.Lazy; @@ -15,6 +15,7 @@ import org.springframework.context.annotation.Lazy;
15 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
16 import org.springframework.validation.annotation.Validated; 16 import org.springframework.validation.annotation.Validated;
17 17
  18 +import java.time.LocalDateTime;
18 import java.util.List; 19 import java.util.List;
19 import java.util.Objects; 20 import java.util.Objects;
20 21
@@ -137,4 +138,14 @@ public class IotProductServiceImpl implements IotProductService { @@ -137,4 +138,14 @@ public class IotProductServiceImpl implements IotProductService {
137 return productMapper.selectList(); 138 return productMapper.selectList();
138 } 139 }
139 140
  141 + @Override
  142 + public Long getProductCount(LocalDateTime createTime) {
  143 + return productMapper.selectCountByCreateTime(createTime);
  144 + }
  145 +
  146 + @Override
  147 + public List<IotProductDO> getProductListByCategoryId(Long categoryId) {
  148 + return productMapper.selectListByCategoryId(categoryId);
  149 + }
  150 +
140 } 151 }
141 \ No newline at end of file 152 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelS @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelS
7 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; 7 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
8 import jakarta.validation.Valid; 8 import jakarta.validation.Valid;
9 9
  10 +import java.time.LocalDateTime;
10 import java.util.List; 11 import java.util.List;
11 12
12 /** 13 /**
@@ -80,4 +81,12 @@ public interface IotThingModelService { @@ -80,4 +81,12 @@ public interface IotThingModelService {
80 */ 81 */
81 List<IotThingModelDO> getThingModelList(IotThingModelListReqVO reqVO); 82 List<IotThingModelDO> getThingModelList(IotThingModelListReqVO reqVO);
82 83
  84 + /**
  85 + * 获得物模型数量
  86 + *
  87 + * @param createTime 创建时间,如果为空,则统计所有物模型数量
  88 + * @return 物模型数量
  89 + */
  90 + Long getThingModelCount(LocalDateTime createTime);
  91 +
83 } 92 }
84 \ No newline at end of file 93 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service; @@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
29 import org.springframework.transaction.annotation.Transactional; 29 import org.springframework.transaction.annotation.Transactional;
30 import org.springframework.validation.annotation.Validated; 30 import org.springframework.validation.annotation.Validated;
31 31
  32 +import java.time.LocalDateTime;
32 import java.util.*; 33 import java.util.*;
33 34
34 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 35 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -363,4 +364,9 @@ public class IotThingModelServiceImpl implements IotThingModelService { @@ -363,4 +364,9 @@ public class IotThingModelServiceImpl implements IotThingModelService {
363 return SpringUtil.getBean(getClass()); 364 return SpringUtil.getBean(getClass());
364 } 365 }
365 366
  367 + @Override
  368 + public Long getThingModelCount(LocalDateTime createTime) {
  369 + return thingModelMapper.selectCountByCreateTime(createTime);
  370 + }
  371 +
366 } 372 }
yudao-server/src/main/resources/application-local.yaml
@@ -78,10 +78,10 @@ spring: @@ -78,10 +78,10 @@ spring:
78 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 78 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
79 data: 79 data:
80 redis: 80 redis:
81 - host: 127.0.0.1 # 地址 81 + host: chaojiniu.top # 地址
82 port: 6379 # 端口 82 port: 6379 # 端口
83 - database: 1 # 数据库索引  
84 - # password: 123456 # 密码,建议生产环境开启 83 + database: 15 # 数据库索引
  84 + password: fsknKD7UvQYZsyf2hXXn # 密码,建议生产环境开启
85 85
86 --- #################### 定时任务相关配置 #################### 86 --- #################### 定时任务相关配置 ####################
87 87