feat: 告警模块添加
This commit is contained in:
@@ -23,4 +23,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode COMMENT_PARENT_ERROR = new ErrorCode(1_100_003_004, "不能设置自己为父评论");
|
ErrorCode COMMENT_PARENT_ERROR = new ErrorCode(1_100_003_004, "不能设置自己为父评论");
|
||||||
ErrorCode COMMENT_CONTENT_DUPLICATE = new ErrorCode(1_100_003_005, "已经存在该内容的评论");
|
ErrorCode COMMENT_CONTENT_DUPLICATE = new ErrorCode(1_100_003_005, "已经存在该内容的评论");
|
||||||
ErrorCode COMMENT_PARENT_IS_CHILD = new ErrorCode(1_100_003_006, "不能设置自己的子Comment为父Comment");
|
ErrorCode COMMENT_PARENT_IS_CHILD = new ErrorCode(1_100_003_006, "不能设置自己的子Comment为父Comment");
|
||||||
|
|
||||||
|
|
||||||
|
ErrorCode ALERT_NOT_EXISTS = new ErrorCode(1_100_004_001, "告警不存在");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package org.agt.module.license.controller.admin.alert;
|
||||||
|
|
||||||
|
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.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.agt.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import org.agt.framework.common.pojo.CommonResult;
|
||||||
|
import org.agt.framework.common.pojo.PageParam;
|
||||||
|
import org.agt.framework.common.pojo.PageResult;
|
||||||
|
import org.agt.framework.common.util.object.BeanUtils;
|
||||||
|
import org.agt.framework.excel.core.util.ExcelUtils;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.AlertPageReqVO;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.AlertRespVO;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.AlertSaveReqVO;
|
||||||
|
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
||||||
|
import org.agt.module.license.service.alert.AlertService;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.agt.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||||
|
import static org.agt.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 告警")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/license/alert")
|
||||||
|
@Validated
|
||||||
|
public class AlertController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AlertService alertService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建告警")
|
||||||
|
@PreAuthorize("@ss.hasPermission('license:alert:create')")
|
||||||
|
public CommonResult<Long> createAlert(@Valid @RequestBody AlertSaveReqVO createReqVO) {
|
||||||
|
return success(alertService.createAlert(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新告警")
|
||||||
|
@PreAuthorize("@ss.hasPermission('license:alert:update')")
|
||||||
|
public CommonResult<Boolean> updateAlert(@Valid @RequestBody AlertSaveReqVO updateReqVO) {
|
||||||
|
alertService.updateAlert(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除告警")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('license:alert:delete')")
|
||||||
|
public CommonResult<Boolean> deleteAlert(@RequestParam("id") Long id) {
|
||||||
|
alertService.deleteAlert(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得告警")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('license:alert:query')")
|
||||||
|
public CommonResult<AlertRespVO> getAlert(@RequestParam("id") Long id) {
|
||||||
|
AlertDO alert = alertService.getAlert(id);
|
||||||
|
return success(BeanUtils.toBean(alert, AlertRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得告警分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('license:alert:query')")
|
||||||
|
public CommonResult<PageResult<AlertRespVO>> getAlertPage(@Valid AlertPageReqVO pageReqVO) {
|
||||||
|
PageResult<AlertDO> pageResult = alertService.getAlertPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, AlertRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出告警 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('license:alert:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportAlertExcel(@Valid AlertPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<AlertDO> list = alertService.getAlertPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "告警.xls", "数据", AlertRespVO.class,
|
||||||
|
BeanUtils.toBean(list, AlertRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.agt.module.license.controller.admin.alert.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import org.agt.framework.common.pojo.PageParam;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static org.agt.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 告警分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class AlertPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "提醒人")
|
||||||
|
private String users;
|
||||||
|
|
||||||
|
@Schema(description = "提醒天数")
|
||||||
|
private String days;
|
||||||
|
|
||||||
|
@Schema(description = "提醒内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "状态-是否启用", example = "2")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "模板code")
|
||||||
|
private String templateCode;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你猜")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package org.agt.module.license.controller.admin.alert.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 告警 Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class AlertRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "4299")
|
||||||
|
@ExcelProperty("主键")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "提醒人")
|
||||||
|
@ExcelProperty("提醒人")
|
||||||
|
private String users;
|
||||||
|
|
||||||
|
@Schema(description = "提醒天数")
|
||||||
|
@ExcelProperty("提醒天数")
|
||||||
|
private String days;
|
||||||
|
|
||||||
|
@Schema(description = "提醒内容")
|
||||||
|
@ExcelProperty("提醒内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "状态-是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@ExcelProperty("状态-是否启用")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "模板code")
|
||||||
|
@ExcelProperty("模板code")
|
||||||
|
private String templateCode;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你猜")
|
||||||
|
@ExcelProperty("备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.agt.module.license.controller.admin.alert.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 告警新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class AlertSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "4299")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "提醒人")
|
||||||
|
private String users;
|
||||||
|
|
||||||
|
@Schema(description = "提醒天数")
|
||||||
|
private String days;
|
||||||
|
|
||||||
|
@Schema(description = "提醒内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "状态-是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@NotNull(message = "状态-是否启用不能为空")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "模板code")
|
||||||
|
private String templateCode;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你猜")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.agt.module.license.dal.dataobject.alert;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import org.agt.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警 DO
|
||||||
|
*
|
||||||
|
* @author super
|
||||||
|
*/
|
||||||
|
@TableName("crm_alert")
|
||||||
|
@KeySequence("crm_alert_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AlertDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 提醒人
|
||||||
|
*/
|
||||||
|
private String users;
|
||||||
|
/**
|
||||||
|
* 提醒天数
|
||||||
|
*/
|
||||||
|
private String days;
|
||||||
|
/**
|
||||||
|
* 提醒内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 状态-是否启用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 模板code
|
||||||
|
*/
|
||||||
|
private String templateCode;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.agt.module.license.dal.mysql.alert;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.agt.framework.common.pojo.PageResult;
|
||||||
|
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import org.agt.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警 Mapper
|
||||||
|
*
|
||||||
|
* @author super
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface AlertMapper extends BaseMapperX<AlertDO> {
|
||||||
|
|
||||||
|
default PageResult<AlertDO> selectPage(AlertPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<AlertDO>()
|
||||||
|
.eqIfPresent(AlertDO::getUsers, reqVO.getUsers())
|
||||||
|
.eqIfPresent(AlertDO::getDays, reqVO.getDays())
|
||||||
|
.eqIfPresent(AlertDO::getContent, reqVO.getContent())
|
||||||
|
.eqIfPresent(AlertDO::getStatus, reqVO.getStatus())
|
||||||
|
.eqIfPresent(AlertDO::getTemplateCode, reqVO.getTemplateCode())
|
||||||
|
.eqIfPresent(AlertDO::getRemark, reqVO.getRemark())
|
||||||
|
.betweenIfPresent(AlertDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(AlertDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.agt.module.license.service.alert;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import jakarta.validation.*;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.*;
|
||||||
|
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
||||||
|
import org.agt.framework.common.pojo.PageResult;
|
||||||
|
import org.agt.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警 Service 接口
|
||||||
|
*
|
||||||
|
* @author super
|
||||||
|
*/
|
||||||
|
public interface AlertService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建告警
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createAlert(@Valid AlertSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新告警
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateAlert(@Valid AlertSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除告警
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteAlert(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得告警
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 告警
|
||||||
|
*/
|
||||||
|
AlertDO getAlert(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得告警分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 告警分页
|
||||||
|
*/
|
||||||
|
PageResult<AlertDO> getAlertPage(AlertPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.agt.module.license.service.alert;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.agt.framework.common.pojo.PageResult;
|
||||||
|
import org.agt.framework.common.util.object.BeanUtils;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.AlertPageReqVO;
|
||||||
|
import org.agt.module.license.controller.admin.alert.vo.AlertSaveReqVO;
|
||||||
|
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
||||||
|
import org.agt.module.license.dal.mysql.alert.AlertMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static org.agt.module.license.enums.ErrorCodeConstants.ALERT_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警 Service 实现类
|
||||||
|
*
|
||||||
|
* @author super
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class AlertServiceImpl implements AlertService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AlertMapper alertMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createAlert(AlertSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
AlertDO alert = BeanUtils.toBean(createReqVO, AlertDO.class);
|
||||||
|
alertMapper.insert(alert);
|
||||||
|
// 返回
|
||||||
|
return alert.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAlert(AlertSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateAlertExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
AlertDO updateObj = BeanUtils.toBean(updateReqVO, AlertDO.class);
|
||||||
|
alertMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteAlert(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateAlertExists(id);
|
||||||
|
// 删除
|
||||||
|
alertMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateAlertExists(Long id) {
|
||||||
|
if (alertMapper.selectById(id) == null) {
|
||||||
|
throw exception(ALERT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AlertDO getAlert(Long id) {
|
||||||
|
return alertMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<AlertDO> getAlertPage(AlertPageReqVO pageReqVO) {
|
||||||
|
return alertMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.agt.module.license.dal.mysql.alert.AlertMapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user