Commit 2f9d760327e885f626333da0b1ce549e429247e1

Authored by YunaiV
1 parent 35dd91d6

【代码评审】IoT:场景联动 review

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*; @@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
20 20
21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
22 22
  23 +// TODO @芋艿:规则场景 要不要,统一改成 场景联动
23 @Tag(name = "管理后台 - IoT 规则场景") 24 @Tag(name = "管理后台 - IoT 规则场景")
24 @RestController 25 @RestController
25 @RequestMapping("/iot/rule-scene") 26 @RequestMapping("/iot/rule-scene")
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/IotRuleScenePageReqVO.java
1 package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene; 1 package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene;
2 2
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 import cn.iocoder.yudao.framework.common.pojo.PageParam; 4 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  5 +import cn.iocoder.yudao.framework.common.validation.InEnum;
4 import io.swagger.v3.oas.annotations.media.Schema; 6 import io.swagger.v3.oas.annotations.media.Schema;
5 import lombok.Data; 7 import lombok.Data;
6 import lombok.EqualsAndHashCode; 8 import lombok.EqualsAndHashCode;
@@ -24,6 +26,7 @@ public class IotRuleScenePageReqVO extends PageParam { @@ -24,6 +26,7 @@ public class IotRuleScenePageReqVO extends PageParam {
24 private String description; 26 private String description;
25 27
26 @Schema(description = "场景状态", example = "1") 28 @Schema(description = "场景状态", example = "1")
  29 + @InEnum(CommonStatusEnum.class)
27 private Integer status; 30 private Integer status;
28 31
29 @Schema(description = "创建时间") 32 @Schema(description = "创建时间")
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneActionConfig.java
@@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
4 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; 4 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
5 import lombok.Data; 5 import lombok.Data;
6 6
  7 +// TODO @puhui999:这个要不内嵌到 IoTRuleSceneDO 里面?
7 /** 8 /**
8 * 执行器配置 9 * 执行器配置
9 * 10 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneActionDeviceControl.java
@@ -9,6 +9,7 @@ import lombok.Data; @@ -9,6 +9,7 @@ import lombok.Data;
9 import java.util.List; 9 import java.util.List;
10 import java.util.Map; 10 import java.util.Map;
11 11
  12 +// TODO @puhui999:这个要不内嵌到 IoTRuleSceneDO 里面?
12 /** 13 /**
13 * 执行设备控制 14 * 执行设备控制
14 * 15 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneTriggerCondition.java
@@ -6,6 +6,7 @@ import lombok.Data; @@ -6,6 +6,7 @@ import lombok.Data;
6 6
7 import java.util.List; 7 import java.util.List;
8 8
  9 +// TODO @puhui999:这个要不内嵌到 IoTRuleSceneDO 里面?
9 /** 10 /**
10 * 触发条件 11 * 触发条件
11 * 12 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneTriggerConditionParameter.java
@@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
4 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; 4 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum;
5 import lombok.Data; 5 import lombok.Data;
6 6
  7 +// TODO @puhui999:这个要不内嵌到 IoTRuleSceneDO 里面?
7 /** 8 /**
8 * 触发条件参数 9 * 触发条件参数
9 * 10 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneTriggerConfig.java
@@ -7,6 +7,7 @@ import lombok.Data; @@ -7,6 +7,7 @@ import lombok.Data;
7 7
8 import java.util.List; 8 import java.util.List;
9 9
  10 +// TODO @puhui999:这个要不内嵌到 IoTRuleSceneDO 里面?
10 /** 11 /**
11 * 触发器配置 12 * 触发器配置
12 * 13 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java
@@ -61,15 +61,15 @@ public class IotThingModelController { @@ -61,15 +61,15 @@ public class IotThingModelController {
61 return success(BeanUtils.toBean(thingModel, IotThingModelRespVO.class)); 61 return success(BeanUtils.toBean(thingModel, IotThingModelRespVO.class));
62 } 62 }
63 63
  64 + // TODO @puhui999:要不叫 get-tsl,去掉 product-id;后续,把
64 @GetMapping("/tsl-by-product-id") 65 @GetMapping("/tsl-by-product-id")
65 @Operation(summary = "获得产品物模型 TSL") 66 @Operation(summary = "获得产品物模型 TSL")
66 - @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") 67 + @Parameter(name = "productId", description = "产品 ID", required = true, example = "1024")
67 @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") 68 @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
68 public CommonResult<IotThingModelTSLRespVO> getThingModelTslByProductId(@RequestParam("productId") Long productId) { 69 public CommonResult<IotThingModelTSLRespVO> getThingModelTslByProductId(@RequestParam("productId") Long productId) {
69 return success(thingModelService.getThingModelTslByProductId(productId)); 70 return success(thingModelService.getThingModelTslByProductId(productId));
70 } 71 }
71 72
72 - // TODO @puhui @super:getThingModelListByProductId 和 getThingModelListByProductId 可以融合么?  
73 @GetMapping("/list") 73 @GetMapping("/list")
74 @Operation(summary = "获得产品物模型列表") 74 @Operation(summary = "获得产品物模型列表")
75 @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") 75 @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
@@ -151,26 +151,27 @@ public class IotThingModelServiceImpl implements IotThingModelService { @@ -151,26 +151,27 @@ public class IotThingModelServiceImpl implements IotThingModelService {
151 return thingModelMapper.selectList(reqVO); 151 return thingModelMapper.selectList(reqVO);
152 } 152 }
153 153
  154 + // TODO @puhui999:这个转换,放在 controller 貌似也行?
154 @Override 155 @Override
155 public IotThingModelTSLRespVO getThingModelTslByProductId(Long productId) { 156 public IotThingModelTSLRespVO getThingModelTslByProductId(Long productId) {
156 IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO(); 157 IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO();
157 // 1. 获得产品所有物模型定义 158 // 1. 获得产品所有物模型定义
158 - List<IotThingModelDO> thingModelList = thingModelMapper.selectListByProductId(productId);  
159 - if (CollUtil.isEmpty(thingModelList)) { 159 + List<IotThingModelDO> thingModels = thingModelMapper.selectListByProductId(productId);
  160 + if (CollUtil.isEmpty(thingModels)) {
160 return tslRespVO; 161 return tslRespVO;
161 } 162 }
162 163
163 // 2.1 设置公共部分参数 164 // 2.1 设置公共部分参数
164 - IotThingModelDO thingModel = thingModelList.get(0); 165 + IotThingModelDO thingModel = thingModels.get(0);
165 tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey()); 166 tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey());
166 // 2.2 处理属性列表 167 // 2.2 处理属性列表
167 - tslRespVO.setProperties(convertList(filterList(thingModelList, item -> 168 + tslRespVO.setProperties(convertList(filterList(thingModels, item ->
168 ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty)); 169 ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty));
169 // 2.3 处理服务列表 170 // 2.3 处理服务列表
170 - tslRespVO.setServices(convertList(filterList(thingModelList, item -> 171 + tslRespVO.setServices(convertList(filterList(thingModels, item ->
171 ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService)); 172 ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService));
172 // 2.4 处理事件列表 173 // 2.4 处理事件列表
173 - tslRespVO.setEvents(convertList(filterList(thingModelList, item -> 174 + tslRespVO.setEvents(convertList(filterList(thingModels, item ->
174 ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent)); 175 ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent));
175 return tslRespVO; 176 return tslRespVO;
176 } 177 }