Commit 1beb5c039cad0fc7679c5abc176fd9ad328bf316
1 parent
9d6b37c4
feat:【IoT 物联网】完成告警配置的管理
Showing
9 changed files
with
110 additions
and
31 deletions
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 org.springframework.web.bind.annotation.*; | 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.IotAlertConfigPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigRespVO; | ||
| 8 | +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; | ||
| 10 | +import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService; | ||
| 11 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 12 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 13 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 14 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 15 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 4 | import jakarta.annotation.Resource; | 16 | import jakarta.annotation.Resource; |
| 5 | -import org.springframework.validation.annotation.Validated; | 17 | +import jakarta.validation.Valid; |
| 6 | import org.springframework.security.access.prepost.PreAuthorize; | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
| 7 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 8 | -import io.swagger.v3.oas.annotations.Parameter; | ||
| 9 | -import io.swagger.v3.oas.annotations.Operation; | 19 | +import org.springframework.validation.annotation.Validated; |
| 20 | +import org.springframework.web.bind.annotation.*; | ||
| 10 | 21 | ||
| 11 | -import jakarta.validation.constraints.*; | ||
| 12 | -import jakarta.validation.*; | ||
| 13 | -import jakarta.servlet.http.*; | ||
| 14 | -import java.util.*; | ||
| 15 | -import java.io.IOException; | 22 | +import java.util.Map; |
| 23 | +import java.util.Objects; | ||
| 24 | +import java.util.stream.Collectors; | ||
| 16 | 25 | ||
| 17 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 18 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 19 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 20 | -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 22 | - | ||
| 23 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 24 | - | ||
| 25 | -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | ||
| 26 | -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; | ||
| 27 | - | ||
| 28 | -import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*; | ||
| 29 | -import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; | ||
| 30 | -import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService; | 27 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; |
| 31 | 28 | ||
| 32 | @Tag(name = "管理后台 - IoT 告警配置") | 29 | @Tag(name = "管理后台 - IoT 告警配置") |
| 33 | @RestController | 30 | @RestController |
| @@ -38,6 +35,9 @@ public class IotAlertConfigController { | @@ -38,6 +35,9 @@ public class IotAlertConfigController { | ||
| 38 | @Resource | 35 | @Resource |
| 39 | private IotAlertConfigService alertConfigService; | 36 | private IotAlertConfigService alertConfigService; |
| 40 | 37 | ||
| 38 | + @Resource | ||
| 39 | + private AdminUserApi adminUserApi; | ||
| 40 | + | ||
| 41 | @PostMapping("/create") | 41 | @PostMapping("/create") |
| 42 | @Operation(summary = "创建告警配置") | 42 | @Operation(summary = "创建告警配置") |
| 43 | @PreAuthorize("@ss.hasPermission('iot:alert-config:create')") | 43 | @PreAuthorize("@ss.hasPermission('iot:alert-config:create')") |
| @@ -76,7 +76,12 @@ public class IotAlertConfigController { | @@ -76,7 +76,12 @@ public class IotAlertConfigController { | ||
| 76 | @PreAuthorize("@ss.hasPermission('iot:alert-config:query')") | 76 | @PreAuthorize("@ss.hasPermission('iot:alert-config:query')") |
| 77 | public CommonResult<PageResult<IotAlertConfigRespVO>> getAlertConfigPage(@Valid IotAlertConfigPageReqVO pageReqVO) { | 77 | public CommonResult<PageResult<IotAlertConfigRespVO>> getAlertConfigPage(@Valid IotAlertConfigPageReqVO pageReqVO) { |
| 78 | PageResult<IotAlertConfigDO> pageResult = alertConfigService.getAlertConfigPage(pageReqVO); | 78 | PageResult<IotAlertConfigDO> pageResult = alertConfigService.getAlertConfigPage(pageReqVO); |
| 79 | - return success(BeanUtils.toBean(pageResult, IotAlertConfigRespVO.class)); | 79 | + // 转换返回 |
| 80 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | ||
| 81 | + 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())))); | ||
| 80 | } | 85 | } |
| 81 | 86 | ||
| 82 | } | 87 | } |
| 83 | \ No newline at end of file | 88 | \ 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/IotAlertConfigRespVO.java
| @@ -31,6 +31,9 @@ public class IotAlertConfigRespVO { | @@ -31,6 +31,9 @@ public class IotAlertConfigRespVO { | ||
| 31 | @Schema(description = "接收的用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100,200") | 31 | @Schema(description = "接收的用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100,200") |
| 32 | private List<Long> receiveUserIds; | 32 | private List<Long> receiveUserIds; |
| 33 | 33 | ||
| 34 | + @Schema(description = "接收的用户名称数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三,李四") | ||
| 35 | + private List<String> receiveUserNames; | ||
| 36 | + | ||
| 34 | @Schema(description = "接收的类型数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") | 37 | @Schema(description = "接收的类型数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") |
| 35 | private List<Integer> receiveTypes; | 38 | private List<Integer> receiveTypes; |
| 36 | 39 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java
| 1 | package cn.iocoder.yudao.module.iot.controller.admin.rule; | 1 | package cn.iocoder.yudao.module.iot.controller.admin.rule; |
| 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; |
| @@ -18,7 +19,10 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -18,7 +19,10 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 18 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 19 | import org.springframework.web.bind.annotation.*; | 20 | import org.springframework.web.bind.annotation.*; |
| 20 | 21 | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 24 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 25 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 22 | 26 | ||
| 23 | @Tag(name = "管理后台 - IoT 场景联动") | 27 | @Tag(name = "管理后台 - IoT 场景联动") |
| 24 | @RestController | 28 | @RestController |
| @@ -70,6 +74,14 @@ public class IotRuleSceneController { | @@ -70,6 +74,14 @@ public class IotRuleSceneController { | ||
| 70 | return success(BeanUtils.toBean(pageResult, IotRuleSceneRespVO.class)); | 74 | return success(BeanUtils.toBean(pageResult, IotRuleSceneRespVO.class)); |
| 71 | } | 75 | } |
| 72 | 76 | ||
| 77 | + @GetMapping("/simple-list") | ||
| 78 | + @Operation(summary = "获取场景联动的精简信息列表", description = "主要用于前端的下拉选项") | ||
| 79 | + public CommonResult<List<IotRuleSceneRespVO>> getRuleSceneSimpleList() { | ||
| 80 | + List<IotRuleSceneDO> list = ruleSceneService.getRuleSceneListByStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 81 | + return success(convertList(list, scene -> // 只返回 id、name 字段 | ||
| 82 | + new IotRuleSceneRespVO().setId(scene.getId()).setName(scene.getName()))); | ||
| 83 | + } | ||
| 84 | + | ||
| 73 | @GetMapping("/test") | 85 | @GetMapping("/test") |
| 74 | @PermitAll | 86 | @PermitAll |
| 75 | public void test() { | 87 | public void test() { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/alert/IotAlertConfigDO.java
| @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; | @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; | ||
| 6 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; | 6 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; |
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; |
| 8 | import cn.iocoder.yudao.module.iot.enums.DictTypeConstants; | 8 | import cn.iocoder.yudao.module.iot.enums.DictTypeConstants; |
| 9 | -import cn.iocoder.yudao.module.iot.enums.alert.IotAlertConfigReceiveTypeEnum; | 9 | +import cn.iocoder.yudao.module.iot.enums.alert.IotAlertReceiveTypeEnum; |
| 10 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 10 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 11 | import com.baomidou.mybatisplus.annotation.KeySequence; | 11 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 12 | import com.baomidou.mybatisplus.annotation.TableField; | 12 | import com.baomidou.mybatisplus.annotation.TableField; |
| @@ -24,7 +24,7 @@ import java.util.List; | @@ -24,7 +24,7 @@ import java.util.List; | ||
| 24 | * | 24 | * |
| 25 | * @author 芋道源码 | 25 | * @author 芋道源码 |
| 26 | */ | 26 | */ |
| 27 | -@TableName("iot_alert_config") | 27 | +@TableName(value = "iot_alert_config", autoResultMap = true) |
| 28 | @KeySequence("iot_alert_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | 28 | @KeySequence("iot_alert_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 |
| 29 | @Data | 29 | @Data |
| 30 | @Builder | 30 | @Builder |
| @@ -76,7 +76,7 @@ public class IotAlertConfigDO extends BaseDO { | @@ -76,7 +76,7 @@ public class IotAlertConfigDO extends BaseDO { | ||
| 76 | /** | 76 | /** |
| 77 | * 接收的类型数组 | 77 | * 接收的类型数组 |
| 78 | * | 78 | * |
| 79 | - * 枚举 {@link IotAlertConfigReceiveTypeEnum} | 79 | + * 枚举 {@link IotAlertReceiveTypeEnum} |
| 80 | */ | 80 | */ |
| 81 | @TableField(typeHandler = IntegerListTypeHandler.class) | 81 | @TableField(typeHandler = IntegerListTypeHandler.class) |
| 82 | private List<Integer> receiveTypes; | 82 | private List<Integer> receiveTypes; |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java
| @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePa | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePa | ||
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 10 | /** | 12 | /** |
| 11 | * IoT 场景联动 Mapper | 13 | * IoT 场景联动 Mapper |
| 12 | * | 14 | * |
| @@ -24,4 +26,8 @@ public interface IotRuleSceneMapper extends BaseMapperX<IotRuleSceneDO> { | @@ -24,4 +26,8 @@ public interface IotRuleSceneMapper extends BaseMapperX<IotRuleSceneDO> { | ||
| 24 | .orderByDesc(IotRuleSceneDO::getId)); | 26 | .orderByDesc(IotRuleSceneDO::getId)); |
| 25 | } | 27 | } |
| 26 | 28 | ||
| 29 | + default List<IotRuleSceneDO> selectListByStatus(Integer status) { | ||
| 30 | + return selectList(IotRuleSceneDO::getStatus, status); | ||
| 31 | + } | ||
| 32 | + | ||
| 27 | } | 33 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/alert/IotAlertConfigReceiveTypeEnum.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/alert/IotAlertReceiveTypeEnum.java
| @@ -7,21 +7,22 @@ import lombok.RequiredArgsConstructor; | @@ -7,21 +7,22 @@ import lombok.RequiredArgsConstructor; | ||
| 7 | import java.util.Arrays; | 7 | import java.util.Arrays; |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | - * IoT 告警配置的接收方式枚举 | 10 | + * IoT 告警的接收方式枚举 |
| 11 | * | 11 | * |
| 12 | * @author 芋道源码 | 12 | * @author 芋道源码 |
| 13 | */ | 13 | */ |
| 14 | @RequiredArgsConstructor | 14 | @RequiredArgsConstructor |
| 15 | @Getter | 15 | @Getter |
| 16 | -public enum IotAlertConfigReceiveTypeEnum implements ArrayValuable<Integer> { | 16 | +public enum IotAlertReceiveTypeEnum implements ArrayValuable<Integer> { |
| 17 | 17 | ||
| 18 | SMS(1), // 短信 | 18 | SMS(1), // 短信 |
| 19 | MAIL(2), // 邮箱 | 19 | MAIL(2), // 邮箱 |
| 20 | - NOTIFY(3); // 通知 | 20 | + NOTIFY(3); // 站内信 |
| 21 | + // TODO 待实现(欢迎 pull request):webhook 4 | ||
| 21 | 22 | ||
| 22 | private final Integer type; | 23 | private final Integer type; |
| 23 | 24 | ||
| 24 | - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotAlertConfigReceiveTypeEnum::getType).toArray(Integer[]::new); | 25 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotAlertReceiveTypeEnum::getType).toArray(Integer[]::new); |
| 25 | 26 | ||
| 26 | @Override | 27 | @Override |
| 27 | public Integer[] array() { | 28 | public Integer[] array() { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java
| @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageR | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageR | ||
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO; | 6 | import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; |
| 8 | import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertConfigMapper; | 8 | import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertConfigMapper; |
| 9 | +import cn.iocoder.yudao.module.iot.service.rule.scene.IotRuleSceneService; | ||
| 10 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 9 | import jakarta.annotation.Resource; | 11 | import jakarta.annotation.Resource; |
| 10 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| @@ -25,8 +27,18 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { | @@ -25,8 +27,18 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { | ||
| 25 | @Resource | 27 | @Resource |
| 26 | private IotAlertConfigMapper alertConfigMapper; | 28 | private IotAlertConfigMapper alertConfigMapper; |
| 27 | 29 | ||
| 30 | + @Resource | ||
| 31 | + private IotRuleSceneService ruleSceneService; | ||
| 32 | + | ||
| 33 | + @Resource | ||
| 34 | + private AdminUserApi adminUserApi; | ||
| 35 | + | ||
| 28 | @Override | 36 | @Override |
| 29 | public Long createAlertConfig(IotAlertConfigSaveReqVO createReqVO) { | 37 | public Long createAlertConfig(IotAlertConfigSaveReqVO createReqVO) { |
| 38 | + // 校验关联数据是否存在 | ||
| 39 | + ruleSceneService.validateRuleSceneList(createReqVO.getSceneRuleIds()); | ||
| 40 | + adminUserApi.validateUserList(createReqVO.getReceiveUserIds()); | ||
| 41 | + | ||
| 30 | IotAlertConfigDO alertConfig = BeanUtils.toBean(createReqVO, IotAlertConfigDO.class); | 42 | IotAlertConfigDO alertConfig = BeanUtils.toBean(createReqVO, IotAlertConfigDO.class); |
| 31 | alertConfigMapper.insert(alertConfig); | 43 | alertConfigMapper.insert(alertConfig); |
| 32 | return alertConfig.getId(); | 44 | return alertConfig.getId(); |
| @@ -36,6 +48,10 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { | @@ -36,6 +48,10 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService { | ||
| 36 | public void updateAlertConfig(IotAlertConfigSaveReqVO updateReqVO) { | 48 | public void updateAlertConfig(IotAlertConfigSaveReqVO updateReqVO) { |
| 37 | // 校验存在 | 49 | // 校验存在 |
| 38 | validateAlertConfigExists(updateReqVO.getId()); | 50 | validateAlertConfigExists(updateReqVO.getId()); |
| 51 | + // 校验关联数据是否存在 | ||
| 52 | + ruleSceneService.validateRuleSceneList(updateReqVO.getSceneRuleIds()); | ||
| 53 | + adminUserApi.validateUserList(updateReqVO.getReceiveUserIds()); | ||
| 54 | + | ||
| 39 | // 更新 | 55 | // 更新 |
| 40 | IotAlertConfigDO updateObj = BeanUtils.toBean(updateReqVO, IotAlertConfigDO.class); | 56 | IotAlertConfigDO updateObj = BeanUtils.toBean(updateReqVO, IotAlertConfigDO.class); |
| 41 | alertConfigMapper.updateById(updateObj); | 57 | alertConfigMapper.updateById(updateObj); |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotRuleSceneService.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | ||
| 8 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; | 8 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; |
| 9 | import jakarta.validation.Valid; | 9 | import jakarta.validation.Valid; |
| 10 | 10 | ||
| 11 | +import java.util.Collection; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| @@ -56,6 +57,22 @@ public interface IotRuleSceneService { | @@ -56,6 +57,22 @@ public interface IotRuleSceneService { | ||
| 56 | PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO); | 57 | PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO); |
| 57 | 58 | ||
| 58 | /** | 59 | /** |
| 60 | + * 校验规则场景编号们是否存在。如下情况,视为无效: | ||
| 61 | + * 1. 规则场景编号不存在 | ||
| 62 | + * | ||
| 63 | + * @param ids 规则场景编号数组 | ||
| 64 | + */ | ||
| 65 | + void validateRuleSceneList(Collection<Long> ids); | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 获得指定状态的场景联动列表 | ||
| 69 | + * | ||
| 70 | + * @param status 状态 | ||
| 71 | + * @return 场景联动列表 | ||
| 72 | + */ | ||
| 73 | + List<IotRuleSceneDO> getRuleSceneListByStatus(Integer status); | ||
| 74 | + | ||
| 75 | + /** | ||
| 59 | * 【缓存】获得指定设备的场景列表 | 76 | * 【缓存】获得指定设备的场景列表 |
| 60 | * | 77 | * |
| 61 | * @param productKey 产品 Key | 78 | * @param productKey 产品 Key |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotRuleSceneServiceImpl.java
| @@ -42,9 +42,12 @@ import org.springframework.validation.annotation.Validated; | @@ -42,9 +42,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 42 | import java.util.HashMap; | 42 | import java.util.HashMap; |
| 43 | import java.util.List; | 43 | import java.util.List; |
| 44 | import java.util.Map; | 44 | import java.util.Map; |
| 45 | +import java.util.Collection; | ||
| 46 | +import java.util.Set; | ||
| 45 | 47 | ||
| 46 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 48 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 47 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | 49 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 50 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 48 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | 51 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| 49 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.RULE_SCENE_NOT_EXISTS; | 52 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.RULE_SCENE_NOT_EXISTS; |
| 50 | 53 | ||
| @@ -109,6 +112,22 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { | @@ -109,6 +112,22 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { | ||
| 109 | return ruleSceneMapper.selectPage(pageReqVO); | 112 | return ruleSceneMapper.selectPage(pageReqVO); |
| 110 | } | 113 | } |
| 111 | 114 | ||
| 115 | + @Override | ||
| 116 | + public void validateRuleSceneList(Collection<Long> ids) { | ||
| 117 | + if (CollUtil.isEmpty(ids)) { | ||
| 118 | + return; | ||
| 119 | + } | ||
| 120 | + // 批量查询存在的规则场景 | ||
| 121 | + List<IotRuleSceneDO> existingScenes = ruleSceneMapper.selectByIds(ids); | ||
| 122 | + if (existingScenes.size() != ids.size()) { | ||
| 123 | + throw exception(RULE_SCENE_NOT_EXISTS); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public List<IotRuleSceneDO> getRuleSceneListByStatus(Integer status) { | ||
| 129 | + return ruleSceneMapper.selectListByStatus(status); | ||
| 130 | + } | ||
| 112 | 131 | ||
| 113 | // TODO 芋艿,缓存待实现 | 132 | // TODO 芋艿,缓存待实现 |
| 114 | @Override | 133 | @Override |