fix:使用模板引擎消息模板
This commit is contained in:
parent
9c07c72421
commit
20163e1fba
|
@ -121,6 +121,17 @@ public class MessageDTO implements Serializable {
|
||||||
this.toUser = toUser;
|
this.toUser = toUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageDTO(String title, String template, Map<String, Object> data) {
|
||||||
|
this.title = title;
|
||||||
|
this.templateCode = template;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageDTO(String template, Map<String, Object> data) {
|
||||||
|
this.templateCode = template;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isMarkdown() {
|
public boolean isMarkdown() {
|
||||||
return this.isMarkdown;
|
return this.isMarkdown;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,6 @@ public interface RedisConstant {
|
||||||
String MANAGE_TOKEN = "Token:Manage"; // 运管系统Token
|
String MANAGE_TOKEN = "Token:Manage"; // 运管系统Token
|
||||||
|
|
||||||
String QIYE_EMAIL_TOKEN = "Token:QiyeEmail"; // 网易企业邮箱Token
|
String QIYE_EMAIL_TOKEN = "Token:QiyeEmail"; // 网易企业邮箱Token
|
||||||
|
|
||||||
|
String PREFIX_TEMPLATE = "Template:"; // 消息模板
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.jeecg.common.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DataTool {
|
||||||
|
|
||||||
|
private int counter = 1;
|
||||||
|
|
||||||
|
private final Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
public DataTool put(Object value) {
|
||||||
|
data.put(String.format("${%d}", counter), value);
|
||||||
|
counter++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataTool put(String key, Object value) {
|
||||||
|
data.put(String.format("${%s}", key), value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> get(){
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataTool getInstance(){
|
||||||
|
return new DataTool();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.jeecg.common.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
|
import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory;
|
||||||
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
|
import org.thymeleaf.TemplateEngine;
|
||||||
|
import org.thymeleaf.context.Context;
|
||||||
|
import org.thymeleaf.templatemode.TemplateMode;
|
||||||
|
import org.thymeleaf.templateresolver.DefaultTemplateResolver;
|
||||||
|
import org.thymeleaf.templateresolver.StringTemplateResolver;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 模板工具类
|
||||||
|
* */
|
||||||
|
public class TemplateUtil {
|
||||||
|
|
||||||
|
private static final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
static {
|
||||||
|
redisUtil = SpringContextUtils.getBean(RedisUtil.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDTO parse(String code, Map<String, Object> data){
|
||||||
|
String key = RedisConstant.PREFIX_TEMPLATE + code;
|
||||||
|
MessageDTO messageDTO = new MessageDTO();
|
||||||
|
if (!redisUtil.hasKey(key))
|
||||||
|
return messageDTO;
|
||||||
|
SysMessageTemplate template = (SysMessageTemplate) redisUtil.get(key);
|
||||||
|
String templateName = template.getTemplateName();
|
||||||
|
String templateContent = template.getTemplateContent();
|
||||||
|
|
||||||
|
messageDTO.setTitle(templateName);
|
||||||
|
if (MapUtil.isEmpty(data))
|
||||||
|
return messageDTO;
|
||||||
|
String content = FreemarkerParseFactory
|
||||||
|
.parseTemplateContent(templateContent, data, true);
|
||||||
|
messageDTO.setContent(content);
|
||||||
|
return messageDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDTO parse(String title, String code, Map<String, Object> data){
|
||||||
|
String key = RedisConstant.PREFIX_TEMPLATE + code;
|
||||||
|
MessageDTO messageDTO = new MessageDTO();
|
||||||
|
if (!redisUtil.hasKey(key))
|
||||||
|
return messageDTO;
|
||||||
|
SysMessageTemplate template = (SysMessageTemplate) redisUtil.get(key);
|
||||||
|
String templateName = template.getTemplateName();
|
||||||
|
String templateContent = template.getTemplateContent();
|
||||||
|
|
||||||
|
messageDTO.setTitle(StrUtil.isBlank(title) ? templateName : title);
|
||||||
|
if (MapUtil.isEmpty(data))
|
||||||
|
return messageDTO;
|
||||||
|
String content = FreemarkerParseFactory
|
||||||
|
.parseTemplateContent(templateContent, data, true);
|
||||||
|
messageDTO.setContent(content);
|
||||||
|
return messageDTO;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package org.jeecg.modules.base.entity;
|
package org.jeecg.modules.base.entity;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ -15,4 +16,12 @@ public class Rule implements Serializable {
|
||||||
private Double threshold; // 阈值
|
private Double threshold; // 阈值
|
||||||
|
|
||||||
private String units; // 单位
|
private String units; // 单位
|
||||||
|
|
||||||
|
public String joint(){
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
units = StrUtil.isBlank(units) ? "" : units;
|
||||||
|
sb.append(name).append(StrUtil.SPACE).append(operator)
|
||||||
|
.append(StrUtil.SPACE).append(threshold).append(units);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jeecg.modules.message.entity;
|
package org.jeecg.modules.base.entity.postgre;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
|
@ -3,11 +3,15 @@ package org.jeecg.modules.base.enums;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
/*
|
||||||
|
* 模板枚举
|
||||||
|
* */
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum Template {
|
public enum Template {
|
||||||
IDC_DATASOURCE_STATUS("IDC_Datasource_Status");
|
IDC_DATASOURCE_STATUS("IDC_Datasource_Status"),
|
||||||
|
MONITOR_SERVER("Monitor_Server"), MONITOR_EMAIL("Monitor_Email"),
|
||||||
|
MONITOR_DATABASE("Monitor_Database"), ANALYSIS_NUCLIDE("Analysis_Nuclide");
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ public interface SystemClient {
|
||||||
Map<String, SysUser> findUserMap();
|
Map<String, SysUser> findUserMap();
|
||||||
|
|
||||||
@GetMapping("/sys/sendMessage/send")
|
@GetMapping("/sys/sendMessage/send")
|
||||||
void sendMessage(@RequestParam String title,
|
void sendMessage(@RequestParam MessageDTO messageDTO,
|
||||||
@RequestParam String message,
|
|
||||||
@RequestParam String groupId,
|
@RequestParam String groupId,
|
||||||
@RequestParam String notific);
|
@RequestParam String notific);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
||||||
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||||
|
import org.jeecg.common.util.DataTool;
|
||||||
import org.jeecg.common.util.JDBCUtil;
|
import org.jeecg.common.util.JDBCUtil;
|
||||||
import org.jeecg.common.util.TokenUtils;
|
import org.jeecg.common.util.TokenUtils;
|
||||||
import org.jeecg.modules.base.dto.ConnR;
|
import org.jeecg.modules.base.dto.ConnR;
|
||||||
|
@ -12,15 +13,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.scheduling.annotation.Schedules;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.jeecg.modules.base.enums.Template.IDC_DATASOURCE_STATUS;
|
import static org.jeecg.modules.base.enums.Template.IDC_DATASOURCE_STATUS;
|
||||||
|
|
||||||
|
@ -77,15 +74,15 @@ public class TemplateManager {
|
||||||
template = JDBCUtil.template(urlM, usernameM, passwordM);
|
template = JDBCUtil.template(urlM, usernameM, passwordM);
|
||||||
this.setTemplate(template);
|
this.setTemplate(template);
|
||||||
} else {
|
} else {
|
||||||
|
String info = "发送%s数据源异常信息失败: {}";
|
||||||
// 为当前线程设置临时Token 避免OpenFeign调用其它服务接口时401
|
// 为当前线程设置临时Token 避免OpenFeign调用其它服务接口时401
|
||||||
UserTokenContext.setToken(TokenUtils.getTempToken());
|
UserTokenContext.setToken(TokenUtils.getTempToken());
|
||||||
// 给admin发送数据源异常消息
|
// 给admin发送数据源异常消息
|
||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = DataTool.getInstance()
|
||||||
data.put("param1", "inland");
|
.put("inland").put(connR.getInfo()).get();
|
||||||
data.put("param2", connR.getInfo());
|
|
||||||
messageDTO.setData(data);
|
messageDTO.setData(data);
|
||||||
try { systemClient.sendTo(messageDTO); }
|
try { systemClient.sendTo(messageDTO); }
|
||||||
catch(Exception e) {log.error("发送inland数据源异常信息失败: {}" , e.getMessage());}
|
catch(Exception e) {log.error(String.format(info, "inland") , e.getMessage());}
|
||||||
connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
connR = JDBCUtil.isConnection(urlS, usernameS, passwordS);
|
||||||
if (connR.isConn()){
|
if (connR.isConn()){
|
||||||
template = JDBCUtil.template(urlS, usernameS, passwordS);
|
template = JDBCUtil.template(urlS, usernameS, passwordS);
|
||||||
|
@ -93,11 +90,10 @@ public class TemplateManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 给admin发送数据源异常消息
|
// 给admin发送数据源异常消息
|
||||||
data.put("param1", "oversea");
|
data = DataTool.getInstance().put("oversea").put(connR.getInfo()).get();
|
||||||
data.put("param2", connR.getInfo());
|
|
||||||
messageDTO.setData(data);
|
messageDTO.setData(data);
|
||||||
try { systemClient.sendTo(messageDTO); }
|
try { systemClient.sendTo(messageDTO); }
|
||||||
catch(Exception e) {log.error("发送oversea数据源异常信息失败: {}" , e.getMessage());}
|
catch(Exception e) {log.error(String.format(info, "oversea") , e.getMessage());}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("定时检查inland/oversea数据源状态异常: {}", e.getMessage());
|
log.error("定时检查inland/oversea数据源状态异常: {}", e.getMessage());
|
||||||
|
|
|
@ -11,6 +11,7 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
||||||
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.constant.CommonConstant;
|
||||||
import org.jeecg.common.constant.SymbolConstant;
|
import org.jeecg.common.constant.SymbolConstant;
|
||||||
|
@ -199,8 +200,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
// 发送报警信息
|
// 发送报警信息
|
||||||
String groupId = info.getGroupId();
|
String groupId = info.getGroupId();
|
||||||
if (StrUtil.isNotBlank(groupId))
|
if (StrUtil.isNotBlank(groupId))
|
||||||
systemClient.sendMessage("Nuclide Analysis Warn Message",
|
systemClient.sendMessage(new MessageDTO(), groupId, ALL.getValue());
|
||||||
alarmInfo.toString(), groupId, ALL.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ public interface ISysBaseAPI extends CommonAPI {
|
||||||
*/
|
*/
|
||||||
void sendTemplateMessage(MessageDTO message);
|
void sendTemplateMessage(MessageDTO message);
|
||||||
|
|
||||||
|
void sendMessage(MessageDTO message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据模板编码获取模板内容【新,支持自定义推送类型】
|
* 根据模板编码获取模板内容【新,支持自定义推送类型】
|
||||||
* @param templateCode
|
* @param templateCode
|
||||||
|
|
|
@ -49,10 +49,7 @@ public class SendMessage {
|
||||||
* 根据联系人组id向用户推送消息
|
* 根据联系人组id向用户推送消息
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void send(String title, String message, String groupId, String notific){
|
public void send(MessageDTO messageDTO, String groupId, String notific){
|
||||||
// 封装MessageDTO消息体
|
|
||||||
MessageDTO messageDTO = new MessageDTO(title, message);
|
|
||||||
|
|
||||||
Map<String, String> contact = getContact(groupId);
|
Map<String, String> contact = getContact(groupId);
|
||||||
if (StrUtil.isBlank(notific))return;
|
if (StrUtil.isBlank(notific))return;
|
||||||
List<String> ways = ListUtil.toList(notific.split(comma));
|
List<String> ways = ListUtil.toList(notific.split(comma));
|
||||||
|
@ -65,7 +62,7 @@ public class SendMessage {
|
||||||
if (StrUtil.isNotBlank(toSys)){
|
if (StrUtil.isNotBlank(toSys)){
|
||||||
messageDTO.setToUser(toSys);
|
messageDTO.setToUser(toSys);
|
||||||
messageDTO.setType(XT.getType());
|
messageDTO.setType(XT.getType());
|
||||||
sysBaseAPI.sendTemplateMessage(messageDTO);
|
sysBaseAPI.sendMessage(messageDTO);
|
||||||
}
|
}
|
||||||
} else if (way.equals(YJ.getValue())) {// 2.推送邮箱
|
} else if (way.equals(YJ.getValue())) {// 2.推送邮箱
|
||||||
String toEmail = contact.get(Email);
|
String toEmail = contact.get(Email);
|
||||||
|
@ -75,14 +72,14 @@ public class SendMessage {
|
||||||
Map<String, String> userEmail = new HashMap<>(contact);
|
Map<String, String> userEmail = new HashMap<>(contact);
|
||||||
MapUtil.removeAny(userEmail, Sms, Email, System);
|
MapUtil.removeAny(userEmail, Sms, Email, System);
|
||||||
messageDTO.setUserEmail(userEmail);
|
messageDTO.setUserEmail(userEmail);
|
||||||
sysBaseAPI.sendTemplateMessage(messageDTO);
|
sysBaseAPI.sendMessage(messageDTO);
|
||||||
}
|
}
|
||||||
} else if (way.equals(SMS.getValue())) {// 3.推送短信
|
} else if (way.equals(SMS.getValue())) {// 3.推送短信
|
||||||
String toSms = contact.get(Sms);
|
String toSms = contact.get(Sms);
|
||||||
if (StrUtil.isNotBlank(toSms)){
|
if (StrUtil.isNotBlank(toSms)){
|
||||||
messageDTO.setToUser(toSms);
|
messageDTO.setToUser(toSms);
|
||||||
messageDTO.setType(SMS.getType());
|
messageDTO.setType(SMS.getType());
|
||||||
sysBaseAPI.sendTemplateMessage(messageDTO);
|
sysBaseAPI.sendMessage(messageDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import org.jeecg.modules.message.SendMessage;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("sys/sendMessage")
|
@RequestMapping("sys/sendMessage")
|
||||||
public class SendMessageController {
|
public class SendMessageController {
|
||||||
|
@ -17,11 +19,10 @@ public class SendMessageController {
|
||||||
private ISysBaseAPI sysBaseAPI;
|
private ISysBaseAPI sysBaseAPI;
|
||||||
|
|
||||||
@GetMapping("send")
|
@GetMapping("send")
|
||||||
public void sendMessage(@RequestParam String title,
|
public void sendMessage(@RequestParam MessageDTO messageDTO,
|
||||||
@RequestParam String message,
|
|
||||||
@RequestParam String groupId,
|
@RequestParam String groupId,
|
||||||
@RequestParam String notific){
|
@RequestParam String notific){
|
||||||
sendMessage.send(title, message, groupId, notific);
|
sendMessage.send(messageDTO, groupId, notific);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("sendTo")
|
@PostMapping("sendTo")
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.jeecg.modules.message.controller;
|
package org.jeecg.modules.message.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
@ -12,7 +15,7 @@ import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.common.system.query.QueryGenerator;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.jeecg.modules.message.entity.MsgParams;
|
import org.jeecg.modules.message.entity.MsgParams;
|
||||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
||||||
import org.jeecg.modules.message.util.PushMsgUtil;
|
import org.jeecg.modules.message.util.PushMsgUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -34,10 +37,6 @@ import java.util.Map;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/sys/message/sysMessageTemplate")
|
@RequestMapping("/sys/message/sysMessageTemplate")
|
||||||
public class SysMessageTemplateController extends JeecgController<SysMessageTemplate, ISysMessageTemplateService> {
|
public class SysMessageTemplateController extends JeecgController<SysMessageTemplate, ISysMessageTemplateService> {
|
||||||
@Autowired
|
|
||||||
private ISysMessageTemplateService sysMessageTemplateService;
|
|
||||||
@Autowired
|
|
||||||
private PushMsgUtil pushMsgUtil;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysBaseAPI sysBaseApi;
|
private ISysBaseAPI sysBaseApi;
|
||||||
|
@ -56,7 +55,7 @@ public class SysMessageTemplateController extends JeecgController<SysMessageTemp
|
||||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||||
QueryWrapper<SysMessageTemplate> queryWrapper = QueryGenerator.initQueryWrapper(sysMessageTemplate, req.getParameterMap());
|
QueryWrapper<SysMessageTemplate> queryWrapper = QueryGenerator.initQueryWrapper(sysMessageTemplate, req.getParameterMap());
|
||||||
Page<SysMessageTemplate> page = new Page<SysMessageTemplate>(pageNo, pageSize);
|
Page<SysMessageTemplate> page = new Page<SysMessageTemplate>(pageNo, pageSize);
|
||||||
IPage<SysMessageTemplate> pageList = sysMessageTemplateService.page(page, queryWrapper);
|
IPage<SysMessageTemplate> pageList = service.page(page, queryWrapper);
|
||||||
return Result.ok(pageList);
|
return Result.ok(pageList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +67,7 @@ public class SysMessageTemplateController extends JeecgController<SysMessageTemp
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
public Result<?> add(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
public Result<?> add(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
||||||
sysMessageTemplateService.save(sysMessageTemplate);
|
return service.addOrUpdate(sysMessageTemplate);
|
||||||
return Result.ok("添加成功!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,8 +78,7 @@ public class SysMessageTemplateController extends JeecgController<SysMessageTemp
|
||||||
*/
|
*/
|
||||||
@PutMapping(value = "/edit")
|
@PutMapping(value = "/edit")
|
||||||
public Result<?> edit(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
public Result<?> edit(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
||||||
sysMessageTemplateService.updateById(sysMessageTemplate);
|
return service.addOrUpdate(sysMessageTemplate);
|
||||||
return Result.ok("更新成功!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,9 +88,8 @@ public class SysMessageTemplateController extends JeecgController<SysMessageTemp
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@DeleteMapping(value = "/delete")
|
@DeleteMapping(value = "/delete")
|
||||||
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
public Result<?> delete(@RequestParam String id) {
|
||||||
sysMessageTemplateService.removeById(id);
|
return service.delById(id);
|
||||||
return Result.ok("删除成功!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,9 +99,9 @@ public class SysMessageTemplateController extends JeecgController<SysMessageTemp
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@DeleteMapping(value = "/deleteBatch")
|
@DeleteMapping(value = "/deleteBatch")
|
||||||
public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
public Result<?> deleteBatch(@RequestParam String ids) {
|
||||||
this.sysMessageTemplateService.removeByIds(Arrays.asList(ids.split(",")));
|
String[] idArr = StrUtil.split(ids, StrUtil.COMMA);
|
||||||
return Result.ok("批量删除成功!");
|
return service.delByIds(ListUtil.toList(idArr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +112,7 @@ public class SysMessageTemplateController extends JeecgController<SysMessageTemp
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/queryById")
|
@GetMapping(value = "/queryById")
|
||||||
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
|
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||||
SysMessageTemplate sysMessageTemplate = sysMessageTemplateService.getById(id);
|
SysMessageTemplate sysMessageTemplate = service.getById(id);
|
||||||
return Result.ok(sysMessageTemplate);
|
return Result.ok(sysMessageTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.jeecg.modules.message.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.jeecg.modules.message.service;
|
package org.jeecg.modules.message.service;
|
||||||
|
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.base.service.JeecgService;
|
import org.jeecg.common.system.base.service.JeecgService;
|
||||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -19,4 +20,10 @@ public interface ISysMessageTemplateService extends JeecgService<SysMessageTempl
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SysMessageTemplate> selectByCode(String code);
|
List<SysMessageTemplate> selectByCode(String code);
|
||||||
|
|
||||||
|
Result<?> addOrUpdate(SysMessageTemplate template);
|
||||||
|
|
||||||
|
Result<?> delById(String id);
|
||||||
|
|
||||||
|
Result<?> delByIds(List<String> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
package org.jeecg.modules.message.service.impl;
|
package org.jeecg.modules.message.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.constant.Prompt;
|
||||||
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
import org.jeecg.common.system.base.service.impl.JeecgServiceImpl;
|
import org.jeecg.common.system.base.service.impl.JeecgServiceImpl;
|
||||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
import org.jeecg.common.util.RedisUtil;
|
||||||
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.mapper.SysMessageTemplateMapper;
|
import org.jeecg.modules.message.mapper.SysMessageTemplateMapper;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 消息模板
|
* @Description: 消息模板
|
||||||
|
@ -19,11 +26,50 @@ import java.util.List;
|
||||||
public class SysMessageTemplateServiceImpl extends JeecgServiceImpl<SysMessageTemplateMapper, SysMessageTemplate> implements ISysMessageTemplateService {
|
public class SysMessageTemplateServiceImpl extends JeecgServiceImpl<SysMessageTemplateMapper, SysMessageTemplate> implements ISysMessageTemplateService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysMessageTemplateMapper sysMessageTemplateMapper;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
|
private final String PREFIX = RedisConstant.PREFIX_TEMPLATE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysMessageTemplate> selectByCode(String code) {
|
public List<SysMessageTemplate> selectByCode(String code) {
|
||||||
return sysMessageTemplateMapper.selectByCode(code);
|
return baseMapper.selectByCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Result<?> addOrUpdate(SysMessageTemplate template) {
|
||||||
|
boolean success = this.saveOrUpdate(template);
|
||||||
|
if (success){
|
||||||
|
String code = template.getTemplateCode();
|
||||||
|
redisUtil.set(PREFIX + code, template);
|
||||||
|
return Result.OK(Prompt.UPDATE_SUCC);
|
||||||
|
}
|
||||||
|
return Result.error(Prompt.UPDATE_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<?> delById(String id) {
|
||||||
|
SysMessageTemplate template = this.getById(id);
|
||||||
|
String key = PREFIX + template.getTemplateCode();
|
||||||
|
boolean success = this.removeById(id);
|
||||||
|
if (success){
|
||||||
|
redisUtil.del(key);
|
||||||
|
return Result.OK(Prompt.DELETE_SUCC);
|
||||||
|
}
|
||||||
|
return Result.OK(Prompt.DELETE_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Result<?> delByIds(List<String> ids) {
|
||||||
|
List<SysMessageTemplate> templates = this.listByIds(ids);
|
||||||
|
List<String> keys = templates.stream().map(template -> PREFIX + template.getTemplateCode())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
boolean success = this.removeByIds(ids);
|
||||||
|
if (success){
|
||||||
|
redisUtil.del(ArrayUtil.toArray(keys, String.class));
|
||||||
|
return Result.OK(Prompt.DELETE_SUCC);
|
||||||
|
}
|
||||||
|
return Result.OK(Prompt.DELETE_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
import org.jeecg.modules.message.entity.SysMessage;
|
import org.jeecg.modules.message.entity.SysMessage;
|
||||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum;
|
import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum;
|
||||||
import org.jeecg.modules.message.service.ISysMessageService;
|
import org.jeecg.modules.message.service.ISysMessageService;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
||||||
|
|
|
@ -8,14 +8,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
||||||
import org.jeecg.common.constant.DateConstant;
|
import org.jeecg.common.constant.DateConstant;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
import org.jeecg.common.util.JDBCUtil;
|
import org.jeecg.common.util.*;
|
||||||
import org.jeecg.common.util.NumUtil;
|
|
||||||
import org.jeecg.common.util.RedisStreamUtil;
|
|
||||||
import org.jeecg.common.util.SpringContextUtils;
|
|
||||||
import org.jeecg.modules.base.dto.NameValue;
|
import org.jeecg.modules.base.dto.NameValue;
|
||||||
import org.jeecg.modules.base.entity.Rule;
|
import org.jeecg.modules.base.entity.Rule;
|
||||||
import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
||||||
|
@ -31,11 +29,14 @@ import org.quartz.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||||
import static org.jeecg.modules.base.enums.Op.*;
|
import static org.jeecg.modules.base.enums.Op.*;
|
||||||
import static org.jeecg.modules.base.enums.SourceType.DATABASE;
|
import static org.jeecg.modules.base.enums.SourceType.DATABASE;
|
||||||
|
import static org.jeecg.modules.base.enums.Template.MONITOR_DATABASE;
|
||||||
|
import static org.jeecg.modules.base.enums.Template.MONITOR_SERVER;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -98,14 +99,14 @@ public class DatabaseJob extends Monitor implements Job{
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
alarmLog.setOperator(operator);
|
alarmLog.setOperator(operator);
|
||||||
alarmLog.setAlarmValue(StrUtil.toString(current));
|
alarmLog.setAlarmValue(StrUtil.toString(current));
|
||||||
String ruleName = alarmRule.getName();
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
message.append(String.format("您的数据源: [%s]", databaseName));
|
|
||||||
message.append(String.format(",设定的预警规则: %s", ruleName));
|
|
||||||
message.append(String.format(",预警信息为: %s,当前值为: %s", operator, current));
|
|
||||||
alarmLog.setAlarmInfo(message.toString());
|
|
||||||
getAlarmClient().create(alarmLog);
|
|
||||||
|
|
||||||
|
String ruleName = alarmRule.getName();
|
||||||
|
Map<String, Object> data = DataTool.getInstance().
|
||||||
|
put(databaseName).put(ruleName).put(rule.joint()).put(current).get();
|
||||||
|
MessageDTO messageDTO = TemplateUtil.parse(MONITOR_DATABASE.getCode(), data);
|
||||||
|
|
||||||
|
alarmLog.setAlarmInfo(messageDTO.getContent());
|
||||||
|
getAlarmClient().create(alarmLog);
|
||||||
// 规则触发报警后,设置该规则的沉默周期(如果有)
|
// 规则触发报警后,设置该规则的沉默周期(如果有)
|
||||||
// 沉默周期失效之前,该规则不会再次被触发
|
// 沉默周期失效之前,该规则不会再次被触发
|
||||||
Long silenceCycle = alarmRule.getSilenceCycle();
|
Long silenceCycle = alarmRule.getSilenceCycle();
|
||||||
|
@ -114,7 +115,7 @@ public class DatabaseJob extends Monitor implements Job{
|
||||||
// 发送报警信息
|
// 发送报警信息
|
||||||
String groupId = alarmRule.getContactId();
|
String groupId = alarmRule.getContactId();
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send("Database Monitor Warn Message", message.toString(), groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||||
|
|
|
@ -7,8 +7,11 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
|
import org.jeecg.common.util.DataTool;
|
||||||
import org.jeecg.common.util.NumUtil;
|
import org.jeecg.common.util.NumUtil;
|
||||||
|
import org.jeecg.common.util.TemplateUtil;
|
||||||
import org.jeecg.modules.base.dto.NameValue;
|
import org.jeecg.modules.base.dto.NameValue;
|
||||||
import org.jeecg.modules.base.entity.Rule;
|
import org.jeecg.modules.base.entity.Rule;
|
||||||
import org.jeecg.modules.base.entity.postgre.AlarmLog;
|
import org.jeecg.modules.base.entity.postgre.AlarmLog;
|
||||||
|
@ -18,10 +21,13 @@ import org.jeecg.modules.base.enums.Item;
|
||||||
import org.jeecg.modules.quartz.entity.Monitor;
|
import org.jeecg.modules.quartz.entity.Monitor;
|
||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jeecg.modules.base.enums.SourceType.DATABASE;
|
import static org.jeecg.modules.base.enums.SourceType.DATABASE;
|
||||||
import static org.jeecg.modules.base.enums.SourceType.EMAIL;
|
import static org.jeecg.modules.base.enums.SourceType.EMAIL;
|
||||||
|
import static org.jeecg.modules.base.enums.Template.MONITOR_DATABASE;
|
||||||
|
import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -84,14 +90,14 @@ public class EmailJob extends Monitor implements Job{
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
alarmLog.setOperator(operator);
|
alarmLog.setOperator(operator);
|
||||||
alarmLog.setAlarmValue(StrUtil.toString(current));
|
alarmLog.setAlarmValue(StrUtil.toString(current));
|
||||||
String ruleName = alarmRule.getName();
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
message.append(String.format("您的邮箱: [%s]", emailName));
|
|
||||||
message.append(String.format(",设定的预警规则: %s", ruleName));
|
|
||||||
message.append(String.format(",预警信息为: %s,当前值为: %s", operator, current));
|
|
||||||
alarmLog.setAlarmInfo(message.toString());
|
|
||||||
getAlarmClient().create(alarmLog);
|
|
||||||
|
|
||||||
|
String ruleName = alarmRule.getName();
|
||||||
|
Map<String, Object> data = DataTool.getInstance().
|
||||||
|
put(emailName).put(ruleName).put(rule.joint()).put(current).get();
|
||||||
|
MessageDTO messageDTO = TemplateUtil.parse(MONITOR_EMAIL.getCode(), data);
|
||||||
|
|
||||||
|
alarmLog.setAlarmInfo(messageDTO.getContent());
|
||||||
|
getAlarmClient().create(alarmLog);
|
||||||
// 规则触发报警后,设置该规则的沉默周期(如果有)
|
// 规则触发报警后,设置该规则的沉默周期(如果有)
|
||||||
// 沉默周期失效之前,该规则不会再次被触发
|
// 沉默周期失效之前,该规则不会再次被触发
|
||||||
Long silenceCycle = alarmRule.getSilenceCycle();
|
Long silenceCycle = alarmRule.getSilenceCycle();
|
||||||
|
@ -100,7 +106,7 @@ public class EmailJob extends Monitor implements Job{
|
||||||
// 发送报警信息
|
// 发送报警信息
|
||||||
String groupId = alarmRule.getContactId();
|
String groupId = alarmRule.getContactId();
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send("Email Monitor Warn Message", message.toString(), groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||||
|
|
|
@ -8,30 +8,28 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import feign.FeignException;
|
import feign.FeignException;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
|
||||||
import org.jeecg.common.constant.DateConstant;
|
import org.jeecg.common.constant.DateConstant;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
|
import org.jeecg.common.util.DataTool;
|
||||||
import org.jeecg.common.util.NumUtil;
|
import org.jeecg.common.util.NumUtil;
|
||||||
import org.jeecg.common.util.RedisStreamUtil;
|
import org.jeecg.common.util.TemplateUtil;
|
||||||
import org.jeecg.common.util.SpringContextUtils;
|
|
||||||
import org.jeecg.modules.base.entity.Rule;
|
import org.jeecg.modules.base.entity.Rule;
|
||||||
import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
||||||
import org.jeecg.modules.base.entity.postgre.AlarmLog;
|
import org.jeecg.modules.base.entity.postgre.AlarmLog;
|
||||||
import org.jeecg.modules.base.entity.postgre.AlarmRule;
|
import org.jeecg.modules.base.entity.postgre.AlarmRule;
|
||||||
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
|
|
||||||
import org.jeecg.modules.feignclient.ManageUtil;
|
import org.jeecg.modules.feignclient.ManageUtil;
|
||||||
import org.jeecg.modules.feignclient.MonitorSystem;
|
|
||||||
import org.jeecg.modules.message.SendMessage;
|
|
||||||
import org.jeecg.modules.quartz.entity.Monitor;
|
import org.jeecg.modules.quartz.entity.Monitor;
|
||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jeecg.modules.base.enums.Op.*;
|
|
||||||
import static org.jeecg.modules.base.enums.SourceType.SERVER;
|
import static org.jeecg.modules.base.enums.SourceType.SERVER;
|
||||||
|
import static org.jeecg.modules.base.enums.Template.MONITOR_SERVER;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -107,14 +105,14 @@ public class ServerJob extends Monitor implements Job {
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
alarmLog.setOperator(operator);
|
alarmLog.setOperator(operator);
|
||||||
alarmLog.setAlarmValue(StrUtil.toString(current));
|
alarmLog.setAlarmValue(StrUtil.toString(current));
|
||||||
String ruleName = alarmRule.getName();
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
message.append(String.format("您的服务器: [%s]", serverName));
|
|
||||||
message.append(String.format(",设定的预警规则: %s", ruleName));
|
|
||||||
message.append(String.format(",预警信息为: %s,当前值为: %s", operator, current));
|
|
||||||
alarmLog.setAlarmInfo(message.toString());
|
|
||||||
getAlarmClient().create(alarmLog);
|
|
||||||
|
|
||||||
|
String ruleName = alarmRule.getName();
|
||||||
|
Map<String, Object> data = DataTool.getInstance().
|
||||||
|
put(serverName).put(ruleName).put(rule.joint()).put(current).get();
|
||||||
|
MessageDTO messageDTO = TemplateUtil.parse(MONITOR_SERVER.getCode(), data);
|
||||||
|
|
||||||
|
alarmLog.setAlarmInfo(messageDTO.getContent());
|
||||||
|
getAlarmClient().create(alarmLog);
|
||||||
// 规则触发报警后,设置该规则的沉默周期(如果有)
|
// 规则触发报警后,设置该规则的沉默周期(如果有)
|
||||||
// 沉默周期失效之前,该规则不会再次被触发
|
// 沉默周期失效之前,该规则不会再次被触发
|
||||||
Long silenceCycle = alarmRule.getSilenceCycle();
|
Long silenceCycle = alarmRule.getSilenceCycle();
|
||||||
|
@ -123,7 +121,7 @@ public class ServerJob extends Monitor implements Job {
|
||||||
// 发送报警信息
|
// 发送报警信息
|
||||||
String groupId = alarmRule.getContactId();
|
String groupId = alarmRule.getContactId();
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send("Server Monitor Warn Message", message.toString(), groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
}
|
}
|
||||||
}catch (FeignException.Unauthorized e){
|
}catch (FeignException.Unauthorized e){
|
||||||
ManageUtil.refreshToken();
|
ManageUtil.refreshToken();
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.jeecg.common.util.YouBianCodeUtil;
|
||||||
import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory;
|
import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.jeecg.modules.base.entity.postgre.*;
|
import org.jeecg.modules.base.entity.postgre.*;
|
||||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.handle.impl.EmailPushMsgHandle;
|
import org.jeecg.modules.message.handle.impl.EmailPushMsgHandle;
|
||||||
import org.jeecg.modules.message.handle.impl.EmailSendMsgHandle;
|
import org.jeecg.modules.message.handle.impl.EmailSendMsgHandle;
|
||||||
import org.jeecg.modules.message.handle.impl.SmsSendMsgHandle;
|
import org.jeecg.modules.message.handle.impl.SmsSendMsgHandle;
|
||||||
|
@ -1261,6 +1261,19 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(MessageDTO message) {
|
||||||
|
String type = message.getType();
|
||||||
|
|
||||||
|
if(XT.getType().equals(type)){ // 站内消息
|
||||||
|
systemSendMsgHandle.sendMessage(message);
|
||||||
|
}else if(YJ.getType().equals(type)){ // 邮箱消息
|
||||||
|
emailPushMsgHandle.sendMessage(message);
|
||||||
|
} else if (SMS.getType().equals(type)) { // 手机短信
|
||||||
|
smsSendMsgHandle.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTemplateContent(String code) {
|
public String getTemplateContent(String code) {
|
||||||
List<SysMessageTemplate> list = sysMessageTemplateService.selectByCode(code);
|
List<SysMessageTemplate> list = sysMessageTemplateService.selectByCode(code);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user