diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NameValue.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NameValue.java index 338ad40f..d243ed8f 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NameValue.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NameValue.java @@ -14,4 +14,11 @@ public class NameValue implements Serializable { private String name; private Boolean value; + + private Integer usage; // 单位 MB + + public NameValue(String name, Boolean value) { + this.name = name; + this.value = value; + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/exceptionhandler/MonitorExceptionHandler.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/exceptionhandler/MonitorExceptionHandler.java index 722d5a4c..0caf6534 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/exceptionhandler/MonitorExceptionHandler.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/exceptionhandler/MonitorExceptionHandler.java @@ -1,8 +1,10 @@ package org.jeecg.modules.exceptionhandler; +import feign.FeignException; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.controller.SystemMonitorController; +import org.jeecg.modules.feignclient.ManageUtil; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -12,11 +14,18 @@ import org.springframework.web.bind.annotation.ExceptionHandler; @Slf4j public class MonitorExceptionHandler { + @ExceptionHandler(FeignException.Unauthorized.class) + public ResponseEntity> handleFeignExceptionUnauthorized(FeignException.Unauthorized e) { + ManageUtil.refreshToken(); + log.warn("运管服务Token失效,Token已刷新"); + return ResponseEntity.status(HttpStatus.OK) + .body(Result.error("Management system token is invalid and refreshed")); + } + @ExceptionHandler(Exception.class) public ResponseEntity> handleException(Exception e) { log.error("运管服务调用异常: {}", e.getMessage()); return ResponseEntity.status(HttpStatus.OK) .body(Result.error("Management system is abnormal, data cannot be displayed")); } - } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java index 72a0f74b..f7499eef 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java @@ -39,7 +39,14 @@ public class ManageUtil { LoginVo loginVo = new LoginVo(username, password); Result loginRes = monitorAlarm.login(loginVo); String token = loginRes.getResult().getToken(); - redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME * 2 / 1000 - 10); + redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); return token; } + + public static void refreshToken(){ + LoginVo loginVo = new LoginVo(username, password); + Result loginRes = monitorAlarm.login(loginVo); + String token = loginRes.getResult().getToken(); + redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/MailBox.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/MailBox.java index 6bfb09b0..c83d0bb7 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/MailBox.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/MailBox.java @@ -14,11 +14,11 @@ public class MailBox { public static Integer unreadMsg(QiyeOpenPlatSDK platSDK, RParam rParam){ Q q = Q.init(rParam); if (ObjectUtil.isNull(platSDK)) - return -1; + return 0; R> result = platSDK.commonInvoke(q, MailBoxAPI.UNREADMSG); Map data = result.getData(); if (ObjectUtil.isNull(data)) - return -1; - return data.getOrDefault("count", -1); + return 0; + return data.getOrDefault("count", 0); } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java index 37fc2fc8..48e9d388 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import feign.FeignException; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.MonitorConstant; @@ -113,7 +114,11 @@ public class AlarmItemServiceImpl extends ServiceImpl implements ISysEmailLogService { + @Autowired + private RedisUtil redisUtil; + @Autowired private SysEmailMapper sysEmailMapper; @@ -81,6 +87,11 @@ public class SysEmailLogServiceImpl extends ServiceImpl map = MapUtil.newHashMap(); + map.put("usage", "0.00GB"); + NameValue nameValue = (NameValue)redisUtil.hget(RedisConstant.EMAIL_STATUS, emailId); + if (ObjectUtil.isNotNull(nameValue)) + map.put("usage", m2G(nameValue.getUsage())); // 邮箱空间使用量 单位G + map.put("unreadMsg", 0); if (ObjectUtil.isNull(sysEmail) || StrUtil.isBlank(emailUsername)) return map; String[] info = StrUtil.split(emailUsername, SymbolConstant.AT); @@ -96,10 +107,7 @@ public class SysEmailLogServiceImpl extends ServiceImpl implements ISysEmailService { @@ -81,37 +82,19 @@ public class SysEmailServiceImpl extends ServiceImpl i // 邮箱状态Map key:id value:状态(true|false) String statusKey = RedisConstant.EMAIL_STATUS; Map statusMap = redisUtil.hmget(statusKey); - // 查询是否有企业邮箱 - List hasQieye = emailDtos.stream().map(EmailDto::getIsQiye) - .filter(ObjectUtil::isNotNull).filter(isQiye -> Qiye.IS.getValue() == isQiye) - .collect(Collectors.toList()); - QiyeOpenPlatSDK platSDK = null; - // 如果emailDtos中存在企业邮箱 则提前登录为查询邮箱信息做准备 - if (CollUtil.isNotEmpty(hasQieye)) platSDK = InstanceSDK.getInstance(); // 遍历emailDtos 完善每一个邮箱的详细配置信息 for (EmailDto emailDto : emailDtos) { - String id = emailDto.getId(); - Integer isQiye = emailDto.getIsQiye(); - String capacity = "--"; - if (ObjectUtil.isNotNull(isQiye) && Qiye.IS.getValue() == isQiye){ - String username = emailDto.getUsername(); - String[] info = StrUtil.split(username, SymbolConstant.AT); - if (ArrayUtil.length(info) == 2 && ObjectUtil.isNotNull(platSDK)){ - String accountName = info[0]; - String domain = info[1]; - RParam param = new RParam(accountName, domain); - AccountInfo accountInfo = Account.getMailAccountInfo(platSDK, param); - Integer usedQuota = accountInfo.getUsedQuota(); - if (ObjectUtil.isNotNull(usedQuota)) - capacity = usedQuota + " MB"; - } - } - NameValue nameValue = (NameValue) statusMap.get(id); boolean online = false; + String capacity = "--"; + String id = emailDto.getId(); + NameValue nameValue = (NameValue) statusMap.get(id); if (ObjectUtil.isNotNull(nameValue)){ Boolean value = nameValue.getValue(); + Integer usage = nameValue.getUsage(); if (ObjectUtil.isNotNull(value)) online = value; + if (ObjectUtil.isNotNull(usage)) + capacity = usage + "MB"; } emailDto.setOnline(online).setStoerCapacity(capacity).setStoerRed(true) .setToday(todayMap.getOrDefault(id, 0)) @@ -238,12 +221,33 @@ public class SysEmailServiceImpl extends ServiceImpl i public void status2Redis() { // 获取所有配置的邮箱服务器 List emails = list(); + // 查询是否有企业邮箱 + List hasQieye = emails.stream().map(SysEmail::getIsQiye) + .filter(ObjectUtil::isNotNull).filter(isQiye -> Qiye.IS.getValue() == isQiye) + .collect(Collectors.toList()); + QiyeOpenPlatSDK platSDK = null; + // 如果emails中存在企业邮箱 则提前登录为查询邮箱信息做准备 + if (CollUtil.isNotEmpty(hasQieye)) platSDK = InstanceSDK.getInstance(); Map statusMap = new HashMap<>(); for (SysEmail email : emails) { String id = email.getId(); String name = email.getName(); + Integer isQiye = email.getIsQiye(); boolean isConn = EmailUtil.isConnection(email); - statusMap.put(id, new NameValue(name, isConn)); + NameValue nameValue = new NameValue(name, isConn); + if (ObjectUtil.isNotNull(isQiye) && isQiye == IS.getValue()){ + String username = email.getUsername(); + String[] info = StrUtil.split(username, SymbolConstant.AT); + if (ArrayUtil.length(info) == 2 && ObjectUtil.isNotNull(platSDK)){ + String accountName = info[0]; + String domain = info[1]; + RParam param = new RParam(accountName, domain); + AccountInfo accountInfo = Account.getMailAccountInfo(platSDK, param); + Integer usedQuota = accountInfo.getUsedQuota(); + nameValue.setUsage(usedQuota); + } + } + statusMap.put(id, nameValue); } // 将邮箱服务器连接状态更新到reids String statusKey = RedisConstant.EMAIL_STATUS; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java index 823b045b..362d4175 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java @@ -10,6 +10,7 @@ import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import feign.FeignException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.QueryRequest; @@ -78,7 +79,10 @@ public class SysServerServiceImpl extends ServiceImpl转换为Map @@ -250,7 +254,10 @@ public class SysServerServiceImpl extends ServiceImpl