mirror of
https://gitee.com/zhijiantianya/ruoyi-vue-pro.git
synced 2025-12-26 08:26:44 +08:00
!1398 perf:【IoT 物联网】场景联动代码优化
Merge pull request !1398 from puhui999/feature/iot
This commit is contained in:
commit
eb7df7157c
@ -8,13 +8,12 @@ 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;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -71,7 +70,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,22 +78,16 @@ 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())));
|
||||
}
|
||||
|
||||
@GetMapping("/test")
|
||||
@PermitAll
|
||||
public void test() {
|
||||
ruleSceneService.test();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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,12 +218,20 @@ public class IotRuleSceneDO extends TenantBaseDO {
|
||||
* 关联 {@link IotDeviceDO#getId()}
|
||||
*/
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 标识符(服务)
|
||||
* <p>
|
||||
* 关联 {@link IotThingModelDO#getIdentifier()}
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*
|
||||
* 一般来说,对应 {@link IotDeviceMessage#getParams()} 请求参数
|
||||
*/
|
||||
private Object params;
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 告警配置编号
|
||||
@ -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} 场景,执行规则场景
|
||||
@ -103,9 +103,4 @@ public interface IotRuleSceneService {
|
||||
*/
|
||||
void executeRuleSceneByTimer(Long id);
|
||||
|
||||
/**
|
||||
* TODO 芋艿:测试方法,需要删除
|
||||
*/
|
||||
void test();
|
||||
|
||||
}
|
||||
|
||||
@ -21,29 +21,24 @@ 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;
|
||||
import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager;
|
||||
import cn.iocoder.yudao.module.iot.job.rule.IotRuleSceneJob;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
||||
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
||||
import cn.iocoder.yudao.module.iot.service.rule.scene.action.IotSceneRuleAction;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.quartz.TriggerKey;
|
||||
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 +72,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 +82,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 +91,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 +110,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 +125,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 +154,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 +172,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 +214,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 +227,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 +237,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 +255,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 +273,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 +281,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 +293,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 +333,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 +365,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 +379,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 +402,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 +469,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 +523,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. 遍历规则场景的动作
|
||||
@ -554,50 +549,4 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void test() {
|
||||
// TODO @芋艿:测试思路代码,记得删除!!!
|
||||
// 1. Job 类:IotRuleSceneJob DONE
|
||||
// 2. 参数:id DONE
|
||||
// 3. jobHandlerName:IotRuleSceneJob + id DONE
|
||||
|
||||
// 新增:addJob
|
||||
// 修改:不存在 addJob、存在 updateJob
|
||||
// 有 + 禁用:1)存在、停止;2)不存在:不处理;TODO 测试:直接暂停,是否可以???(结论:可以)pauseJob
|
||||
// 有 + 开启:1)存在,更新;2)不存在,新增;结论:使用 save(addOrUpdateJob)
|
||||
// 无 + 禁用、开启:1)存在,删除;TODO 测试:直接删除???(结论:可以)deleteJob
|
||||
|
||||
//
|
||||
if (false) {
|
||||
Long id = 1L;
|
||||
Map<String, Object> jobDataMap = IotRuleSceneJob.buildJobDataMap(id);
|
||||
schedulerManager.addOrUpdateJob(IotRuleSceneJob.class,
|
||||
IotRuleSceneJob.buildJobName(id),
|
||||
"0/10 * * * * ?",
|
||||
jobDataMap);
|
||||
}
|
||||
if (false) {
|
||||
Long id = 1L;
|
||||
schedulerManager.pauseJob(IotRuleSceneJob.buildJobName(id));
|
||||
}
|
||||
if (true) {
|
||||
Long id = 1L;
|
||||
schedulerManager.deleteJob(IotRuleSceneJob.buildJobName(id));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main2(String[] args) throws SchedulerException {
|
||||
// System.out.println(QuartzJobBean.class);
|
||||
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
|
||||
scheduler.start();
|
||||
|
||||
String jobHandlerName = "123";
|
||||
// 暂停 Trigger 对象
|
||||
scheduler.pauseTrigger(new TriggerKey(jobHandlerName));
|
||||
// 取消并删除 Job 调度
|
||||
scheduler.unscheduleJob(new TriggerKey(jobHandlerName));
|
||||
scheduler.deleteJob(new JobKey(jobHandlerName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
* 获得类型
|
||||
|
||||
@ -0,0 +1,211 @@
|
||||
package cn.iocoder.yudao.module.iot.service.rule.scene;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO;
|
||||
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.framework.job.core.IotSchedulerManager;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
||||
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
||||
import cn.iocoder.yudao.module.iot.service.rule.scene.action.IotSceneRuleAction;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link IotRuleSceneServiceImpl} 的简化单元测试类
|
||||
* 使用 Mockito 进行纯单元测试,不依赖 Spring 容器
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class IotRuleSceneServiceSimpleTest extends BaseMockitoUnitTest {
|
||||
|
||||
@InjectMocks
|
||||
private IotRuleSceneServiceImpl ruleSceneService;
|
||||
|
||||
@Mock
|
||||
private IotRuleSceneMapper ruleSceneMapper;
|
||||
|
||||
@Mock
|
||||
private List<IotSceneRuleAction> ruleSceneActions;
|
||||
|
||||
@Mock
|
||||
private IotSchedulerManager schedulerManager;
|
||||
|
||||
@Mock
|
||||
private IotProductService productService;
|
||||
|
||||
@Mock
|
||||
private IotDeviceService deviceService;
|
||||
|
||||
@Test
|
||||
public void testCreateRuleScene_success() {
|
||||
// 准备参数
|
||||
IotRuleSceneSaveReqVO createReqVO = randomPojo(IotRuleSceneSaveReqVO.class, o -> {
|
||||
o.setId(null);
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setTriggers(Collections.singletonList(randomPojo(IotSceneRuleDO.Trigger.class)));
|
||||
o.setActions(Collections.singletonList(randomPojo(IotSceneRuleDO.Action.class)));
|
||||
});
|
||||
|
||||
// Mock 行为
|
||||
Long expectedId = randomLongId();
|
||||
when(ruleSceneMapper.insert(any(IotSceneRuleDO.class))).thenAnswer(invocation -> {
|
||||
IotSceneRuleDO ruleScene = invocation.getArgument(0);
|
||||
ruleScene.setId(expectedId);
|
||||
return 1;
|
||||
});
|
||||
|
||||
// 调用
|
||||
Long ruleSceneId = ruleSceneService.createRuleScene(createReqVO);
|
||||
|
||||
// 断言
|
||||
assertEquals(expectedId, ruleSceneId);
|
||||
verify(ruleSceneMapper, times(1)).insert(any(IotSceneRuleDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRuleScene_success() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
IotRuleSceneSaveReqVO updateReqVO = randomPojo(IotRuleSceneSaveReqVO.class, o -> {
|
||||
o.setId(id);
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setTriggers(Collections.singletonList(randomPojo(IotSceneRuleDO.Trigger.class)));
|
||||
o.setActions(Collections.singletonList(randomPojo(IotSceneRuleDO.Action.class)));
|
||||
});
|
||||
|
||||
// Mock 行为
|
||||
IotSceneRuleDO existingRuleScene = randomPojo(IotSceneRuleDO.class, o -> o.setId(id));
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(existingRuleScene);
|
||||
when(ruleSceneMapper.updateById(any(IotSceneRuleDO.class))).thenReturn(1);
|
||||
|
||||
// 调用
|
||||
assertDoesNotThrow(() -> ruleSceneService.updateRuleScene(updateReqVO));
|
||||
|
||||
// 验证
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
verify(ruleSceneMapper, times(1)).updateById(any(IotSceneRuleDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleScene_success() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// Mock 行为
|
||||
IotSceneRuleDO existingRuleScene = randomPojo(IotSceneRuleDO.class, o -> o.setId(id));
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(existingRuleScene);
|
||||
when(ruleSceneMapper.deleteById(id)).thenReturn(1);
|
||||
|
||||
// 调用
|
||||
assertDoesNotThrow(() -> ruleSceneService.deleteRuleScene(id));
|
||||
|
||||
// 验证
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
verify(ruleSceneMapper, times(1)).deleteById(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleScene() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
IotSceneRuleDO expectedRuleScene = randomPojo(IotSceneRuleDO.class, o -> o.setId(id));
|
||||
|
||||
// Mock 行为
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(expectedRuleScene);
|
||||
|
||||
// 调用
|
||||
IotSceneRuleDO result = ruleSceneService.getRuleScene(id);
|
||||
|
||||
// 断言
|
||||
assertEquals(expectedRuleScene, result);
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRuleSceneStatus_success() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
Integer status = CommonStatusEnum.DISABLE.getStatus();
|
||||
|
||||
// Mock 行为
|
||||
IotSceneRuleDO existingRuleScene = randomPojo(IotSceneRuleDO.class, o -> {
|
||||
o.setId(id);
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
});
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(existingRuleScene);
|
||||
when(ruleSceneMapper.updateById(any(IotSceneRuleDO.class))).thenReturn(1);
|
||||
|
||||
// 调用
|
||||
assertDoesNotThrow(() -> ruleSceneService.updateRuleSceneStatus(id, status));
|
||||
|
||||
// 验证
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
verify(ruleSceneMapper, times(1)).updateById(any(IotSceneRuleDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteRuleSceneByTimer_success() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// Mock 行为
|
||||
IotSceneRuleDO ruleScene = randomPojo(IotSceneRuleDO.class, o -> {
|
||||
o.setId(id);
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
});
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(ruleScene);
|
||||
|
||||
// 调用
|
||||
assertDoesNotThrow(() -> ruleSceneService.executeRuleSceneByTimer(id));
|
||||
|
||||
// 验证
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteRuleSceneByTimer_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// Mock 行为
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(null);
|
||||
|
||||
// 调用 - 不存在的场景规则应该不会抛异常,只是记录日志
|
||||
assertDoesNotThrow(() -> ruleSceneService.executeRuleSceneByTimer(id));
|
||||
|
||||
// 验证
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteRuleSceneByTimer_disabled() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// Mock 行为
|
||||
IotSceneRuleDO ruleScene = randomPojo(IotSceneRuleDO.class, o -> {
|
||||
o.setId(id);
|
||||
o.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
});
|
||||
when(ruleSceneMapper.selectById(id)).thenReturn(ruleScene);
|
||||
|
||||
// 调用 - 禁用的场景规则应该不会执行,只是记录日志
|
||||
assertDoesNotThrow(() -> ruleSceneService.executeRuleSceneByTimer(id));
|
||||
|
||||
// 验证
|
||||
verify(ruleSceneMapper, times(1)).selectById(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
spring:
|
||||
main:
|
||||
lazy-initialization: true # 开启懒加载,加快速度
|
||||
banner-mode: off # 单元测试,禁用 Banner
|
||||
# 数据源配置项
|
||||
datasource:
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=value; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
druid:
|
||||
async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
|
||||
initial-size: 1 # 单元测试,配置为 1,提升启动速度
|
||||
sql:
|
||||
init:
|
||||
schema-locations: classpath:/sql/create_tables.sql
|
||||
|
||||
mybatis-plus:
|
||||
lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
|
||||
type-aliases-package: ${yudao.info.base-package}.module.*.dal.dataobject
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
--- #################### 配置中心相关配置 ####################
|
||||
|
||||
--- #################### 服务保障相关配置 ####################
|
||||
|
||||
# Lock4j 配置项(单元测试,禁用 Lock4j)
|
||||
|
||||
--- #################### 监控相关配置 ####################
|
||||
|
||||
--- #################### 芋道相关配置 ####################
|
||||
|
||||
# 芋道配置项,设置当前项目所有自定义的配置
|
||||
yudao:
|
||||
info:
|
||||
base-package: cn.iocoder.yudao
|
||||
tenant: # 多租户相关配置项
|
||||
enable: true
|
||||
xss:
|
||||
enable: false
|
||||
demo: false # 关闭演示模式
|
||||
@ -0,0 +1,4 @@
|
||||
<configuration>
|
||||
<!-- 引用 Spring Boot 的 logback 基础配置 -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
</configuration>
|
||||
@ -0,0 +1,21 @@
|
||||
-- IoT 模块测试数据清理脚本
|
||||
DELETE
|
||||
FROM "iot_scene_rule";
|
||||
DELETE
|
||||
FROM "iot_product";
|
||||
DELETE
|
||||
FROM "iot_device";
|
||||
DELETE
|
||||
FROM "iot_thing_model";
|
||||
DELETE
|
||||
FROM "iot_device_data";
|
||||
DELETE
|
||||
FROM "iot_alert_config";
|
||||
DELETE
|
||||
FROM "iot_alert_record";
|
||||
DELETE
|
||||
FROM "iot_ota_firmware";
|
||||
DELETE
|
||||
FROM "iot_ota_task";
|
||||
DELETE
|
||||
FROM "iot_ota_record";
|
||||
@ -0,0 +1,472 @@
|
||||
-- IoT 模块测试数据库表结构
|
||||
-- 基于 H2 数据库语法,兼容 MySQL 模式
|
||||
|
||||
-- IoT 场景联动规则表
|
||||
CREATE TABLE IF NOT EXISTS "iot_scene_rule"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"description" varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"status" tinyint NOT NULL DEFAULT '0',
|
||||
"triggers" text,
|
||||
"actions" text,
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 场景联动规则表';
|
||||
|
||||
-- IoT 产品表
|
||||
CREATE TABLE IF NOT EXISTS "iot_product"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"product_key" varchar
|
||||
(
|
||||
100
|
||||
) NOT NULL DEFAULT '',
|
||||
"protocol_type" tinyint NOT NULL DEFAULT '0',
|
||||
"category_id" bigint DEFAULT NULL,
|
||||
"description" varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"data_format" tinyint NOT NULL DEFAULT '0',
|
||||
"device_type" tinyint NOT NULL DEFAULT '0',
|
||||
"net_type" tinyint NOT NULL DEFAULT '0',
|
||||
"validate_type" tinyint NOT NULL DEFAULT '0',
|
||||
"status" tinyint NOT NULL DEFAULT '0',
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 产品表';
|
||||
|
||||
-- IoT 设备表
|
||||
CREATE TABLE IF NOT EXISTS "iot_device"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"device_name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"product_id" bigint NOT NULL,
|
||||
"device_key" varchar
|
||||
(
|
||||
100
|
||||
) NOT NULL DEFAULT '',
|
||||
"device_secret" varchar
|
||||
(
|
||||
100
|
||||
) NOT NULL DEFAULT '',
|
||||
"nickname" varchar
|
||||
(
|
||||
255
|
||||
) DEFAULT NULL,
|
||||
"status" tinyint NOT NULL DEFAULT '0',
|
||||
"status_last_update_time" timestamp DEFAULT NULL,
|
||||
"last_online_time" timestamp DEFAULT NULL,
|
||||
"last_offline_time" timestamp DEFAULT NULL,
|
||||
"active_time" timestamp DEFAULT NULL,
|
||||
"ip" varchar
|
||||
(
|
||||
50
|
||||
) DEFAULT NULL,
|
||||
"firmware_version" varchar
|
||||
(
|
||||
50
|
||||
) DEFAULT NULL,
|
||||
"device_type" tinyint NOT NULL DEFAULT '0',
|
||||
"gateway_id" bigint DEFAULT NULL,
|
||||
"sub_device_count" int NOT NULL DEFAULT '0',
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 设备表';
|
||||
|
||||
-- IoT 物模型表
|
||||
CREATE TABLE IF NOT EXISTS "iot_thing_model"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"product_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"identifier"
|
||||
varchar
|
||||
(
|
||||
100
|
||||
) NOT NULL DEFAULT '',
|
||||
"name" varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"description" varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"type" tinyint NOT NULL DEFAULT '1',
|
||||
"property" text,
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 物模型表';
|
||||
|
||||
-- IoT 设备数据表
|
||||
CREATE TABLE IF NOT EXISTS "iot_device_data"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"device_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"product_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"identifier"
|
||||
varchar
|
||||
(
|
||||
100
|
||||
) NOT NULL DEFAULT '',
|
||||
"type" tinyint NOT NULL DEFAULT '1',
|
||||
"data" text,
|
||||
"ts" bigint NOT NULL DEFAULT '0',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 设备数据表';
|
||||
|
||||
-- IoT 告警配置表
|
||||
CREATE TABLE IF NOT EXISTS "iot_alert_config"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"product_id" bigint NOT NULL,
|
||||
"device_id" bigint DEFAULT NULL,
|
||||
"rule_id" bigint DEFAULT NULL,
|
||||
"status" tinyint NOT NULL DEFAULT '0',
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 告警配置表';
|
||||
|
||||
-- IoT 告警记录表
|
||||
CREATE TABLE IF NOT EXISTS "iot_alert_record"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"alert_config_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"alert_name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"product_id" bigint NOT NULL,
|
||||
"device_id" bigint DEFAULT NULL,
|
||||
"rule_id" bigint DEFAULT NULL,
|
||||
"alert_data" text,
|
||||
"alert_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deal_status" tinyint NOT NULL DEFAULT '0',
|
||||
"deal_time" timestamp DEFAULT NULL,
|
||||
"deal_user_id" bigint DEFAULT NULL,
|
||||
"deal_remark" varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT 告警记录表';
|
||||
|
||||
-- IoT OTA 固件表
|
||||
CREATE TABLE IF NOT EXISTS "iot_ota_firmware"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"product_id" bigint NOT NULL,
|
||||
"version" varchar
|
||||
(
|
||||
50
|
||||
) NOT NULL DEFAULT '',
|
||||
"description" varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"file_url" varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"file_size" bigint NOT NULL DEFAULT '0',
|
||||
"status" tinyint NOT NULL DEFAULT '0',
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT OTA 固件表';
|
||||
|
||||
-- IoT OTA 升级任务表
|
||||
CREATE TABLE IF NOT EXISTS "iot_ota_task"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"name"
|
||||
varchar
|
||||
(
|
||||
255
|
||||
) NOT NULL DEFAULT '',
|
||||
"firmware_id" bigint NOT NULL,
|
||||
"product_id" bigint NOT NULL,
|
||||
"upgrade_type" tinyint NOT NULL DEFAULT '0',
|
||||
"status" tinyint NOT NULL DEFAULT '0',
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT OTA 升级任务表';
|
||||
|
||||
-- IoT OTA 升级记录表
|
||||
CREATE TABLE IF NOT EXISTS "iot_ota_record"
|
||||
(
|
||||
"id"
|
||||
bigint
|
||||
NOT
|
||||
NULL
|
||||
GENERATED
|
||||
BY
|
||||
DEFAULT AS
|
||||
IDENTITY,
|
||||
"task_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"firmware_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"device_id"
|
||||
bigint
|
||||
NOT
|
||||
NULL,
|
||||
"status"
|
||||
tinyint
|
||||
NOT
|
||||
NULL
|
||||
DEFAULT
|
||||
'0',
|
||||
"progress"
|
||||
int
|
||||
NOT
|
||||
NULL
|
||||
DEFAULT
|
||||
'0',
|
||||
"error_msg"
|
||||
varchar
|
||||
(
|
||||
500
|
||||
) DEFAULT NULL,
|
||||
"start_time" timestamp DEFAULT NULL,
|
||||
"end_time" timestamp DEFAULT NULL,
|
||||
"creator" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar
|
||||
(
|
||||
64
|
||||
) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY
|
||||
(
|
||||
"id"
|
||||
)
|
||||
) COMMENT 'IoT OTA 升级记录表';
|
||||
Loading…
x
Reference in New Issue
Block a user