From 58db07b591d05a3ef9a51642cf5fdaa0360d95b1 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 16 Nov 2023 16:04:56 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9AqiyeEmail=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/constant/DBSQL.java | 2 +- .../controller/SysEmailLogController.java | 20 ++++----- .../jeecg/modules/mapper/SysEmailMapper.java | 3 +- .../modules/qiyeEmail/base/InstanceSDK.java | 10 ++--- .../modules/qiyeEmail/service/Account.java | 15 +++---- .../modules/service/ISysEmailLogService.java | 12 +++-- .../service/impl/SysEmailLogServiceImpl.java | 45 +++++++++++++++++++ .../service/impl/SysEmailServiceImpl.java | 34 -------------- .../armd-abnormal-alarm-start/pom.xml | 4 ++ 9 files changed, 78 insertions(+), 67 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java index 097dc967..423c16f9 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DBSQL.java @@ -4,7 +4,7 @@ public interface DBSQL { /* PostgreSQL */ String DBNAMES_PG = "SELECT datname FROM pg_database WHERE datistemplate = false"; - String DBINFO_PG = " SELECT relname AS tableName, 0 AS numRow, 0.0 AS used," + + String DBINFO_PG = "SELECT relname AS tableName, 0 AS numRow, 0.0 AS used," + "ROUND( pg_relation_size ( relid ) / ( 1024 * 1024 ), 2 ) AS dataSize," + "ROUND( pg_indexes_size ( relid ) / ( 1024 * 1024 ), 2 ) AS indexSize " + "FROM pg_stat_user_tables WHERE schemaname = 'public'"; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailLogController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailLogController.java index 5952618e..34a6eebb 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailLogController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysEmailLogController.java @@ -6,6 +6,9 @@ import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.EmailConstant; import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.qiyeEmail.base.RParam; +import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo; +import org.jeecg.modules.qiyeEmail.service.Account; import org.jeecg.modules.service.ISysEmailLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; +import java.util.Map; @RestController @RequestMapping("sysEmailLog") @@ -27,7 +31,7 @@ public class SysEmailLogController { @GetMapping("status") @ApiOperation("邮箱服务器状态") - public Result status(@RequestParam("emailId") String emailId){ + public Result status(@RequestParam("emailId") String emailId){ String key = EmailConstant.EMAIL_STATUS_PREFIX; Boolean emailSatus = (Boolean) redisUtil.hget(key, emailId); return Result.OK(emailSatus == null ? false : emailSatus); @@ -35,29 +39,25 @@ public class SysEmailLogController { @GetMapping("space") @ApiOperation("邮箱服务器空间") - public Result space(@RequestParam("emailId") String emailId){ - HashMap map = MapUtil.newHashMap(); - map.put("total","500G"); - map.put("residue","300G"); - map.put("usage","74.3%"); - return Result.OK(map); + public Result space(@RequestParam("emailId") String emailId){ + return Result.OK(sysEmailLogService.space(emailId)); } @GetMapping("total") @ApiOperation("今天|昨天|过去一周邮件量") - public Result totalEmail(@RequestParam("emailId") String emailId){ + public Result totalEmail(@RequestParam("emailId") String emailId){ return sysEmailLogService.totalEmail(emailId); } @GetMapping("today") @ApiOperation("今日邮件接收量") - public Result today(@RequestParam("emailId") String emailId){ + public Result today(@RequestParam("emailId") String emailId){ return sysEmailLogService.todayMin(emailId); } @GetMapping("analysis") @ApiOperation("根据日期统计-折线图") - public Result analysis(@RequestParam("emailId") String emailId, + public Result analysis(@RequestParam("emailId") String emailId, @RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate){ return sysEmailLogService.analysis(emailId, startDate, endDate); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java index cc32f6a8..9f5a8c80 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysEmailMapper.java @@ -1,6 +1,7 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.jeecg.modules.base.dto.EmailDto; import org.jeecg.modules.base.dto.IdCount; @@ -9,7 +10,7 @@ import org.jeecg.modules.entity.AlarmHistory; import java.util.List; import java.util.Map; - +@Mapper public interface SysEmailMapper extends BaseMapper { List findAlarmHistory(Map params); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/base/InstanceSDK.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/base/InstanceSDK.java index eaf32e22..0d776437 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/base/InstanceSDK.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/base/InstanceSDK.java @@ -13,15 +13,11 @@ public class InstanceSDK { public static QiyeOpenPlatSDK getInstance() { //init - //Environment env = SpringContextUtils.getBean(Environment.class); - /*String appId = env.getProperty("qiyeEmail.appId"); + Environment env = SpringContextUtils.getBean(Environment.class); + String appId = env.getProperty("qiyeEmail.appId"); String orgOpenId = env.getProperty("qiyeEmail.orgOpenId"); String authCode = env.getProperty("qiyeEmail.authCode"); - String urlPrefix = env.getProperty("qiyeEmail.urlPrefix");*/ - String appId = "qy20231114144636B85B"; - String orgOpenId = "9c96b0ec1e6be89a"; - String authCode = "O1eSXJwU"; - String urlPrefix = "https://api.qiye.163.com"; + String urlPrefix = env.getProperty("qiyeEmail.urlPrefix"); QiyeOpenPlatSDKConfig qiyeOpenPlatSDKConfig = QiyeOpenPlatSDKConfig.builder() //应用ID diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/Account.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/Account.java index 37b84771..36f952c1 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/Account.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/qiyeEmail/service/Account.java @@ -17,25 +17,20 @@ import org.jeecg.modules.qiyeEmail.base.dto.ResponseText; public class Account { - public static AccountInfo getMailAccountInfo(RParam rParam){ + public static AccountInfo getMailAccountInfo(RParam rParam) { QiyeOpenPlatSDK platSDK = InstanceSDK.getInstance(); Q reqParam = Q.init(rParam); R result = platSDK.commonInvoke(reqParam, AccountAPI.ACCOUNTINFO); String responseText = result.getResponseText(); + AccountInfo accountInfo = new AccountInfo(); try { ObjectMapper objectMapper = new ObjectMapper(); ResponseText response = objectMapper.readValue(responseText, ResponseText.class); - return BeanUtil.mapToBean(response.getCon(),AccountInfo.class, CopyOptions.create()); + accountInfo = BeanUtil.mapToBean(response.getCon(), AccountInfo.class, CopyOptions.create()); + return accountInfo; } catch (Exception e) { e.printStackTrace(); - return null; + return accountInfo; } } - - public static void main(String[] args) { - RParam rParam = new RParam(); - rParam.setDomain("ndc.org.cn"); - rParam.setAccount_name("cnndc.rn.ng"); - System.out.println(getMailAccountInfo(rParam)); - } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailLogService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailLogService.java index a0d0af71..aec848c3 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailLogService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysEmailLogService.java @@ -4,12 +4,16 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.base.entity.postgre.SysEmailLog; +import java.util.Map; + public interface ISysEmailLogService extends IService { - Result totalEmail(String emailId); + Result totalEmail(String emailId); - Result todayHour(String emailId); + Map space(String emailId); - Result todayMin(String emailId); + Result todayHour(String emailId); - Result analysis(String emailId, String startDate, String endDate); + Result todayMin(String emailId); + + Result analysis(String emailId, String startDate, String endDate); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailLogServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailLogServiceImpl.java index 431daf04..901628b5 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailLogServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailLogServiceImpl.java @@ -2,17 +2,28 @@ package org.jeecg.modules.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ArrayUtil; +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 org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.DateConstant; import org.jeecg.common.constant.Prompt; +import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jeecg.modules.base.entity.postgre.SysEmailLog; import org.jeecg.modules.mapper.SysEmailLogMapper; +import org.jeecg.modules.mapper.SysEmailMapper; +import org.jeecg.modules.qiyeEmail.base.RParam; +import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo; +import org.jeecg.modules.qiyeEmail.service.Account; import org.jeecg.modules.service.ISysEmailLogService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -26,6 +37,9 @@ import java.util.stream.IntStream; @Service("sysEmailLogService") public class SysEmailLogServiceImpl extends ServiceImpl implements ISysEmailLogService { + @Autowired + private SysEmailMapper sysEmailMapper; + @Override public Result totalEmail(String emailId) { // 当日邮件量 @@ -59,6 +73,37 @@ public class SysEmailLogServiceImpl extends ServiceImpl space(String emailId) { + SysEmail sysEmail = sysEmailMapper.selectById(emailId); + String emailUsername = sysEmail.getUsername(); + Map map = MapUtil.newHashMap(); + if (ObjectUtil.isNull(sysEmail) || StrUtil.isBlank(emailUsername)) + return map; + String[] info = StrUtil.split(emailUsername, "@"); + if (ArrayUtil.length(info) < 2) + return map; + RParam rParam = new RParam(); + rParam.setDomain(info[1]); + rParam.setAccount_name(info[0]); + AccountInfo mailAccountInfo = Account.getMailAccountInfo(rParam); + Integer usedQuota = mailAccountInfo.getUsedQuota(); + Integer maxQuota = mailAccountInfo.getMaxQuota(); + map.put("total", maxQuota < 0 ? maxQuota + "(No Limit)" : m2G(maxQuota)); + map.put("residue", m2G(usedQuota)); + map.put("usage","74.3%"); + return map; + } + + private String m2G(Integer mb) { + if (ObjectUtil.isNull(mb)) + return "0.00GB"; + BigDecimal bigMB = new BigDecimal(mb); + BigDecimal bigGB = bigMB.divide(BigDecimal.valueOf(1024), + 2, RoundingMode.HALF_UP); + return bigGB + "GB"; + } + @Override public Result todayHour(String emailId) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java index ff444e59..8162f8ef 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java @@ -196,38 +196,4 @@ public class SysEmailServiceImpl extends ServiceImpl i } return sourceDtos; } - - public static void main(String[] args) throws MessagingException { - Properties prop = System.getProperties(); - - String host = "imaphz.qiye.163.com"; - String username = "cnndc.rn.dr@ndc.org.cn"; - String password = "cnndc66367220"; - - prop.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); - prop.setProperty("mail.imap.host", host); - prop.setProperty("mail.imap.port", "993"); - prop.setProperty("mail.imap.starttls.enable", "true"); - prop.setProperty("mail.imap.socketFactory.fallback", "false"); - prop.setProperty("mail.debug", "true"); - - Session ses = Session.getInstance(prop, null); - Store store = ses.getStore("imap"); - store.connect(host, username, password); - - if (!IMAPStore.class.isInstance(store)) - throw new IllegalStateException("Is not IMAPStore"); - IMAPStore imapStore = (IMAPStore) store; - Quota[] quotas = imapStore.getQuota("INBOX"); - - for (Quota quota : quotas) { - System.out.println(String.format("quotaRoot:%s", quota.quotaRoot)); - - for (Quota.Resource resource : quota.resources) { - System.out.println(String.format("name:%s, limit:%s, usage:%s", - resource.name, resource.limit, resource.usage)); - } - } - } - } diff --git a/jeecg-server-cloud/armd-abnormal-alarm-start/pom.xml b/jeecg-server-cloud/armd-abnormal-alarm-start/pom.xml index 6c7e7966..8c7f40a2 100644 --- a/jeecg-server-cloud/armd-abnormal-alarm-start/pom.xml +++ b/jeecg-server-cloud/armd-abnormal-alarm-start/pom.xml @@ -25,6 +25,10 @@ org.springframework.boot spring-boot-maven-plugin + + + true +