From 9d6b37c47637fc883ba7c1ad0218f7b91ecdd82a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 27 Jun 2025 22:39:25 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E5=88=9D=E5=A7=8B=E5=8C=96=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/alert/IotAlertConfigController.java | 82 +++++++++++++++++++ .../alert/vo/IotAlertConfigPageReqVO.java | 26 ++++++ .../admin/alert/vo/IotAlertConfigRespVO.java | 40 +++++++++ .../alert/vo/IotAlertConfigSaveReqVO.java | 47 +++++++++++ .../dal/mysql/alert/IotAlertConfigMapper.java | 26 ++++++ .../module/iot/enums/ErrorCodeConstants.java | 3 + .../service/alert/IotAlertConfigService.java | 54 ++++++++++++ .../alert/IotAlertConfigServiceImpl.java | 68 +++++++++++++++ 8 files changed, 346 insertions(+) create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertConfigController.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigPageReqVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigRespVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigSaveReqVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertConfigMapper.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigService.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertConfigController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertConfigController.java new file mode 100644 index 0000000000..228926bb70 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertConfigController.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.iot.controller.admin.alert; + +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.constraints.*; +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*; +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; +import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService; + +@Tag(name = "管理后台 - IoT 告警配置") +@RestController +@RequestMapping("/iot/alert-config") +@Validated +public class IotAlertConfigController { + + @Resource + private IotAlertConfigService alertConfigService; + + @PostMapping("/create") + @Operation(summary = "创建告警配置") + @PreAuthorize("@ss.hasPermission('iot:alert-config:create')") + public CommonResult createAlertConfig(@Valid @RequestBody IotAlertConfigSaveReqVO createReqVO) { + return success(alertConfigService.createAlertConfig(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新告警配置") + @PreAuthorize("@ss.hasPermission('iot:alert-config:update')") + public CommonResult updateAlertConfig(@Valid @RequestBody IotAlertConfigSaveReqVO updateReqVO) { + alertConfigService.updateAlertConfig(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除告警配置") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('iot:alert-config:delete')") + public CommonResult deleteAlertConfig(@RequestParam("id") Long id) { + alertConfigService.deleteAlertConfig(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得告警配置") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('iot:alert-config:query')") + public CommonResult getAlertConfig(@RequestParam("id") Long id) { + IotAlertConfigDO alertConfig = alertConfigService.getAlertConfig(id); + return success(BeanUtils.toBean(alertConfig, IotAlertConfigRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得告警配置分页") + @PreAuthorize("@ss.hasPermission('iot:alert-config:query')") + public CommonResult> getAlertConfigPage(@Valid IotAlertConfigPageReqVO pageReqVO) { + PageResult pageResult = alertConfigService.getAlertConfigPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, IotAlertConfigRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigPageReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigPageReqVO.java new file mode 100644 index 0000000000..2a6ecdf7c6 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigPageReqVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - IoT 告警配置分页 Request VO") +@Data +public class IotAlertConfigPageReqVO extends PageParam { + + @Schema(description = "配置名称", example = "赵六") + private String name; + + @Schema(description = "配置状态", example = "1") + private Integer status; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigRespVO.java new file mode 100644 index 0000000000..d15ec4b2ab --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigRespVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Schema(description = "管理后台 - IoT 告警配置 Response VO") +@Data +public class IotAlertConfigRespVO { + + @Schema(description = "配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3566") + private Long id; + + @Schema(description = "配置名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + private String name; + + @Schema(description = "配置描述", example = "你猜") + private String description; + + @Schema(description = "告警级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer level; + + @Schema(description = "配置状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + + @Schema(description = "关联的场景联动规则编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") + private List sceneRuleIds; + + @Schema(description = "接收的用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100,200") + private List receiveUserIds; + + @Schema(description = "接收的类型数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") + private List receiveTypes; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigSaveReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigSaveReqVO.java new file mode 100644 index 0000000000..231bd4717a --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/vo/IotAlertConfigSaveReqVO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +@Schema(description = "管理后台 - IoT 告警配置新增/修改 Request VO") +@Data +public class IotAlertConfigSaveReqVO { + + @Schema(description = "配置编号", example = "3566") + private Long id; + + @Schema(description = "配置名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + @NotEmpty(message = "配置名称不能为空") + private String name; + + @Schema(description = "配置描述", example = "你猜") + private String description; + + @Schema(description = "告警级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "告警级别不能为空") + private Integer level; + + @Schema(description = "配置状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "配置状态不能为空") + @InEnum(CommonStatusEnum.class) + private Integer status; + + @Schema(description = "关联的场景联动规则编号数组") + @NotEmpty(message = "关联的场景联动规则编号数组不能为空") + private List sceneRuleIds; + + @Schema(description = "接收的用户编号数组") + @NotEmpty(message = "接收的用户编号数组不能为空") + private List receiveUserIds; + + @Schema(description = "接收的类型数组") + @NotEmpty(message = "接收的类型数组不能为空") + private List receiveTypes; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertConfigMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertConfigMapper.java new file mode 100644 index 0000000000..6871763211 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertConfigMapper.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.iot.dal.mysql.alert; + +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.alert.vo.IotAlertConfigPageReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * IoT 告警配置 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface IotAlertConfigMapper extends BaseMapperX { + + default PageResult selectPage(IotAlertConfigPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(IotAlertConfigDO::getName, reqVO.getName()) + .eqIfPresent(IotAlertConfigDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(IotAlertConfigDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(IotAlertConfigDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java index 8217a5b2ae..d186cd2f86 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java @@ -64,4 +64,7 @@ public interface ErrorCodeConstants { // ========== IoT 场景联动 1-050-012-000 ========== ErrorCode RULE_SCENE_NOT_EXISTS = new ErrorCode(1_050_012_000, "场景联动不存在"); + // ========== IoT 告警配置 1-050-013-000 ========== + ErrorCode ALERT_CONFIG_NOT_EXISTS = new ErrorCode(1_050_013_000, "IoT 告警配置不存在"); + } \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigService.java new file mode 100644 index 0000000000..cf539f6a88 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigService.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.iot.service.alert; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageReqVO; +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; +import jakarta.validation.Valid; + +/** + * IoT 告警配置 Service 接口 + * + * @author 芋道源码 + */ +public interface IotAlertConfigService { + + /** + * 创建告警配置 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createAlertConfig(@Valid IotAlertConfigSaveReqVO createReqVO); + + /** + * 更新告警配置 + * + * @param updateReqVO 更新信息 + */ + void updateAlertConfig(@Valid IotAlertConfigSaveReqVO updateReqVO); + + /** + * 删除告警配置 + * + * @param id 编号 + */ + void deleteAlertConfig(Long id); + + /** + * 获得告警配置 + * + * @param id 编号 + * @return 告警配置 + */ + IotAlertConfigDO getAlertConfig(Long id); + + /** + * 获得告警配置分页 + * + * @param pageReqVO 分页查询 + * @return 告警配置分页 + */ + PageResult getAlertConfigPage(IotAlertConfigPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java new file mode 100644 index 0000000000..ead8559dd7 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.iot.service.alert; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageReqVO; +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; +import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertConfigMapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.ALERT_CONFIG_NOT_EXISTS; + +/** + * IoT 告警配置 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class IotAlertConfigServiceImpl implements IotAlertConfigService { + + @Resource + private IotAlertConfigMapper alertConfigMapper; + + @Override + public Long createAlertConfig(IotAlertConfigSaveReqVO createReqVO) { + IotAlertConfigDO alertConfig = BeanUtils.toBean(createReqVO, IotAlertConfigDO.class); + alertConfigMapper.insert(alertConfig); + return alertConfig.getId(); + } + + @Override + public void updateAlertConfig(IotAlertConfigSaveReqVO updateReqVO) { + // 校验存在 + validateAlertConfigExists(updateReqVO.getId()); + // 更新 + IotAlertConfigDO updateObj = BeanUtils.toBean(updateReqVO, IotAlertConfigDO.class); + alertConfigMapper.updateById(updateObj); + } + + @Override + public void deleteAlertConfig(Long id) { + // 校验存在 + validateAlertConfigExists(id); + // 删除 + alertConfigMapper.deleteById(id); + } + + private void validateAlertConfigExists(Long id) { + if (alertConfigMapper.selectById(id) == null) { + throw exception(ALERT_CONFIG_NOT_EXISTS); + } + } + + @Override + public IotAlertConfigDO getAlertConfig(Long id) { + return alertConfigMapper.selectById(id); + } + + @Override + public PageResult getAlertConfigPage(IotAlertConfigPageReqVO pageReqVO) { + return alertConfigMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file