增加预警通知相关接口

This commit is contained in:
lxd 2025-06-17 15:06:22 +08:00
parent b2c8dbc6d0
commit 0c4818bec2
9 changed files with 511 additions and 0 deletions

View File

@ -0,0 +1,91 @@
package cn.iocoder.yudao.module.system.controller.admin.alertmessage;
import org.springframework.web.bind.annotation.*;
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 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.system.controller.admin.alertmessage.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.alertmessage.AlertMessageDO;
import cn.iocoder.yudao.module.system.service.alertmessage.AlertMessageService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@Tag(name = "管理后台 - 预警信息")
@RestController
@RequestMapping("/system/alert-message")
@Validated
public class AlertMessageController {
@Resource
private AlertMessageService alertMessageService;
@PostMapping("/create")
@Operation(summary = "创建预警信息")
public CommonResult<Integer> createAlertMessage(@Valid @RequestBody AlertMessageSaveReqVO createReqVO) {
return success(alertMessageService.createAlertMessage(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新预警信息")
public CommonResult<Boolean> updateAlertMessage(@Valid @RequestBody AlertMessageSaveReqVO updateReqVO) {
alertMessageService.updateAlertMessage(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除预警信息")
@Parameter(name = "id", description = "编号", required = true)
public CommonResult<Boolean> deleteAlertMessage(@RequestParam("id") Integer id) {
alertMessageService.deleteAlertMessage(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得预警信息")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<AlertMessageRespVO> getAlertMessage(@RequestParam("id") Integer id) {
AlertMessageDO alertMessage = alertMessageService.getAlertMessage(id);
return success(BeanUtils.toBean(alertMessage, AlertMessageRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得预警信息分页")
public CommonResult<PageResult<AlertMessageRespVO>> getAlertMessagePage(@Valid AlertMessagePageReqVO pageReqVO) {
PageResult<AlertMessageDO> pageResult = alertMessageService.getAlertMessagePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, AlertMessageRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出预警信息 Excel")
@ApiAccessLog(operateType = EXPORT)
public void exportAlertMessageExcel(@Valid AlertMessagePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<AlertMessageDO> list = alertMessageService.getAlertMessagePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "预警信息.xls", "数据", AlertMessageRespVO.class,
BeanUtils.toBean(list, AlertMessageRespVO.class));
}
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.system.controller.admin.alertmessage.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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 = "管理后台 - 预警信息分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AlertMessagePageReqVO extends PageParam {
@Schema(description = "预警类型1 SOS/ 2 分析预警", example = "2")
private Integer alerttype;
@Schema(description = "预警内容")
private String content;
@Schema(description = "用户ID", example = "20700")
private Integer userid;
@Schema(description = "状态0-未读 1-已读", example = "1")
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createtime;
@Schema(description = "更新时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] updatetime;
@Schema(description = "设备ID")
private Integer devicecode;
@Schema(description = "设备类型", example = "2")
private String devicetype;
@Schema(description = "机构ID", example = "30089")
private Integer orgid;
@Schema(description = "机构名称", example = "王五")
private String orgname;
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.system.controller.admin.alertmessage.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 AlertMessageRespVO {
@Schema(description = "预警ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19298")
@ExcelProperty("预警ID")
private Integer id;
@Schema(description = "预警类型1 SOS/ 2 分析预警", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("预警类型1 SOS/ 2 分析预警")
private Integer alerttype;
@Schema(description = "预警内容")
@ExcelProperty("预警内容")
private String content;
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20700")
@ExcelProperty("用户ID")
private Integer userid;
@Schema(description = "状态0-未读 1-已读", example = "1")
@ExcelProperty("状态0-未读 1-已读")
private Integer status;
@Schema(description = "创建时间")
@ExcelProperty("创建时间")
private LocalDateTime createtime;
@Schema(description = "更新时间")
@ExcelProperty("更新时间")
private LocalDateTime updatetime;
@Schema(description = "设备ID")
@ExcelProperty("设备ID")
private Integer devicecode;
@Schema(description = "设备类型", example = "2")
@ExcelProperty("设备类型")
private String devicetype;
@Schema(description = "机构ID", example = "30089")
@ExcelProperty("机构ID")
private Integer orgid;
@Schema(description = "机构名称", example = "王五")
@ExcelProperty("机构名称")
private String orgname;
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.system.controller.admin.alertmessage.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 预警信息新增/修改 Request VO")
@Data
public class AlertMessageSaveReqVO {
@Schema(description = "预警ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19298")
private Integer id;
@Schema(description = "预警类型1 SOS/ 2 分析预警", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "预警类型1 SOS/ 2 分析预警不能为空")
private Integer alerttype;
@Schema(description = "预警内容")
private String content;
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20700")
@NotNull(message = "用户ID不能为空")
private Integer userid;
@Schema(description = "状态0-未读 1-已读", example = "1")
private Integer status;
@Schema(description = "创建时间")
private LocalDateTime createtime;
@Schema(description = "更新时间")
private LocalDateTime updatetime;
@Schema(description = "设备ID")
private Integer devicecode;
@Schema(description = "设备类型", example = "2")
private String devicetype;
@Schema(description = "机构ID", example = "30089")
private Integer orgid;
@Schema(description = "机构名称", example = "王五")
private String orgname;
}

View File

@ -0,0 +1,81 @@
package cn.iocoder.yudao.module.system.dal.dataobject.alertmessage;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 预警信息 DO
*
* @author 全智安
*/
@TableName("tb_alert_message")
@KeySequence("tb_alert_message_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AlertMessageDO {
/**
* 预警ID
*/
@TableId
private Integer id;
/**
* 预警类型1 SOS/ 2 分析预警
*/
@TableField("alerttype")
private Integer alerttype;
/**
* 预警内容
*/
@TableField("content")
private String content;
/**
* 用户ID
*/
@TableField("userid")
private Integer userid;
/**
* 状态0-未读 1-已读
*/
@TableField("status")
private Integer status;
/**
* 创建时间
*/
@TableField("createtime")
private LocalDateTime createtime;
/**
* 更新时间
*/
@TableField("updatetime")
private LocalDateTime updatetime;
/**
* 设备ID
*/
@TableField("devicecode")
private Integer devicecode;
/**
* 设备类型
*/
@TableField("devicetype")
private String devicetype;
/**
* 机构ID
*/
@TableField("orgid")
private Integer orgid;
/**
* 机构名称
*/
@TableField("orgname")
private String orgname;
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.system.dal.mysql.alertmessage;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.alertmessage.AlertMessageDO;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.alertmessage.vo.*;
/**
* 预警信息 Mapper
*
* @author 全智安
*/
@Mapper
@InterceptorIgnore(tenantLine = "true")
public interface AlertMessageMapper extends BaseMapperX<AlertMessageDO> {
default PageResult<AlertMessageDO> selectPage(AlertMessagePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AlertMessageDO>()
.eqIfPresent(AlertMessageDO::getAlerttype, reqVO.getAlerttype())
.eqIfPresent(AlertMessageDO::getContent, reqVO.getContent())
.eqIfPresent(AlertMessageDO::getUserid, reqVO.getUserid())
.eqIfPresent(AlertMessageDO::getStatus, reqVO.getStatus())
.betweenIfPresent(AlertMessageDO::getCreatetime, reqVO.getCreatetime())
.betweenIfPresent(AlertMessageDO::getUpdatetime, reqVO.getUpdatetime())
.eqIfPresent(AlertMessageDO::getDevicecode, reqVO.getDevicecode())
.eqIfPresent(AlertMessageDO::getDevicetype, reqVO.getDevicetype())
.eqIfPresent(AlertMessageDO::getOrgid, reqVO.getOrgid())
.likeIfPresent(AlertMessageDO::getOrgname, reqVO.getOrgname())
.orderByDesc(AlertMessageDO::getId));
}
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.system.service.alertmessage;
import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.alertmessage.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.alertmessage.AlertMessageDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import javax.validation.Valid;
/**
* 预警信息 Service 接口
*
* @author 全智安
*/
public interface AlertMessageService {
/**
* 创建预警信息
*
* @param createReqVO 创建信息
* @return 编号
*/
Integer createAlertMessage(@Valid AlertMessageSaveReqVO createReqVO);
/**
* 更新预警信息
*
* @param updateReqVO 更新信息
*/
void updateAlertMessage(@Valid AlertMessageSaveReqVO updateReqVO);
/**
* 删除预警信息
*
* @param id 编号
*/
void deleteAlertMessage(Integer id);
/**
* 获得预警信息
*
* @param id 编号
* @return 预警信息
*/
AlertMessageDO getAlertMessage(Integer id);
/**
* 获得预警信息分页
*
* @param pageReqVO 分页查询
* @return 预警信息分页
*/
PageResult<AlertMessageDO> getAlertMessagePage(AlertMessagePageReqVO pageReqVO);
}

View File

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.system.service.alertmessage;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.alertmessage.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.alertmessage.AlertMessageDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.dal.mysql.alertmessage.AlertMessageMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
* 预警信息 Service 实现类
*
* @author 全智安
*/
@Service
@Validated
public class AlertMessageServiceImpl implements AlertMessageService {
@Resource
private AlertMessageMapper alertMessageMapper;
@Override
public Integer createAlertMessage(AlertMessageSaveReqVO createReqVO) {
// 插入
AlertMessageDO alertMessage = BeanUtils.toBean(createReqVO, AlertMessageDO.class);
alertMessageMapper.insert(alertMessage);
// 返回
return alertMessage.getId();
}
@Override
public void updateAlertMessage(AlertMessageSaveReqVO updateReqVO) {
// 校验存在
validateAlertMessageExists(updateReqVO.getId());
// 更新
AlertMessageDO updateObj = BeanUtils.toBean(updateReqVO, AlertMessageDO.class);
alertMessageMapper.updateById(updateObj);
}
@Override
public void deleteAlertMessage(Integer id) {
// 校验存在
validateAlertMessageExists(id);
// 删除
alertMessageMapper.deleteById(id);
}
private void validateAlertMessageExists(Integer id) {
if (alertMessageMapper.selectById(id) == null) {
}
}
@Override
public AlertMessageDO getAlertMessage(Integer id) {
return alertMessageMapper.selectById(id);
}
@Override
public PageResult<AlertMessageDO> getAlertMessagePage(AlertMessagePageReqVO pageReqVO) {
return alertMessageMapper.selectPage(pageReqVO);
}
}

View File

@ -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="cn.iocoder.yudao.module.system.dal.mysql.alertmessage.AlertMessageMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>