报警管理模块

This commit is contained in:
sqlicong
2025-07-25 18:20:54 +08:00
parent 0d7d919a77
commit 0d19d2ccee
25 changed files with 952 additions and 203 deletions

File diff suppressed because one or more lines are too long

View File

@@ -35,6 +35,12 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system</artifactId>
<version>2.6.1-jdk8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@@ -0,0 +1,104 @@
package cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig;
import org.springframework.web.bind.annotation.*;
import javax.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 javax.validation.constraints.*;
import javax.validation.*;
import javax.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.kfc.controller.admin.alarmconfig.vo.*;
import cn.iocoder.yudao.module.kfc.dal.dataobject.alarmconfig.AlarmConfigDO;
import cn.iocoder.yudao.module.kfc.service.alarmconfig.AlarmConfigService;
@Tag(name = "管理后台 - 报警配置")
@RestController
@RequestMapping("/kfc/alarm-config")
@Validated
public class AlarmConfigController {
@Resource
private AlarmConfigService alarmConfigService;
@PostMapping("/create")
@Operation(summary = "创建报警配置")
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:create')")
public CommonResult<Long> createAlarmConfig(@Valid @RequestBody AlarmConfigSaveReqVO createReqVO) {
return success(alarmConfigService.createAlarmConfig(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新报警配置")
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:update')")
public CommonResult<Boolean> updateAlarmConfig(@Valid @RequestBody AlarmConfigSaveReqVO updateReqVO) {
alarmConfigService.updateAlarmConfig(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除报警配置")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:delete')")
public CommonResult<Boolean> deleteAlarmConfig(@RequestParam("id") Long id) {
alarmConfigService.deleteAlarmConfig(id);
return success(true);
}
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除报警配置")
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:delete')")
public CommonResult<Boolean> deleteAlarmConfigList(@RequestParam("ids") List<Long> ids) {
alarmConfigService.deleteAlarmConfigListByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得报警配置")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:query')")
public CommonResult<AlarmConfigRespVO> getAlarmConfig(@RequestParam("id") Long id) {
AlarmConfigDO alarmConfig = alarmConfigService.getAlarmConfig(id);
return success(BeanUtils.toBean(alarmConfig, AlarmConfigRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得报警配置分页")
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:query')")
public CommonResult<PageResult<AlarmConfigRespVO>> getAlarmConfigPage(@Valid AlarmConfigPageReqVO pageReqVO) {
PageResult<AlarmConfigDO> pageResult = alarmConfigService.getAlarmConfigPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, AlarmConfigRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出报警配置 Excel")
@PreAuthorize("@ss.hasPermission('kfc:alarm-config:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportAlarmConfigExcel(@Valid AlarmConfigPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<AlarmConfigDO> list = alarmConfigService.getAlarmConfigPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "报警配置.xls", "数据", AlarmConfigRespVO.class,
BeanUtils.toBean(list, AlarmConfigRespVO.class));
}
}

View File

@@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig.vo;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
import lombok.*;
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 java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 报警配置分页 Request VO")
@Data
public class AlarmConfigPageReqVO extends PageParam {
@Schema(description = "报警名称")
private String title;
@Schema(description = "报警描述", example = "你猜")
private String description;
@Schema(description = "报警等级(严重程度)", example = "1")
private Integer alarmLevel;
@Schema(description = "报警类型", example = "1")
private String type;
@Schema(description = "触发条件")
private String triggerCondition;
@Schema(description = "接收用户数组")
private List<Long> receiveUserIds;
@Schema(description = "通知方式")
private List<AlarmConfigReceiveTypeEnum> notificationWay;
@Schema(description = "配置状态默认NULL", example = "2")
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,60 @@
package cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig.vo;
import cn.iocoder.yudao.module.kfc.enums.DictTypeConstants;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
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.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 报警配置 Response VO")
@Data
@ExcelIgnoreUnannotated
public class AlarmConfigRespVO {
@Schema(description = "报警配置id", requiredMode = Schema.RequiredMode.REQUIRED, example = "14367")
@ExcelProperty("报警配置id")
private Long id;
@Schema(description = "报警名称")
@ExcelProperty("报警名称")
private String title;
@Schema(description = "报警描述", example = "你猜")
@ExcelProperty("报警描述")
private String description;
@Schema(description = "报警等级(严重程度)", example = "1")
@ExcelProperty("报警等级")
private Integer alarmLevel;
@Schema(description = "报警类型", example = "1")
@ExcelProperty(value = "报警类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.ALARM_TYPE)
private String type;
@Schema(description = "触发条件")
@ExcelProperty("触发条件")
private String triggerCondition;
@Schema(description = "接收用户数组")
@ExcelProperty("接收用户数组")
private List<Long> receiveUserIds;
@Schema(description = "通知方式")
@ExcelProperty("通知方式")
private List<AlarmConfigReceiveTypeEnum> notificationWay;
@Schema(description = "配置状态", example = "2")
@ExcelProperty("配置状态")
private Integer status;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 报警配置新增/修改 Request VO")
@Data
public class AlarmConfigSaveReqVO {
@Schema(description = "报警配置id", requiredMode = Schema.RequiredMode.REQUIRED, example = "14367")
private Long id;
@Schema(description = "报警名称")
private String title;
@Schema(description = "报警描述", example = "你猜")
private String description;
@Schema(description = "报警等级(严重程度)", example = "1")
private Integer alarmLevel;
@Schema(description = "报警类型", example = "1")
private String type;
@Schema(description = "触发条件")
private String triggerCondition;
@Schema(description = "接收用户数组")
private List<Long> receiveUserIds;
@Schema(description = "通知方式")
private List<AlarmConfigReceiveTypeEnum> notificationWay;
@Schema(description = "配置状态", example = "2")
private Integer status;
}

View File

@@ -41,7 +41,7 @@ public class AlarmRecordController {
@PostMapping("/create")
@Operation(summary = "创建报警信息")
@PreAuthorize("@ss.hasPermission('kfc:alarm-record:create')")
public CommonResult<Integer> createAlarmRecord(@Valid @RequestBody AlarmRecordSaveReqVO createReqVO) {
public CommonResult<Long> createAlarmRecord(@Valid @RequestBody AlarmRecordSaveReqVO createReqVO) {
return success(alarmRecordService.createAlarmRecord(createReqVO));
}
@@ -57,7 +57,7 @@ public class AlarmRecordController {
@Operation(summary = "删除报警信息")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('kfc:alarm-record:delete')")
public CommonResult<Boolean> deleteAlarmRecord(@RequestParam("id") Integer id) {
public CommonResult<Boolean> deleteAlarmRecord(@RequestParam("id") Long id) {
alarmRecordService.deleteAlarmRecord(id);
return success(true);
}
@@ -65,8 +65,8 @@ public class AlarmRecordController {
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除报警信息")
@PreAuthorize("@ss.hasPermission('kfc:alarm-record:delete')")
public CommonResult<Boolean> deleteAlarmRecordList(@RequestParam("ids") List<Integer> ids) {
@PreAuthorize("@ss.hasPermission('kfc:alarm-record:delete')")
public CommonResult<Boolean> deleteAlarmRecordList(@RequestParam("ids") List<Long> ids) {
alarmRecordService.deleteAlarmRecordListByIds(ids);
return success(true);
}
@@ -75,7 +75,7 @@ public class AlarmRecordController {
@Operation(summary = "获得报警信息")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('kfc:alarm-record:query')")
public CommonResult<AlarmRecordRespVO> getAlarmRecord(@RequestParam("id") Integer id) {
public CommonResult<AlarmRecordRespVO> getAlarmRecord(@RequestParam("id") Long id) {
AlarmRecordDO alarmRecord = alarmRecordService.getAlarmRecord(id);
return success(BeanUtils.toBean(alarmRecord, AlarmRecordRespVO.class));
}

View File

@@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.kfc.controller.admin.alarmrecord.vo;
import com.alibaba.excel.annotation.ExcelProperty;
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;
@@ -25,9 +25,12 @@ public class AlarmRecordPageReqVO extends PageParam {
@Schema(description = "报警内容", example = "随便")
private String description;
@Schema(description = "报警状态默认NULL", example = "2")
@Schema(description = "报警状态", example = "2")
private Integer status;
@Schema(description = "处理结果", example = "随便")
private String solveResult;
@Schema(description = "报警时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] alarmTime;

View File

@@ -1,8 +1,9 @@
package cn.iocoder.yudao.module.kfc.controller.admin.alarmrecord.vo;
import cn.iocoder.yudao.module.kfc.enums.DictTypeConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
@@ -15,7 +16,7 @@ public class AlarmRecordRespVO {
@Schema(description = "报警记录id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24531")
@ExcelProperty("报警记录id")
private Integer id;
private Long id;
@Schema(description = "报警名称")
@ExcelProperty("报警名称")
@@ -23,7 +24,7 @@ public class AlarmRecordRespVO {
@Schema(description = "报警类型", example = "1")
@ExcelProperty(value = "报警类型", converter = DictConvert.class)
@DictFormat("infra_config_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
@DictFormat(DictTypeConstants.ALARM_TYPE)
private String type;
@Schema(description = "关联的会员账户id", example = "9150")
@@ -34,14 +35,18 @@ public class AlarmRecordRespVO {
@ExcelProperty("报警内容")
private String description;
@Schema(description = "报警状态默认NULL", example = "2")
@ExcelProperty("报警状态默认NULL")
@Schema(description = "报警状态", example = "2")
@ExcelProperty("报警状态")
private Integer status;
@Schema(description = "报警时间")
@ExcelProperty("报警时间")
private LocalDateTime alarmTime;
@Schema(description = "处理结果", example = "随便")
@ExcelProperty("处理结果")
private String solveResult;
@Schema(description = "处理时间")
@ExcelProperty("处理时间")
private LocalDateTime solveTime;

View File

@@ -2,22 +2,25 @@ package cn.iocoder.yudao.module.kfc.controller.admin.alarmrecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.Valid;
import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 报警信息新增/修改 Request VO")
@Data
@Valid
public class AlarmRecordSaveReqVO {
@Schema(description = "报警记录id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24531")
private Integer id;
private Long id;
@Schema(description = "报警名称")
private String title;
@Schema(description = "报警类型", example = "1")
@NotEmpty(message = "报警类型不能为空")
private String type;
@Schema(description = "关联的会员账户id", example = "9150")
@@ -26,9 +29,12 @@ public class AlarmRecordSaveReqVO {
@Schema(description = "报警内容", example = "随便")
private String description;
@Schema(description = "报警状态默认NULL", example = "2")
@Schema(description = "报警状态", example = "2")
private Integer status;
@Schema(description = "处理结果", example = "随便")
private String solveResult;
@Schema(description = "报警时间")
private LocalDateTime alarmTime;

View File

@@ -0,0 +1,72 @@
package cn.iocoder.yudao.module.kfc.dal.dataobject.alarmconfig;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import java.util.List;
/**
* 报警配置 DO
*
* @author kfc
*/
@TableName(value = "sq_alarm_config",autoResultMap = true)
@KeySequence("sq_alarm_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AlarmConfigDO extends BaseDO {
/**
* 报警配置id
*/
@TableId
private Long id;
/**
* 报警名称
*/
private String title;
/**
* 报警描述
*/
private String description;
/**
* 报警等级
*/
private Integer alarmLevel;
/**
* 报警类型
*
* 枚举 {@link cn.iocoder.yudao.module.kfc.enums.DictTypeConstants#ALARM_TYPE}
*/
private String type;
/**
* 触发条件
*/
private String triggerCondition;
/**
* 接收用户数组
*/
@TableField(typeHandler =JacksonTypeHandler.class)
private List<Long> receiveUserIds;
/**
* 通知方式
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<AlarmConfigReceiveTypeEnum> notificationWay;
/**
* 配置状态
*/
private Integer status;
}

View File

@@ -1,11 +1,10 @@
package cn.iocoder.yudao.module.kfc.dal.dataobject.alarmrecord;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@@ -28,7 +27,7 @@ public class AlarmRecordDO extends BaseDO {
* 报警记录id
*/
@TableId
private Integer id;
private Long id;
/**
* 报警名称
*/
@@ -36,7 +35,7 @@ public class AlarmRecordDO extends BaseDO {
/**
* 报警类型
*
* 枚举 {@link TODO infra_config_type 对应的类}
* 枚举 {@link cn.iocoder.yudao.module.kfc.enums.DictTypeConstants#ALARM_TYPE}
*/
private String type;
/**
@@ -48,9 +47,13 @@ public class AlarmRecordDO extends BaseDO {
*/
private String description;
/**
* 报警状态默认NULL
* 报警状态
*/
private Integer status;
/**
* 处理结果
*/
private String solveResult;
/**
* 报警时间
*/

View File

@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.kfc.dal.mysql.alarmconfig;
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.kfc.dal.dataobject.alarmconfig.AlarmConfigDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig.vo.*;
/**
* 报警配置 Mapper
*
* @author kfc
*/
@Mapper
public interface AlarmConfigMapper extends BaseMapperX<AlarmConfigDO> {
default PageResult<AlarmConfigDO> selectPage(AlarmConfigPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AlarmConfigDO>()
.likeIfPresent(AlarmConfigDO::getTitle, reqVO.getTitle())
.likeIfPresent(AlarmConfigDO::getDescription, reqVO.getDescription())
.eqIfPresent(AlarmConfigDO::getType, reqVO.getType())
.likeIfPresent(AlarmConfigDO::getTriggerCondition, reqVO.getTriggerCondition())
.eqIfPresent(AlarmConfigDO::getReceiveUserIds, reqVO.getReceiveUserIds())
.eqIfPresent(AlarmConfigDO::getNotificationWay, reqVO.getNotificationWay())
.eqIfPresent(AlarmConfigDO::getStatus, reqVO.getStatus())
.betweenIfPresent(AlarmConfigDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(AlarmConfigDO::getId));
}
}

View File

@@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.kfc.enums;
/**
* Infra 字典类型的枚举类
* kfc 字典类型的枚举类
*
* @author 芋道源码
*/
public interface DictTypeConstants {
String ALARM_TYPE = "alarm_type";
}

View File

@@ -5,4 +5,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
public interface ErrorCodeConstants {
ErrorCode ALARM_RECORD_NOT_EXISTS = new ErrorCode(2_001_000_001, "报警信息不存在");
ErrorCode ALARM_CONFIG_NOT_EXISTS = new ErrorCode(2_001_000_002, "报警配置不存在");
ErrorCode ALARM_CONFIG_EXISTS = new ErrorCode(2_001_000_102, "已存在相同类型的报警配置");
ErrorCode CHANGE_CONFIG_TYPE_NOT_ALLOW = new ErrorCode(2_001_000_202, "报警配置类型不可更改");
}

View File

@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.kfc.enums.alarm;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
/**
* IoT 告警配置的接收方式枚举
*
* @author 芋道源码
*/
@RequiredArgsConstructor
@Getter
public enum AlarmConfigReceiveTypeEnum implements ArrayValuable<Integer> {
SMS(1), // 短信
MAIL(2), // 邮箱
NOTIFY(3); // 通知
private final Integer type;
public static final Integer[] ARRAYS = Arrays.stream(values()).map(AlarmConfigReceiveTypeEnum::getType).toArray(Integer[]::new);
@Override
public Integer[] array() {
return ARRAYS;
}
}

View File

@@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.kfc.service.alarmconfig;
import java.util.*;
import javax.validation.*;
import javax.validation.constraints.NotEmpty;
import cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig.vo.*;
import cn.iocoder.yudao.module.kfc.dal.dataobject.alarmconfig.AlarmConfigDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 报警配置 Service 接口
*
* @author kfc
*/
public interface AlarmConfigService {
/**
* 创建报警配置
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createAlarmConfig(@Valid AlarmConfigSaveReqVO createReqVO);
/**
* 更新报警配置
*
* @param updateReqVO 更新信息
*/
void updateAlarmConfig(@Valid AlarmConfigSaveReqVO updateReqVO);
/**
* 删除报警配置
*
* @param id 编号
*/
void deleteAlarmConfig(Long id);
/**
* 批量删除报警配置
*
* @param ids 编号
*/
void deleteAlarmConfigListByIds(List<Long> ids);
/**
* 获得报警配置
*
* @param id 编号
* @return 报警配置
*/
AlarmConfigDO getAlarmConfig(Long id);
/**
* 获得报警配置分页
*
* @param pageReqVO 分页查询
* @return 报警配置分页
*/
PageResult<AlarmConfigDO> getAlarmConfigPage(AlarmConfigPageReqVO pageReqVO);
AlarmConfigDO getAlarmConfigByType(@NotEmpty(message = "报警类型不能为空") String type);
}

View File

@@ -0,0 +1,94 @@
package cn.iocoder.yudao.module.kfc.service.alarmconfig;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.kfc.controller.admin.alarmconfig.vo.*;
import cn.iocoder.yudao.module.kfc.dal.dataobject.alarmconfig.AlarmConfigDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.kfc.dal.mysql.alarmconfig.AlarmConfigMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.kfc.enums.ErrorCodeConstants.*;
/**
* 报警配置 Service 实现类
*
* @author kfc
*/
@Service
@Validated
public class AlarmConfigServiceImpl implements AlarmConfigService {
@Resource
private AlarmConfigMapper alarmConfigMapper;
@Override
public Long createAlarmConfig(AlarmConfigSaveReqVO createReqVO) {
// 插入
AlarmConfigDO alarmConfig = BeanUtils.toBean(createReqVO, AlarmConfigDO.class);
//同类配置只能有一个
AlarmConfigDO config = getAlarmConfigByType(alarmConfig.getType());
if (config != null) throw exception(ALARM_CONFIG_EXISTS);
//插入数据
alarmConfigMapper.insert(alarmConfig);
// 返回
return alarmConfig.getId();
}
@Override
public void updateAlarmConfig(AlarmConfigSaveReqVO updateReqVO) {
// 校验存在
AlarmConfigDO configDO = validateAlarmConfigExists(updateReqVO.getId());
if (ObjectUtil.notEqual(configDO.getType(),updateReqVO.getType())) throw exception(CHANGE_CONFIG_TYPE_NOT_ALLOW);
// 更新
AlarmConfigDO updateObj = BeanUtils.toBean(updateReqVO, AlarmConfigDO.class);
alarmConfigMapper.updateById(updateObj);
}
@Override
public void deleteAlarmConfig(Long id) {
// 校验存在
validateAlarmConfigExists(id);
// 删除
alarmConfigMapper.deleteById(id);
}
@Override
public void deleteAlarmConfigListByIds(List<Long> ids) {
// 删除
alarmConfigMapper.deleteByIds(ids);
}
private AlarmConfigDO validateAlarmConfigExists(Long id) {
AlarmConfigDO configDO = alarmConfigMapper.selectById(id);
if (configDO == null) {
throw exception(ALARM_CONFIG_NOT_EXISTS);
}
return configDO;
}
@Override
public AlarmConfigDO getAlarmConfig(Long id) {
return alarmConfigMapper.selectById(id);
}
@Override
public PageResult<AlarmConfigDO> getAlarmConfigPage(AlarmConfigPageReqVO pageReqVO) {
return alarmConfigMapper.selectPage(pageReqVO);
}
@Override
public AlarmConfigDO getAlarmConfigByType(String type) {
return alarmConfigMapper.selectOne(AlarmConfigDO::getType, type);
}
}

View File

@@ -20,7 +20,7 @@ public interface AlarmRecordService {
* @param createReqVO 创建信息
* @return 编号
*/
Integer createAlarmRecord(@Valid AlarmRecordSaveReqVO createReqVO);
Long createAlarmRecord(@Valid AlarmRecordSaveReqVO createReqVO);
/**
* 更新报警信息
@@ -34,14 +34,14 @@ public interface AlarmRecordService {
*
* @param id 编号
*/
void deleteAlarmRecord(Integer id);
void deleteAlarmRecord(Long id);
/**
* 批量删除报警信息
*
* @param ids 编号
*/
void deleteAlarmRecordListByIds(List<Integer> ids);
void deleteAlarmRecordListByIds(List<Long> ids);
/**
* 获得报警信息
@@ -49,7 +49,7 @@ public interface AlarmRecordService {
* @param id 编号
* @return 报警信息
*/
AlarmRecordDO getAlarmRecord(Integer id);
AlarmRecordDO getAlarmRecord(Long id);
/**
* 获得报警信息分页

View File

@@ -1,23 +1,25 @@
package cn.iocoder.yudao.module.kfc.service.alarmrecord;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.kfc.dal.dataobject.alarmconfig.AlarmConfigDO;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
import cn.iocoder.yudao.module.kfc.service.alarmconfig.AlarmConfigService;
import cn.iocoder.yudao.module.kfc.service.message.MessageSendService;
import cn.iocoder.yudao.module.kfc.utils.AssertUtils;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.kfc.controller.admin.alarmrecord.vo.*;
import cn.iocoder.yudao.module.kfc.dal.dataobject.alarmrecord.AlarmRecordDO;
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.kfc.dal.mysql.alarmrecord.AlarmRecordMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.kfc.enums.ErrorCodeConstants.*;
/**
@@ -32,12 +34,38 @@ public class AlarmRecordServiceImpl implements AlarmRecordService {
@Resource
private AlarmRecordMapper alarmRecordMapper;
@Resource
private AlarmConfigService alarmConfigService;
@Resource
private MessageSendService messageSendService;
@Resource
private AdminUserService adminUserService;
@Override
public Integer createAlarmRecord(AlarmRecordSaveReqVO createReqVO) {
public Long createAlarmRecord(AlarmRecordSaveReqVO createReqVO) {
// 插入
AlarmRecordDO alarmRecord = BeanUtils.toBean(createReqVO, AlarmRecordDO.class);
alarmRecordMapper.insert(alarmRecord);
//查询配置
AlarmConfigDO config = alarmConfigService.getAlarmConfigByType(createReqVO.getType());
AssertUtils.notNull(config,ALARM_CONFIG_NOT_EXISTS);
//获取处理人ids数组
List<Long> receiveUserIds = config.getReceiveUserIds();
//获取通知方式数组
List<AlarmConfigReceiveTypeEnum> notificationWay = config.getNotificationWay();
//todo 给所有处理人发送不同类型通知消息
receiveUserIds.forEach(userId -> {
AdminUserDO user = adminUserService.getUser(userId);
notificationWay.forEach(way -> {
//发送消息
Map<String,Object> map = new HashMap<>();
String message =String.format("%s登陆异常", createReqVO.getMemberId());
map.put("message", message);
messageSendService.send(way,user.getMobile(),user.getEmail(),userId,"alarm_message",map);
});
});
// 返回
return alarmRecord.getId();
}
@@ -52,7 +80,7 @@ public class AlarmRecordServiceImpl implements AlarmRecordService {
}
@Override
public void deleteAlarmRecord(Integer id) {
public void deleteAlarmRecord(Long id) {
// 校验存在
validateAlarmRecordExists(id);
// 删除
@@ -60,20 +88,20 @@ public class AlarmRecordServiceImpl implements AlarmRecordService {
}
@Override
public void deleteAlarmRecordListByIds(List<Integer> ids) {
public void deleteAlarmRecordListByIds(List<Long> ids) {
// 删除
alarmRecordMapper.deleteByIds(ids);
}
private void validateAlarmRecordExists(Integer id) {
private void validateAlarmRecordExists(Long id) {
if (alarmRecordMapper.selectById(id) == null) {
throw exception(ALARM_RECORD_NOT_EXISTS);
}
}
@Override
public AlarmRecordDO getAlarmRecord(Integer id) {
public AlarmRecordDO getAlarmRecord(Long id) {
return alarmRecordMapper.selectById(id);
}

View File

@@ -0,0 +1,11 @@
package cn.iocoder.yudao.module.kfc.service.message;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
import java.util.Map;
public interface MessageSendService {
void send(AlarmConfigReceiveTypeEnum type, String mobile, String mail, Long userId,
String templateCode, Map<String, Object> templateParams);
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.kfc.service.message;
import cn.iocoder.yudao.module.kfc.enums.alarm.AlarmConfigReceiveTypeEnum;
import cn.iocoder.yudao.module.system.service.mail.MailSendService;
import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Map;
@Service
public class MessageSendServiceImpl implements MessageSendService {
@Resource
private SmsSendService smsSendService;
@Resource
private NotifySendService notifySendService;
@Resource
private MailSendService mailSendService;
@Override
public void send(AlarmConfigReceiveTypeEnum type, String mobile, String mail, Long userId,
String templateCode, Map<String, Object> templateParams) {
if (type == null) return;
switch (type) {
case SMS:
smsSendService.sendSingleSmsToAdmin(mobile,userId,templateCode,templateParams);
break;
case NOTIFY:
notifySendService.sendSingleNotifyToAdmin(userId,templateCode,templateParams);
break;
case MAIL:
mailSendService.sendSingleMailToAdmin(mail,userId,templateCode,templateParams);
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.kfc.utils;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
public class AssertUtils {
public static void notNull(Object object, ErrorCode errorCode) {
if (object == null) {
throw exception(errorCode);
}
}
}

View File

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

View File

@@ -2,11 +2,5 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.kfc.dal.mysql.alarmrecord.AlarmRecordMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>