mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-06-09 10:23:53 +08:00
代码优化
This commit is contained in:
@@ -66,8 +66,6 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Configuration
|
||||
@@ -466,11 +464,9 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer {
|
||||
@Bean
|
||||
public MagicConfiguration magicConfiguration(List<MagicModule> magicModules,
|
||||
List<LanguageProvider> languageProviders,
|
||||
@Autowired(required = false) MagicDynamicDataSource magicDynamicDataSource,
|
||||
Resource magicResource,
|
||||
ResultProvider resultProvider,
|
||||
MagicAPIService magicAPIService,
|
||||
MagicNotifyService magicNotifyService,
|
||||
ApiServiceProvider apiServiceProvider,
|
||||
GroupServiceProvider groupServiceProvider,
|
||||
MappingHandlerMapping mappingHandlerMapping,
|
||||
@@ -491,16 +487,12 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer {
|
||||
configuration.setApiServiceProvider(apiServiceProvider);
|
||||
configuration.setGroupServiceProvider(groupServiceProvider);
|
||||
configuration.setMappingHandlerMapping(mappingHandlerMapping);
|
||||
configuration.setMagicNotifyService(magicNotifyService);
|
||||
configuration.setFunctionServiceProvider(functionServiceProvider);
|
||||
SecurityConfig securityConfig = properties.getSecurityConfig();
|
||||
configuration.setUsername(securityConfig.getUsername());
|
||||
configuration.setPassword(securityConfig.getPassword());
|
||||
configuration.setDebugTimeout(properties.getDebugConfig().getTimeout());
|
||||
configuration.setHttpMessageConverters(Optional.ofNullable(httpMessageConverters).orElse(Collections.emptyList()));
|
||||
configuration.setResultProvider(resultProvider);
|
||||
configuration.setThrowException(properties.isThrowException());
|
||||
configuration.setMagicDynamicDataSource(magicDynamicDataSource);
|
||||
configuration.setEditorConfig(properties.getEditorConfig());
|
||||
configuration.setWorkspace(magicResource);
|
||||
configuration.setAuthorizationInterceptor(authorizationInterceptor);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class MagicSwaggerConfiguration {
|
||||
|
||||
private final MagicAPIProperties properties;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public MagicSwaggerConfiguration(MagicAPIProperties properties,ApplicationContext applicationContext) {
|
||||
this.properties = properties;
|
||||
@@ -69,11 +69,9 @@ public class MagicSwaggerConfiguration {
|
||||
List<SwaggerResource> resources = new ArrayList<>();
|
||||
Map<String, SwaggerResourcesProvider> beans = applicationContext.getBeansOfType(SwaggerResourcesProvider.class);
|
||||
// 获取已定义的文档信息
|
||||
if (beans != null) {
|
||||
for (Map.Entry<String, SwaggerResourcesProvider> entry : beans.entrySet()) {
|
||||
if (!"magicSwaggerResourcesProvider".equalsIgnoreCase(entry.getKey())) {
|
||||
resources.addAll(entry.getValue().get());
|
||||
}
|
||||
for (Map.Entry<String, SwaggerResourcesProvider> entry : beans.entrySet()) {
|
||||
if (!"magicSwaggerResourcesProvider".equalsIgnoreCase(entry.getKey())) {
|
||||
resources.addAll(entry.getValue().get());
|
||||
}
|
||||
}
|
||||
// 追加Magic Swagger信息
|
||||
@@ -87,7 +85,6 @@ public class MagicSwaggerConfiguration {
|
||||
*
|
||||
* @param name 名字
|
||||
* @param location 位置
|
||||
* @return
|
||||
*/
|
||||
private SwaggerResource swaggerResource(String name, String location) {
|
||||
SwaggerResource resource = new SwaggerResource();
|
||||
|
||||
@@ -24,14 +24,6 @@ public class MagicConfiguration {
|
||||
* 函数管理
|
||||
*/
|
||||
private MagicFunctionManager magicFunctionManager;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 编辑器配置文件
|
||||
*/
|
||||
@@ -51,11 +43,6 @@ public class MagicConfiguration {
|
||||
*/
|
||||
private FunctionServiceProvider functionServiceProvider;
|
||||
|
||||
/**
|
||||
* 动态数据源
|
||||
*/
|
||||
private MagicDynamicDataSource magicDynamicDataSource;
|
||||
|
||||
private MagicAPIService magicAPIService;
|
||||
|
||||
/**
|
||||
@@ -74,8 +61,6 @@ public class MagicConfiguration {
|
||||
|
||||
private AuthorizationInterceptor authorizationInterceptor;
|
||||
|
||||
private MagicNotifyService magicNotifyService;
|
||||
|
||||
/**
|
||||
* debug 超时时间
|
||||
*/
|
||||
@@ -95,22 +80,6 @@ public class MagicConfiguration {
|
||||
this.mappingHandlerMapping = mappingHandlerMapping;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public AuthorizationInterceptor getAuthorizationInterceptor() {
|
||||
return authorizationInterceptor;
|
||||
}
|
||||
@@ -139,14 +108,6 @@ public class MagicConfiguration {
|
||||
this.groupServiceProvider = groupServiceProvider;
|
||||
}
|
||||
|
||||
public MagicDynamicDataSource getMagicDynamicDataSource() {
|
||||
return magicDynamicDataSource;
|
||||
}
|
||||
|
||||
public void setMagicDynamicDataSource(MagicDynamicDataSource magicDynamicDataSource) {
|
||||
this.magicDynamicDataSource = magicDynamicDataSource;
|
||||
}
|
||||
|
||||
public boolean isThrowException() {
|
||||
return throwException;
|
||||
}
|
||||
@@ -227,13 +188,6 @@ public class MagicConfiguration {
|
||||
this.magicAPIService = magicAPIService;
|
||||
}
|
||||
|
||||
public MagicNotifyService getMagicNotifyService() {
|
||||
return magicNotifyService;
|
||||
}
|
||||
|
||||
public void setMagicNotifyService(MagicNotifyService magicNotifyService) {
|
||||
this.magicNotifyService = magicNotifyService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印banner
|
||||
|
||||
@@ -22,9 +22,9 @@ public class MagicCorsFilter implements Filter {
|
||||
}
|
||||
|
||||
public void process(HttpServletRequest request, HttpServletResponse response) {
|
||||
String value = request.getHeader("Origin");
|
||||
String value = request.getHeader(HttpHeaders.ORIGIN);
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, StringUtils.isBlank(value) ? "*" : value);
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, Constants.CONST_STRING_TRUE);
|
||||
value = request.getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, value);
|
||||
|
||||
@@ -21,9 +21,9 @@ import java.util.stream.Collectors;
|
||||
public class MagicFunctionManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MagicFunctionManager.class);
|
||||
private static Map<String, FunctionInfo> mappings = new ConcurrentHashMap<>();
|
||||
private GroupServiceProvider groupServiceProvider;
|
||||
private FunctionServiceProvider functionServiceProvider;
|
||||
private static final Map<String, FunctionInfo> mappings = new ConcurrentHashMap<>();
|
||||
private final GroupServiceProvider groupServiceProvider;
|
||||
private final FunctionServiceProvider functionServiceProvider;
|
||||
private TreeNode<Group> groups;
|
||||
|
||||
public MagicFunctionManager(GroupServiceProvider groupServiceProvider, FunctionServiceProvider functionServiceProvider) {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class MagicWebRequestInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final MagicCorsFilter magicCorsFilter;
|
||||
|
||||
private AuthorizationInterceptor authorizationInterceptor;
|
||||
private final AuthorizationInterceptor authorizationInterceptor;
|
||||
|
||||
public MagicWebRequestInterceptor(MagicCorsFilter magicCorsFilter, AuthorizationInterceptor authorizationInterceptor) {
|
||||
this.magicCorsFilter = magicCorsFilter;
|
||||
|
||||
@@ -9,12 +9,12 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class LoggerManager {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(LoggerManager.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoggerManager.class);
|
||||
|
||||
/**
|
||||
* 创建一个新的appender至项目中,用于UI界面
|
||||
*/
|
||||
public static MagicLoggerContext createMagicAppender() {
|
||||
public static void createMagicAppender() {
|
||||
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
|
||||
String loggerFactoryClassName = loggerFactory.getClass().getName();
|
||||
MagicLoggerContext magicLoggerContext = null;
|
||||
@@ -30,6 +30,5 @@ public class LoggerManager {
|
||||
} else {
|
||||
magicLoggerContext.generateAppender();
|
||||
}
|
||||
return magicLoggerContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ public class BoundSql {
|
||||
/**
|
||||
* 获取缓存值
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
private <T> T getCacheValue(String sql, Object[] params, Supplier<T> supplier) {
|
||||
if (cacheName == null) {
|
||||
return supplier.get();
|
||||
|
||||
@@ -417,7 +417,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
|
||||
return "db";
|
||||
}
|
||||
|
||||
class MagicKeyHolder extends GeneratedKeyHolder {
|
||||
static class MagicKeyHolder extends GeneratedKeyHolder {
|
||||
|
||||
private final boolean useGeneratedKeys;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public abstract class StoreServiceProvider<T extends MagicEntity> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(StoreServiceProvider.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(StoreServiceProvider.class);
|
||||
protected Resource workspace;
|
||||
protected Resource backupResource;
|
||||
protected Map<String, Resource> mappings = new HashMap<>();
|
||||
|
||||
@@ -7,9 +7,9 @@ import javax.script.ScriptException;
|
||||
|
||||
public class UnCompileScript extends CompiledScript {
|
||||
|
||||
private ScriptEngine engine;
|
||||
private final ScriptEngine engine;
|
||||
|
||||
private String script;
|
||||
private final String script;
|
||||
|
||||
public UnCompileScript(String script, ScriptEngine engine) {
|
||||
this.script = script;
|
||||
|
||||
@@ -13,9 +13,9 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class IoUtils {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(IoUtils.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(IoUtils.class);
|
||||
|
||||
private static Pattern FILE_NAME_PATTERN = Pattern.compile("^[\\u4e00-\\u9fa5_a-zA-Z0-9]+$");
|
||||
private static final Pattern FILE_NAME_PATTERN = Pattern.compile("^[\\u4e00-\\u9fa5_a-zA-Z0-9]+$");
|
||||
|
||||
public static boolean validateFileName(String name) {
|
||||
return FILE_NAME_PATTERN.matcher(name).matches();
|
||||
@@ -73,7 +73,7 @@ public class IoUtils {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[4096];
|
||||
int len = -1;
|
||||
int len;
|
||||
while ((len = inputStream.read(buf, 0, buf.length)) != -1) {
|
||||
baos.write(buf, 0, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user