refactor:【IoT 物联网】IotRuleSceneDO => IotSceneRuleDO
This commit is contained in:
@@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePa
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneUpdateStatusReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.service.rule.scene.IotRuleSceneService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -71,7 +71,7 @@ public class IotRuleSceneController {
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('iot:rule-scene:query')")
|
||||
public CommonResult<IotRuleSceneRespVO> getRuleScene(@RequestParam("id") Long id) {
|
||||
IotRuleSceneDO ruleScene = ruleSceneService.getRuleScene(id);
|
||||
IotSceneRuleDO ruleScene = ruleSceneService.getRuleScene(id);
|
||||
return success(BeanUtils.toBean(ruleScene, IotRuleSceneRespVO.class));
|
||||
}
|
||||
|
||||
@@ -79,14 +79,14 @@ public class IotRuleSceneController {
|
||||
@Operation(summary = "获得场景联动分页")
|
||||
@PreAuthorize("@ss.hasPermission('iot:rule-scene:query')")
|
||||
public CommonResult<PageResult<IotRuleSceneRespVO>> getRuleScenePage(@Valid IotRuleScenePageReqVO pageReqVO) {
|
||||
PageResult<IotRuleSceneDO> pageResult = ruleSceneService.getRuleScenePage(pageReqVO);
|
||||
PageResult<IotSceneRuleDO> pageResult = ruleSceneService.getRuleScenePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, IotRuleSceneRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/simple-list")
|
||||
@Operation(summary = "获取场景联动的精简信息列表", description = "主要用于前端的下拉选项")
|
||||
public CommonResult<List<IotRuleSceneRespVO>> getRuleSceneSimpleList() {
|
||||
List<IotRuleSceneDO> list = ruleSceneService.getRuleSceneListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<IotSceneRuleDO> list = ruleSceneService.getRuleSceneListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
return success(convertList(list, scene -> // 只返回 id、name 字段
|
||||
new IotRuleSceneRespVO().setId(scene.getId()).setName(scene.getName())));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -24,10 +24,10 @@ public class IotRuleSceneRespVO {
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<IotRuleSceneDO.Trigger> triggers;
|
||||
private List<IotSceneRuleDO.Trigger> triggers;
|
||||
|
||||
@Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<IotRuleSceneDO.Action> actions;
|
||||
private List<IotSceneRuleDO.Action> actions;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -31,10 +31,10 @@ public class IotRuleSceneSaveReqVO {
|
||||
|
||||
@Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "触发器数组不能为空")
|
||||
private List<IotRuleSceneDO.Trigger> triggers;
|
||||
private List<IotSceneRuleDO.Trigger> triggers;
|
||||
|
||||
@Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "执行器数组不能为空")
|
||||
private List<IotRuleSceneDO.Action> actions;
|
||||
private List<IotSceneRuleDO.Action> actions;
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.DictTypeConstants;
|
||||
import cn.iocoder.yudao.module.iot.enums.alert.IotAlertReceiveTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
@@ -61,7 +61,7 @@ public class IotAlertConfigDO extends BaseDO {
|
||||
/**
|
||||
* 关联的场景联动规则编号数组
|
||||
*
|
||||
* 关联 {@link IotRuleSceneDO#getId()}
|
||||
* 关联 {@link IotSceneRuleDO#getId()}
|
||||
*/
|
||||
@TableField(typeHandler = LongListTypeHandler.class)
|
||||
private List<Long> sceneRuleIds;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@@ -55,7 +55,7 @@ public class IotAlertRecordDO extends BaseDO {
|
||||
/**
|
||||
* 场景规则编号
|
||||
*
|
||||
* 关联 {@link IotRuleSceneDO#getId()}
|
||||
* 关联 {@link IotSceneRuleDO#getId()}
|
||||
*/
|
||||
private Long sceneRuleId;
|
||||
|
||||
|
||||
@@ -23,19 +23,18 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO @puhui999:名字改成 IotSceneRuleDO
|
||||
/**
|
||||
* IoT 场景联动规则 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "iot_rule_scene", autoResultMap = true)
|
||||
@KeySequence("iot_rule_scene_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@TableName(value = "iot_scene_rule", autoResultMap = true)
|
||||
@KeySequence("iot_scene_rule_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IotRuleSceneDO extends TenantBaseDO {
|
||||
public class IotSceneRuleDO extends TenantBaseDO {
|
||||
|
||||
/**
|
||||
* 场景联动编号
|
||||
@@ -219,6 +218,14 @@ public class IotRuleSceneDO extends TenantBaseDO {
|
||||
* 关联 {@link IotDeviceDO#getId()}
|
||||
*/
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 标识符(服务)
|
||||
* <p>
|
||||
* 关联 {@link IotThingModelDO#getIdentifier()}
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*
|
||||
@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -15,19 +15,19 @@ import java.util.List;
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Mapper
|
||||
public interface IotRuleSceneMapper extends BaseMapperX<IotRuleSceneDO> {
|
||||
public interface IotRuleSceneMapper extends BaseMapperX<IotSceneRuleDO> {
|
||||
|
||||
default PageResult<IotRuleSceneDO> selectPage(IotRuleScenePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<IotRuleSceneDO>()
|
||||
.likeIfPresent(IotRuleSceneDO::getName, reqVO.getName())
|
||||
.likeIfPresent(IotRuleSceneDO::getDescription, reqVO.getDescription())
|
||||
.eqIfPresent(IotRuleSceneDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(IotRuleSceneDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(IotRuleSceneDO::getId));
|
||||
default PageResult<IotSceneRuleDO> selectPage(IotRuleScenePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<IotSceneRuleDO>()
|
||||
.likeIfPresent(IotSceneRuleDO::getName, reqVO.getName())
|
||||
.likeIfPresent(IotSceneRuleDO::getDescription, reqVO.getDescription())
|
||||
.eqIfPresent(IotSceneRuleDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(IotSceneRuleDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(IotSceneRuleDO::getId));
|
||||
}
|
||||
|
||||
default List<IotRuleSceneDO> selectListByStatus(Integer status) {
|
||||
return selectList(IotRuleSceneDO::getStatus, status);
|
||||
default List<IotSceneRuleDO> selectListByStatus(Integer status) {
|
||||
return selectList(IotSceneRuleDO::getStatus, status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@@ -54,7 +54,7 @@ public interface IotRuleSceneService {
|
||||
* @param id 编号
|
||||
* @return 场景联动
|
||||
*/
|
||||
IotRuleSceneDO getRuleScene(Long id);
|
||||
IotSceneRuleDO getRuleScene(Long id);
|
||||
|
||||
/**
|
||||
* 获得场景联动分页
|
||||
@@ -62,7 +62,7 @@ public interface IotRuleSceneService {
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 场景联动分页
|
||||
*/
|
||||
PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO);
|
||||
PageResult<IotSceneRuleDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 校验规则场景联动规则编号们是否存在。如下情况,视为无效:
|
||||
@@ -78,7 +78,7 @@ public interface IotRuleSceneService {
|
||||
* @param status 状态
|
||||
* @return 场景联动列表
|
||||
*/
|
||||
List<IotRuleSceneDO> getRuleSceneListByStatus(Integer status);
|
||||
List<IotSceneRuleDO> getRuleSceneListByStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 【缓存】获得指定设备的场景列表
|
||||
@@ -87,7 +87,7 @@ public interface IotRuleSceneService {
|
||||
* @param deviceName 设备名称
|
||||
* @return 场景列表
|
||||
*/
|
||||
List<IotRuleSceneDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName);
|
||||
List<IotSceneRuleDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName);
|
||||
|
||||
/**
|
||||
* 基于 {@link IotRuleSceneTriggerTypeEnum#DEVICE} 场景,执行规则场景
|
||||
|
||||
@@ -21,9 +21,8 @@ import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotRuleSceneMapper;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionOperatorEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum;
|
||||
@@ -43,7 +42,10 @@ import org.quartz.impl.StdSchedulerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
@@ -77,7 +79,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
|
||||
@Override
|
||||
public Long createRuleScene(IotRuleSceneSaveReqVO createReqVO) {
|
||||
IotRuleSceneDO ruleScene = BeanUtils.toBean(createReqVO, IotRuleSceneDO.class);
|
||||
IotSceneRuleDO ruleScene = BeanUtils.toBean(createReqVO, IotSceneRuleDO.class);
|
||||
ruleSceneMapper.insert(ruleScene);
|
||||
return ruleScene.getId();
|
||||
}
|
||||
@@ -87,7 +89,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
// 校验存在
|
||||
validateRuleSceneExists(updateReqVO.getId());
|
||||
// 更新
|
||||
IotRuleSceneDO updateObj = BeanUtils.toBean(updateReqVO, IotRuleSceneDO.class);
|
||||
IotSceneRuleDO updateObj = BeanUtils.toBean(updateReqVO, IotSceneRuleDO.class);
|
||||
ruleSceneMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@@ -96,7 +98,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
// 校验存在
|
||||
validateRuleSceneExists(id);
|
||||
// 更新状态
|
||||
IotRuleSceneDO updateObj = new IotRuleSceneDO().setId(id).setStatus(status);
|
||||
IotSceneRuleDO updateObj = new IotSceneRuleDO().setId(id).setStatus(status);
|
||||
ruleSceneMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@@ -115,12 +117,12 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IotRuleSceneDO getRuleScene(Long id) {
|
||||
public IotSceneRuleDO getRuleScene(Long id) {
|
||||
return ruleSceneMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO) {
|
||||
public PageResult<IotSceneRuleDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO) {
|
||||
return ruleSceneMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@@ -130,27 +132,27 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
return;
|
||||
}
|
||||
// 批量查询存在的规则场景
|
||||
List<IotRuleSceneDO> existingScenes = ruleSceneMapper.selectByIds(ids);
|
||||
List<IotSceneRuleDO> existingScenes = ruleSceneMapper.selectByIds(ids);
|
||||
if (existingScenes.size() != ids.size()) {
|
||||
throw exception(RULE_SCENE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IotRuleSceneDO> getRuleSceneListByStatus(Integer status) {
|
||||
public List<IotSceneRuleDO> getRuleSceneListByStatus(Integer status) {
|
||||
return ruleSceneMapper.selectListByStatus(status);
|
||||
}
|
||||
|
||||
// TODO 芋艿,缓存待实现
|
||||
@Override
|
||||
@TenantIgnore // 忽略租户隔离:因为 IotRuleSceneMessageHandler 调用时,一般未传递租户,所以需要忽略
|
||||
public List<IotRuleSceneDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) {
|
||||
public List<IotSceneRuleDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) {
|
||||
// TODO @puhui999:一些注释,看看要不要优化下;
|
||||
// 注意:旧的测试代码已删除,因为使用了废弃的数据结构
|
||||
// 如需测试,请使用上面的新结构测试代码示例
|
||||
List<IotRuleSceneDO> list = ruleSceneMapper.selectList();
|
||||
List<IotSceneRuleDO> list = ruleSceneMapper.selectList();
|
||||
// 只返回启用状态的规则场景
|
||||
List<IotRuleSceneDO> enabledList = filterList(list,
|
||||
List<IotSceneRuleDO> enabledList = filterList(list,
|
||||
ruleScene -> CommonStatusEnum.ENABLE.getStatus().equals(ruleScene.getStatus()));
|
||||
|
||||
// 根据 productKey 和 deviceName 进行匹配
|
||||
@@ -159,7 +161,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (IotRuleSceneDO.Trigger trigger : ruleScene.getTriggers()) {
|
||||
for (IotSceneRuleDO.Trigger trigger : ruleScene.getTriggers()) {
|
||||
// 检查触发器是否匹配指定的产品和设备
|
||||
if (isMatchProductAndDevice(trigger, productKey, deviceName)) {
|
||||
return true;
|
||||
@@ -177,7 +179,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param deviceName 设备名称
|
||||
* @return 是否匹配
|
||||
*/
|
||||
private boolean isMatchProductAndDevice(IotRuleSceneDO.Trigger trigger, String productKey, String deviceName) {
|
||||
private boolean isMatchProductAndDevice(IotSceneRuleDO.Trigger trigger, String productKey, String deviceName) {
|
||||
try {
|
||||
// 1. 检查产品是否匹配
|
||||
if (trigger.getProductId() != null) {
|
||||
@@ -219,7 +221,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
// TODO @芋艿:这里的 tenantId,通过设备获取;
|
||||
TenantUtils.execute(message.getTenantId(), () -> {
|
||||
// 1. 获得设备匹配的规则场景
|
||||
List<IotRuleSceneDO> ruleScenes = getMatchedRuleSceneListByMessage(message);
|
||||
List<IotSceneRuleDO> ruleScenes = getMatchedRuleSceneListByMessage(message);
|
||||
if (CollUtil.isEmpty(ruleScenes)) {
|
||||
return;
|
||||
}
|
||||
@@ -232,7 +234,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
@Override
|
||||
public void executeRuleSceneByTimer(Long id) {
|
||||
// 1.1 获得规则场景
|
||||
IotRuleSceneDO scene = TenantUtils.executeIgnore(() -> ruleSceneMapper.selectById(id));
|
||||
IotSceneRuleDO scene = TenantUtils.executeIgnore(() -> ruleSceneMapper.selectById(id));
|
||||
if (scene == null) {
|
||||
log.error("[executeRuleSceneByTimer][规则场景({}) 不存在]", id);
|
||||
return;
|
||||
@@ -242,7 +244,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
return;
|
||||
}
|
||||
// 1.2 判断是否有定时触发器,避免脏数据
|
||||
IotRuleSceneDO.Trigger config = CollUtil.findOne(scene.getTriggers(),
|
||||
IotSceneRuleDO.Trigger config = CollUtil.findOne(scene.getTriggers(),
|
||||
trigger -> ObjUtil.equals(trigger.getType(), IotRuleSceneTriggerTypeEnum.TIMER.getType()));
|
||||
if (config == null) {
|
||||
log.error("[executeRuleSceneByTimer][规则场景({}) 不存在定时触发器]", scene);
|
||||
@@ -260,7 +262,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param message 设备消息
|
||||
* @return 规则场景列表
|
||||
*/
|
||||
private List<IotRuleSceneDO> getMatchedRuleSceneListByMessage(IotDeviceMessage message) {
|
||||
private List<IotSceneRuleDO> getMatchedRuleSceneListByMessage(IotDeviceMessage message) {
|
||||
// 1. 匹配设备
|
||||
// TODO @芋艿:可能需要 getSelf(); 缓存
|
||||
// 1.1 通过 deviceId 获取设备信息
|
||||
@@ -278,7 +280,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
}
|
||||
|
||||
// 1.3 获取匹配的规则场景
|
||||
List<IotRuleSceneDO> ruleScenes = getRuleSceneListByProductKeyAndDeviceNameFromCache(
|
||||
List<IotSceneRuleDO> ruleScenes = getRuleSceneListByProductKeyAndDeviceNameFromCache(
|
||||
product.getProductKey(), device.getDeviceName());
|
||||
if (CollUtil.isEmpty(ruleScenes)) {
|
||||
return ruleScenes;
|
||||
@@ -286,7 +288,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
|
||||
// 2. 匹配 trigger 触发器的条件
|
||||
return filterList(ruleScenes, ruleScene -> {
|
||||
for (IotRuleSceneDO.Trigger trigger : ruleScene.getTriggers()) {
|
||||
for (IotSceneRuleDO.Trigger trigger : ruleScene.getTriggers()) {
|
||||
// 2.1 检查触发器类型,根据新的枚举值进行匹配
|
||||
// TODO @芋艿:需要根据新的触发器类型枚举进行适配
|
||||
// 原来使用 IotRuleSceneTriggerTypeEnum.DEVICE,新结构可能有不同的类型
|
||||
@@ -298,14 +300,14 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
|
||||
// 2.3 检查条件分组:分组与分组之间是"或"的关系,条件与条件之间是"且"的关系
|
||||
boolean anyGroupMatched = false;
|
||||
for (List<IotRuleSceneDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) {
|
||||
for (List<IotSceneRuleDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) {
|
||||
if (CollUtil.isEmpty(conditionGroup)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查当前分组中的所有条件是否都匹配(且关系)
|
||||
boolean allConditionsMatched = true;
|
||||
for (IotRuleSceneDO.TriggerCondition condition : conditionGroup) {
|
||||
for (IotSceneRuleDO.TriggerCondition condition : conditionGroup) {
|
||||
// TODO @芋艿:这里需要实现具体的条件匹配逻辑
|
||||
// 根据新的 TriggerCondition 结构进行匹配
|
||||
if (!isTriggerConditionMatched(message, condition, ruleScene, trigger)) {
|
||||
@@ -338,8 +340,8 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param trigger 触发器(用于日志,无其它作用)
|
||||
* @return 是否匹配
|
||||
*/
|
||||
private boolean isTriggerConditionMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition,
|
||||
IotRuleSceneDO ruleScene, IotRuleSceneDO.Trigger trigger) {
|
||||
private boolean isTriggerConditionMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition,
|
||||
IotSceneRuleDO ruleScene, IotSceneRuleDO.Trigger trigger) {
|
||||
try {
|
||||
// 1. 根据条件类型进行匹配
|
||||
if (IotRuleSceneConditionTypeEnum.DEVICE_STATE.getType().equals(condition.getType())) {
|
||||
@@ -370,7 +372,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param condition 触发条件
|
||||
* @return 是否匹配
|
||||
*/
|
||||
private boolean matchDeviceStateCondition(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition) {
|
||||
private boolean matchDeviceStateCondition(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
|
||||
// TODO @芋艿:需要根据设备状态进行匹配
|
||||
// 这里需要检查消息中的设备状态是否符合条件中定义的状态
|
||||
log.debug("[matchDeviceStateCondition][设备状态条件匹配逻辑待实现] condition: {}", condition);
|
||||
@@ -384,7 +386,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param condition 触发条件
|
||||
* @return 是否匹配
|
||||
*/
|
||||
private boolean matchDevicePropertyCondition(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition) {
|
||||
private boolean matchDevicePropertyCondition(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
|
||||
// 1. 检查标识符是否匹配
|
||||
String messageIdentifier = IotDeviceMessageUtils.getIdentifier(message);
|
||||
if (StrUtil.isBlank(condition.getIdentifier()) || !condition.getIdentifier().equals(messageIdentifier)) {
|
||||
@@ -407,7 +409,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param condition 触发条件
|
||||
* @return 是否匹配
|
||||
*/
|
||||
private boolean matchCurrentTimeCondition(IotRuleSceneDO.TriggerCondition condition) {
|
||||
private boolean matchCurrentTimeCondition(IotSceneRuleDO.TriggerCondition condition) {
|
||||
// TODO @芋艿:需要根据当前时间进行匹配
|
||||
// 这里需要检查当前时间是否符合条件中定义的时间范围
|
||||
log.debug("[matchCurrentTimeCondition][当前时间条件匹配逻辑待实现] condition: {}", condition);
|
||||
@@ -474,8 +476,8 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @return 是否匹配
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "DataFlowIssue"})
|
||||
private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition,
|
||||
IotRuleSceneDO ruleScene, IotRuleSceneDO.Trigger trigger) {
|
||||
private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition,
|
||||
IotSceneRuleDO ruleScene, IotSceneRuleDO.Trigger trigger) {
|
||||
// 1.1 校验操作符是否合法
|
||||
IotRuleSceneConditionOperatorEnum operator =
|
||||
IotRuleSceneConditionOperatorEnum.operatorOf(condition.getOperator());
|
||||
@@ -528,7 +530,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
* @param message 设备消息
|
||||
* @param ruleScenes 规则场景列表
|
||||
*/
|
||||
private void executeRuleSceneAction(IotDeviceMessage message, List<IotRuleSceneDO> ruleScenes) {
|
||||
private void executeRuleSceneAction(IotDeviceMessage message, List<IotSceneRuleDO> ruleScenes) {
|
||||
// 1. 遍历规则场景
|
||||
ruleScenes.forEach(ruleScene -> {
|
||||
// 2. 遍历规则场景的动作
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -30,7 +30,7 @@ public class IotAlertRecoverSceneRuleAction implements IotSceneRuleAction {
|
||||
|
||||
@Override
|
||||
public void execute(IotDeviceMessage message,
|
||||
IotRuleSceneDO rule, IotRuleSceneDO.Action actionConfig) throws Exception {
|
||||
IotSceneRuleDO rule, IotSceneRuleDO.Action actionConfig) throws Exception {
|
||||
Long deviceId = message != null ? message.getDeviceId() : null;
|
||||
List<IotAlertRecordDO> alertRecords = alertRecordService.getAlertRecordListBySceneRuleId(
|
||||
rule.getId(), deviceId, false);
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService;
|
||||
import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
|
||||
@@ -40,7 +40,7 @@ public class IotAlertTriggerSceneRuleAction implements IotSceneRuleAction {
|
||||
|
||||
@Override
|
||||
public void execute(@Nullable IotDeviceMessage message,
|
||||
IotRuleSceneDO rule, IotRuleSceneDO.Action actionConfig) throws Exception {
|
||||
IotSceneRuleDO rule, IotSceneRuleDO.Action actionConfig) throws Exception {
|
||||
List<IotAlertConfigDO> alertConfigs = alertConfigService.getAlertConfigListBySceneRuleIdAndStatus(
|
||||
rule.getId(), CommonStatusEnum.ENABLE.getStatus());
|
||||
if (CollUtil.isEmpty(alertConfigs)) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.service.rule.scene.action;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
||||
import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
|
||||
@@ -26,8 +26,8 @@ public class IotDeviceControlRuleSceneAction implements IotSceneRuleAction {
|
||||
// TODO @puhui999:这里
|
||||
@Override
|
||||
public void execute(IotDeviceMessage message,
|
||||
IotRuleSceneDO rule, IotRuleSceneDO.Action actionConfig) {
|
||||
//IotRuleSceneDO.ActionDeviceControl control = actionConfig.getDeviceControl();
|
||||
IotSceneRuleDO rule, IotSceneRuleDO.Action actionConfig) {
|
||||
//IotSceneRuleDO.ActionDeviceControl control = actionConfig.getDeviceControl();
|
||||
//Assert.notNull(control, "设备控制配置不能为空");
|
||||
//// 遍历每个设备,下发消息
|
||||
//control.getDeviceNames().forEach(deviceName -> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.service.rule.scene.action;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -23,8 +23,8 @@ public interface IotSceneRuleAction {
|
||||
* @param actionConfig 执行配置(实际对应规则里的哪条执行配置)
|
||||
*/
|
||||
void execute(@Nullable IotDeviceMessage message,
|
||||
IotRuleSceneDO rule,
|
||||
IotRuleSceneDO.Action actionConfig) throws Exception;
|
||||
IotSceneRuleDO rule,
|
||||
IotSceneRuleDO.Action actionConfig) throws Exception;
|
||||
|
||||
/**
|
||||
* 获得类型
|
||||
|
||||
Reference in New Issue
Block a user