Commit 6d6547be392e6e22a345476775775d83f8660a72
1 parent
638976da
【功能新增】IoT: 规则场景基础 CRUD
Showing
10 changed files
with
272 additions
and
118 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
| ... | ... | @@ -72,4 +72,7 @@ public interface ErrorCodeConstants { |
| 72 | 72 | // ========== IoT 数据桥梁 1-050-010-000 ========== |
| 73 | 73 | ErrorCode DATA_BRIDGE_NOT_EXISTS = new ErrorCode(1_050_010_000, "IoT 数据桥梁不存在"); |
| 74 | 74 | |
| 75 | + // ========== IoT 规则场景(场景联动) 1-050-011-000 ========== | |
| 76 | + ErrorCode RULE_SCENE_NOT_EXISTS = new ErrorCode(1_050_011_000, "IoT 规则场景(场景联动)不存在"); | |
| 77 | + | |
| 75 | 78 | } |
| 76 | 79 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerConditionParameterOperatorEnum.java
| ... | ... | @@ -50,7 +50,7 @@ public enum IotRuleSceneTriggerConditionParameterOperatorEnum implements ArrayVa |
| 50 | 50 | /** |
| 51 | 51 | * Spring 表达式 - 目标值数组 |
| 52 | 52 | */ |
| 53 | - public static final String SPRING_EXPRESSION_VALUE_List = "values"; | |
| 53 | + public static final String SPRING_EXPRESSION_VALUE_LIST = "values"; | |
| 54 | 54 | |
| 55 | 55 | public static IotRuleSceneTriggerConditionParameterOperatorEnum operatorOf(String operator) { |
| 56 | 56 | return ArrayUtil.firstMatch(item -> item.getOperator().equals(operator), values()); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.rule; |
| 2 | 2 | |
| 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.rule.vo.scene.IotRuleScenePageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneRespVO; | |
| 8 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 3 | 10 | import cn.iocoder.yudao.module.iot.service.rule.IotRuleSceneService; |
| 11 | +import io.swagger.v3.oas.annotations.Operation; | |
| 12 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 4 | 13 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 5 | 14 | import jakarta.annotation.Resource; |
| 6 | 15 | import jakarta.annotation.security.PermitAll; |
| 16 | +import jakarta.validation.Valid; | |
| 17 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | 18 | import org.springframework.validation.annotation.Validated; |
| 8 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 9 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 10 | -import org.springframework.web.bind.annotation.RestController; | |
| 19 | +import org.springframework.web.bind.annotation.*; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 11 | 22 | |
| 12 | 23 | @Tag(name = "管理后台 - IoT 规则场景") |
| 13 | 24 | @RestController |
| ... | ... | @@ -18,6 +29,47 @@ public class IotRuleSceneController { |
| 18 | 29 | @Resource |
| 19 | 30 | private IotRuleSceneService ruleSceneService; |
| 20 | 31 | |
| 32 | + @PostMapping("/create") | |
| 33 | + @Operation(summary = "创建规则场景(场景联动)") | |
| 34 | + @PreAuthorize("@ss.hasPermission('iot:rule-scene:create')") | |
| 35 | + public CommonResult<Long> createRuleScene(@Valid @RequestBody IotRuleSceneSaveReqVO createReqVO) { | |
| 36 | + return success(ruleSceneService.createRuleScene(createReqVO)); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @PutMapping("/update") | |
| 40 | + @Operation(summary = "更新规则场景(场景联动)") | |
| 41 | + @PreAuthorize("@ss.hasPermission('iot:rule-scene:update')") | |
| 42 | + public CommonResult<Boolean> updateRuleScene(@Valid @RequestBody IotRuleSceneSaveReqVO updateReqVO) { | |
| 43 | + ruleSceneService.updateRuleScene(updateReqVO); | |
| 44 | + return success(true); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @DeleteMapping("/delete") | |
| 48 | + @Operation(summary = "删除规则场景(场景联动)") | |
| 49 | + @Parameter(name = "id", description = "编号", required = true) | |
| 50 | + @PreAuthorize("@ss.hasPermission('iot:rule-scene:delete')") | |
| 51 | + public CommonResult<Boolean> deleteRuleScene(@RequestParam("id") Long id) { | |
| 52 | + ruleSceneService.deleteRuleScene(id); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @GetMapping("/get") | |
| 57 | + @Operation(summary = "获得规则场景(场景联动)") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 59 | + @PreAuthorize("@ss.hasPermission('iot:rule-scene:query')") | |
| 60 | + public CommonResult<IotRuleSceneRespVO> getRuleScene(@RequestParam("id") Long id) { | |
| 61 | + IotRuleSceneDO ruleScene = ruleSceneService.getRuleScene(id); | |
| 62 | + return success(BeanUtils.toBean(ruleScene, IotRuleSceneRespVO.class)); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @GetMapping("/page") | |
| 66 | + @Operation(summary = "获得规则场景(场景联动)分页") | |
| 67 | + @PreAuthorize("@ss.hasPermission('iot:rule-scene:query')") | |
| 68 | + public CommonResult<PageResult<IotRuleSceneRespVO>> getRuleScenePage(@Valid IotRuleScenePageReqVO pageReqVO) { | |
| 69 | + PageResult<IotRuleSceneDO> pageResult = ruleSceneService.getRuleScenePage(pageReqVO); | |
| 70 | + return success(BeanUtils.toBean(pageResult, IotRuleSceneRespVO.class)); | |
| 71 | + } | |
| 72 | + | |
| 21 | 73 | @GetMapping("/test") |
| 22 | 74 | @PermitAll |
| 23 | 75 | public void test() { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/IotRuleScenePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - IoT 规则场景(场景联动)分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class IotRuleScenePageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "场景名称", example = "赵六") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @Schema(description = "场景描述", example = "你猜") | |
| 24 | + private String description; | |
| 25 | + | |
| 26 | + @Schema(description = "场景状态", example = "1") | |
| 27 | + private Integer status; | |
| 28 | + | |
| 29 | + @Schema(description = "创建时间") | |
| 30 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 31 | + private LocalDateTime[] createTime; | |
| 32 | + | |
| 33 | +} | |
| 0 | 34 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/IotRuleSceneRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - IoT 规则场景(场景联动) Response VO") | |
| 9 | +@Data | |
| 10 | +public class IotRuleSceneRespVO { | |
| 11 | + | |
| 12 | + @Schema(description = "场景编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15865") | |
| 13 | + private Long id; | |
| 14 | + | |
| 15 | + @Schema(description = "场景名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 16 | + private String name; | |
| 17 | + | |
| 18 | + @Schema(description = "场景描述", example = "你猜") | |
| 19 | + private String description; | |
| 20 | + | |
| 21 | + @Schema(description = "场景状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 22 | + private Integer status; | |
| 23 | + | |
| 24 | + @Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | + private String triggers; | |
| 26 | + | |
| 27 | + @Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 28 | + private String actions; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + private LocalDateTime createTime; | |
| 32 | + | |
| 33 | +} | |
| 0 | 34 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/IotRuleSceneSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import jakarta.validation.constraints.NotEmpty; | |
| 7 | +import jakarta.validation.constraints.NotNull; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - IoT 规则场景(场景联动)新增/修改 Request VO") | |
| 11 | +@Data | |
| 12 | +public class IotRuleSceneSaveReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "场景编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15865") | |
| 15 | + private Long id; | |
| 16 | + | |
| 17 | + @Schema(description = "场景名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 18 | + @NotEmpty(message = "场景名称不能为空") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "场景描述", example = "你猜") | |
| 22 | + private String description; | |
| 23 | + | |
| 24 | + @Schema(description = "场景状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | |
| 25 | + @NotNull(message = "场景状态不能为空") | |
| 26 | + @InEnum(CommonStatusEnum.class) | |
| 27 | + private Integer status; | |
| 28 | + | |
| 29 | + @Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 30 | + @NotEmpty(message = "触发器数组不能为空") | |
| 31 | + private String triggers; | |
| 32 | + | |
| 33 | + @Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 34 | + @NotEmpty(message = "执行器数组不能为空") | |
| 35 | + private String actions; | |
| 36 | + | |
| 37 | +} | |
| 0 | 38 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.http deleted
| 1 | -### 请求 /iot/think-model-function/create 接口 => 成功 | |
| 2 | -POST {{baseUrl}}/iot/think-model-function/create | |
| 3 | -Content-Type: application/json | |
| 4 | -tenant-id: {{adminTenantId}} | |
| 5 | -Authorization: Bearer {{token}} | |
| 6 | - | |
| 7 | -{ | |
| 8 | - "productId": 1001, | |
| 9 | - "productKey": "smart-sensor-001", | |
| 10 | - "identifier": "Temperature", | |
| 11 | - "name": "温度", | |
| 12 | - "description": "当前温度值", | |
| 13 | - "type": 1, | |
| 14 | - "property": { | |
| 15 | - "identifier": "Temperature", | |
| 16 | - "name": "温度", | |
| 17 | - "accessMode": "r", | |
| 18 | - "required": true, | |
| 19 | - "dataType": { | |
| 20 | - "type": "float", | |
| 21 | - "specs": { | |
| 22 | - "min": -10.0, | |
| 23 | - "max": 100.0, | |
| 24 | - "step": 0.1, | |
| 25 | - "unit": "℃" | |
| 26 | - } | |
| 27 | - }, | |
| 28 | - "description": "当前温度值" | |
| 29 | - } | |
| 30 | -} | |
| 31 | - | |
| 32 | -### 请求 /iot/think-model-function/create 接口 => 成功 | |
| 33 | -POST {{baseUrl}}/iot/think-model-function/create | |
| 34 | -Content-Type: application/json | |
| 35 | -tenant-id: {{adminTenantId}} | |
| 36 | -Authorization: Bearer {{token}} | |
| 37 | - | |
| 38 | -{ | |
| 39 | - "productId": 1001, | |
| 40 | - "productKey": "smart-sensor-001", | |
| 41 | - "identifier": "Humidity", | |
| 42 | - "name": "湿度", | |
| 43 | - "description": "当前湿度值", | |
| 44 | - "type": 1, | |
| 45 | - "property": { | |
| 46 | - "identifier": "Humidity", | |
| 47 | - "name": "湿度", | |
| 48 | - "accessMode": "r", | |
| 49 | - "required": true, | |
| 50 | - "dataType": { | |
| 51 | - "type": "float", | |
| 52 | - "specs": { | |
| 53 | - "min": 0.0, | |
| 54 | - "max": 100.0, | |
| 55 | - "step": 0.1, | |
| 56 | - "unit": "%" | |
| 57 | - } | |
| 58 | - }, | |
| 59 | - "description": "当前湿度值" | |
| 60 | - } | |
| 61 | -} | |
| 62 | - | |
| 63 | - | |
| 64 | - | |
| 65 | - | |
| 66 | -### 请求 /iot/think-model-function/update 接口 => 成功 | |
| 67 | -PUT {{baseUrl}}/iot/think-model-function/update | |
| 68 | -Content-Type: application/json | |
| 69 | -tenant-id: {{adminTenantId}} | |
| 70 | -Authorization: Bearer {{token}} | |
| 71 | - | |
| 72 | -{ | |
| 73 | - "id": 11, | |
| 74 | - "productId": 1001, | |
| 75 | - "productKey": "smart-sensor-001", | |
| 76 | - "identifier": "Temperature", | |
| 77 | - "name": "温度", | |
| 78 | - "description": "当前温度值", | |
| 79 | - "type": 1, | |
| 80 | - "property": { | |
| 81 | - "identifier": "Temperature", | |
| 82 | - "name": "温度", | |
| 83 | - "accessMode": "r", | |
| 84 | - "required": true, | |
| 85 | - "dataType": { | |
| 86 | - "type": "float", | |
| 87 | - "specs": { | |
| 88 | - "min": -111.0, | |
| 89 | - "max": 222.0, | |
| 90 | - "step": 0.1, | |
| 91 | - "unit": "℃" | |
| 92 | - } | |
| 93 | - }, | |
| 94 | - "description": "当前温度值" | |
| 95 | - } | |
| 96 | -} | |
| 97 | - | |
| 98 | -### 请求 /iot/think-model-function/delete 接口 => 成功 | |
| 99 | -DELETE {{baseUrl}}/iot/think-model-function/delete?id=7 | |
| 100 | -tenant-id: {{adminTenantId}} | |
| 101 | -Authorization: Bearer {{token}} | |
| 102 | - | |
| 103 | -### 请求 /iot/think-model-function/get 接口 => 成功 | |
| 104 | -GET {{baseUrl}}/iot/think-model-function/get?id=10 | |
| 105 | -tenant-id: {{adminTenantId}} | |
| 106 | -Authorization: Bearer {{token}} | |
| 107 | - | |
| 108 | - | |
| 109 | -### 请求 /iot/think-model-function/list-by-product-id 接口 => 成功 | |
| 110 | -GET {{baseUrl}}/iot/think-model-function/list-by-product-id?productId=1001 | |
| 111 | -tenant-id: {{adminTenantId}} | |
| 112 | -Authorization: Bearer {{token}} | |
| 113 | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.dal.mysql.rule; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 3 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO; | |
| 4 | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; |
| 5 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 9 | |
| 10 | +/** | |
| 11 | + * IoT 规则场景(场景联动) Mapper | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 7 | 15 | @Mapper |
| 8 | 16 | public interface IotRuleSceneMapper extends BaseMapperX<IotRuleSceneDO> { |
| 9 | 17 | |
| 18 | + default PageResult<IotRuleSceneDO> selectPage(IotRuleScenePageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<IotRuleSceneDO>() | |
| 20 | + .likeIfPresent(IotRuleSceneDO::getName, reqVO.getName()) | |
| 21 | + .likeIfPresent(IotRuleSceneDO::getDescription, reqVO.getDescription()) | |
| 22 | + .eqIfPresent(IotRuleSceneDO::getStatus, reqVO.getStatus()) | |
| 23 | + .betweenIfPresent(IotRuleSceneDO::getCreateTime, reqVO.getCreateTime()) | |
| 24 | + .orderByDesc(IotRuleSceneDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 10 | 27 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneService.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.rule; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO; | |
| 3 | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; |
| 4 | 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; |
| 5 | 8 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 9 | +import jakarta.validation.Valid; | |
| 6 | 10 | |
| 7 | 11 | import java.util.List; |
| 8 | 12 | |
| ... | ... | @@ -14,6 +18,44 @@ import java.util.List; |
| 14 | 18 | public interface IotRuleSceneService { |
| 15 | 19 | |
| 16 | 20 | /** |
| 21 | + * 创建规则场景(场景联动) | |
| 22 | + * | |
| 23 | + * @param createReqVO 创建信息 | |
| 24 | + * @return 编号 | |
| 25 | + */ | |
| 26 | + Long createRuleScene(@Valid IotRuleSceneSaveReqVO createReqVO); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 更新规则场景(场景联动) | |
| 30 | + * | |
| 31 | + * @param updateReqVO 更新信息 | |
| 32 | + */ | |
| 33 | + void updateRuleScene(@Valid IotRuleSceneSaveReqVO updateReqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 删除规则场景(场景联动) | |
| 37 | + * | |
| 38 | + * @param id 编号 | |
| 39 | + */ | |
| 40 | + void deleteRuleScene(Long id); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 获得规则场景(场景联动) | |
| 44 | + * | |
| 45 | + * @param id 编号 | |
| 46 | + * @return 规则场景(场景联动) | |
| 47 | + */ | |
| 48 | + IotRuleSceneDO getRuleScene(Long id); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 获得规则场景(场景联动)分页 | |
| 52 | + * | |
| 53 | + * @param pageReqVO 分页查询 | |
| 54 | + * @return 规则场景(场景联动)分页 | |
| 55 | + */ | |
| 56 | + PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO); | |
| 57 | + | |
| 58 | + /** | |
| 17 | 59 | * 【缓存】获得指定设备的场景列表 |
| 18 | 60 | * |
| 19 | 61 | * @param productKey 产品 Key | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java
| ... | ... | @@ -8,11 +8,15 @@ import cn.hutool.core.util.NumberUtil; |
| 8 | 8 | import cn.hutool.core.util.ObjUtil; |
| 9 | 9 | import cn.hutool.core.util.StrUtil; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 11 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 11 | 12 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| 13 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 12 | 14 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 13 | 15 | import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; |
| 14 | 16 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; |
| 15 | 17 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 18 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO; | |
| 19 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO; | |
| 16 | 20 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; |
| 17 | 21 | import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotRuleSceneMapper; |
| 18 | 22 | import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; |
| ... | ... | @@ -39,8 +43,10 @@ import java.util.HashMap; |
| 39 | 43 | import java.util.List; |
| 40 | 44 | import java.util.Map; |
| 41 | 45 | |
| 46 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 42 | 47 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 43 | 48 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| 49 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.RULE_SCENE_NOT_EXISTS; | |
| 44 | 50 | |
| 45 | 51 | /** |
| 46 | 52 | * IoT 规则场景 Service 实现类 |
| ... | ... | @@ -61,6 +67,49 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 61 | 67 | @Resource(name = "iotSchedulerManager") |
| 62 | 68 | private IotSchedulerManager schedulerManager; |
| 63 | 69 | |
| 70 | + @Override | |
| 71 | + public Long createRuleScene(IotRuleSceneSaveReqVO createReqVO) { | |
| 72 | + // 插入 | |
| 73 | + IotRuleSceneDO ruleScene = BeanUtils.toBean(createReqVO, IotRuleSceneDO.class); | |
| 74 | + ruleSceneMapper.insert(ruleScene); | |
| 75 | + // 返回 | |
| 76 | + return ruleScene.getId(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Override | |
| 80 | + public void updateRuleScene(IotRuleSceneSaveReqVO updateReqVO) { | |
| 81 | + // 校验存在 | |
| 82 | + validateRuleSceneExists(updateReqVO.getId()); | |
| 83 | + // 更新 | |
| 84 | + IotRuleSceneDO updateObj = BeanUtils.toBean(updateReqVO, IotRuleSceneDO.class); | |
| 85 | + ruleSceneMapper.updateById(updateObj); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + public void deleteRuleScene(Long id) { | |
| 90 | + // 校验存在 | |
| 91 | + validateRuleSceneExists(id); | |
| 92 | + // 删除 | |
| 93 | + ruleSceneMapper.deleteById(id); | |
| 94 | + } | |
| 95 | + | |
| 96 | + private void validateRuleSceneExists(Long id) { | |
| 97 | + if (ruleSceneMapper.selectById(id) == null) { | |
| 98 | + throw exception(RULE_SCENE_NOT_EXISTS); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Override | |
| 103 | + public IotRuleSceneDO getRuleScene(Long id) { | |
| 104 | + return ruleSceneMapper.selectById(id); | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO) { | |
| 109 | + return ruleSceneMapper.selectPage(pageReqVO); | |
| 110 | + } | |
| 111 | + | |
| 112 | + | |
| 64 | 113 | // TODO 芋艿,缓存待实现 |
| 65 | 114 | @Override |
| 66 | 115 | @TenantIgnore // 忽略租户隔离:因为 IotRuleSceneMessageHandler 调用时,一般未传递租户,所以需要忽略 |
| ... | ... | @@ -331,7 +380,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 331 | 380 | springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_SOURCE, messageValue); |
| 332 | 381 | springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE, parameter.getValue()); |
| 333 | 382 | List<String> parameterValues = StrUtil.splitTrim(parameter.getValue(), CharPool.COMMA); |
| 334 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_List, parameterValues); | |
| 383 | + springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_LIST, parameterValues); | |
| 335 | 384 | // 特殊:解决数字的比较。因为 Spring 是基于它的 compareTo 方法,对数字的比较存在问题! |
| 336 | 385 | if (ObjectUtils.equalsAny(operator, IotRuleSceneTriggerConditionParameterOperatorEnum.BETWEEN, |
| 337 | 386 | IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_BETWEEN, |
| ... | ... | @@ -345,7 +394,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 345 | 394 | NumberUtil.parseDouble(messageValue)); |
| 346 | 395 | springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE, |
| 347 | 396 | NumberUtil.parseDouble(parameter.getValue())); |
| 348 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_List, | |
| 397 | + springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_LIST, | |
| 349 | 398 | convertList(parameterValues, NumberUtil::parseDouble)); |
| 350 | 399 | } |
| 351 | 400 | // 2.2 计算 Spring 表达式 | ... | ... |