Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
314992b835
@ -7,6 +7,8 @@ package com.agileboot.common.constant;
|
||||
* @author valarchie
|
||||
*/
|
||||
public class Constants {
|
||||
private Constants() {
|
||||
}
|
||||
|
||||
public static final int KB = 1024;
|
||||
|
||||
@ -26,6 +28,10 @@ public class Constants {
|
||||
|
||||
|
||||
public static class Token {
|
||||
|
||||
private Token() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
@ -39,6 +45,10 @@ public class Constants {
|
||||
}
|
||||
|
||||
public static class Captcha {
|
||||
|
||||
private Captcha() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 令牌
|
||||
*/
|
||||
@ -58,6 +68,9 @@ public class Constants {
|
||||
|
||||
public static class UploadSubDir {
|
||||
|
||||
private UploadSubDir() {
|
||||
}
|
||||
|
||||
public static final String IMPORT_PATH = "import";
|
||||
|
||||
public static final String AVATAR_PATH = "avatar";
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
package com.agileboot.common.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
*
|
||||
@ -15,6 +16,9 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
*/
|
||||
public class ServletHolderUtil {
|
||||
|
||||
private ServletHolderUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取request
|
||||
*/
|
||||
|
||||
@ -13,15 +13,16 @@ import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Business;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Internal;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 文件上传工具类
|
||||
*
|
||||
@ -42,17 +43,20 @@ public class FileUploadUtils {
|
||||
/**
|
||||
* 允许上传和下载的文件类型
|
||||
*/
|
||||
public static final String[] ALLOWED_EXTENSIONS = {
|
||||
// 图片
|
||||
"bmp", "gif", "jpg", "jpeg", "png",
|
||||
// word excel powerpoint
|
||||
"doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
|
||||
// 压缩文件
|
||||
"rar", "zip", "gz", "bz2",
|
||||
// 视频格式
|
||||
"mp4", "avi", "rmvb",
|
||||
// pdf
|
||||
"pdf"};
|
||||
private static final String[] ALLOWED_EXTENSIONS = {
|
||||
// 图片
|
||||
"bmp", "gif", "jpg", "jpeg", "png",
|
||||
// word excel powerpoint
|
||||
"doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
|
||||
// 压缩文件
|
||||
"rar", "zip", "gz", "bz2",
|
||||
// 视频格式
|
||||
"mp4", "avi", "rmvb",
|
||||
// pdf
|
||||
"pdf"};
|
||||
|
||||
private FileUploadUtils() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -11,6 +11,9 @@ import org.springframework.context.i18n.LocaleContextHolder;
|
||||
*/
|
||||
public class MessageUtils {
|
||||
|
||||
private MessageUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息键和参数 获取消息 委托给spring messageSource
|
||||
*
|
||||
|
||||
@ -4,10 +4,14 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* IP地理位置工具类
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
public class IpRegionUtil {
|
||||
|
||||
private IpRegionUtil() {
|
||||
}
|
||||
|
||||
public static IpRegion getIpRegion(String ip) {
|
||||
if (StrUtil.isEmpty(ip)) {
|
||||
return new IpRegion();
|
||||
|
||||
@ -1,19 +1,23 @@
|
||||
package com.agileboot.common.utils.ip;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* ip校验器
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
public class IpUtil {
|
||||
|
||||
public final static String INNER_IP_REGEX = "^(127\\.0\\.0\\.\\d{1,3})|(localhost)|(10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(172\\.((1[6-9])|(2\\d)|(3[01]))\\.\\d{1,3}\\.\\d{1,3})|(192\\.168\\.\\d{1,3}\\.\\d{1,3})$";
|
||||
public static final String INNER_IP_REGEX = "^(127\\.0\\.0\\.\\d{1,3})|(localhost)|(10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(172\\.((1[6-9])|(2\\d)|(3[01]))\\.\\d{1,3}\\.\\d{1,3})|(192\\.168\\.\\d{1,3}\\.\\d{1,3})$";
|
||||
public static final Pattern INNER_IP_PATTERN = Pattern.compile(INNER_IP_REGEX);
|
||||
|
||||
public final static Pattern INNER_IP_PATTERN = Pattern.compile(INNER_IP_REGEX);
|
||||
private IpUtil() {
|
||||
}
|
||||
|
||||
public static boolean isInnerIp(String ip) {
|
||||
return INNER_IP_PATTERN.matcher(ip).matches() || isLocalHost(ip);
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.agileboot.common.utils.ip;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@ -15,6 +16,9 @@ public class OfflineIpRegionUtil {
|
||||
|
||||
private static Searcher searcher;
|
||||
|
||||
private OfflineIpRegionUtil() {
|
||||
}
|
||||
|
||||
static {
|
||||
InputStream resourceAsStream = OfflineIpRegionUtil.class.getResourceAsStream("/ip2region.xdb");
|
||||
|
||||
|
||||
@ -15,6 +15,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class OnlineIpRegionUtil {
|
||||
|
||||
private OnlineIpRegionUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* website for query geography address from ip
|
||||
*/
|
||||
@ -22,7 +25,7 @@ public class OnlineIpRegionUtil {
|
||||
|
||||
|
||||
public static IpRegion getIpRegion(String ip) {
|
||||
if(StrUtil.isBlank(ip) || IpUtil.isValidIpv6(ip) || !IpUtil.isValidIpv4(ip)) {
|
||||
if (StrUtil.isBlank(ip) || IpUtil.isValidIpv6(ip) || !IpUtil.isValidIpv4(ip)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -7,20 +7,24 @@ import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.annotation.ExcelSheet;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode.Internal;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 自定义Excel 导入导出工具
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
public class CustomExcelUtil {
|
||||
|
||||
private CustomExcelUtil() {
|
||||
}
|
||||
|
||||
public static <T> void writeToResponse(List<T> list, Class<T> clazz, HttpServletResponse response) {
|
||||
try {
|
||||
|
||||
@ -1,18 +1,23 @@
|
||||
package com.agileboot.common.utils.time;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import java.util.Date;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@Slf4j
|
||||
public class DatePickUtil {
|
||||
|
||||
private DatePickUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全地获取日期的一天开始时间, date为null 则返回null
|
||||
* DateUtil.beginOfDay(date) 如果传null 会NPE
|
||||
* DateUtil.beginOfDay(date) 如果传null 会NPE
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
|
||||
@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public class FileUploadUtilsTest {
|
||||
class FileUploadUtilsTest {
|
||||
|
||||
@Test
|
||||
void testIsAllowedExtension() {
|
||||
|
||||
@ -21,7 +21,7 @@ class IpRegionUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithIpv6() {
|
||||
void testGetIpRegionWithIpv6() {
|
||||
IpRegion ipRegion = IpRegionUtil.getIpRegion("2001:0DB8:0000:0023:0008:0800:200C:417A");
|
||||
|
||||
Assertions.assertNotNull(ipRegion);
|
||||
@ -30,7 +30,7 @@ class IpRegionUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithEmpty() {
|
||||
void testGetIpRegionWithEmpty() {
|
||||
IpRegion ipRegion = IpRegionUtil.getIpRegion("");
|
||||
|
||||
Assertions.assertNotNull(ipRegion);
|
||||
@ -39,7 +39,7 @@ class IpRegionUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithNull() {
|
||||
void testGetIpRegionWithNull() {
|
||||
IpRegion ipRegion = IpRegionUtil.getIpRegion(null);
|
||||
|
||||
Assertions.assertNotNull(ipRegion);
|
||||
@ -48,7 +48,7 @@ class IpRegionUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithWrongIpString() {
|
||||
void testGetIpRegionWithWrongIpString() {
|
||||
IpRegion ipRegion = IpRegionUtil.getIpRegion("xsdfwefsfsd");
|
||||
|
||||
Assertions.assertNotNull(ipRegion);
|
||||
|
||||
@ -4,49 +4,49 @@ package com.agileboot.common.utils.ip;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class OfflineIpRegionUtilTest {
|
||||
class OfflineIpRegionUtilTest {
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWhenIpv4() {
|
||||
IpRegion ipRegion = OfflineIpRegionUtil.getIpRegion("110.81.189.80");
|
||||
@Test
|
||||
void testGetIpRegionWhenIpv4() {
|
||||
IpRegion ipRegion = OfflineIpRegionUtil.getIpRegion("110.81.189.80");
|
||||
|
||||
Assertions.assertEquals("中国", ipRegion.getCountry());
|
||||
Assertions.assertEquals("福建省", ipRegion.getProvince());
|
||||
Assertions.assertEquals("泉州市", ipRegion.getCity());
|
||||
}
|
||||
Assertions.assertEquals("中国", ipRegion.getCountry());
|
||||
Assertions.assertEquals("福建省", ipRegion.getProvince());
|
||||
Assertions.assertEquals("泉州市", ipRegion.getCity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetIpRegionWithIpv6() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion("2001:0DB8:0000:0023:0008:0800:200C:417A")
|
||||
);
|
||||
@Test
|
||||
void testGetIpRegionWithIpv6() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion("2001:0DB8:0000:0023:0008:0800:200C:417A")
|
||||
);
|
||||
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithEmpty() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion("")
|
||||
);
|
||||
@Test
|
||||
void testGetIpRegionWithEmpty() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion("")
|
||||
);
|
||||
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithNull() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion(null)
|
||||
);
|
||||
@Test
|
||||
void testGetIpRegionWithNull() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion(null)
|
||||
);
|
||||
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIpRegionWithWrongIpString() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion("asfdsfdsff")
|
||||
);
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void testGetIpRegionWithWrongIpString() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OfflineIpRegionUtil.getIpRegion("asfdsfdsff")
|
||||
);
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,25 +5,25 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class OnlineIpRegionUtilTest {
|
||||
class OnlineIpRegionUtilTest {
|
||||
|
||||
@BeforeEach
|
||||
public void enableOnlineAddressQuery(){
|
||||
public void enableOnlineAddressQuery() {
|
||||
AgileBootConfig agileBootConfig = new AgileBootConfig();
|
||||
agileBootConfig.setAddressEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getIpRegionWithIpv6() {
|
||||
void getIpRegionWithIpv6() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OnlineIpRegionUtil.getIpRegion("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789")
|
||||
OnlineIpRegionUtil.getIpRegion("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789")
|
||||
);
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIpRegionWithIpv4() {
|
||||
void getIpRegionWithIpv4() {
|
||||
IpRegion ipRegion = OnlineIpRegionUtil.getIpRegion("120.42.247.130");
|
||||
|
||||
Assertions.assertEquals("福建省", ipRegion.getProvince());
|
||||
@ -31,9 +31,9 @@ public class OnlineIpRegionUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIpRegionWithEmpty() {
|
||||
void getIpRegionWithEmpty() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OnlineIpRegionUtil.getIpRegion("")
|
||||
OnlineIpRegionUtil.getIpRegion("")
|
||||
);
|
||||
|
||||
Assertions.assertNull(region);
|
||||
@ -41,18 +41,18 @@ public class OnlineIpRegionUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void getIpRegionWithNull() {
|
||||
void getIpRegionWithNull() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OnlineIpRegionUtil.getIpRegion(null)
|
||||
OnlineIpRegionUtil.getIpRegion(null)
|
||||
);
|
||||
|
||||
Assertions.assertNull(region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIpRegionWithWrongIpString() {
|
||||
void getIpRegionWithWrongIpString() {
|
||||
IpRegion region = Assertions.assertDoesNotThrow(() ->
|
||||
OnlineIpRegionUtil.getIpRegion("seffsdfsdf")
|
||||
OnlineIpRegionUtil.getIpRegion("seffsdfsdf")
|
||||
);
|
||||
|
||||
Assertions.assertNull(region);
|
||||
|
||||
@ -9,4 +9,6 @@ public class CacheNameConstants {
|
||||
|
||||
public static final String REDIS = "redis";
|
||||
|
||||
private CacheNameConstants() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,17 +4,10 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.agileboot.orm.common.annotations.Dictionary;
|
||||
import com.agileboot.orm.common.enums.BusinessTypeEnum;
|
||||
import com.agileboot.orm.common.enums.GenderEnum;
|
||||
import com.agileboot.orm.common.enums.LoginStatusEnum;
|
||||
import com.agileboot.orm.common.enums.NoticeStatusEnum;
|
||||
import com.agileboot.orm.common.enums.NoticeTypeEnum;
|
||||
import com.agileboot.orm.common.enums.OperationStatusEnum;
|
||||
import com.agileboot.orm.common.enums.StatusEnum;
|
||||
import com.agileboot.orm.common.enums.VisibleStatusEnum;
|
||||
import com.agileboot.orm.common.enums.YesOrNoEnum;
|
||||
import com.agileboot.orm.common.enums.*;
|
||||
import com.agileboot.orm.common.interfaces.DictionaryEnum;
|
||||
import com.agileboot.orm.common.result.DictionaryData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -30,6 +23,9 @@ public class MapCache {
|
||||
|
||||
private static final Map<String, List<DictionaryData>> DICTIONARY_CACHE = MapUtil.newHashMap(128);
|
||||
|
||||
private MapCache() {
|
||||
}
|
||||
|
||||
static {
|
||||
initDictionaryCache();
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.agileboot.infrastructure.filter.TestFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
@ -32,7 +33,7 @@ public class FilterConfig {
|
||||
registration.setFilter(new GlobalExceptionFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("exceptionFilter");
|
||||
registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
|
||||
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
return registration;
|
||||
}
|
||||
|
||||
|
||||
@ -2,16 +2,21 @@ package com.agileboot.infrastructure.mybatisplus;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 由于H2不支持大部分Mysql的函数 所以要自己实现
|
||||
* 在H2的初始化 h2sql/agileboot_schema.sql加上这句
|
||||
* CREATE ALIAS FIND_IN_SET FOR "com.agileboot.infrastructure.mybatisplus.MySqlFunction.find_in_set";
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
public class MySqlFunction {
|
||||
|
||||
private MySqlFunction() {
|
||||
}
|
||||
|
||||
public static boolean findInSet(String target, String setString) {
|
||||
if (setString == null) {
|
||||
return false;
|
||||
|
||||
@ -21,13 +21,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class AsyncTaskFactory {
|
||||
|
||||
private AsyncTaskFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param username 用户名
|
||||
* @param loginStatusEnum 状态
|
||||
* @param message 消息
|
||||
* @param message 消息
|
||||
* @return 任务task
|
||||
*/
|
||||
public static Runnable loginInfoTask(final String username, final LoginStatusEnum loginStatusEnum, final String message) {
|
||||
|
||||
@ -16,6 +16,8 @@ public class ThreadConfig {
|
||||
/**
|
||||
* 操作延迟10毫秒
|
||||
*/
|
||||
public final static int OPERATE_DELAY_TIME = 10;
|
||||
public static final int OPERATE_DELAY_TIME = 10;
|
||||
|
||||
private ThreadConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,11 @@
|
||||
package com.agileboot.infrastructure.thread;
|
||||
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 异步任务管理器
|
||||
*
|
||||
@ -21,14 +15,13 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
public class ThreadPoolManager {
|
||||
|
||||
private static final ThreadPoolExecutor THREAD_EXECUTOR = new ThreadPoolExecutor(
|
||||
ThreadConfig.CORE_POOL_SIZE, ThreadConfig.MAX_POOL_SIZE,
|
||||
ThreadConfig.KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(), new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
|
||||
ThreadConfig.CORE_POOL_SIZE, ThreadConfig.MAX_POOL_SIZE,
|
||||
ThreadConfig.KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(), new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
private static final ScheduledExecutorService SCHEDULED_EXECUTOR = new ScheduledThreadPoolExecutor(
|
||||
ThreadConfig.CORE_POOL_SIZE,
|
||||
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||
ThreadConfig.CORE_POOL_SIZE,
|
||||
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||
@Override
|
||||
protected void afterExecute(Runnable r, Throwable t) {
|
||||
if (t == null && r instanceof Future<?>) {
|
||||
@ -51,6 +44,9 @@ public class ThreadPoolManager {
|
||||
}
|
||||
};
|
||||
|
||||
private ThreadPoolManager() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行schedule任务
|
||||
|
||||
@ -13,16 +13,17 @@ import com.agileboot.orm.common.enums.OperationStatusEnum;
|
||||
import com.agileboot.orm.common.enums.RequestMethodEnum;
|
||||
import com.agileboot.orm.common.util.BasicEnumUtil;
|
||||
import com.agileboot.orm.system.entity.SysOperationLogEntity;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
*/
|
||||
@ -31,10 +32,11 @@ public class OperationLogModel extends SysOperationLogEntity {
|
||||
|
||||
public static final int MAX_DATA_LENGTH = 512;
|
||||
|
||||
HttpServletRequest request = ServletHolderUtil.getRequest();
|
||||
|
||||
public void fillOperatorInfo() {
|
||||
// 获取当前的用户
|
||||
String ip = ServletUtil.getClientIP(ServletHolderUtil.getRequest());
|
||||
String ip = ServletUtil.getClientIP(request);
|
||||
setOperatorIp(ip);
|
||||
LoginUser loginUser = AuthenticationUtils.getLoginUser();
|
||||
if (loginUser != null) {
|
||||
@ -46,7 +48,7 @@ public class OperationLogModel extends SysOperationLogEntity {
|
||||
|
||||
|
||||
public void fillRequestInfo(final JoinPoint joinPoint, AccessLog accessLog, Object jsonResult) {
|
||||
this.setRequestUrl(ServletHolderUtil.getRequest().getRequestURI());
|
||||
this.setRequestUrl(request.getRequestURI());
|
||||
// 设置方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
@ -54,7 +56,7 @@ public class OperationLogModel extends SysOperationLogEntity {
|
||||
this.setCalledMethod(methodFormat);
|
||||
// 设置请求方式
|
||||
RequestMethodEnum requestMethodEnum = EnumUtil.fromString(RequestMethodEnum.class,
|
||||
ServletHolderUtil.getRequest().getMethod());
|
||||
request.getMethod());
|
||||
this.setRequestMethod(requestMethodEnum != null ? requestMethodEnum.getValue() : RequestMethodEnum.UNKNOWN.getValue());
|
||||
|
||||
|
||||
@ -103,8 +105,8 @@ public class OperationLogModel extends SysOperationLogEntity {
|
||||
String params = argsArrayToString(joinPoint.getArgs());
|
||||
this.setOperationParam(StrUtil.sub(params, 0, MAX_DATA_LENGTH));
|
||||
} else {
|
||||
Map<?, ?> paramsMap = (Map<?, ?>) ServletHolderUtil.getRequest()
|
||||
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
||||
Map<?, ?> paramsMap = (Map<?, ?>) request
|
||||
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
||||
this.setOperationParam(StrUtil.sub(paramsMap.toString(), 0, MAX_DATA_LENGTH));
|
||||
}
|
||||
}
|
||||
@ -114,7 +116,7 @@ public class OperationLogModel extends SysOperationLogEntity {
|
||||
*/
|
||||
private String argsArrayToString(Object[] paramsArray) {
|
||||
StringBuilder params = new StringBuilder();
|
||||
if (paramsArray != null && paramsArray.length > 0) {
|
||||
if (paramsArray != null) {
|
||||
for (Object o : paramsArray) {
|
||||
if (o != null && !isCanNotBeParseToJson(o)) {
|
||||
try {
|
||||
|
||||
@ -12,4 +12,6 @@ public class RateLimitKey {
|
||||
|
||||
public static final String TEST_KEY = PREFIX + "Test:";
|
||||
|
||||
private RateLimitKey() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
package com.agileboot.infrastructure.annotations;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.agileboot.infrastructure.annotations.RateLimit.LimitType;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RateLimitTypeTest {
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class RateLimitTypeTest {
|
||||
|
||||
@Test
|
||||
public void testCombinedKey() {
|
||||
void testCombinedKey() {
|
||||
RateLimit mockLimit = mock(RateLimit.class);
|
||||
when(mockLimit.key()).thenReturn("Test");
|
||||
|
||||
|
||||
@ -13,4 +13,6 @@ public class CssTag {
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String INFO = "info";
|
||||
|
||||
private CssTag() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.orm.common.interfaces.BasicEnum;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -11,6 +12,9 @@ import java.util.Objects;
|
||||
*/
|
||||
public class BasicEnumUtil {
|
||||
|
||||
private BasicEnumUtil() {
|
||||
}
|
||||
|
||||
public static final String UNKNOWN = "未知";
|
||||
|
||||
public static <E extends Enum<E>> E fromValueSafely(Class<E> enumClass, Object value) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user