Commit db03c6d7a84ee9535a802ad087498442fac4c951

Authored by YunaiV
1 parent 779cde24

feat:【IoT 物联网】新增告警记录管理功能,包括告警记录接口和前端展示页面

Showing 21 changed files with 442 additions and 32 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java
1 package cn.iocoder.yudao.framework.mybatis.config; 1 package cn.iocoder.yudao.framework.mybatis.config;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.hutool.core.util.StrUtil; 4 import cn.hutool.core.util.StrUtil;
4 import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler; 5 import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler;
5 import com.baomidou.mybatisplus.annotation.DbType; 6 import com.baomidou.mybatisplus.annotation.DbType;
6 import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; 7 import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
7 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; 8 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
8 import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; 9 import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
  10 +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
9 import com.baomidou.mybatisplus.extension.incrementer.*; 11 import com.baomidou.mybatisplus.extension.incrementer.*;
10 import com.baomidou.mybatisplus.extension.parser.JsqlParserGlobal; 12 import com.baomidou.mybatisplus.extension.parser.JsqlParserGlobal;
11 import com.baomidou.mybatisplus.extension.parser.cache.JdkSerialCaffeineJsqlParseCache; 13 import com.baomidou.mybatisplus.extension.parser.cache.JdkSerialCaffeineJsqlParseCache;
12 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 14 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
13 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 15 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
  16 +import com.fasterxml.jackson.databind.ObjectMapper;
14 import org.apache.ibatis.annotations.Mapper; 17 import org.apache.ibatis.annotations.Mapper;
15 import org.mybatis.spring.annotation.MapperScan; 18 import org.mybatis.spring.annotation.MapperScan;
16 import org.springframework.boot.autoconfigure.AutoConfiguration; 19 import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -18,6 +21,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -18,6 +21,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
18 import org.springframework.context.annotation.Bean; 21 import org.springframework.context.annotation.Bean;
19 import org.springframework.core.env.ConfigurableEnvironment; 22 import org.springframework.core.env.ConfigurableEnvironment;
20 23
  24 +import java.util.List;
21 import java.util.concurrent.TimeUnit; 25 import java.util.concurrent.TimeUnit;
22 26
23 /** 27 /**
@@ -73,4 +77,11 @@ public class YudaoMybatisAutoConfiguration { @@ -73,4 +77,11 @@ public class YudaoMybatisAutoConfiguration {
73 throw new IllegalArgumentException(StrUtil.format("DbType{} 找不到合适的 IKeyGenerator 实现类", dbType)); 77 throw new IllegalArgumentException(StrUtil.format("DbType{} 找不到合适的 IKeyGenerator 实现类", dbType));
74 } 78 }
75 79
  80 + @Bean
  81 + public JacksonTypeHandler jacksonTypeHandler(List<ObjectMapper> objectMappers) {
  82 + // 特殊:设置 JacksonTypeHandler 的 ObjectMapper!
  83 + JacksonTypeHandler.setObjectMapper(CollUtil.getFirst(objectMappers));
  84 + return new JacksonTypeHandler(Object.class);
  85 + }
  86 +
76 } 87 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertConfigController.java
1 package cn.iocoder.yudao.module.iot.controller.admin.alert; 1 package cn.iocoder.yudao.module.iot.controller.admin.alert;
2 2
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -15,15 +16,18 @@ import io.swagger.v3.oas.annotations.Parameter; @@ -15,15 +16,18 @@ import io.swagger.v3.oas.annotations.Parameter;
15 import io.swagger.v3.oas.annotations.tags.Tag; 16 import io.swagger.v3.oas.annotations.tags.Tag;
16 import jakarta.annotation.Resource; 17 import jakarta.annotation.Resource;
17 import jakarta.validation.Valid; 18 import jakarta.validation.Valid;
  19 +
18 import org.springframework.security.access.prepost.PreAuthorize; 20 import org.springframework.security.access.prepost.PreAuthorize;
19 import org.springframework.validation.annotation.Validated; 21 import org.springframework.validation.annotation.Validated;
20 import org.springframework.web.bind.annotation.*; 22 import org.springframework.web.bind.annotation.*;
21 23
  24 +import java.util.List;
22 import java.util.Map; 25 import java.util.Map;
23 import java.util.Objects; 26 import java.util.Objects;
24 import java.util.stream.Collectors; 27 import java.util.stream.Collectors;
25 28
26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 29 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  30 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
27 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; 31 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
28 32
29 @Tag(name = "管理后台 - IoT 告警配置") 33 @Tag(name = "管理后台 - IoT 告警配置")
@@ -34,7 +38,7 @@ public class IotAlertConfigController { @@ -34,7 +38,7 @@ public class IotAlertConfigController {
34 38
35 @Resource 39 @Resource
36 private IotAlertConfigService alertConfigService; 40 private IotAlertConfigService alertConfigService;
37 - 41 +
38 @Resource 42 @Resource
39 private AdminUserApi adminUserApi; 43 private AdminUserApi adminUserApi;
40 44
@@ -76,12 +80,26 @@ public class IotAlertConfigController { @@ -76,12 +80,26 @@ public class IotAlertConfigController {
76 @PreAuthorize("@ss.hasPermission('iot:alert-config:query')") 80 @PreAuthorize("@ss.hasPermission('iot:alert-config:query')")
77 public CommonResult<PageResult<IotAlertConfigRespVO>> getAlertConfigPage(@Valid IotAlertConfigPageReqVO pageReqVO) { 81 public CommonResult<PageResult<IotAlertConfigRespVO>> getAlertConfigPage(@Valid IotAlertConfigPageReqVO pageReqVO) {
78 PageResult<IotAlertConfigDO> pageResult = alertConfigService.getAlertConfigPage(pageReqVO); 82 PageResult<IotAlertConfigDO> pageResult = alertConfigService.getAlertConfigPage(pageReqVO);
  83 +
79 // 转换返回 84 // 转换返回
80 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( 85 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
81 convertSetByFlatMap(pageResult.getList(), config -> config.getReceiveUserIds().stream())); 86 convertSetByFlatMap(pageResult.getList(), config -> config.getReceiveUserIds().stream()));
82 - return success(BeanUtils.toBean(pageResult, IotAlertConfigRespVO.class, vo ->  
83 - vo.setReceiveUserNames(vo.getReceiveUserIds().stream().map(userMap::get)  
84 - .filter(Objects::nonNull).map(AdminUserRespDTO::getNickname).collect(Collectors.toList())))); 87 + return success(BeanUtils.toBean(pageResult, IotAlertConfigRespVO.class, vo -> {
  88 + vo.setReceiveUserNames(vo.getReceiveUserIds().stream()
  89 + .map(userMap::get)
  90 + .filter(Objects::nonNull)
  91 + .map(AdminUserRespDTO::getNickname)
  92 + .collect(Collectors.toList()));
  93 + }));
  94 + }
  95 +
  96 + @GetMapping("/simple-list")
  97 + @Operation(summary = "获得告警配置简单列表", description = "只包含被开启的告警配置,主要用于前端的下拉选项")
  98 + @PreAuthorize("@ss.hasPermission('iot:alert-config:query')")
  99 + public CommonResult<List<IotAlertConfigRespVO>> getAlertConfigSimpleList() {
  100 + List<IotAlertConfigDO> list = alertConfigService.getAlertConfigListByStatus(CommonStatusEnum.ENABLE.getStatus());
  101 + return success(convertList(list, config -> // 只返回 id、name 字段
  102 + new IotAlertConfigRespVO().setId(config.getId()).setName(config.getName())));
85 } 103 }
86 104
87 } 105 }
88 \ No newline at end of file 106 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertRecordController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert;
  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.alert.vo.recrod.IotAlertRecordPageReqVO;
  7 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordProcessReqVO;
  8 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordRespVO;
  9 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
  10 +import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
  11 +import io.swagger.v3.oas.annotations.Operation;
  12 +import io.swagger.v3.oas.annotations.Parameter;
  13 +import io.swagger.v3.oas.annotations.tags.Tag;
  14 +import jakarta.annotation.Resource;
  15 +import jakarta.validation.Valid;
  16 +import org.springframework.security.access.prepost.PreAuthorize;
  17 +import org.springframework.validation.annotation.Validated;
  18 +import org.springframework.web.bind.annotation.*;
  19 +
  20 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  21 +
  22 +@Tag(name = "管理后台 - IoT 告警记录")
  23 +@RestController
  24 +@RequestMapping("/iot/alert-record")
  25 +@Validated
  26 +public class IotAlertRecordController {
  27 +
  28 + @Resource
  29 + private IotAlertRecordService alertRecordService;
  30 +
  31 + @GetMapping("/get")
  32 + @Operation(summary = "获得告警记录")
  33 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  34 + @PreAuthorize("@ss.hasPermission('iot:alert-record:query')")
  35 + public CommonResult<IotAlertRecordRespVO> getAlertRecord(@RequestParam("id") Long id) {
  36 + IotAlertRecordDO alertRecord = alertRecordService.getAlertRecord(id);
  37 + return success(BeanUtils.toBean(alertRecord, IotAlertRecordRespVO.class));
  38 + }
  39 +
  40 + @GetMapping("/page")
  41 + @Operation(summary = "获得告警记录分页")
  42 + @PreAuthorize("@ss.hasPermission('iot:alert-record:query')")
  43 + public CommonResult<PageResult<IotAlertRecordRespVO>> getAlertRecordPage(@Valid IotAlertRecordPageReqVO pageReqVO) {
  44 + PageResult<IotAlertRecordDO> pageResult = alertRecordService.getAlertRecordPage(pageReqVO);
  45 + return success(BeanUtils.toBean(pageResult, IotAlertRecordRespVO.class));
  46 + }
  47 +
  48 + @PutMapping("/process")
  49 + @Operation(summary = "处理告警记录")
  50 + @PreAuthorize("@ss.hasPermission('iot:alert-record:process')")
  51 + public CommonResult<Boolean> processAlertRecord(@Valid @RequestBody IotAlertRecordProcessReqVO processReqVO) {
  52 + alertRecordService.processAlertRecord(processReqVO);
  53 + return success(true);
  54 + }
  55 +
  56 +}
0 \ No newline at end of file 57 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/recrod/IotAlertRecordPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod;
  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 org.springframework.format.annotation.DateTimeFormat;
  7 +
  8 +import java.time.LocalDateTime;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Schema(description = "管理后台 - IoT 告警记录分页 Request VO")
  13 +@Data
  14 +public class IotAlertRecordPageReqVO extends PageParam {
  15 +
  16 + @Schema(description = "告警配置编号", example = "29320")
  17 + private Long configId;
  18 +
  19 + @Schema(description = "告警级别", example = "1")
  20 + private Integer level;
  21 +
  22 + @Schema(description = "产品编号", example = "2050")
  23 + private Long productId;
  24 +
  25 + @Schema(description = "设备编号", example = "21727")
  26 + private String deviceId;
  27 +
  28 + @Schema(description = "是否处理", example = "true")
  29 + private Boolean processStatus;
  30 +
  31 + @Schema(description = "创建时间")
  32 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  33 + private LocalDateTime[] createTime;
  34 +
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/recrod/IotAlertRecordProcessReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
  5 +import lombok.Data;
  6 +
  7 +@Schema(description = "管理后台 - IoT 告警记录处理 Request VO")
  8 +@Data
  9 +public class IotAlertRecordProcessReqVO {
  10 +
  11 + @Schema(description = "记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  12 + @NotNull(message = "记录编号不能为空")
  13 + private Long id;
  14 +
  15 + @Schema(description = "处理结果(备注)", requiredMode = Schema.RequiredMode.REQUIRED, example = "已处理告警,问题已解决")
  16 + private String processRemark;
  17 +
  18 +}
0 \ No newline at end of file 19 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/recrod/IotAlertRecordRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod;
  2 +
  3 +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +
  7 +import java.time.LocalDateTime;
  8 +
  9 +@Schema(description = "管理后台 - IoT 告警记录 Response VO")
  10 +@Data
  11 +public class IotAlertRecordRespVO {
  12 +
  13 + @Schema(description = "记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19904")
  14 + private Long id;
  15 +
  16 + @Schema(description = "告警配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29320")
  17 + private Long configId;
  18 +
  19 + @Schema(description = "告警名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
  20 + private String configName;
  21 +
  22 + @Schema(description = "告警级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  23 + private Integer configLevel;
  24 +
  25 + @Schema(description = "产品编号", example = "2050")
  26 + private Long productId;
  27 +
  28 + @Schema(description = "设备编号", example = "21727")
  29 + private Long deviceId;
  30 +
  31 + @Schema(description = "触发的设备消息")
  32 + private IotDeviceMessage deviceMessage;
  33 +
  34 + @Schema(description = "是否处理", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  35 + private Boolean processStatus;
  36 +
  37 + @Schema(description = "处理结果(备注)", example = "你说的对")
  38 + private String processRemark;
  39 +
  40 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  41 + private LocalDateTime createTime;
  42 +
  43 +}
0 \ No newline at end of file 44 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/alert/IotAlertRecordDO.java
@@ -19,7 +19,7 @@ import lombok.NoArgsConstructor; @@ -19,7 +19,7 @@ import lombok.NoArgsConstructor;
19 * 19 *
20 * @author 芋道源码 20 * @author 芋道源码
21 */ 21 */
22 -@TableName("iot_alert_record") 22 +@TableName(value = "iot_alert_record", autoResultMap = true)
23 @KeySequence("iot_alert_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 23 @KeySequence("iot_alert_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
24 @Data 24 @Data
25 @Builder 25 @Builder
@@ -44,6 +44,13 @@ public class IotAlertRecordDO extends BaseDO { @@ -44,6 +44,13 @@ public class IotAlertRecordDO extends BaseDO {
44 * 冗余 {@link IotAlertConfigDO#getName()} 44 * 冗余 {@link IotAlertConfigDO#getName()}
45 */ 45 */
46 private String configName; 46 private String configName;
  47 + /**
  48 + * 告警级别
  49 + *
  50 + * 冗余 {@link IotAlertConfigDO#getLevel()}
  51 + * 字典 {@link cn.iocoder.yudao.module.iot.enums.DictTypeConstants#ALERT_LEVEL}
  52 + */
  53 + private Integer configLevel;
47 54
48 /** 55 /**
49 * 产品编号 56 * 产品编号
@@ -56,7 +63,7 @@ public class IotAlertRecordDO extends BaseDO { @@ -56,7 +63,7 @@ public class IotAlertRecordDO extends BaseDO {
56 * 63 *
57 * 关联 {@link IotDeviceDO#getId()} 64 * 关联 {@link IotDeviceDO#getId()}
58 */ 65 */
59 - private String deviceId; 66 + private Long deviceId;
60 /** 67 /**
61 * 触发的设备消息 68 * 触发的设备消息
62 */ 69 */
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java
@@ -198,14 +198,6 @@ public class IotRuleSceneDO extends TenantBaseDO { @@ -198,14 +198,6 @@ public class IotRuleSceneDO extends TenantBaseDO {
198 */ 198 */
199 private ActionDeviceControl deviceControl; 199 private ActionDeviceControl deviceControl;
200 200
201 - /**  
202 - * 数据桥接编号  
203 - *  
204 - * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DATA_BRIDGE} 时  
205 - * 关联:{@link IotDataSinkDO#getId()}  
206 - */  
207 - private Long dataBridgeId;  
208 -  
209 } 201 }
210 202
211 /** 203 /**
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertConfigMapper.java
@@ -3,10 +3,13 @@ package cn.iocoder.yudao.module.iot.dal.mysql.alert; @@ -3,10 +3,13 @@ package cn.iocoder.yudao.module.iot.dal.mysql.alert;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
6 import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.config.IotAlertConfigPageReqVO; 7 import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.config.IotAlertConfigPageReqVO;
7 import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; 8 import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
8 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
9 10
  11 +import java.util.List;
  12 +
10 /** 13 /**
11 * IoT 告警配置 Mapper 14 * IoT 告警配置 Mapper
12 * 15 *
@@ -23,4 +26,14 @@ public interface IotAlertConfigMapper extends BaseMapperX&lt;IotAlertConfigDO&gt; { @@ -23,4 +26,14 @@ public interface IotAlertConfigMapper extends BaseMapperX&lt;IotAlertConfigDO&gt; {
23 .orderByDesc(IotAlertConfigDO::getId)); 26 .orderByDesc(IotAlertConfigDO::getId));
24 } 27 }
25 28
  29 + default List<IotAlertConfigDO> selectListByStatus(Integer status) {
  30 + return selectList(IotAlertConfigDO::getStatus, status);
  31 + }
  32 +
  33 + default List<IotAlertConfigDO> selectListBySceneRuleIdAndStatus(Long sceneRuleId, Integer status) {
  34 + return selectList(new LambdaQueryWrapperX<IotAlertConfigDO>()
  35 + .eq(IotAlertConfigDO::getStatus, status)
  36 + .apply(MyBatisUtils.findInSet("scene_rule_id", sceneRuleId)));
  37 + }
  38 +
26 } 39 }
27 \ No newline at end of file 40 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertRecordMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.dal.mysql.alert;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  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.alert.vo.recrod.IotAlertRecordPageReqVO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * IoT 告警记录 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface IotAlertRecordMapper extends BaseMapperX<IotAlertRecordDO> {
  17 +
  18 + default PageResult<IotAlertRecordDO> selectPage(IotAlertRecordPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<IotAlertRecordDO>()
  20 + .eqIfPresent(IotAlertRecordDO::getConfigId, reqVO.getConfigId())
  21 + .eqIfPresent(IotAlertRecordDO::getConfigLevel, reqVO.getLevel())
  22 + .eqIfPresent(IotAlertRecordDO::getProductId, reqVO.getProductId())
  23 + .eqIfPresent(IotAlertRecordDO::getDeviceId, reqVO.getDeviceId())
  24 + .eqIfPresent(IotAlertRecordDO::getProcessStatus, reqVO.getProcessStatus())
  25 + .betweenIfPresent(IotAlertRecordDO::getCreateTime, reqVO.getCreateTime())
  26 + .orderByDesc(IotAlertRecordDO::getId));
  27 + }
  28 +
  29 +}
0 \ No newline at end of file 30 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
@@ -67,4 +67,7 @@ public interface ErrorCodeConstants { @@ -67,4 +67,7 @@ public interface ErrorCodeConstants {
67 // ========== IoT 告警配置 1-050-013-000 ========== 67 // ========== IoT 告警配置 1-050-013-000 ==========
68 ErrorCode ALERT_CONFIG_NOT_EXISTS = new ErrorCode(1_050_013_000, "IoT 告警配置不存在"); 68 ErrorCode ALERT_CONFIG_NOT_EXISTS = new ErrorCode(1_050_013_000, "IoT 告警配置不存在");
69 69
  70 + // ========== IoT 告警记录 1-050-014-000 ==========
  71 + ErrorCode ALERT_RECORD_NOT_EXISTS = new ErrorCode(1_050_014_000, "IoT 告警记录不存在");
  72 +
70 } 73 }
71 \ No newline at end of file 74 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/rule/IotDataRuleMessageHandler.java
@@ -10,8 +10,6 @@ import jakarta.annotation.Resource; @@ -10,8 +10,6 @@ import jakarta.annotation.Resource;
10 import lombok.extern.slf4j.Slf4j; 10 import lombok.extern.slf4j.Slf4j;
11 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Component;
12 12
13 -// TODO @puhui999:后面重构哈  
14 -  
15 /** 13 /**
16 * 针对 {@link IotDeviceMessage} 的消费者,处理数据流转 14 * 针对 {@link IotDeviceMessage} 的消费者,处理数据流转
17 * 15 *
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigService.java
@@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.config.IotAlertConf @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.config.IotAlertConf
6 import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; 6 import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
7 import jakarta.validation.Valid; 7 import jakarta.validation.Valid;
8 8
  9 +import java.util.List;
  10 +
9 /** 11 /**
10 * IoT 告警配置 Service 接口 12 * IoT 告警配置 Service 接口
11 * 13 *
@@ -51,4 +53,20 @@ public interface IotAlertConfigService { @@ -51,4 +53,20 @@ public interface IotAlertConfigService {
51 */ 53 */
52 PageResult<IotAlertConfigDO> getAlertConfigPage(IotAlertConfigPageReqVO pageReqVO); 54 PageResult<IotAlertConfigDO> getAlertConfigPage(IotAlertConfigPageReqVO pageReqVO);
53 55
  56 + /**
  57 + * 获得告警配置列表
  58 + *
  59 + * @param status 状态
  60 + * @return 告警配置列表
  61 + */
  62 + List<IotAlertConfigDO> getAlertConfigListByStatus(Integer status);
  63 +
  64 + /**
  65 + * 获得告警配置列表
  66 + *
  67 + * @param sceneRuleId 场景流动规则编号
  68 + * @return 告警配置列表
  69 + */
  70 + List<IotAlertConfigDO> getAlertConfigListBySceneRuleIdAndStatus(Long sceneRuleId, Integer status);
  71 +
54 } 72 }
55 \ No newline at end of file 73 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java
@@ -9,9 +9,12 @@ import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertConfigMapper; @@ -9,9 +9,12 @@ import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertConfigMapper;
9 import cn.iocoder.yudao.module.iot.service.rule.scene.IotRuleSceneService; 9 import cn.iocoder.yudao.module.iot.service.rule.scene.IotRuleSceneService;
10 import cn.iocoder.yudao.module.system.api.user.AdminUserApi; 10 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
11 import jakarta.annotation.Resource; 11 import jakarta.annotation.Resource;
  12 +import org.springframework.context.annotation.Lazy;
12 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
13 import org.springframework.validation.annotation.Validated; 14 import org.springframework.validation.annotation.Validated;
14 15
  16 +import java.util.List;
  17 +
15 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 18 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
16 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.ALERT_CONFIG_NOT_EXISTS; 19 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.ALERT_CONFIG_NOT_EXISTS;
17 20
@@ -28,6 +31,7 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { @@ -28,6 +31,7 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService {
28 private IotAlertConfigMapper alertConfigMapper; 31 private IotAlertConfigMapper alertConfigMapper;
29 32
30 @Resource 33 @Resource
  34 + @Lazy // 延迟,避免循环依赖报错
31 private IotRuleSceneService ruleSceneService; 35 private IotRuleSceneService ruleSceneService;
32 36
33 @Resource 37 @Resource
@@ -39,6 +43,7 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { @@ -39,6 +43,7 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService {
39 ruleSceneService.validateRuleSceneList(createReqVO.getSceneRuleIds()); 43 ruleSceneService.validateRuleSceneList(createReqVO.getSceneRuleIds());
40 adminUserApi.validateUserList(createReqVO.getReceiveUserIds()); 44 adminUserApi.validateUserList(createReqVO.getReceiveUserIds());
41 45
  46 + // 插入
42 IotAlertConfigDO alertConfig = BeanUtils.toBean(createReqVO, IotAlertConfigDO.class); 47 IotAlertConfigDO alertConfig = BeanUtils.toBean(createReqVO, IotAlertConfigDO.class);
43 alertConfigMapper.insert(alertConfig); 48 alertConfigMapper.insert(alertConfig);
44 return alertConfig.getId(); 49 return alertConfig.getId();
@@ -81,4 +86,14 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { @@ -81,4 +86,14 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService {
81 return alertConfigMapper.selectPage(pageReqVO); 86 return alertConfigMapper.selectPage(pageReqVO);
82 } 87 }
83 88
  89 + @Override
  90 + public List<IotAlertConfigDO> getAlertConfigListByStatus(Integer status) {
  91 + return alertConfigMapper.selectListByStatus(status);
  92 + }
  93 +
  94 + @Override
  95 + public List<IotAlertConfigDO> getAlertConfigListBySceneRuleIdAndStatus(Long sceneRuleId, Integer status) {
  96 + return alertConfigMapper.selectListBySceneRuleIdAndStatus(sceneRuleId, status);
  97 + }
  98 +
84 } 99 }
85 \ No newline at end of file 100 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertRecordService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.alert;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordPageReqVO;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordProcessReqVO;
  6 +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
  8 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
  9 +
  10 +/**
  11 + * IoT 告警记录 Service 接口
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +public interface IotAlertRecordService {
  16 +
  17 + /**
  18 + * 获得告警记录
  19 + *
  20 + * @param id 编号
  21 + * @return 告警记录
  22 + */
  23 + IotAlertRecordDO getAlertRecord(Long id);
  24 +
  25 + /**
  26 + * 获得告警记录分页
  27 + *
  28 + * @param pageReqVO 分页查询
  29 + * @return 告警记录分页
  30 + */
  31 + PageResult<IotAlertRecordDO> getAlertRecordPage(IotAlertRecordPageReqVO pageReqVO);
  32 +
  33 + /**
  34 + * 处理告警记录
  35 + *
  36 + * @param processReqVO 处理请求
  37 + */
  38 + void processAlertRecord(IotAlertRecordProcessReqVO processReqVO);
  39 +
  40 + /**
  41 + * 创建告警记录
  42 + *
  43 + * @param config 告警配置
  44 + * @param deviceMessage 设备消息,可为空
  45 + * @return 告警记录编号
  46 + */
  47 + Long createAlertRecord(IotAlertConfigDO config, IotDeviceMessage deviceMessage);
  48 +
  49 +}
0 \ No newline at end of file 50 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertRecordServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.alert;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordPageReqVO;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordProcessReqVO;
  6 +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
  8 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
  9 +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
  10 +import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertRecordMapper;
  11 +import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
  12 +import jakarta.annotation.Resource;
  13 +import org.springframework.stereotype.Service;
  14 +import org.springframework.validation.annotation.Validated;
  15 +
  16 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  17 +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.ALERT_RECORD_NOT_EXISTS;
  18 +
  19 +/**
  20 + * IoT 告警记录 Service 实现类
  21 + *
  22 + * @author 芋道源码
  23 + */
  24 +@Service
  25 +@Validated
  26 +public class IotAlertRecordServiceImpl implements IotAlertRecordService {
  27 +
  28 + @Resource
  29 + private IotAlertRecordMapper alertRecordMapper;
  30 +
  31 + @Resource
  32 + private IotDeviceService deviceService;
  33 +
  34 + @Override
  35 + public IotAlertRecordDO getAlertRecord(Long id) {
  36 + return alertRecordMapper.selectById(id);
  37 + }
  38 +
  39 + @Override
  40 + public PageResult<IotAlertRecordDO> getAlertRecordPage(IotAlertRecordPageReqVO pageReqVO) {
  41 + return alertRecordMapper.selectPage(pageReqVO);
  42 + }
  43 +
  44 + @Override
  45 + public void processAlertRecord(IotAlertRecordProcessReqVO processReqVO) {
  46 + // 校验告警记录是否存在
  47 + IotAlertRecordDO alertRecord = alertRecordMapper.selectById(processReqVO.getId());
  48 + if (alertRecord == null) {
  49 + throw exception(ALERT_RECORD_NOT_EXISTS);
  50 + }
  51 +
  52 + // 更新处理状态和备注
  53 + alertRecordMapper.updateById(IotAlertRecordDO.builder()
  54 + .id(processReqVO.getId())
  55 + .processStatus(true)
  56 + .processRemark(processReqVO.getProcessRemark())
  57 + .build());
  58 + }
  59 +
  60 + @Override
  61 + public Long createAlertRecord(IotAlertConfigDO config, IotDeviceMessage message) {
  62 + // 构建告警记录
  63 + IotAlertRecordDO.IotAlertRecordDOBuilder builder = IotAlertRecordDO.builder()
  64 + .configId(config.getId()).configName(config.getName()).configLevel(config.getLevel())
  65 + .processStatus(false);
  66 + if (message != null) {
  67 + builder.deviceMessage(message);
  68 + // 填充设备信息
  69 + IotDeviceDO device = deviceService.getDeviceFromCache(message.getDeviceId());
  70 + if (device!= null) {
  71 + builder.productId(device.getProductId()).deviceId(device.getId());
  72 + }
  73 + }
  74 + // 插入记录
  75 + IotAlertRecordDO record = builder.build();
  76 + alertRecordMapper.insert(record);
  77 + return record.getId();
  78 + }
  79 +
  80 +}
0 \ No newline at end of file 81 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotRuleSceneService.java
@@ -12,7 +12,7 @@ import java.util.Collection; @@ -12,7 +12,7 @@ import java.util.Collection;
12 import java.util.List; 12 import java.util.List;
13 13
14 /** 14 /**
15 - * IoT 规则场景 Service 接口 15 + * IoT 规则场景规则 Service 接口
16 * 16 *
17 * @author 芋道源码 17 * @author 芋道源码
18 */ 18 */
@@ -57,10 +57,10 @@ public interface IotRuleSceneService { @@ -57,10 +57,10 @@ public interface IotRuleSceneService {
57 PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO); 57 PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO);
58 58
59 /** 59 /**
60 - * 校验规则场景编号们是否存在。如下情况,视为无效:  
61 - * 1. 规则场景编号不存在 60 + * 校验规则场景联动规则编号们是否存在。如下情况,视为无效:
  61 + * 1. 规则场景联动规则编号不存在
62 * 62 *
63 - * @param ids 规则场景编号数组 63 + * @param ids 场景联动规则编号数组
64 */ 64 */
65 void validateRuleSceneList(Collection<Long> ids); 65 void validateRuleSceneList(Collection<Long> ids);
66 66
@@ -91,7 +91,7 @@ public interface IotRuleSceneService { @@ -91,7 +91,7 @@ public interface IotRuleSceneService {
91 /** 91 /**
92 * 基于 {@link IotRuleSceneTriggerTypeEnum#TIMER} 场景,执行规则场景 92 * 基于 {@link IotRuleSceneTriggerTypeEnum#TIMER} 场景,执行规则场景
93 * 93 *
94 - * @param id 场景编号 94 + * @param id 场景联动规则编号
95 */ 95 */
96 void executeRuleSceneByTimer(Long id); 96 void executeRuleSceneByTimer(Long id);
97 97
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotRuleSceneServiceImpl.java
@@ -443,7 +443,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { @@ -443,7 +443,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
443 // 3.2 执行动作 443 // 3.2 执行动作
444 actions.forEach(action -> { 444 actions.forEach(action -> {
445 try { 445 try {
446 - action.execute(message, actionConfig); 446 + action.execute(message, ruleScene, actionConfig);
447 log.info("[executeRuleSceneAction][消息({}) 规则场景编号({}) 的执行动作({}) 成功]", 447 log.info("[executeRuleSceneAction][消息({}) 规则场景编号({}) 的执行动作({}) 成功]",
448 message, ruleScene.getId(), actionConfig); 448 message, ruleScene.getId(), actionConfig);
449 } catch (Exception e) { 449 } catch (Exception e) {
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertTriggerRuleSceneAction.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertTriggerSceneRuleAction.java
1 package cn.iocoder.yudao.module.iot.service.rule.scene.action; 1 package cn.iocoder.yudao.module.iot.service.rule.scene.action;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; 5 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
  6 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
4 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; 7 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
5 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; 8 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
  9 +import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService;
  10 +import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
  11 +import jakarta.annotation.Resource;
6 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
7 13
8 import javax.annotation.Nullable; 14 import javax.annotation.Nullable;
  15 +import java.util.List;
9 16
  17 +// TODO @puhui999、@芋艿:未测试;需要场景联动开发完
10 /** 18 /**
11 * IoT 告警触发的 {@link IotSceneRuleAction} 实现类 19 * IoT 告警触发的 {@link IotSceneRuleAction} 实现类
12 * 20 *
13 * @author 芋道源码 21 * @author 芋道源码
14 */ 22 */
15 @Component 23 @Component
16 -public class IotAlertTriggerRuleSceneAction implements IotSceneRuleAction { 24 +public class IotAlertTriggerSceneRuleAction implements IotSceneRuleAction {
  25 +
  26 + @Resource
  27 + private IotAlertConfigService alertConfigService;
  28 +
  29 + @Resource
  30 + private IotAlertRecordService alertRecordService;
17 31
18 @Override 32 @Override
19 - public void execute(@Nullable IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) {  
20 - // TODO @AI: 33 + public void execute(@Nullable IotDeviceMessage message,
  34 + IotRuleSceneDO rule, IotRuleSceneDO.ActionConfig actionConfig) throws Exception {
  35 + List<IotAlertConfigDO> alertConfigs = alertConfigService.getAlertConfigListBySceneRuleIdAndStatus(
  36 + rule.getId(), CommonStatusEnum.ENABLE.getStatus());
  37 + if (CollUtil.isEmpty(alertConfigs)) {
  38 + return;
  39 + }
  40 + alertConfigs.forEach(alertConfig ->
  41 + alertRecordService.createAlertRecord(alertConfig, message));
21 } 42 }
22 43
23 @Override 44 @Override
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotDeviceControlRuleSceneAction.java
@@ -26,23 +26,24 @@ public class IotDeviceControlRuleSceneAction implements IotSceneRuleAction { @@ -26,23 +26,24 @@ public class IotDeviceControlRuleSceneAction implements IotSceneRuleAction {
26 private IotDeviceMessageService deviceMessageService; 26 private IotDeviceMessageService deviceMessageService;
27 27
28 @Override 28 @Override
29 - public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) {  
30 - IotRuleSceneDO.ActionDeviceControl control = config.getDeviceControl(); 29 + public void execute(IotDeviceMessage message,
  30 + IotRuleSceneDO rule, IotRuleSceneDO.ActionConfig actionConfig) {
  31 + IotRuleSceneDO.ActionDeviceControl control = actionConfig.getDeviceControl();
31 Assert.notNull(control, "设备控制配置不能为空"); 32 Assert.notNull(control, "设备控制配置不能为空");
32 // 遍历每个设备,下发消息 33 // 遍历每个设备,下发消息
33 control.getDeviceNames().forEach(deviceName -> { 34 control.getDeviceNames().forEach(deviceName -> {
34 IotDeviceDO device = deviceService.getDeviceFromCache(control.getProductKey(), deviceName); 35 IotDeviceDO device = deviceService.getDeviceFromCache(control.getProductKey(), deviceName);
35 if (device == null) { 36 if (device == null) {
36 - log.error("[execute][message({}) config({}) 对应的设备不存在]", message, config); 37 + log.error("[execute][message({}) actionConfig({}) 对应的设备不存在]", message, actionConfig);
37 return; 38 return;
38 } 39 }
39 try { 40 try {
40 // TODO @芋艿:@puhui999:这块可能要改,从 type => method 41 // TODO @芋艿:@puhui999:这块可能要改,从 type => method
41 IotDeviceMessage downstreamMessage = deviceMessageService.sendDeviceMessage(IotDeviceMessage.requestOf( 42 IotDeviceMessage downstreamMessage = deviceMessageService.sendDeviceMessage(IotDeviceMessage.requestOf(
42 control.getType() + control.getIdentifier(), control.getData()).setDeviceId(device.getId())); 43 control.getType() + control.getIdentifier(), control.getData()).setDeviceId(device.getId()));
43 - log.info("[execute][message({}) config({}) 下发消息({})成功]", message, config, downstreamMessage); 44 + log.info("[execute][message({}) actionConfig({}) 下发消息({})成功]", message, actionConfig, downstreamMessage);
44 } catch (Exception e) { 45 } catch (Exception e) {
45 - log.error("[execute][message({}) config({}) 下发消息失败]", message, config, e); 46 + log.error("[execute][message({}) actionConfig({}) 下发消息失败]", message, actionConfig, e);
46 } 47 }
47 }); 48 });
48 } 49 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotSceneRuleAction.java
@@ -19,9 +19,12 @@ public interface IotSceneRuleAction { @@ -19,9 +19,12 @@ public interface IotSceneRuleAction {
19 * @param message 消息,允许空 19 * @param message 消息,允许空
20 * 1. 空的情况:定时触发 20 * 1. 空的情况:定时触发
21 * 2. 非空的情况:设备触发 21 * 2. 非空的情况:设备触发
22 - * @param config 配置 22 + * @param rule 规则
  23 + * @param actionConfig 执行配置(实际对应规则里的哪条执行配置)
23 */ 24 */
24 - void execute(@Nullable IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) throws Exception; 25 + void execute(@Nullable IotDeviceMessage message,
  26 + IotRuleSceneDO rule,
  27 + IotRuleSceneDO.ActionConfig actionConfig) throws Exception;
25 28
26 /** 29 /**
27 * 获得类型 30 * 获得类型