BUGFIX: format;

This commit is contained in:
shahaibo
2023-10-20 14:47:18 +08:00
parent f18c27fe02
commit 9fa605f83e
134 changed files with 1345 additions and 1203 deletions

View File

@@ -23,16 +23,17 @@ public class AccessLimitUtils {
* @param interfaceName
* @return
*/
public static void validate(String interfaceName,Integer count) {
Integer useCount= LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
if(useCount >count){
public static void validate(String interfaceName, Integer count) {
Integer useCount = LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
if (useCount > count) {
//系统繁忙
throw new BusinessException("system busy !");
}else{
useCount ++;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName,useCount);
} else {
useCount++;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName, useCount);
}
}
/**
* 校验过后 接口完毕 去掉限流
*
@@ -40,9 +41,9 @@ public class AccessLimitUtils {
* @return
*/
public static void validateOut(String interfaceName) {
Integer useCount= LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
useCount --;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName,useCount);
Integer useCount = LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
useCount--;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName, useCount);
}
}

View File

@@ -54,11 +54,11 @@ public class ConvertUtil {
return sb.toString();
}
public static String lowerCaseFirstLetter(String str){
if(StrUtil.isNotBlank(str)){
public static String lowerCaseFirstLetter(String str) {
if (StrUtil.isNotBlank(str)) {
str = str.trim();
String result = str.substring(0, 1).toLowerCase();
if(str.length() > 1){
if (str.length() > 1) {
result += str.substring(1);
}
return result;

View File

@@ -12,11 +12,13 @@ import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@Slf4j
public class DateUtil {
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public static final String YYYYMM = "yyyyMM";
public static final String YYYY_MM_DD = "yyyyMMdd";
/**
* LocalDate -> Date
*/
@@ -25,13 +27,15 @@ public class DateUtil {
}
/**
* LocalDateTime -> Date
* LocalDateTime -> Date
*/
public static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
/**
* date 装 String
*
* @param date
* @param formatter
* @return
@@ -43,21 +47,23 @@ public class DateUtil {
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
return dateTimeFormatter.format(localDateTime);
}
/**
* 根据时区获取时间
*
* @param timeZone "Asia/Tokyo"
* @return
*/
public static Date getByTimeZone(String timeZone) {
String dateStr = dateToStr(new Date(),YYYY_MM_DD_HH_MM_SS);
String dateStr = dateToStr(new Date(), YYYY_MM_DD_HH_MM_SS);
SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
// 设置时区
sdf.setTimeZone(TimeZone.getTimeZone(timeZone));
Date date = null;
try{
Date date = null;
try {
date = sdf.parse(dateStr);
}catch (ParseException parseException){
log.error("时间转换异常!",parseException);
} catch (ParseException parseException) {
log.error("时间转换异常!", parseException);
}
return date;
}

View File

@@ -129,53 +129,56 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/**
* 获取文件尺寸
*/
public static FileVO getFileSize(MultipartFile file) {
public static FileVO getFileSize(MultipartFile file) {
int width = 0;
int height = 0;
try{
try {
// 图片对象
BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
// 宽度
width = bufferedImage.getWidth();
width = bufferedImage.getWidth();
// 高度
height = bufferedImage.getHeight();
}catch (IOException ioException){
height = bufferedImage.getHeight();
} catch (IOException ioException) {
log.error("获取文件尺寸异常###{}", ExceptionUtil.stacktraceToString(ioException));
}
return new FileVO(height,width);
return new FileVO(height, width);
}
/**
* 获取文件尺寸
*/
public static FileVO getFileSize(InputStream inputStream) {
public static FileVO getFileSize(InputStream inputStream) {
int width = 0;
int height = 0;
try{
try {
// 图片对象
BufferedImage bufferedImage = ImageIO.read(inputStream);
// 宽度
width = bufferedImage.getWidth();
// 高度
height = bufferedImage.getHeight();
}catch (IOException ioException){
} catch (IOException ioException) {
log.error("获取文件尺寸异常###{}", ExceptionUtil.stacktraceToString(ioException));
}
return new FileVO(height,width);
return new FileVO(height, width);
}
/**
* 获取远程文件流
*/
public static InputStream getOriginFile(String path) {
public static InputStream getOriginFile(String path) {
try{
try {
//远程
URL url = new URL(path);
return url.openStream();
}catch (IOException ioException){
log.error("获取文件尺寸异常###{}###path##{}", ExceptionUtil.stacktraceToString(ioException),path);
} catch (IOException ioException) {
log.error("获取文件尺寸异常###{}###path##{}", ExceptionUtil.stacktraceToString(ioException), path);
throw new BusinessException("get file is failed!");
}
}
/**
* 将文件名解析成文件的上传路径
*/
@@ -183,7 +186,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
String suffix = getExtensionName(file.getOriginalFilename());
String nowStr = format.format(date)+"-" ;
String nowStr = format.format(date) + "-";
try {
String fileName = file.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
@@ -204,6 +207,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
}
return null;
}
/**
* 将文件名解析成文件的上传路径
*/
@@ -211,7 +215,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
String suffix = getExtensionName(file.getOriginalFilename());
String nowStr = format.format(date)+"-" ;
String nowStr = format.format(date) + "-";
try {
String fileName = file.getOriginalFilename();
String path = filePath + fileName;
@@ -242,6 +246,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
}
return false;
}
/**
* 获取指定文件夹下所有文件,不含文件夹里的文件
*
@@ -249,7 +254,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
* @return
*/
public static List<File> getAllFile(String dirFilePath) {
if (StrUtil.isBlank(dirFilePath)){
if (StrUtil.isBlank(dirFilePath)) {
return null;
}
return getAllFile(new File(dirFilePath));
@@ -263,11 +268,11 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
*/
public static List<File> getAllFile(File dirFile) {
// 如果文件夹不存在或着不是文件夹,则返回 null
if (Objects.isNull(dirFile) || !dirFile.exists() || dirFile.isFile()){
if (Objects.isNull(dirFile) || !dirFile.exists() || dirFile.isFile()) {
return null;
}
File[] childrenFiles = dirFile.listFiles();
if (Objects.isNull(childrenFiles) || childrenFiles.length == 0){
if (Objects.isNull(childrenFiles) || childrenFiles.length == 0) {
return null;
}
List<File> files = new ArrayList<>();
@@ -280,7 +285,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
else {
// 如果是文件夹,则将其内部文件添加进结果集合
List<File> cFiles = getAllFile(childFile);
if (Objects.isNull(cFiles) || cFiles.isEmpty()){
if (Objects.isNull(cFiles) || cFiles.isEmpty()) {
continue;
}
files.addAll(cFiles);

View File

@@ -14,10 +14,11 @@ import java.io.IOException;
@Slf4j
public class ImageUtil {
static BufferedImage bufferedImage;
static int r,g,b; // 分别用来存放获取的RGB值
static int heigth,width;
static int r, g, b; // 分别用来存放获取的RGB值
static int heigth, width;
static int id = 0;
public static void find(){
public static void find() {
// 读取要操作的图片,这里的图片路径请改成自己要处理的图片
try {
bufferedImage = ImageIO.read(new File("D:\\programManager\\private\\curtain\\curtain\\WechatIMG170.png"));
@@ -27,16 +28,16 @@ public class ImageUtil {
// 获取图片的宽和高;
heigth = bufferedImage.getHeight();
width = bufferedImage.getHeight();
System.out.println("heigth = "+heigth +", width ="+width);
System.out.println("heigth = " + heigth + ", width =" + width);
// 采用行优先遍历,先遍历宽
for (int y = 0; y < heigth; y++) {
for (int x = 0; x < width; x++) {
id++;
Color color = new Color(bufferedImage.getRGB(x,y));
Color color = new Color(bufferedImage.getRGB(x, y));
r = color.getRed();
g = color.getGreen();
b = color.getBlue();
System.out.println("此时的id为 "+ id+ " R = "+ r + ", G = "+g+", B ="+b);
System.out.println("此时的id为 " + id + " R = " + r + ", G = " + g + ", B =" + b);
}
}
}

View File

@@ -25,25 +25,26 @@ public final class LocalCacheUtils {
* token
*/
private static LoadingCache<String, String> tokenCache = loadTokenCache();
/**
*
*缓存接口这里是LoadingCacheLoadingCache在缓存项不存在时可以自动加载缓存
* 缓存接口这里是LoadingCacheLoadingCache在缓存项不存在时可以自动加载缓存
*/
private static LoadingCache<String, String> loadTokenCache(){
LoadingCache<String, String> tokenCache = CacheBuilder.newBuilder()
private static LoadingCache<String, String> loadTokenCache() {
LoadingCache<String, String> tokenCache = CacheBuilder.newBuilder()
.concurrencyLevel(10)
.expireAfterWrite(24*100, TimeUnit.HOURS)
.expireAfterWrite(24 * 100, TimeUnit.HOURS)
.initialCapacity(100)
.maximumSize(10000)
.recordStats()
.build(new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
return "null";
}
@Override
public String load(String key) throws Exception {
return "null";
}
});
return tokenCache;
}
/**
* 邮箱,短信验证码
*/
@@ -51,7 +52,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后10分钟过期,防止跨洲发送慢失效问题
.expireAfterWrite(60*30, TimeUnit.SECONDS)
.expireAfterWrite(60 * 30, TimeUnit.SECONDS)
//刷新机制 每隔一定时间刷新缓存loader 只有调用get具体的操作才生效(懒加载) 不设置则不刷新
// .refreshAfterWrite(60, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
@@ -75,7 +76,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后一天过期
.expireAfterWrite(60*60*24, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(100)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -96,7 +97,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后一天过期
.expireAfterWrite(60*60*24, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(100)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -118,7 +119,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后一天过期
.expireAfterWrite(60*60*24, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24, TimeUnit.SECONDS)
//设置缓存容器的初始容量为15000
.initialCapacity(15000)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -133,27 +134,27 @@ public final class LocalCacheUtils {
}
});
/**
/**
* design文件进度统计
*/
private static LoadingCache<Long, List<String>> designProcessCache = CacheBuilder.newBuilder()
//设置并发级别为10并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后5分钟过期
.expireAfterWrite(60*5, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(5)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
.maximumSize(100)
//设置要统计缓存的命中率
.recordStats()
//build方法中可以指定CacheLoader在缓存不存在时通过CacheLoader的实现自动加载缓存
.build(new CacheLoader<Long, List<String>>() {
@Override
public List<String> load(Long key) throws Exception {
return Collections.EMPTY_LIST;
}
});
//设置并发级别为10并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后5分钟过期
.expireAfterWrite(60 * 5, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(5)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
.maximumSize(100)
//设置要统计缓存的命中率
.recordStats()
//build方法中可以指定CacheLoader在缓存不存在时通过CacheLoader的实现自动加载缓存
.build(new CacheLoader<Long, List<String>>() {
@Override
public List<String> load(Long key) throws Exception {
return Collections.EMPTY_LIST;
}
});
/**
* aida 接口限流(先粗暴做)
@@ -162,7 +163,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(20)
//设置写缓存后30天过期
.expireAfterWrite(60*60*24*30, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24 * 30, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(5)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -176,8 +177,10 @@ public final class LocalCacheUtils {
return 0;
}
});
/**
* 添加token本地缓存
*
* @param key
* @param value
*/
@@ -187,6 +190,7 @@ public final class LocalCacheUtils {
/**
* 获取token本地缓存
*
* @param key
* @return
*/
@@ -202,8 +206,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 删除token本地缓存(登出)
*
* @param key
* @return
*/
@@ -214,8 +220,10 @@ public final class LocalCacheUtils {
log.error("delTokenCache方法错误", e);
}
}
/**
* 添加验证码本地缓存
*
* @param key
* @param value
*/
@@ -225,6 +233,7 @@ public final class LocalCacheUtils {
/**
* 获取验证码本地缓存
*
* @param key
* @return
*/
@@ -240,8 +249,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 添加系统文本地缓存
*
* @param key
* @param sysFile
*/
@@ -251,6 +262,7 @@ public final class LocalCacheUtils {
/**
* 获取系统文件本地缓存
*
* @param key
* @return
*/
@@ -263,8 +275,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 清除所有系统文件本地缓存
*
* @return
*/
public static void clearAllSysFileCache() {
@@ -274,8 +288,10 @@ public final class LocalCacheUtils {
log.error("clearAllSysFileCache方法错误", e);
}
}
/**
* 添加系统文本地缓存,通过类型
*
* @param level1Type
* @param sysFileList
*/
@@ -285,6 +301,7 @@ public final class LocalCacheUtils {
/**
* 获取系统文件本地缓存
*
* @param level2Type
* @return
*/
@@ -296,8 +313,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 清除所有系统文件本地缓存
*
* @return
*/
public static void clearAllSysFileCacheByLevel2Type() {
@@ -307,8 +326,10 @@ public final class LocalCacheUtils {
log.error("clearAllSysFileCacheByLevel2Type方法错误", e);
}
}
/**
* 添加系统文件范围最大最小值本地缓存
*
* @param key
* @param value
*/
@@ -318,6 +339,7 @@ public final class LocalCacheUtils {
/**
* 获取系统文件范围最大最小值本地缓存
*
* @param key
* @return
*/
@@ -333,8 +355,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 清除所有系统文件范围最大最小值本地缓存
*
* @return
*/
public static void clearAllMaxMinValueCache() {
@@ -344,8 +368,10 @@ public final class LocalCacheUtils {
log.error("clearAllMaxMinValueCache方法错误", e);
}
}
/**
* 添加系design文件进度统计
*
* @param key
* @param value
*/
@@ -355,6 +381,7 @@ public final class LocalCacheUtils {
/**
* 获取design文件进度统计
*
* @param key
* @return
*/
@@ -367,8 +394,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 进度统计完后 删除进度
*
* @param key
* @return
*/
@@ -382,6 +411,7 @@ public final class LocalCacheUtils {
/**
* 设置本次接口流量数
*
* @param key
* @param value
*/
@@ -391,6 +421,7 @@ public final class LocalCacheUtils {
/**
* 获取本次接口流量数
*
* @param key
* @return
*/

View File

@@ -58,6 +58,7 @@ public class MD5Utils {
}
return md5;
}
/**
* MD5加密文件
*

View File

@@ -37,6 +37,7 @@ import java.util.stream.Collectors;
public class MinioUtil {
@Autowired
private MinioClient minioClient;
/**
* description: 判断bucket是否存在不存在则创建
*
@@ -55,6 +56,7 @@ public class MinioUtil {
/**
* 创建存储bucket
*
* @param bucketName 存储bucket名称
* @return Boolean
*/
@@ -72,6 +74,7 @@ public class MinioUtil {
/**
* 删除存储bucket
*
* @param bucketName 存储bucket名称
* @return Boolean
*/
@@ -86,6 +89,7 @@ public class MinioUtil {
}
return true;
}
/**
* description: 上传文件
*
@@ -93,7 +97,6 @@ public class MinioUtil {
* @param path
* @param multipartFile
* @return: java.lang.String
*/
public List<String> uploadBatch(String bucketName, String path, MultipartFile[] multipartFile) {
List<String> names = new ArrayList<>(multipartFile.length);
@@ -138,7 +141,6 @@ public class MinioUtil {
* @param path
* @param file
* @return: java.lang.String
*/
public String upload(String bucketName, String path, MultipartFile file) {
String fileName = file.getOriginalFilename();
@@ -292,6 +294,7 @@ public class MinioUtil {
/**
* 查看文件对象
*
* @param bucketName 存储bucket名称
* @return 存储bucket内文件对象信息
*/
@@ -316,8 +319,9 @@ public class MinioUtil {
/**
* 批量删除文件对象
*
* @param bucketName 存储bucket名称
* @param objects 对象名称集合
* @param objects 对象名称集合
*/
public Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> objects) {
List<DeleteObject> dos = objects.stream().map(e -> new DeleteObject(e)).collect(Collectors.toList());
@@ -372,7 +376,7 @@ public class MinioUtil {
public String getPresignedUrl(String path, int expiry) {
if (LocalCacheUtils.getPresignedUrlCache(path) != null) {
return LocalCacheUtils.getPresignedUrlCache(path);
}else {
} else {
if (!path.contains("/")) {
throw new BusinessException("The path is error!");
}
@@ -387,21 +391,22 @@ public class MinioUtil {
/**
* 将桶名、文件名从url中分离出来
* @param url 带桶名、文件名的url
*
* @param url 带桶名、文件名的url
* @param expiry 图片过期时间
* @return 可以直接访问的minio图片地址
*/
public String splitThenGetPreviewUrl(String url,int expiry){
public String splitThenGetPreviewUrl(String url, int expiry) {
String[] parts = url.split("/");
String bucketName = parts[0];
StringBuilder fileName = new StringBuilder();
for (int i = 1; i < parts.length; i++){
for (int i = 1; i < parts.length; i++) {
fileName.append(parts[i]);
if (i != parts.length -1){
if (i != parts.length - 1) {
fileName.append("/");
}
}
return getPresignedUrl(bucketName, String.valueOf(fileName),expiry);
return getPresignedUrl(bucketName, String.valueOf(fileName), expiry);
}
public boolean doesObjectExist(String bucketName, String objectName) {

View File

@@ -45,24 +45,20 @@ public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
while ((line = reader.readLine()) != null) {
sb.append(line);
}
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
finally {
} finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
if (reader != null) {
try {
reader.close();
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -72,6 +68,7 @@ public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
/**
* 复制输入流
*
* @param inputStream 请求输入流
* @return 复制出来的输入流
*/
@@ -84,8 +81,7 @@ public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
byteArrayOutputStream.write(buffer, 0, len);
}
byteArrayOutputStream.flush();
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());

View File

@@ -1,4 +1,5 @@
package com.ai.da.common.utils;
import java.util.*;
import java.lang.reflect.Field;

View File

@@ -5,10 +5,10 @@ public class PantoneUtils {
public static int[] rgbToHsv(int[] rgb) {
//切割rgb数组
int red = rgb[0];
int green= rgb[1];
int green = rgb[1];
int blue = rgb[2];
float r = (float) red / 255;
float r = (float) red / 255;
float g = (float) green / 255;
float b = (float) blue / 255;
@@ -21,7 +21,7 @@ public class PantoneUtils {
hsv[0] = 60 * (
(hsv[2] == min) ? Float.NaN :
(hsv[2] == r) ? (g - b) / (hsv[2] - min) + ((g < b) ? 6 : 0) :
(hsv[2] == g) ? (b - r) / (hsv[2] - min) + 2:
(hsv[2] == g) ? (b - r) / (hsv[2] - min) + 2 :
(r - g) / (hsv[2] - min) + 4
);

View File

@@ -35,16 +35,17 @@ public class RandomsUtil {
* @param randomEnd
*/
public static String generateVerifyCode(Long randomStart, Long randomEnd) {
return String.valueOf(RandomUtil.randomLong(randomStart,randomEnd));
return String.valueOf(RandomUtil.randomLong(randomStart, randomEnd));
}
/**
* 生成随机系统图片
*
* @param randomStart 可以等于
* @param randomEnd 小于最大值
* @param randomEnd 小于最大值
*/
public static Long randomSysFile(Long randomStart, Long randomEnd) {
return RandomUtil.randomLong(randomStart,randomEnd);
return RandomUtil.randomLong(randomStart, randomEnd);
}

View File

@@ -13,36 +13,36 @@ import java.util.concurrent.TimeUnit;
**/
public final class RedisCacheUtils {
private static RedisTemplate<String, Object> getRedisTemplate(){
private static RedisTemplate<String, Object> getRedisTemplate() {
return SpringUtils.getBean("redisTemplate");
}
private static <T> RedisTemplate<String, T> getRedisTemplate(Class<T> clazz){
private static <T> RedisTemplate<String, T> getRedisTemplate(Class<T> clazz) {
return SpringUtils.getBean("redisTemplate");
}
private static <T> RedisTemplate<String, List<T>> getListRedisTemplate(Class<T> clazz){
private static <T> RedisTemplate<String, List<T>> getListRedisTemplate(Class<T> clazz) {
return SpringUtils.getBean("redisTemplate");
}
public static <T> T get(String key, Class<T> clazz){
public static <T> T get(String key, Class<T> clazz) {
return getRedisTemplate(clazz).opsForValue().get(key);
}
public static <T> List<T> getList(String key, Class<T> clazz){
public static <T> List<T> getList(String key, Class<T> clazz) {
return getListRedisTemplate(clazz).opsForValue().get(key);
}
public static void set(String key, Object value){
public static void set(String key, Object value) {
getRedisTemplate().opsForValue().set(key, value);
}
public static void set(String key, Object value, long time, TimeUnit unit){
public static void set(String key, Object value, long time, TimeUnit unit) {
getRedisTemplate().opsForValue().set(key, value, time, unit);
}
public static boolean delete(String key){
if(StrUtil.isNotEmpty(key)){
public static boolean delete(String key) {
if (StrUtil.isNotEmpty(key)) {
return Boolean.TRUE.equals(getRedisTemplate().delete(key));
}
return false;

View File

@@ -10,17 +10,16 @@ public class RequestInfoUtil {
* @param request
* @return java.lang.String
* @version 1.0
*
*
* <p>
* <p>
* 使用了ng等代理服务器要在ng加以下配置
* location / {
* proxy_pass http://127.0.0.1:10678;
* proxy_set_header Host $host;
* proxy_set_header X-Real-IP $remote_addr;
* proxy_set_header REMOTE-HOST $remote_addr;
* proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
* }
* proxy_pass http://127.0.0.1:10678;
* proxy_set_header Host $host;
* proxy_set_header X-Real-IP $remote_addr;
* proxy_set_header REMOTE-HOST $remote_addr;
* proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
* }
*/
public static String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");

View File

@@ -59,6 +59,7 @@ public class RsaDecryptUtils {
/**
* 解密
*
* @param args
* @throws NoSuchAlgorithmException
*/

View File

@@ -8,15 +8,15 @@ public class SecurityContextUtils {
public static AuthPrincipalVo getCurrentUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null && authentication.getPrincipal() != null){
return (AuthPrincipalVo) authentication.getPrincipal();
if (authentication != null && authentication.getPrincipal() != null) {
return (AuthPrincipalVo) authentication.getPrincipal();
}
return null;
}
public static Long getCurrentUserId() {
AuthPrincipalVo currentUser = getCurrentUser();
if(currentUser != null){
if (currentUser != null) {
return currentUser.getId();
}
return null;
@@ -24,7 +24,7 @@ public class SecurityContextUtils {
public static String getCurrentUsername() {
AuthPrincipalVo currentUser = getCurrentUser();
if(currentUser != null){
if (currentUser != null) {
return currentUser.getUsername();
}
return null;

View File

@@ -65,8 +65,8 @@ public class SendEmailUtil {
public static Long BIND_MAILBOX_TEMPLATE_ID = 45619L;
public static Boolean send(String receiverAddress,String ip,Long templateId,String verifyCode) {
try{
public static Boolean send(String receiverAddress, String ip, Long templateId, String verifyCode) {
try {
// 实例化一个认证对象入参需要传入腾讯云账户secretIdsecretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
@@ -85,30 +85,31 @@ public class SendEmailUtil {
req.setDestination(new String[]{receiverAddress});
String subject = templateId == LOGIN_TEMPLATE_ID ? LOGIN_SUBJECT :
templateId == UPDATE_PWD_TEMPLATE_ID ? FORGET_PWD_SUBJECT :
templateId == EXCEPTION_ID_TEMPLATE_ID ? EXCEPTION_ID_SUBJECT :BIND_MAILBOX_SUBJECT;
templateId == EXCEPTION_ID_TEMPLATE_ID ? EXCEPTION_ID_SUBJECT : BIND_MAILBOX_SUBJECT;
req.setSubject(subject);
req.setTemplate(contractTemplate(templateId, verifyCode,ip));
req.setTemplate(contractTemplate(templateId, verifyCode, ip));
// 返回的resp是一个SendEmailResponse的实例与请求对象对应
SendEmailResponse resp = client.SendEmail(req);
// 输出json格式的字符串回包
log.info("短信发送结果res###{}",SendEmailResponse.toJsonString(resp));
return Boolean.TRUE;
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
return Boolean.TRUE;
} catch (TencentCloudSDKException e) {
log.info("邮件发送失败###{}",e.toString());
log.info("邮件发送失败###{}", e.toString());
throw new BusinessException(e.getMessage());
}
}
private static Template contractTemplate(Long templateId,String verifyCode,String ip){
private static Template contractTemplate(Long templateId, String verifyCode, String ip) {
Template template = new Template();
template.setTemplateID(templateId);
JSONObject jsonObject = new JSONObject();
if(templateId == EXCEPTION_ID_TEMPLATE_ID ){
jsonObject.put("exceptionIp",ip);
jsonObject.put("loginTime",DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD_HH_MM_SS));
}else{
jsonObject.put("code",verifyCode);
if (templateId == EXCEPTION_ID_TEMPLATE_ID) {
jsonObject.put("exceptionIp", ip);
jsonObject.put("loginTime", DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD_HH_MM_SS));
} else {
jsonObject.put("code", verifyCode);
}
template.setTemplateData(jsonObject.toJSONString());
return template;

View File

@@ -27,18 +27,18 @@ public class SpringUtils implements ApplicationContextAware {
}
public static <T> T getBean(String beanName) {
if(applicationContext.containsBean(beanName)){
if (applicationContext.containsBean(beanName)) {
return (T) applicationContext.getBean(beanName);
}else{
} else {
return null;
}
}
public static <T> Map<String, T> getBeansOfType(Class<T> baseType){
public static <T> Map<String, T> getBeansOfType(Class<T> baseType) {
return applicationContext.getBeansOfType(baseType);
}
public static ApplicationContext getApplicationContext(){
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}