mirror of https://github.com/longtai-cn/hippo4j
parent
e91e989447
commit
de18fd509e
@ -1,15 +1,15 @@
|
||||
package cn.hippo4j.config.mapper;
|
||||
|
||||
import cn.hippo4j.config.model.AlarmInfo;
|
||||
import cn.hippo4j.config.model.NotifyInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* Alarm info mapper.
|
||||
* Notify info mapper.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:04
|
||||
*/
|
||||
@Mapper
|
||||
public interface AlarmInfoMapper extends BaseMapper<AlarmInfo> {
|
||||
public interface NotifyInfoMapper extends BaseMapper<NotifyInfo> {
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package cn.hippo4j.config.model.biz.alarm;
|
||||
|
||||
import cn.hippo4j.config.model.AlarmInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Alarm list resp dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:53
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class AlarmListRespDTO {
|
||||
|
||||
/**
|
||||
* 线程池ID
|
||||
*/
|
||||
private String threadPoolId;
|
||||
|
||||
/**
|
||||
* 报警配置
|
||||
*/
|
||||
private List<AlarmInfo> alarmNotifyList;
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package cn.hippo4j.config.model.biz.alarm;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Alarm query req dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:52
|
||||
*/
|
||||
@Data
|
||||
public class AlarmQueryReqDTO extends Page {
|
||||
|
||||
/**
|
||||
* groupKeys
|
||||
*/
|
||||
private List<String> groupKeys;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.hippo4j.config.model.biz.notify;
|
||||
|
||||
import cn.hippo4j.config.model.NotifyInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Notify list resp dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:53
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class NotifyListRespDTO {
|
||||
|
||||
/**
|
||||
* 通知 Key
|
||||
*/
|
||||
private String notifyKey;
|
||||
|
||||
/**
|
||||
* 通知配置
|
||||
*/
|
||||
private List<NotifyInfo> notifyList;
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package cn.hippo4j.config.model.biz.notify;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Notify query req dto.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:52
|
||||
*/
|
||||
@Data
|
||||
public class NotifyQueryReqDTO extends Page {
|
||||
|
||||
/**
|
||||
* groupKeys
|
||||
*/
|
||||
private List<String> groupKeys;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package cn.hippo4j.config.model.biz.notify;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 消息通知入参实体.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/18 20:15
|
||||
*/
|
||||
@Data
|
||||
public class NotifyReqDTO {
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
/**
|
||||
* 通知平台
|
||||
*/
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* 通知类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 密钥
|
||||
*/
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* 报警间隔
|
||||
*/
|
||||
private Integer interval;
|
||||
|
||||
/**
|
||||
* 接收者
|
||||
*/
|
||||
private String receives;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Integer enable;
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package cn.hippo4j.config.model.biz.notify;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 消息通知返回.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/18 20:07
|
||||
*/
|
||||
@Data
|
||||
public class NotifyRespDTO {
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 线程池id
|
||||
*/
|
||||
private String tpId;
|
||||
|
||||
/**
|
||||
* 通知平台
|
||||
*/
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* 通知类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 密钥
|
||||
*/
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* 报警间隔
|
||||
*/
|
||||
private Integer interval;
|
||||
|
||||
/**
|
||||
* 接收者
|
||||
*/
|
||||
private String receives;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Integer enable;
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package cn.hippo4j.config.service.biz;
|
||||
|
||||
import cn.hippo4j.config.model.biz.alarm.AlarmListRespDTO;
|
||||
import cn.hippo4j.config.model.biz.alarm.AlarmQueryReqDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报警管理.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:01
|
||||
*/
|
||||
public interface AlarmService {
|
||||
|
||||
/**
|
||||
* 查询报警配置集合.
|
||||
*
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
List<AlarmListRespDTO> listAlarmConfig(AlarmQueryReqDTO reqDTO);
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package cn.hippo4j.config.service.biz;
|
||||
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyListRespDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyQueryReqDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyReqDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyRespDTO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知管理.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:01
|
||||
*/
|
||||
public interface NotifyService {
|
||||
|
||||
/**
|
||||
* 查询通知配置集合.
|
||||
*
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
List<NotifyListRespDTO> listNotifyConfig(NotifyQueryReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 分页查询.
|
||||
*
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
IPage<NotifyRespDTO> queryPage(NotifyQueryReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 新增通知配置.
|
||||
*
|
||||
* @param reqDTO
|
||||
*/
|
||||
void save(NotifyReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 修改通知配置.
|
||||
*
|
||||
* @param reqDTO
|
||||
*/
|
||||
void update(NotifyReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 删除通知配置.
|
||||
*
|
||||
* @param reqDTO
|
||||
*/
|
||||
void delete(NotifyReqDTO reqDTO);
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package cn.hippo4j.config.service.biz.impl;
|
||||
|
||||
import cn.hippo4j.common.toolkit.GroupKey;
|
||||
import cn.hippo4j.config.mapper.AlarmInfoMapper;
|
||||
import cn.hippo4j.config.model.AlarmInfo;
|
||||
import cn.hippo4j.config.model.biz.alarm.AlarmListRespDTO;
|
||||
import cn.hippo4j.config.model.biz.alarm.AlarmQueryReqDTO;
|
||||
import cn.hippo4j.config.service.biz.AlarmService;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报警管理.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:02
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AlarmServiceImpl implements AlarmService {
|
||||
|
||||
private final AlarmInfoMapper alarmInfoMapper;
|
||||
|
||||
@Override
|
||||
public List<AlarmListRespDTO> listAlarmConfig(AlarmQueryReqDTO reqDTO) {
|
||||
List<AlarmListRespDTO> alarmListRespList = Lists.newArrayList();
|
||||
reqDTO.getGroupKeys().forEach(each -> {
|
||||
String[] parseKey = GroupKey.parseKey(each);
|
||||
LambdaQueryWrapper<AlarmInfo> queryWrapper = Wrappers.lambdaQuery(AlarmInfo.class)
|
||||
.eq(AlarmInfo::getTenantId, parseKey[2])
|
||||
.eq(AlarmInfo::getItemId, parseKey[1])
|
||||
.eq(AlarmInfo::getTpId, parseKey[0]);
|
||||
List<AlarmInfo> alarmInfos = alarmInfoMapper.selectList(queryWrapper);
|
||||
if (CollUtil.isNotEmpty(alarmInfos)) {
|
||||
alarmListRespList.add(new AlarmListRespDTO(parseKey[0], alarmInfos));
|
||||
}
|
||||
});
|
||||
|
||||
return alarmListRespList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package cn.hippo4j.config.service.biz.impl;
|
||||
|
||||
import cn.hippo4j.common.toolkit.GroupKey;
|
||||
import cn.hippo4j.config.enums.DelEnum;
|
||||
import cn.hippo4j.config.mapper.NotifyInfoMapper;
|
||||
import cn.hippo4j.config.model.NotifyInfo;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyListRespDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyQueryReqDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyReqDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyRespDTO;
|
||||
import cn.hippo4j.config.service.biz.NotifyService;
|
||||
import cn.hippo4j.config.toolkit.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知管理.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:02
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class NotifyServiceImpl implements NotifyService {
|
||||
|
||||
private final NotifyInfoMapper notifyInfoMapper;
|
||||
|
||||
@Override
|
||||
public List<NotifyListRespDTO> listNotifyConfig(NotifyQueryReqDTO reqDTO) {
|
||||
List<NotifyListRespDTO> notifyListRespList = Lists.newArrayList();
|
||||
reqDTO.getGroupKeys().forEach(each -> {
|
||||
String[] parseKey = GroupKey.parseKey(each);
|
||||
List<NotifyInfo> notifyInfos = listNotifyCommon("CONFIG", parseKey);
|
||||
if (CollUtil.isNotEmpty(notifyInfos)) {
|
||||
notifyListRespList.add(new NotifyListRespDTO(StrUtil.builder(parseKey[0], "+", "CONFIG").toString(), notifyInfos));
|
||||
}
|
||||
|
||||
List<NotifyInfo> alarmInfos = listNotifyCommon("ALARM", parseKey);
|
||||
if (CollUtil.isNotEmpty(alarmInfos)) {
|
||||
notifyListRespList.add(new NotifyListRespDTO(StrUtil.builder(parseKey[0], "+", "ALARM").toString(), alarmInfos));
|
||||
}
|
||||
});
|
||||
|
||||
return notifyListRespList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<NotifyRespDTO> queryPage(NotifyQueryReqDTO reqDTO) {
|
||||
LambdaQueryWrapper<NotifyInfo> queryWrapper = Wrappers.lambdaQuery(NotifyInfo.class)
|
||||
.eq(StrUtil.isNotBlank(reqDTO.getTenantId()), NotifyInfo::getTenantId, reqDTO.getTenantId())
|
||||
.eq(StrUtil.isNotBlank(reqDTO.getItemId()), NotifyInfo::getItemId, reqDTO.getItemId())
|
||||
.eq(StrUtil.isNotBlank(reqDTO.getTpId()), NotifyInfo::getTpId, reqDTO.getTpId());
|
||||
|
||||
IPage<NotifyInfo> resultPage = notifyInfoMapper.selectPage(reqDTO, queryWrapper);
|
||||
return resultPage.convert(each -> BeanUtil.convert(each, NotifyRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NotifyReqDTO reqDTO) {
|
||||
notifyInfoMapper.insert(BeanUtil.convert(reqDTO, NotifyInfo.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(NotifyReqDTO reqDTO) {
|
||||
NotifyInfo notifyInfo = BeanUtil.convert(reqDTO, NotifyInfo.class);
|
||||
LambdaUpdateWrapper<NotifyInfo> updateWrapper = Wrappers.lambdaUpdate(NotifyInfo.class)
|
||||
.eq(NotifyInfo::getTenantId, reqDTO.getTenantId())
|
||||
.eq(NotifyInfo::getItemId, reqDTO.getItemId())
|
||||
.eq(NotifyInfo::getTpId, reqDTO.getTpId());
|
||||
|
||||
notifyInfoMapper.update(notifyInfo, updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(NotifyReqDTO reqDTO) {
|
||||
LambdaUpdateWrapper<NotifyInfo> updateWrapper = Wrappers.lambdaUpdate(NotifyInfo.class)
|
||||
.eq(NotifyInfo::getTenantId, reqDTO.getTenantId())
|
||||
.eq(NotifyInfo::getItemId, reqDTO.getItemId())
|
||||
.eq(NotifyInfo::getTpId, reqDTO.getTpId());
|
||||
|
||||
notifyInfoMapper.delete(updateWrapper);
|
||||
}
|
||||
|
||||
private List<NotifyInfo> listNotifyCommon(String type, String[] parseKey) {
|
||||
LambdaQueryWrapper<NotifyInfo> queryWrapper = Wrappers.lambdaQuery(NotifyInfo.class)
|
||||
.eq(NotifyInfo::getTenantId, parseKey[2])
|
||||
.eq(NotifyInfo::getItemId, parseKey[1])
|
||||
.eq(NotifyInfo::getTpId, parseKey[0])
|
||||
.eq(NotifyInfo::getEnable, DelEnum.NORMAL)
|
||||
.eq(NotifyInfo::getType, type);
|
||||
List<NotifyInfo> notifyInfos = notifyInfoMapper.selectList(queryWrapper);
|
||||
return notifyInfos;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package cn.hippo4j.console.controller;
|
||||
|
||||
import cn.hippo4j.common.constant.Constants;
|
||||
import cn.hippo4j.common.web.base.Result;
|
||||
import cn.hippo4j.common.web.base.Results;
|
||||
import cn.hippo4j.config.model.biz.alarm.AlarmListRespDTO;
|
||||
import cn.hippo4j.config.model.biz.alarm.AlarmQueryReqDTO;
|
||||
import cn.hippo4j.config.service.biz.AlarmService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报警管理.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:00
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(Constants.BASE_PATH + "/alarm")
|
||||
public class AlarmController {
|
||||
|
||||
private final AlarmService alarmService;
|
||||
|
||||
@PostMapping("/list/config")
|
||||
public Result<List<AlarmListRespDTO>> listAlarmConfig(@RequestBody AlarmQueryReqDTO reqDTO) {
|
||||
List<AlarmListRespDTO> resultData = alarmService.listAlarmConfig(reqDTO);
|
||||
return Results.success(resultData);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package cn.hippo4j.console.controller;
|
||||
|
||||
import cn.hippo4j.common.constant.Constants;
|
||||
import cn.hippo4j.common.web.base.Result;
|
||||
import cn.hippo4j.common.web.base.Results;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyListRespDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyQueryReqDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyReqDTO;
|
||||
import cn.hippo4j.config.model.biz.notify.NotifyRespDTO;
|
||||
import cn.hippo4j.config.service.biz.NotifyService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知管理.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/17 22:00
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(Constants.BASE_PATH + "/notify")
|
||||
public class NotifyController {
|
||||
|
||||
private final NotifyService notifyService;
|
||||
|
||||
@PostMapping("/list/config")
|
||||
public Result<List<NotifyListRespDTO>> listNotifyConfig(@RequestBody NotifyQueryReqDTO reqDTO) {
|
||||
List<NotifyListRespDTO> resultData = notifyService.listNotifyConfig(reqDTO);
|
||||
return Results.success(resultData);
|
||||
}
|
||||
|
||||
@PostMapping("/query/page")
|
||||
public Result<IPage<NotifyRespDTO>> queryPage(@RequestBody NotifyQueryReqDTO reqDTO) {
|
||||
IPage<NotifyRespDTO> resultPage = notifyService.queryPage(reqDTO);
|
||||
return Results.success(resultPage);
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public Result<Void> saveNotifyConfig(@RequestBody NotifyReqDTO reqDTO) {
|
||||
notifyService.save(reqDTO);
|
||||
return Results.success();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Result<Void> updateNotifyConfig(@RequestBody NotifyReqDTO reqDTO) {
|
||||
notifyService.update(reqDTO);
|
||||
return Results.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("/remove")
|
||||
public Result<Void> removeNotifyConfig(@RequestBody NotifyReqDTO reqDTO) {
|
||||
notifyService.delete(reqDTO);
|
||||
return Results.success();
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package cn.hippo4j.starter.alarm;
|
||||
|
||||
/**
|
||||
* Send message enum.
|
||||
* Notify platform enum.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/8/15 15:50
|
||||
*/
|
||||
public enum SendMessageEnum {
|
||||
public enum NotifyPlatformEnum {
|
||||
|
||||
DING
|
||||
|
Loading…
Reference in new issue