feat(alarm): 新增告警配置管理功能
- 实现CsAlarmSetController提供新增、修改、删除、查询等REST接口 - 修复设备消息推送中的参数描述错误,将isAdmin改为推送普通用户
This commit is contained in:
@@ -48,7 +48,7 @@ public class DeviceMessageController extends BaseController {
|
||||
@ApiOperation("根据设备获取需要推送的用户id")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "devId", value = "设备id", required = true, paramType = "query"),
|
||||
@ApiImplicitParam(name = "isAdmin", value = "是否需要推送给管理员", required = true, paramType = "query")
|
||||
@ApiImplicitParam(name = "isAdmin", value = "是否需要推送给普通用户", required = true, paramType = "query")
|
||||
})
|
||||
public HttpResult<List<String>> getEventUserByDeviceId(@RequestParam("devId") String devId, @RequestParam("isAdmin") Boolean isAdmin){
|
||||
String methodDescribe = getMethodDescribe("getEventUserByDeviceId");
|
||||
|
||||
@@ -37,17 +37,17 @@ class DeviceMessageServiceImpl implements DeviceMessageService {
|
||||
|
||||
@Override
|
||||
public List<String> getEventUserByDeviceId(String devId, Boolean isAdmin) {
|
||||
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
|
||||
List<String> result = new ArrayList<>(list);
|
||||
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
|
||||
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
|
||||
if (isAdmin) {
|
||||
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
|
||||
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
|
||||
result.addAll(adminList);
|
||||
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
|
||||
List<String> result = new ArrayList<>(list);
|
||||
adminList.addAll(result);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(result)) {
|
||||
result = result.stream().distinct().collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(adminList)) {
|
||||
adminList = adminList.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
return result;
|
||||
return adminList;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.cssystem.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class CsAlarmSetParam implements Serializable {
|
||||
|
||||
@ApiModelProperty("主键ID")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("方案名称")
|
||||
@NotBlank(message = "方案名称不能为空")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("在线率阈值")
|
||||
@NotNull(message = "在线率阈值不能为空")
|
||||
private Integer onlineRateLimit;
|
||||
|
||||
@ApiModelProperty("完整性阈值")
|
||||
@NotNull(message = "完整性阈值不能为空")
|
||||
private Integer integrityLimit;
|
||||
|
||||
@ApiModelProperty("是否启用 (0:未启用 1:启用)")
|
||||
private Integer active;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.njcn.cssystem.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2026-05-08
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("cs_alarm_set")
|
||||
public class CsAlarmSet extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 方案名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 在线率阈值
|
||||
*/
|
||||
private Integer onlineRateLimit;
|
||||
|
||||
/**
|
||||
* 完整性阈值
|
||||
*/
|
||||
private Integer integrityLimit;
|
||||
|
||||
/**
|
||||
* 是否启用 (0:未启用 1:启用)
|
||||
*/
|
||||
private Integer active;
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.njcn.cssystem.controller.baseinfo;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.cssystem.pojo.param.CsAlarmSetParam;
|
||||
import com.njcn.cssystem.pojo.po.CsAlarmSet;
|
||||
import com.njcn.cssystem.service.ICsAlarmSetService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2026-05-08
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/csAlarmSet")
|
||||
@Api(tags = "告警配置管理")
|
||||
@AllArgsConstructor
|
||||
public class CsAlarmSetController extends BaseController {
|
||||
|
||||
private final ICsAlarmSetService csAlarmSetService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增告警配置")
|
||||
@ApiImplicitParam(name = "param", value = "告警配置参数", required = true)
|
||||
public HttpResult<String> add(@RequestBody @Validated CsAlarmSetParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
boolean result = csAlarmSetService.add(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "新增成功", methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "新增失败", methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改告警配置")
|
||||
@ApiImplicitParam(name = "param", value = "告警配置参数", required = true)
|
||||
public HttpResult<String> update(@RequestBody @Validated CsAlarmSetParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
boolean result = csAlarmSetService.update(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "修改成功", methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "修改失败", methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除告警配置")
|
||||
@ApiImplicitParam(name = "id", value = "配置ID", required = true)
|
||||
public HttpResult<String> delete(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
boolean result = csAlarmSetService.delete(id);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "删除成功", methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "删除失败", methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getById")
|
||||
@ApiOperation("根据ID查询告警配置")
|
||||
@ApiImplicitParam(name = "id", value = "配置ID", required = true)
|
||||
public HttpResult<CsAlarmSet> getById(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getById");
|
||||
CsAlarmSet vo = csAlarmSetService.getById(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/listAll")
|
||||
@ApiOperation("查询所有告警配置")
|
||||
public HttpResult<List<CsAlarmSet>> listAll() {
|
||||
String methodDescribe = getMethodDescribe("listAll");
|
||||
List<CsAlarmSet> list = csAlarmSetService.listAll();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/toggleActive")
|
||||
@ApiOperation("切换告警配置启用状态")
|
||||
@ApiImplicitParam(name = "id", value = "配置ID", required = true)
|
||||
public HttpResult<String> toggleActive(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("toggleActive");
|
||||
boolean result = csAlarmSetService.toggleActive(id);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "切换成功", methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "切换失败", methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getEnabledConfig")
|
||||
@ApiOperation("获取当前启用的告警配置")
|
||||
public HttpResult<CsAlarmSet> getEnabledConfig() {
|
||||
String methodDescribe = getMethodDescribe("getEnabledConfig");
|
||||
CsAlarmSet vo = csAlarmSetService.getEnabledConfig();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.cssystem.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.cssystem.pojo.po.CsAlarmSet;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2026-05-08
|
||||
*/
|
||||
public interface CsAlarmSetMapper extends BaseMapper<CsAlarmSet> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.cssystem.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.cssystem.pojo.param.CsAlarmSetParam;
|
||||
import com.njcn.cssystem.pojo.po.CsAlarmSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2026-05-08
|
||||
*/
|
||||
public interface ICsAlarmSetService extends IService<CsAlarmSet> {
|
||||
|
||||
boolean add(CsAlarmSetParam param);
|
||||
|
||||
boolean update(CsAlarmSetParam param);
|
||||
|
||||
boolean delete(String id);
|
||||
|
||||
CsAlarmSet getById(String id);
|
||||
|
||||
List<CsAlarmSet> listAll();
|
||||
|
||||
boolean toggleActive(String id);
|
||||
|
||||
CsAlarmSet getEnabledConfig();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.njcn.cssystem.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.cssystem.mapper.CsAlarmSetMapper;
|
||||
import com.njcn.cssystem.pojo.param.CsAlarmSetParam;
|
||||
import com.njcn.cssystem.pojo.po.CsAlarmSet;
|
||||
import com.njcn.cssystem.service.ICsAlarmSetService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2026-05-08
|
||||
*/
|
||||
@Service
|
||||
public class CsAlarmSetServiceImpl extends ServiceImpl<CsAlarmSetMapper, CsAlarmSet> implements ICsAlarmSetService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean add(CsAlarmSetParam param) {
|
||||
CsAlarmSet csAlarmSet = new CsAlarmSet();
|
||||
BeanUtils.copyProperties(param, csAlarmSet);
|
||||
if (Objects.isNull(csAlarmSet.getActive())) {
|
||||
csAlarmSet.setActive(0);
|
||||
}
|
||||
return this.save(csAlarmSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(CsAlarmSetParam param) {
|
||||
CsAlarmSet csAlarmSet = new CsAlarmSet();
|
||||
BeanUtils.copyProperties(param, csAlarmSet);
|
||||
return this.updateById(csAlarmSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(String id) {
|
||||
CsAlarmSet csAlarmSet = this.baseMapper.selectById(id);
|
||||
if (Objects.nonNull(csAlarmSet) && Objects.equals(csAlarmSet.getActive(), 1)) {
|
||||
throw new BusinessException("不能删除已启用的配置");
|
||||
}
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsAlarmSet getById(String id) {
|
||||
return this.baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsAlarmSet> listAll() {
|
||||
LambdaQueryWrapper<CsAlarmSet> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.orderByDesc(CsAlarmSet::getCreateTime);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean toggleActive(String id) {
|
||||
CsAlarmSet csAlarmSet = this.baseMapper.selectById(id);
|
||||
if (Objects.isNull(csAlarmSet)) {
|
||||
throw new BusinessException("配置不存在");
|
||||
}
|
||||
|
||||
if (Objects.equals(csAlarmSet.getActive(), 1)) {
|
||||
long enabledCount = this.count(new LambdaQueryWrapper<CsAlarmSet>().eq(CsAlarmSet::getActive, 1));
|
||||
if (enabledCount <= 1) {
|
||||
throw new BusinessException("至少需要保留一条启用的配置");
|
||||
}
|
||||
csAlarmSet.setActive(0);
|
||||
} else {
|
||||
LambdaUpdateWrapper<CsAlarmSet> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(CsAlarmSet::getActive, 0);
|
||||
this.update(updateWrapper);
|
||||
csAlarmSet.setActive(1);
|
||||
}
|
||||
return this.updateById(csAlarmSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsAlarmSet getEnabledConfig() {
|
||||
LambdaQueryWrapper<CsAlarmSet> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CsAlarmSet::getActive, 1);
|
||||
queryWrapper.last("limit 1");
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user