完成基础邮件发送功能

This commit is contained in:
AlanScipio
2024-03-01 13:46:33 +08:00
parent f9f895c518
commit 1e35045f67
19 changed files with 815 additions and 70 deletions

View File

@@ -1,7 +1,5 @@
package com.ruoyi.common.security.utils;
import java.util.Collection;
import java.util.List;
import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.utils.SpringUtils;
@@ -9,35 +7,47 @@ import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.system.api.domain.SysDictData;
import java.util.Collection;
import java.util.List;
/**
* 字典工具类
*
*
* @author ruoyi
*/
public class DictUtils
{
public class DictUtils {
private DictUtils() {
throw new IllegalStateException("Utility class cannot be instantiated");
}
private static RedisService redisService;
/**
* 设置字典缓存
*
* @param key 参数键
* @param dictDatas 字典数据列表
*
* @param key 参数键
* @param dictDataList 字典数据列表
*/
public static void setDictCache(String key, List<SysDictData> dictDatas)
{
SpringUtils.getBean(RedisService.class).setCacheObject(getCacheKey(key), dictDatas);
public static void setDictCache(String key, List<SysDictData> dictDataList) {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
redisService.setCacheObject(getCacheKey(key), dictDataList);
}
/**
* 获取字典缓存
*
*
* @param key 参数键
* @return dictDatas 字典数据列表
* @return dictDataList 字典数据列表
*/
public static List<SysDictData> getDictCache(String key)
{
JSONArray arrayCache = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key));
if (StringUtils.isNotNull(arrayCache))
{
public static List<SysDictData> getDictCache(String key) {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
JSONArray arrayCache = redisService.getCacheObject(getCacheKey(key));
if (StringUtils.isNotNull(arrayCache)) {
return arrayCache.toList(SysDictData.class);
}
return null;
@@ -45,31 +55,34 @@ public class DictUtils
/**
* 删除指定字典缓存
*
*
* @param key 字典键
*/
public static void removeDictCache(String key)
{
SpringUtils.getBean(RedisService.class).deleteObject(getCacheKey(key));
public static void removeDictCache(String key) {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
redisService.deleteObject(getCacheKey(key));
}
/**
* 清空字典缓存
*/
public static void clearDictCache()
{
Collection<String> keys = SpringUtils.getBean(RedisService.class).keys(CacheConstants.SYS_DICT_KEY + "*");
SpringUtils.getBean(RedisService.class).deleteObject(keys);
public static void clearDictCache() {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
Collection<String> keys = redisService.keys(CacheConstants.SYS_DICT_KEY + "*");
redisService.deleteObject(keys);
}
/**
* 设置cache key
*
*
* @param configKey 参数键
* @return 缓存键key
*/
public static String getCacheKey(String configKey)
{
public static String getCacheKey(String configKey) {
return CacheConstants.SYS_DICT_KEY + configKey;
}
}

View File

@@ -0,0 +1,81 @@
package com.ruoyi.common.security.utils;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.redis.service.RedisService;
import java.util.Collection;
/**
* 系统参数工具类 (sys_config)
*
* @author Alan Scipio
* created on 2024/3/1
*/
public class SysConfigUtils {
private SysConfigUtils() {
throw new IllegalStateException("Utility class cannot be instantiated");
}
private static RedisService redisService;
/**
* 设置参数缓存
*
* @param configKey 参数键
* @param configValue 参数值
*/
public static void setConfigCache(String configKey, String configValue) {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
redisService.setCacheObject(getCacheKey(configKey), configValue);
}
/**
* 获取参数缓存
*
* @param configKey 参数键
* @return configValue 参数值
*/
public static String getConfigCache(String configKey) {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
return redisService.getCacheObject(getCacheKey(configKey));
}
/**
* 删除指定参数缓存
*
* @param key 字典键
*/
public static void removeConfigCache(String key) {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
redisService.deleteObject(getCacheKey(key));
}
/**
* 清空所有参数缓存
*/
public static void clearConfigCaches() {
if (redisService == null) {
redisService = SpringUtils.getBean(RedisService.class);
}
Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*");
redisService.deleteObject(keys);
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
public static String getCacheKey(String configKey) {
return CacheConstants.SYS_CONFIG_KEY + configKey;
}
}