Commit 1995c322e7085aa125f90cc5ed1d557a7cf35d3d

Authored by 安浩浩
1 parent 1719b69e

【新增】 产品物模型分页

yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotThingModelTypeEnum.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductFunctionTypeEnum.java
... ... @@ -7,13 +7,13 @@ import lombok.Getter;
7 7 import java.util.Arrays;
8 8  
9 9 /**
10   - * IOT 物模型功能类型枚举类
  10 + * IOT 产品功能类型枚举类
11 11 *
12 12 * @author ahh
13 13 */
14 14 @AllArgsConstructor
15 15 @Getter
16   -public enum IotThingModelTypeEnum implements IntArrayValuable {
  16 +public enum IotProductFunctionTypeEnum implements IntArrayValuable {
17 17  
18 18 /**
19 19 * 属性
... ... @@ -28,7 +28,7 @@ public enum IotThingModelTypeEnum implements IntArrayValuable {
28 28 */
29 29 EVENT(3, "事件");
30 30  
31   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotThingModelTypeEnum::getType).toArray();
  31 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductFunctionTypeEnum::getType).toArray();
32 32  
33 33 /**
34 34 * 类型
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  6 +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
4 7 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO;
5 8 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
6 9 import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
... ... @@ -71,4 +74,12 @@ public class IotThinkModelFunctionController {
71 74 List<IotThinkModelFunctionRespVO> respVO = IotThinkModelFunctionConvert.INSTANCE.convertList(thinkModelFunctionListByProductId);
72 75 return success(respVO);
73 76 }
  77 +
  78 + @GetMapping("/page")
  79 + @Operation(summary = "获得IoT 产品物模型分页")
  80 + @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
  81 + public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) {
  82 + PageResult<IotThinkModelFunctionDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
  83 + return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class));
  84 + }
74 85 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/vo/IotThinkModelFunctionPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
  6 +import io.swagger.v3.oas.annotations.media.Schema;
  7 +import jakarta.validation.constraints.NotNull;
  8 +import lombok.Data;
  9 +import lombok.EqualsAndHashCode;
  10 +import lombok.ToString;
  11 +
  12 +@Schema(description = "管理后台 - IoT 产品物模型分页 Request VO")
  13 +@Data
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@ToString(callSuper = true)
  16 +public class IotThinkModelFunctionPageReqVO extends PageParam {
  17 +
  18 + @Schema(description = "功能标识")
  19 + private String identifier;
  20 +
  21 + @Schema(description = "功能名称", example = "张三")
  22 + private String name;
  23 +
  24 + @Schema(description = "功能类型", example = "1")
  25 + @InEnum(IotProductFunctionTypeEnum.class)
  26 + private Integer type;
  27 +
  28 + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED)
  29 + @NotNull(message = "产品ID不能为空")
  30 + private Long productId;
  31 +
  32 +}
0 33 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/vo/IotThinkModelFunctionSaveReqVO.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.validation.InEnum;
4 4 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
5 5 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
6 6 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
7   -import cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum;
  7 +import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
8 8 import io.swagger.v3.oas.annotations.media.Schema;
9 9 import jakarta.validation.constraints.NotEmpty;
10 10 import jakarta.validation.constraints.NotNull;
... ... @@ -38,7 +38,7 @@ public class IotThinkModelFunctionSaveReqVO {
38 38  
39 39 @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED)
40 40 @NotNull(message = "功能类型不能为空")
41   - @InEnum(IotThingModelTypeEnum.class)
  41 + @InEnum(IotProductFunctionTypeEnum.class)
42 42 private Integer type;
43 43  
44 44 @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thinkmodelfunction/IotThinkModelFunctionConvert.java
... ... @@ -6,7 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
6 6 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO;
7 7 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
8 8 import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
9   -import cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum;
  9 +import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
10 10 import org.mapstruct.Mapper;
11 11 import org.mapstruct.Mapping;
12 12 import org.mapstruct.factory.Mappers;
... ... @@ -26,21 +26,21 @@ public interface IotThinkModelFunctionConvert {
26 26 IotThinkModelFunctionDO convert(IotThinkModelFunctionSaveReqVO bean);
27 27  
28 28 default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) {
29   - if (Objects.equals(bean.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
  29 + if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
30 30 return bean.getProperty();
31 31 }
32 32 return null;
33 33 }
34 34  
35 35 default ThingModelEvent convertToEvent(IotThinkModelFunctionSaveReqVO bean) {
36   - if (Objects.equals(bean.getType(), IotThingModelTypeEnum.EVENT.getType())) {
  36 + if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.EVENT.getType())) {
37 37 return bean.getEvent();
38 38 }
39 39 return null;
40 40 }
41 41  
42 42 default ThingModelService convertToService(IotThinkModelFunctionSaveReqVO bean) {
43   - if (Objects.equals(bean.getType(), IotThingModelTypeEnum.SERVICE.getType())) {
  43 + if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.SERVICE.getType())) {
44 44 return bean.getService();
45 45 }
46 46 return null;
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodelfunction/IotThinkModelFunctionDO.java
... ... @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
5 5 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
6 6 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
7 7 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
  8 +import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
8 9 import com.baomidou.mybatisplus.annotation.KeySequence;
9 10 import com.baomidou.mybatisplus.annotation.TableField;
10 11 import com.baomidou.mybatisplus.annotation.TableId;
... ... @@ -65,7 +66,7 @@ public class IotThinkModelFunctionDO extends BaseDO {
65 66 /**
66 67 * 功能类型
67 68 * <p>
68   - * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum}
  69 + * 枚举 {@link IotProductFunctionTypeEnum}
69 70 */
70 71 private Integer type;
71 72  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodelfunction/IotThinkModelFunctionMapper.java
1 1 package cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction;
2 2  
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
3 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
4 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
5 7 import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
6 8 import org.apache.ibatis.annotations.Mapper;
7 9  
... ... @@ -15,6 +17,16 @@ import java.util.List;
15 17 @Mapper
16 18 public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFunctionDO> {
17 19  
  20 + default PageResult<IotThinkModelFunctionDO> selectPage(IotThinkModelFunctionPageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<IotThinkModelFunctionDO>()
  22 + .eqIfPresent(IotThinkModelFunctionDO::getIdentifier, reqVO.getIdentifier())
  23 + .likeIfPresent(IotThinkModelFunctionDO::getName, reqVO.getName())
  24 + .eqIfPresent(IotThinkModelFunctionDO::getType, reqVO.getType())
  25 + .eqIfPresent(IotThinkModelFunctionDO::getProductId, reqVO.getProductId())
  26 + .orderByDesc(IotThinkModelFunctionDO::getId));
  27 + }
  28 +
  29 +
18 30 default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) {
19 31 return selectOne(IotThinkModelFunctionDO::getProductId, productId,
20 32 IotThinkModelFunctionDO::getIdentifier, identifier);
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionService.java
1 1 package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
2 2  
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
3 5 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
4 6 import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
5 7 import jakarta.validation.Valid;
... ... @@ -51,4 +53,12 @@ public interface IotThinkModelFunctionService {
51 53 * @return 产品物模型列表
52 54 */
53 55 List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductId(Long productId);
  56 +
  57 + /**
  58 + * 获得产品物模型分页
  59 + *
  60 + * @param pageReqVO 分页查询
  61 + * @return 产品物模型分页
  62 + */
  63 + PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
54 64 }
55 65 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionServiceImpl.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ObjectUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
6 7 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
7 8 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
... ... @@ -11,12 +12,13 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
11 12 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArraySpecs;
12 13 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArrayType;
13 14 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelTextType;
  15 +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
14 16 import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
15 17 import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
16 18 import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
17 19 import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper;
18 20 import cn.iocoder.yudao.module.iot.enums.product.IotAccessModeEnum;
19   -import cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum;
  21 +import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
20 22 import jakarta.annotation.Resource;
21 23 import lombok.extern.slf4j.Slf4j;
22 24 import org.springframework.stereotype.Service;
... ... @@ -55,7 +57,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
55 57 thinkModelFunctionMapper.insert(function);
56 58  
57 59 // 3. 如果创建的是属性,需要更新默认的事件和服务
58   - if (Objects.equals(createReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
  60 + if (Objects.equals(createReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
59 61 createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
60 62 }
61 63 return function.getId();
... ... @@ -82,7 +84,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
82 84 thinkModelFunctionMapper.updateById(thinkModelFunction);
83 85  
84 86 // 4. 如果更新的是属性,需要更新默认的事件和服务
85   - if (Objects.equals(updateReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
  87 + if (Objects.equals(updateReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
86 88 createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey());
87 89 }
88 90 }
... ... @@ -107,7 +109,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
107 109 thinkModelFunctionMapper.deleteById(id);
108 110  
109 111 // 3. 如果删除的是属性,需要更新默认的事件和服务
110   - if (Objects.equals(functionDO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
  112 + if (Objects.equals(functionDO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
111 113 createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey());
112 114 }
113 115 }
... ... @@ -133,13 +135,18 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
133 135 return thinkModelFunctionMapper.selectListByProductId(productId);
134 136 }
135 137  
  138 + @Override
  139 + public PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO) {
  140 + return thinkModelFunctionMapper.selectPage(pageReqVO);
  141 + }
  142 +
136 143 /**
137 144 * 创建默认的事件和服务
138 145 */
139 146 public void createDefaultEventsAndServices(Long productId, String productKey) {
140 147 // 1. 获取当前属性列表
141 148 List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper
142   - .selectListByProductIdAndType(productId, IotThingModelTypeEnum.PROPERTY.getType());
  149 + .selectListByProductIdAndType(productId, IotProductFunctionTypeEnum.PROPERTY.getType());
143 150  
144 151 // 2. 生成新的事件和服务列表
145 152 List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>();
... ... @@ -166,7 +173,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
166 173 List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
167 174 productId,
168 175 Arrays.asList("post", "set", "get"),
169   - Arrays.asList(IotThingModelTypeEnum.EVENT.getType(), IotThingModelTypeEnum.SERVICE.getType())
  176 + Arrays.asList(IotProductFunctionTypeEnum.EVENT.getType(), IotProductFunctionTypeEnum.SERVICE.getType())
170 177 );
171 178  
172 179 // 3.1 使用 diffList 方法比较新旧列表
... ... @@ -229,7 +236,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
229 236 .setIdentifier(event.getIdentifier())
230 237 .setName(event.getName())
231 238 .setDescription(event.getDescription())
232   - .setType(IotThingModelTypeEnum.EVENT.getType())
  239 + .setType(IotProductFunctionTypeEnum.EVENT.getType())
233 240 .setEvent(event);
234 241 }
235 242  
... ... @@ -243,7 +250,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
243 250 .setIdentifier(service.getIdentifier())
244 251 .setName(service.getName())
245 252 .setDescription(service.getDescription())
246   - .setType(IotThingModelTypeEnum.SERVICE.getType())
  253 + .setType(IotProductFunctionTypeEnum.SERVICE.getType())
247 254 .setService(service);
248 255 }
249 256  
... ...