fix:Eamil Send

This commit is contained in:
nieziyan 2024-03-14 09:14:46 +08:00
parent cdd9ef1a30
commit 71a4860c63
12 changed files with 101 additions and 48 deletions

View File

@ -328,8 +328,9 @@ public class EmailServiceManager {
props.put("mail.smtp.host", email.getEmailServerAddress()); props.put("mail.smtp.host", email.getEmailServerAddress());
props.put("mail.smtp.port", email.getPort()); props.put("mail.smtp.port", email.getPort());
props.put("mail.smtp.auth", "true"); props.put("mail.smtp.auth", "true");
/*props.put("mail.smtp.socketFactory.port", email.getPort()); props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");*/ props.put("mail.smtp.socketFactory.port", email.getPort());
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session = Session.getInstance(props); Session session = Session.getInstance(props);

View File

@ -3,8 +3,12 @@ package org.jeecg.modules.base.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import org.jeecg.common.util.NumUtil;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Data @Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@ -17,4 +21,8 @@ public class NuclideInfo implements Serializable {
private String datasource; private String datasource;
private String value; private String value;
public void keepSix(){
this.value = NumUtil.keepStr(this.value, 6);
}
} }

View File

@ -150,6 +150,9 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
String betaOrGamma = info.getBetaOrGamma(); String betaOrGamma = info.getBetaOrGamma();
String datasource = info.getDatasource(); String datasource = info.getDatasource();
List<String> conditions = ListUtil.toList(conditionStr.split(COMMA)); List<String> conditions = ListUtil.toList(conditionStr.split(COMMA));
List<String> first = new ArrayList<>();
List<String> average = new ArrayList<>();
List<String> meanwhile = new ArrayList<>();
for (String con : conditions) { for (String con : conditions) {
Condition condition = Condition.valueOf1(con); Condition condition = Condition.valueOf1(con);
if (ObjectUtil.isNotNull(condition)){ if (ObjectUtil.isNotNull(condition)){

View File

@ -75,6 +75,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
List<NuclideInfo> nuclideInfos = mapper.readValue(nuclideInfo, new TypeReference<List<NuclideInfo>>() {}); List<NuclideInfo> nuclideInfos = mapper.readValue(nuclideInfo, new TypeReference<List<NuclideInfo>>() {});
nuclideInfos.forEach(NuclideInfo::keepSix);
logDto.setNuclideList(nuclideInfos); logDto.setNuclideList(nuclideInfos);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("NuclideInfo解析异常: {}", e.getMessage()); log.error("NuclideInfo解析异常: {}", e.getMessage());

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.feignclient; package org.jeecg.modules.feignclient;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.RedisConstant; import org.jeecg.common.constant.RedisConstant;
import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.system.util.JwtUtil;
@ -9,6 +10,7 @@ import org.jeecg.modules.base.dto.LoginResult;
import org.jeecg.modules.base.dto.LoginVo; import org.jeecg.modules.base.dto.LoginVo;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@Slf4j
public class ManageUtil { public class ManageUtil {
private static RedisUtil redisUtil; private static RedisUtil redisUtil;
@ -31,20 +33,28 @@ public class ManageUtil {
* 登录运管系统 获取Token * 登录运管系统 获取Token
* */ * */
public static String getToken(){ public static String getToken(){
String token = null;
try {
if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN)) if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN))
return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN); return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN);
LoginVo loginVo = new LoginVo(username, password); LoginVo loginVo = new LoginVo(username, password);
Result<LoginResult> loginRes = monitorSystem.login(loginVo); Result<LoginResult> loginRes = monitorSystem.login(loginVo);
String token = loginRes.getResult().getToken(); token = loginRes.getResult().getToken();
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
return token; return token;
}catch (RuntimeException e){
return token;
}
} }
public static void refreshToken(){ public static void refreshToken(){
try {
LoginVo loginVo = new LoginVo(username, password); LoginVo loginVo = new LoginVo(username, password);
Result<LoginResult> loginRes = monitorSystem.login(loginVo); Result<LoginResult> loginRes = monitorSystem.login(loginVo);
String token = loginRes.getResult().getToken(); String token = loginRes.getResult().getToken();
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
}catch (RuntimeException e){
log.error("运管系统登录异常, Token刷新失败: {}", e.getMessage());
}
} }
} }

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
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.constant.SymbolConstant; import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.enums.MessageTypeEnum; import org.jeecg.common.constant.enums.MessageTypeEnum;
@ -27,6 +28,7 @@ import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
* @author nieziyan * @author nieziyan
* @date 2023-06-21 * @date 2023-06-21
*/ */
@Slf4j
@Component @Component
public class SendMessage { public class SendMessage {
@ -50,6 +52,7 @@ public class SendMessage {
*/ */
public void send(MessageDTO messageDTO, String groupId, String notific){ public void send(MessageDTO messageDTO, String groupId, String notific){
Map<String, String> contact = getContact(groupId); Map<String, String> contact = getContact(groupId);
if (MapUtil.isEmpty(contact)) return;
if (StrUtil.isBlank(notific)) return; if (StrUtil.isBlank(notific)) return;
List<String> ways = ListUtil.toList(StrUtil.split(notific, COMMA)); List<String> ways = ListUtil.toList(StrUtil.split(notific, COMMA));
if (ways.contains(ALL.getValue())) if (ways.contains(ALL.getValue()))
@ -96,6 +99,8 @@ public class SendMessage {
* @param groupId * @param groupId
*/ */
private Map<String, String> getContact(String groupId){ private Map<String, String> getContact(String groupId){
Map<String,String> result = new HashMap<>();
try {
List<String> userIds = abnormalAlarmClient.userIds(groupId).getResult(); List<String> userIds = abnormalAlarmClient.userIds(groupId).getResult();
// 查询用户信息 // 查询用户信息
List<SysUser> sysUsers = sysUserService.listByIds(userIds); List<SysUser> sysUsers = sysUserService.listByIds(userIds);
@ -107,15 +112,20 @@ public class SendMessage {
.collect(Collectors.joining(COMMA)); .collect(Collectors.joining(COMMA));
// 用户名-邮箱Map // 用户名-邮箱Map
Map<String, String> userEmail = sysUsers.stream() Map<String, String> userEmail = sysUsers.stream()
.filter(item -> StrUtil.isNotBlank(item.getEmail()))
.collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail)); .collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail));
// 手机号码 // 手机号码
String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank) String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank)
.collect(Collectors.joining(COMMA)); .collect(Collectors.joining(COMMA));
Map<String,String> result = new HashMap<>();
result.put(SYSTEM, usernameList); result.put(SYSTEM, usernameList);
result.put(EMAIL, emailList); result.put(EMAIL, emailList);
result.put(SMS, phoneList); result.put(SMS, phoneList);
result.putAll(userEmail); result.putAll(userEmail);
return result; return result;
}catch (Exception e) {
log.error("获取收件人联系信息异常: {}", e.getMessage());
return result;
}
} }
} }

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
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.dto.message.MessageDTO;
@ -102,6 +103,10 @@ public class DatabaseJob extends Monitor implements Job{
}*/ }*/
// 向运管查询监控项数据 // 向运管查询监控项数据
String token = ManageUtil.getToken(); String token = ManageUtil.getToken();
if(StrUtil.isBlank(token)){
log.error("运管系统登录异常, Token获取失败");
continue;
}
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
ItemHistory itemHistory = result.getResult(); ItemHistory itemHistory = result.getResult();
if (ObjectUtil.isNull(itemHistory)){ if (ObjectUtil.isNull(itemHistory)){
@ -141,6 +146,9 @@ public class DatabaseJob extends Monitor implements Job{
getSendMessage().send(messageDTO, groupId, notific); getSendMessage().send(messageDTO, groupId, notific);
getPushAppUtil().pushToSingle(messageDTO, groupId); getPushAppUtil().pushToSingle(messageDTO, groupId);
} }
} catch (FeignException.Unauthorized e){
ManageUtil.refreshToken();
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
} catch (Exception e){ } catch (Exception e){

View File

@ -85,6 +85,10 @@ public class ServerJob extends Monitor implements Job {
// 向运管查询监控项数据 // 向运管查询监控项数据
String token = ManageUtil.getToken(); String token = ManageUtil.getToken();
if(StrUtil.isBlank(token)){
log.error("运管系统登录异常, Token获取失败");
continue;
}
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
ItemHistory itemHistory = result.getResult(); ItemHistory itemHistory = result.getResult();
if (ObjectUtil.isNull(itemHistory)){ if (ObjectUtil.isNull(itemHistory)){

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
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.dto.message.MessageDTO;
@ -86,6 +87,10 @@ public class DatabaseJob extends Monitor {
// 向运管查询监控项数据 // 向运管查询监控项数据
String token = ManageUtil.getToken(); String token = ManageUtil.getToken();
if(StrUtil.isBlank(token)){
log.error("运管系统登录异常, Token获取失败");
continue;
}
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
ItemHistory itemHistory = result.getResult(); ItemHistory itemHistory = result.getResult();
if (ObjectUtil.isNull(itemHistory)){ if (ObjectUtil.isNull(itemHistory)){
@ -125,11 +130,13 @@ public class DatabaseJob extends Monitor {
getSendMessage().send(messageDTO, groupId, notific); getSendMessage().send(messageDTO, groupId, notific);
getPushAppUtil().pushToSingle(messageDTO, groupId); getPushAppUtil().pushToSingle(messageDTO, groupId);
} }
}catch (FeignException.Unauthorized e){
ManageUtil.refreshToken();
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
}catch (Exception e){ }catch (Exception e){
log.error("Database监控异常: {}", e.getMessage()); log.error("Database监控异常: {}", e.getMessage());
e.printStackTrace();
} }
} }
destroy(); destroy();

View File

@ -111,7 +111,6 @@ public class EmailJob extends Monitor{
log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
}catch (Exception e){ }catch (Exception e){
log.error("Email监控异常: {}", e.getMessage()); log.error("Email监控异常: {}", e.getMessage());
e.printStackTrace();
} }
} }
destroy(); destroy();

View File

@ -84,6 +84,10 @@ public class ServerJob extends Monitor{
// 向运管查询监控项数据 // 向运管查询监控项数据
String token = ManageUtil.getToken(); String token = ManageUtil.getToken();
if(StrUtil.isBlank(token)){
log.error("运管系统登录异常, Token获取失败");
continue;
}
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
ItemHistory itemHistory = result.getResult(); ItemHistory itemHistory = result.getResult();
if (ObjectUtil.isNull(itemHistory)){ if (ObjectUtil.isNull(itemHistory)){
@ -130,7 +134,6 @@ public class ServerJob extends Monitor{
log.error("Server预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); log.error("Server预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
} catch (Exception e){ } catch (Exception e){
log.error("Server监控异常: {}", e.getMessage()); log.error("Server监控异常: {}", e.getMessage());
e.printStackTrace();
} }
} }
destroy(); destroy();

View File

@ -44,7 +44,7 @@ public class TableSpaceJob extends Monitor {
/** /**
* 解析Oracle 表空间预警规则 * 解析Oracle 表空间预警规则
**/ **/
@Scheduled(cron = "${task.period-space:0 0 */1 * * ?}") @Scheduled(cron = "${task.period-space:0 0/1 * * * ?}")
public void execute(){ public void execute(){
init(); init();
@ -124,7 +124,6 @@ public class TableSpaceJob extends Monitor {
log.error("Database-TableSpace预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); log.error("Database-TableSpace预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
}catch (Exception e){ }catch (Exception e){
log.error("Database-TableSpace监控异常: {}", e.getMessage()); log.error("Database-TableSpace监控异常: {}", e.getMessage());
e.printStackTrace();
} }
} }
destroy(); destroy();