Commit 9d6b37c47637fc883ba7c1ad0218f7b91ecdd82a

Authored by YunaiV
1 parent 4ebaa3d6

feat:【IoT 物联网】初始化告警配置

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/alert/IotAlertConfigController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert;
  2 +
  3 +import org.springframework.web.bind.annotation.*;
  4 +import jakarta.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +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;
  10 +
  11 +import jakarta.validation.constraints.*;
  12 +import jakarta.validation.*;
  13 +import jakarta.servlet.http.*;
  14 +import java.util.*;
  15 +import java.io.IOException;
  16 +
  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;
  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;
  31 +
  32 +@Tag(name = "管理后台 - IoT 告警配置")
  33 +@RestController
  34 +@RequestMapping("/iot/alert-config")
  35 +@Validated
  36 +public class IotAlertConfigController {
  37 +
  38 + @Resource
  39 + private IotAlertConfigService alertConfigService;
  40 +
  41 + @PostMapping("/create")
  42 + @Operation(summary = "创建告警配置")
  43 + @PreAuthorize("@ss.hasPermission('iot:alert-config:create')")
  44 + public CommonResult<Long> createAlertConfig(@Valid @RequestBody IotAlertConfigSaveReqVO createReqVO) {
  45 + return success(alertConfigService.createAlertConfig(createReqVO));
  46 + }
  47 +
  48 + @PutMapping("/update")
  49 + @Operation(summary = "更新告警配置")
  50 + @PreAuthorize("@ss.hasPermission('iot:alert-config:update')")
  51 + public CommonResult<Boolean> updateAlertConfig(@Valid @RequestBody IotAlertConfigSaveReqVO updateReqVO) {
  52 + alertConfigService.updateAlertConfig(updateReqVO);
  53 + return success(true);
  54 + }
  55 +
  56 + @DeleteMapping("/delete")
  57 + @Operation(summary = "删除告警配置")
  58 + @Parameter(name = "id", description = "编号", required = true)
  59 + @PreAuthorize("@ss.hasPermission('iot:alert-config:delete')")
  60 + public CommonResult<Boolean> deleteAlertConfig(@RequestParam("id") Long id) {
  61 + alertConfigService.deleteAlertConfig(id);
  62 + return success(true);
  63 + }
  64 +
  65 + @GetMapping("/get")
  66 + @Operation(summary = "获得告警配置")
  67 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  68 + @PreAuthorize("@ss.hasPermission('iot:alert-config:query')")
  69 + public CommonResult<IotAlertConfigRespVO> getAlertConfig(@RequestParam("id") Long id) {
  70 + IotAlertConfigDO alertConfig = alertConfigService.getAlertConfig(id);
  71 + return success(BeanUtils.toBean(alertConfig, IotAlertConfigRespVO.class));
  72 + }
  73 +
  74 + @GetMapping("/page")
  75 + @Operation(summary = "获得告警配置分页")
  76 + @PreAuthorize("@ss.hasPermission('iot:alert-config:query')")
  77 + public CommonResult<PageResult<IotAlertConfigRespVO>> getAlertConfigPage(@Valid IotAlertConfigPageReqVO pageReqVO) {
  78 + PageResult<IotAlertConfigDO> pageResult = alertConfigService.getAlertConfigPage(pageReqVO);
  79 + return success(BeanUtils.toBean(pageResult, IotAlertConfigRespVO.class));
  80 + }
  81 +
  82 +}
0 83 \ 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/IotAlertConfigPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import org.springframework.format.annotation.DateTimeFormat;
  7 +
  8 +import java.time.LocalDateTime;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Schema(description = "管理后台 - IoT 告警配置分页 Request VO")
  13 +@Data
  14 +public class IotAlertConfigPageReqVO extends PageParam {
  15 +
  16 + @Schema(description = "配置名称", example = "赵六")
  17 + private String name;
  18 +
  19 + @Schema(description = "配置状态", example = "1")
  20 + private Integer status;
  21 +
  22 + @Schema(description = "创建时间")
  23 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  24 + private LocalDateTime[] createTime;
  25 +
  26 +}
0 27 \ 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 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import java.time.LocalDateTime;
  7 +import java.util.List;
  8 +
  9 +@Schema(description = "管理后台 - IoT 告警配置 Response VO")
  10 +@Data
  11 +public class IotAlertConfigRespVO {
  12 +
  13 + @Schema(description = "配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3566")
  14 + private Long id;
  15 +
  16 + @Schema(description = "配置名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
  17 + private String name;
  18 +
  19 + @Schema(description = "配置描述", example = "你猜")
  20 + private String description;
  21 +
  22 + @Schema(description = "告警级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  23 + private Integer level;
  24 +
  25 + @Schema(description = "配置状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  26 + private Integer status;
  27 +
  28 + @Schema(description = "关联的场景联动规则编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3")
  29 + private List<Long> sceneRuleIds;
  30 +
  31 + @Schema(description = "接收的用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100,200")
  32 + private List<Long> receiveUserIds;
  33 +
  34 + @Schema(description = "接收的类型数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3")
  35 + private List<Integer> receiveTypes;
  36 +
  37 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  38 + private LocalDateTime createTime;
  39 +
  40 +}
0 41 \ 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/IotAlertConfigSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.alert.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import jakarta.validation.constraints.NotEmpty;
  7 +import jakarta.validation.constraints.NotNull;
  8 +import lombok.Data;
  9 +
  10 +import java.util.List;
  11 +
  12 +@Schema(description = "管理后台 - IoT 告警配置新增/修改 Request VO")
  13 +@Data
  14 +public class IotAlertConfigSaveReqVO {
  15 +
  16 + @Schema(description = "配置编号", example = "3566")
  17 + private Long id;
  18 +
  19 + @Schema(description = "配置名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
  20 + @NotEmpty(message = "配置名称不能为空")
  21 + private String name;
  22 +
  23 + @Schema(description = "配置描述", example = "你猜")
  24 + private String description;
  25 +
  26 + @Schema(description = "告警级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  27 + @NotNull(message = "告警级别不能为空")
  28 + private Integer level;
  29 +
  30 + @Schema(description = "配置状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  31 + @NotNull(message = "配置状态不能为空")
  32 + @InEnum(CommonStatusEnum.class)
  33 + private Integer status;
  34 +
  35 + @Schema(description = "关联的场景联动规则编号数组")
  36 + @NotEmpty(message = "关联的场景联动规则编号数组不能为空")
  37 + private List<Long> sceneRuleIds;
  38 +
  39 + @Schema(description = "接收的用户编号数组")
  40 + @NotEmpty(message = "接收的用户编号数组不能为空")
  41 + private List<Long> receiveUserIds;
  42 +
  43 + @Schema(description = "接收的类型数组")
  44 + @NotEmpty(message = "接收的类型数组不能为空")
  45 + private List<Integer> receiveTypes;
  46 +
  47 +}
0 48 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/alert/IotAlertConfigMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.dal.mysql.alert;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageReqVO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * IoT 告警配置 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface IotAlertConfigMapper extends BaseMapperX<IotAlertConfigDO> {
  17 +
  18 + default PageResult<IotAlertConfigDO> selectPage(IotAlertConfigPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<IotAlertConfigDO>()
  20 + .likeIfPresent(IotAlertConfigDO::getName, reqVO.getName())
  21 + .eqIfPresent(IotAlertConfigDO::getStatus, reqVO.getStatus())
  22 + .betweenIfPresent(IotAlertConfigDO::getCreateTime, reqVO.getCreateTime())
  23 + .orderByDesc(IotAlertConfigDO::getId));
  24 + }
  25 +
  26 +}
0 27 \ No newline at end of file
... ...
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 {
64 64 // ========== IoT 场景联动 1-050-012-000 ==========
65 65 ErrorCode RULE_SCENE_NOT_EXISTS = new ErrorCode(1_050_012_000, "场景联动不存在");
66 66  
  67 + // ========== IoT 告警配置 1-050-013-000 ==========
  68 + ErrorCode ALERT_CONFIG_NOT_EXISTS = new ErrorCode(1_050_013_000, "IoT 告警配置不存在");
  69 +
67 70 }
68 71 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.alert;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageReqVO;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO;
  6 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
  7 +import jakarta.validation.Valid;
  8 +
  9 +/**
  10 + * IoT 告警配置 Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface IotAlertConfigService {
  15 +
  16 + /**
  17 + * 创建告警配置
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Long createAlertConfig(@Valid IotAlertConfigSaveReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新告警配置
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateAlertConfig(@Valid IotAlertConfigSaveReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除告警配置
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteAlertConfig(Long id);
  37 +
  38 + /**
  39 + * 获得告警配置
  40 + *
  41 + * @param id 编号
  42 + * @return 告警配置
  43 + */
  44 + IotAlertConfigDO getAlertConfig(Long id);
  45 +
  46 + /**
  47 + * 获得告警配置分页
  48 + *
  49 + * @param pageReqVO 分页查询
  50 + * @return 告警配置分页
  51 + */
  52 + PageResult<IotAlertConfigDO> getAlertConfigPage(IotAlertConfigPageReqVO pageReqVO);
  53 +
  54 +}
0 55 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/alert/IotAlertConfigServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.alert;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigPageReqVO;
  6 +import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.IotAlertConfigSaveReqVO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
  8 +import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertConfigMapper;
  9 +import jakarta.annotation.Resource;
  10 +import org.springframework.stereotype.Service;
  11 +import org.springframework.validation.annotation.Validated;
  12 +
  13 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  14 +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.ALERT_CONFIG_NOT_EXISTS;
  15 +
  16 +/**
  17 + * IoT 告警配置 Service 实现类
  18 + *
  19 + * @author 芋道源码
  20 + */
  21 +@Service
  22 +@Validated
  23 +public class IotAlertConfigServiceImpl implements IotAlertConfigService {
  24 +
  25 + @Resource
  26 + private IotAlertConfigMapper alertConfigMapper;
  27 +
  28 + @Override
  29 + public Long createAlertConfig(IotAlertConfigSaveReqVO createReqVO) {
  30 + IotAlertConfigDO alertConfig = BeanUtils.toBean(createReqVO, IotAlertConfigDO.class);
  31 + alertConfigMapper.insert(alertConfig);
  32 + return alertConfig.getId();
  33 + }
  34 +
  35 + @Override
  36 + public void updateAlertConfig(IotAlertConfigSaveReqVO updateReqVO) {
  37 + // 校验存在
  38 + validateAlertConfigExists(updateReqVO.getId());
  39 + // 更新
  40 + IotAlertConfigDO updateObj = BeanUtils.toBean(updateReqVO, IotAlertConfigDO.class);
  41 + alertConfigMapper.updateById(updateObj);
  42 + }
  43 +
  44 + @Override
  45 + public void deleteAlertConfig(Long id) {
  46 + // 校验存在
  47 + validateAlertConfigExists(id);
  48 + // 删除
  49 + alertConfigMapper.deleteById(id);
  50 + }
  51 +
  52 + private void validateAlertConfigExists(Long id) {
  53 + if (alertConfigMapper.selectById(id) == null) {
  54 + throw exception(ALERT_CONFIG_NOT_EXISTS);
  55 + }
  56 + }
  57 +
  58 + @Override
  59 + public IotAlertConfigDO getAlertConfig(Long id) {
  60 + return alertConfigMapper.selectById(id);
  61 + }
  62 +
  63 + @Override
  64 + public PageResult<IotAlertConfigDO> getAlertConfigPage(IotAlertConfigPageReqVO pageReqVO) {
  65 + return alertConfigMapper.selectPage(pageReqVO);
  66 + }
  67 +
  68 +}
0 69 \ No newline at end of file
... ...