Commit 87537983 by inrgihc

代码结构优化

parent 42d12ad7
...@@ -9,6 +9,8 @@ spring: ...@@ -9,6 +9,8 @@ spring:
allow-bean-definition-overriding: false allow-bean-definition-overriding: false
sqlrest: sqlrest:
executor:
print-sql-log: false
cache: cache:
hazelcast: hazelcast:
enabled: true enabled: true
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// Date : 2024/3/31 // Date : 2024/3/31
// Location: beijing , china // Location: beijing , china
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.filter; package org.dromara.sqlrest.common.service;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
......
package org.dromara.sqlrest.common.service;
public interface VarModuleInterface {
String getVarModuleName();
}
// Copyright tang. All rights reserved.
// https://gitee.com/inrgihc/sqlrest
//
// Use of this source code is governed by a BSD-style license
//
// Author: tang (inrgihc@126.com)
// Date : 2024/3/31
// Location: beijing , china
/////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.exec;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
public class ApiAssignmentCache {
private static final ThreadLocal<ApiAssignmentEntity> THREAD_LOCAL = new ThreadLocal<>();
public static void set(ApiAssignmentEntity entity) {
THREAD_LOCAL.set(entity);
}
public static ApiAssignmentEntity get() {
return THREAD_LOCAL.get();
}
public static void remove() {
THREAD_LOCAL.remove();
}
}
...@@ -10,6 +10,26 @@ ...@@ -10,6 +10,26 @@
package org.dromara.sqlrest.core.exec; package org.dromara.sqlrest.core.exec;
import cn.hutool.crypto.digest.DigestUtil; import cn.hutool.crypto.digest.DigestUtil;
import com.google.common.collect.Lists;
import com.zaxxer.hikari.HikariDataSource;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.dromara.sqlrest.cache.CacheFactory; import org.dromara.sqlrest.cache.CacheFactory;
import org.dromara.sqlrest.cache.DistributedCache; import org.dromara.sqlrest.cache.DistributedCache;
import org.dromara.sqlrest.common.consts.Constants; import org.dromara.sqlrest.common.consts.Constants;
...@@ -31,26 +51,6 @@ import org.dromara.sqlrest.persistence.dao.DataSourceDao; ...@@ -31,26 +51,6 @@ import org.dromara.sqlrest.persistence.dao.DataSourceDao;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity; import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
import org.dromara.sqlrest.persistence.entity.DataSourceEntity; import org.dromara.sqlrest.persistence.entity.DataSourceEntity;
import org.dromara.sqlrest.persistence.util.JsonUtils; import org.dromara.sqlrest.persistence.util.JsonUtils;
import com.google.common.collect.Lists;
import com.zaxxer.hikari.HikariDataSource;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -78,7 +78,7 @@ public class ApiExecuteService { ...@@ -78,7 +78,7 @@ public class ApiExecuteService {
return Constants.getResourceName(config.getMethod().name(), config.getPath()) + ":" + key; return Constants.getResourceName(config.getMethod().name(), config.getPath()) + ":" + key;
} }
public ResultEntity<Object> execute(ApiAssignmentEntity config, HttpServletRequest request) { public ResultEntity<Object> execute(ApiAssignmentEntity config, HttpServletRequest request, boolean printSqlLog) {
String resourceName = Constants.getResourceName(config.getMethod().name(), config.getPath()); String resourceName = Constants.getResourceName(config.getMethod().name(), config.getPath());
try { try {
List<ItemParam> invalidArgs = new ArrayList<>(); List<ItemParam> invalidArgs = new ArrayList<>();
...@@ -87,20 +87,21 @@ public class ApiExecuteService { ...@@ -87,20 +87,21 @@ public class ApiExecuteService {
if (invalidArgs.size() > 0) { if (invalidArgs.size() > 0) {
throw new CommonException(ResponseErrorCode.ERROR_INVALID_ARGUMENT, convertInvalidArgs(invalidArgs)); throw new CommonException(ResponseErrorCode.ERROR_INVALID_ARGUMENT, convertInvalidArgs(invalidArgs));
} }
return execute(config, paramValues); return execute(config, paramValues, printSqlLog);
} catch (IOException e) { } catch (IOException e) {
log.warn("Failed read input body parameters for {}, error:{}", resourceName, e.getMessage()); log.warn("Failed read input body parameters for {}, error:{}", resourceName, e.getMessage());
throw new CommonException(ResponseErrorCode.ERROR_INTERNAL_ERROR, e); throw new CommonException(ResponseErrorCode.ERROR_INTERNAL_ERROR, e);
} }
} }
public ResultEntity<Object> execute(ApiAssignmentEntity config, Map<String, Object> paramValues) { public ResultEntity<Object> execute(ApiAssignmentEntity config, Map<String, Object> paramValues,
boolean printSqlLog) {
if (config.getCacheKeyType().isUseCache()) { if (config.getCacheKeyType().isUseCache()) {
String key = getCacheKeyValue(config, paramValues); String key = getCacheKeyValue(config, paramValues);
DistributedCache cache = getDistributedCache(); DistributedCache cache = getDistributedCache();
ResultEntity result = cache.get(key, ResultEntity.class); ResultEntity result = cache.get(key, ResultEntity.class);
if (null == result) { if (null == result) {
result = doExecute(getDataSourceEntity(config), config, paramValues); result = doExecute(getDataSourceEntity(config), config, paramValues, printSqlLog);
cache.put(key, result, config.getCacheExpireSeconds(), TimeUnit.SECONDS); cache.put(key, result, config.getCacheExpireSeconds(), TimeUnit.SECONDS);
} else { } else {
String resourceName = Constants.getResourceName(config.getMethod().name(), config.getPath()); String resourceName = Constants.getResourceName(config.getMethod().name(), config.getPath());
...@@ -108,7 +109,7 @@ public class ApiExecuteService { ...@@ -108,7 +109,7 @@ public class ApiExecuteService {
} }
return result; return result;
} else { } else {
return doExecute(getDataSourceEntity(config), config, paramValues); return doExecute(getDataSourceEntity(config), config, paramValues, printSqlLog);
} }
} }
...@@ -123,11 +124,11 @@ public class ApiExecuteService { ...@@ -123,11 +124,11 @@ public class ApiExecuteService {
} }
private ResultEntity doExecute(DataSourceEntity dsEntity, ApiAssignmentEntity config, private ResultEntity doExecute(DataSourceEntity dsEntity, ApiAssignmentEntity config,
Map<String, Object> paramValues) { Map<String, Object> paramValues, boolean printSqlLog) {
File driverPath = driverLoadService.getVersionDriverFile(dsEntity.getType(), dsEntity.getVersion()); File driverPath = driverLoadService.getVersionDriverFile(dsEntity.getType(), dsEntity.getVersion());
HikariDataSource dataSource = DataSourceUtils.getHikariDataSource(dsEntity, driverPath.getAbsolutePath()); HikariDataSource dataSource = DataSourceUtils.getHikariDataSource(dsEntity, driverPath.getAbsolutePath());
List<Object> results = ApiExecutorEngineFactory List<Object> results = ApiExecutorEngineFactory
.getExecutor(config.getEngine(), dataSource, dsEntity.getType()) .getExecutor(config.getEngine(), dataSource, dsEntity.getType(), printSqlLog)
.execute(config.getContextList(), paramValues, config.getNamingStrategy()); .execute(config.getContextList(), paramValues, config.getNamingStrategy());
return ResultEntity.success(results.size() > 1 ? results : results.stream().findAny().orElse(null)); return ResultEntity.success(results.size() > 1 ? results : results.stream().findAny().orElse(null));
} }
......
...@@ -9,16 +9,23 @@ ...@@ -9,16 +9,23 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.exec.engine; package org.dromara.sqlrest.core.exec.engine;
import org.dromara.sqlrest.common.enums.ProductTypeEnum;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import org.dromara.sqlrest.common.enums.ProductTypeEnum;
public abstract class AbstractExecutorEngine implements ApiExecutorEngine { public abstract class AbstractExecutorEngine implements ApiExecutorEngine {
protected HikariDataSource dataSource; protected HikariDataSource dataSource;
protected ProductTypeEnum productType; protected ProductTypeEnum productType;
protected boolean printSqlLog;
public AbstractExecutorEngine(HikariDataSource dataSource, ProductTypeEnum productType) { public AbstractExecutorEngine(HikariDataSource dataSource, ProductTypeEnum productType) {
this.dataSource = dataSource; this.dataSource = dataSource;
this.productType = productType; this.productType = productType;
this.printSqlLog = true;
}
@Override
public void setPrintSqlLog(boolean printSqlLog) {
this.printSqlLog = printSqlLog;
} }
} }
...@@ -16,5 +16,7 @@ import java.util.Map; ...@@ -16,5 +16,7 @@ import java.util.Map;
public interface ApiExecutorEngine { public interface ApiExecutorEngine {
void setPrintSqlLog(boolean printSqlLog);
List<Object> execute(List<ApiContextEntity> scripts, Map<String, Object> params, NamingStrategyEnum strategy); List<Object> execute(List<ApiContextEntity> scripts, Map<String, Object> params, NamingStrategyEnum strategy);
} }
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.exec.engine; package org.dromara.sqlrest.core.exec.engine;
import org.dromara.sqlrest.common.enums.ExecuteEngineEnum;
import org.dromara.sqlrest.common.enums.ProductTypeEnum;
import org.dromara.sqlrest.core.exec.engine.impl.ScriptExecutorService;
import org.dromara.sqlrest.core.exec.engine.impl.SqlExecutorService;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import org.dromara.sqlrest.common.enums.ExecuteEngineEnum;
import org.dromara.sqlrest.common.enums.ProductTypeEnum;
import org.dromara.sqlrest.core.exec.engine.impl.ScriptExecutorService;
import org.dromara.sqlrest.core.exec.engine.impl.SqlExecutorService;
public class ApiExecutorEngineFactory { public class ApiExecutorEngineFactory {
...@@ -28,12 +28,14 @@ public class ApiExecutorEngineFactory { ...@@ -28,12 +28,14 @@ public class ApiExecutorEngineFactory {
} }
public static ApiExecutorEngine getExecutor(ExecuteEngineEnum engine, HikariDataSource dataSource, public static ApiExecutorEngine getExecutor(ExecuteEngineEnum engine, HikariDataSource dataSource,
ProductTypeEnum productType) { ProductTypeEnum productType, boolean printSqlLog) {
BiFunction<HikariDataSource, ProductTypeEnum, ApiExecutorEngine> creator = engineMap.get(engine); BiFunction<HikariDataSource, ProductTypeEnum, ApiExecutorEngine> creator = engineMap.get(engine);
if (null == creator) { if (null == creator) {
throw new RuntimeException("Unsupported engine :" + engine); throw new RuntimeException("Unsupported engine :" + engine);
} }
return creator.apply(dataSource, productType); ApiExecutorEngine executorEngine = creator.apply(dataSource, productType);
executorEngine.setPrintSqlLog(printSqlLog);
return executorEngine;
} }
} }
...@@ -20,6 +20,7 @@ import java.util.Map; ...@@ -20,6 +20,7 @@ import java.util.Map;
import org.codehaus.groovy.control.CompilationFailedException; import org.codehaus.groovy.control.CompilationFailedException;
import org.dromara.sqlrest.common.enums.NamingStrategyEnum; import org.dromara.sqlrest.common.enums.NamingStrategyEnum;
import org.dromara.sqlrest.common.enums.ProductTypeEnum; import org.dromara.sqlrest.common.enums.ProductTypeEnum;
import org.dromara.sqlrest.common.service.VarModuleInterface;
import org.dromara.sqlrest.core.dto.ScriptEditorCompletion; import org.dromara.sqlrest.core.dto.ScriptEditorCompletion;
import org.dromara.sqlrest.core.exec.annotation.Module; import org.dromara.sqlrest.core.exec.annotation.Module;
import org.dromara.sqlrest.core.exec.engine.AbstractExecutorEngine; import org.dromara.sqlrest.core.exec.engine.AbstractExecutorEngine;
...@@ -91,10 +92,6 @@ public class ScriptExecutorService extends AbstractExecutorEngine { ...@@ -91,10 +92,6 @@ public class ScriptExecutorService extends AbstractExecutorEngine {
.build()); .build());
} }
public ScriptExecutorService(HikariDataSource dataSource, ProductTypeEnum productType) {
super(dataSource, productType);
}
public static String getModuleVarName(Class clazz) { public static String getModuleVarName(Class clazz) {
if (clazz.isAnnotationPresent(Module.class)) { if (clazz.isAnnotationPresent(Module.class)) {
Module annotation = (Module) clazz.getAnnotation(Module.class); Module annotation = (Module) clazz.getAnnotation(Module.class);
...@@ -103,23 +100,34 @@ public class ScriptExecutorService extends AbstractExecutorEngine { ...@@ -103,23 +100,34 @@ public class ScriptExecutorService extends AbstractExecutorEngine {
return "unknown"; return "unknown";
} }
////////////////////////////////////////////////////////////////////////////////////////
public ScriptExecutorService(HikariDataSource dataSource, ProductTypeEnum productType) {
super(dataSource, productType);
}
private String getModuleVarName(VarModuleInterface varModule) {
return varModule.getVarModuleName();
}
private List<VarModuleInterface> getAllVarModules(Map<String, Object> params, NamingStrategyEnum strategy) {
List<VarModuleInterface> moduleList = new ArrayList<>();
moduleList.addAll(SpringUtil.getBeansOfType(VarModuleInterface.class).values());
moduleList.add(new ReqVarModule(params));
moduleList.add(new DsVarModule(params, strategy, printSqlLog));
moduleList.add(new DbVarModule(dataSource, productType, params, strategy, printSqlLog));
return moduleList;
}
@Override @Override
public List<Object> execute(List<ApiContextEntity> scripts, Map<String, Object> params, NamingStrategyEnum strategy) { public List<Object> execute(List<ApiContextEntity> scripts, Map<String, Object> params, NamingStrategyEnum strategy) {
EnvVarModule envModule = SpringUtil.getBean(EnvVarModule.class); List<VarModuleInterface> varModuleList = getAllVarModules(params, strategy);
CacheVarModule cacheModule = SpringUtil.getBean(CacheVarModule.class);
ReqVarModule reqVarModule = new ReqVarModule(params);
DbVarModule dbModule = new DbVarModule(dataSource, productType, params, strategy);
DsVarModule dsVarModule = new DsVarModule(productType, params, strategy);
List<Object> results = new ArrayList<>(); List<Object> results = new ArrayList<>();
for (ApiContextEntity entity : scripts) { for (ApiContextEntity entity : scripts) {
Binding binding = new Binding(); Binding binding = new Binding();
params.forEach((k, v) -> binding.setProperty(k, v)); params.forEach((k, v) -> binding.setProperty(k, v));
binding.setProperty(getModuleVarName(dbModule.getClass()), dbModule); varModuleList.forEach(m -> binding.setProperty(getModuleVarName(m), m));
binding.setProperty(getModuleVarName(dsVarModule.getClass()), dsVarModule);
binding.setProperty(getModuleVarName(reqVarModule.getClass()), reqVarModule);
binding.setProperty(getModuleVarName(envModule.getClass()), envModule);
binding.setProperty(getModuleVarName(cacheModule.getClass()), cacheModule);
GroovyShell groovyShell = new GroovyShell(binding); GroovyShell groovyShell = new GroovyShell(binding);
try { try {
......
...@@ -9,6 +9,12 @@ ...@@ -9,6 +9,12 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.exec.engine.impl; package org.dromara.sqlrest.core.exec.engine.impl;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sqlrest.common.enums.NamingStrategyEnum; import org.dromara.sqlrest.common.enums.NamingStrategyEnum;
import org.dromara.sqlrest.common.enums.ProductTypeEnum; import org.dromara.sqlrest.common.enums.ProductTypeEnum;
import org.dromara.sqlrest.common.util.LambdaUtils; import org.dromara.sqlrest.common.util.LambdaUtils;
...@@ -18,12 +24,6 @@ import org.dromara.sqlrest.core.util.SqlJdbcUtils; ...@@ -18,12 +24,6 @@ import org.dromara.sqlrest.core.util.SqlJdbcUtils;
import org.dromara.sqlrest.persistence.entity.ApiContextEntity; import org.dromara.sqlrest.persistence.entity.ApiContextEntity;
import org.dromara.sqlrest.template.SqlMeta; import org.dromara.sqlrest.template.SqlMeta;
import org.dromara.sqlrest.template.XmlSqlTemplate; import org.dromara.sqlrest.template.XmlSqlTemplate;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class SqlExecutorService extends AbstractExecutorEngine { public class SqlExecutorService extends AbstractExecutorEngine {
...@@ -44,7 +44,7 @@ public class SqlExecutorService extends AbstractExecutorEngine { ...@@ -44,7 +44,7 @@ public class SqlExecutorService extends AbstractExecutorEngine {
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
int page = PageSizeUtils.getPageFromParams(params); int page = PageSizeUtils.getPageFromParams(params);
int size = PageSizeUtils.getSizeFromParams(params); int size = PageSizeUtils.getSizeFromParams(params);
Object result = SqlJdbcUtils.execute(productType, connection, sqlMeta, strategy, page, size); Object result = SqlJdbcUtils.execute(productType, connection, sqlMeta, strategy, page, size, printSqlLog);
if (sqlMeta.isQuerySQL()) { if (sqlMeta.isQuerySQL()) {
dataList.add(result); dataList.add(result);
} }
......
...@@ -9,22 +9,30 @@ ...@@ -9,22 +9,30 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.exec.module; package org.dromara.sqlrest.core.exec.module;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.dromara.sqlrest.cache.CacheFactory; import org.dromara.sqlrest.cache.CacheFactory;
import org.dromara.sqlrest.cache.DistributedCache; import org.dromara.sqlrest.cache.DistributedCache;
import org.dromara.sqlrest.common.consts.Constants; import org.dromara.sqlrest.common.consts.Constants;
import org.dromara.sqlrest.common.service.VarModuleInterface;
import org.dromara.sqlrest.core.exec.annotation.Comment; import org.dromara.sqlrest.core.exec.annotation.Comment;
import org.dromara.sqlrest.core.exec.annotation.Module; import org.dromara.sqlrest.core.exec.annotation.Module;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@Module("cache") @Module(CacheVarModule.VAR_NAME)
public class CacheVarModule { public class CacheVarModule implements VarModuleInterface {
protected static final String VAR_NAME = "cache";
@Resource @Resource
private CacheFactory cacheFactory; private CacheFactory cacheFactory;
@Override
public String getVarModuleName() {
return VAR_NAME;
}
private DistributedCache getDistributedCache() { private DistributedCache getDistributedCache() {
return cacheFactory.getDistributedCache(Constants.CACHE_NAME_API_VAR); return cacheFactory.getDistributedCache(Constants.CACHE_NAME_API_VAR);
} }
......
...@@ -24,9 +24,10 @@ import javax.sql.DataSource; ...@@ -24,9 +24,10 @@ import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dromara.sqlrest.common.enums.NamingStrategyEnum; import org.dromara.sqlrest.common.enums.NamingStrategyEnum;
import org.dromara.sqlrest.common.enums.ProductTypeEnum; import org.dromara.sqlrest.common.enums.ProductTypeEnum;
import org.dromara.sqlrest.core.exec.logger.SqlExecuteLogger; import org.dromara.sqlrest.common.service.VarModuleInterface;
import org.dromara.sqlrest.core.exec.annotation.Comment; import org.dromara.sqlrest.core.exec.annotation.Comment;
import org.dromara.sqlrest.core.exec.annotation.Module; import org.dromara.sqlrest.core.exec.annotation.Module;
import org.dromara.sqlrest.core.exec.logger.SqlExecuteLogger;
import org.dromara.sqlrest.core.util.ConvertUtils; import org.dromara.sqlrest.core.util.ConvertUtils;
import org.dromara.sqlrest.core.util.PageSizeUtils; import org.dromara.sqlrest.core.util.PageSizeUtils;
import org.dromara.sqlrest.core.util.PageSqlUtils; import org.dromara.sqlrest.core.util.PageSqlUtils;
...@@ -40,17 +41,20 @@ import org.springframework.jdbc.core.ResultSetExtractor; ...@@ -40,17 +41,20 @@ import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.GeneratedKeyHolder;
@Slf4j @Slf4j
@Module("db") @Module(DbVarModule.VAR_NAME)
public class DbVarModule { public class DbVarModule implements VarModuleInterface {
protected static final String VAR_NAME = "db";
private DataSource dataSource; private DataSource dataSource;
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
private ProductTypeEnum productType; private ProductTypeEnum productType;
private Map<String, Object> params; private Map<String, Object> params;
private Function<String, String> converter; private Function<String, String> converter;
private boolean printSqlLog;
public DbVarModule(DataSource dataSource, ProductTypeEnum productType, Map<String, Object> params, public DbVarModule(DataSource dataSource, ProductTypeEnum productType, Map<String, Object> params,
NamingStrategyEnum strategy) { NamingStrategyEnum strategy, boolean printSqlLog) {
this.dataSource = dataSource; this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(dataSource); this.jdbcTemplate = new JdbcTemplate(dataSource);
this.productType = productType; this.productType = productType;
...@@ -60,6 +64,12 @@ public class DbVarModule { ...@@ -60,6 +64,12 @@ public class DbVarModule {
strategy = NamingStrategyEnum.NONE; strategy = NamingStrategyEnum.NONE;
} }
this.converter = strategy.getFunction(); this.converter = strategy.getFunction();
this.printSqlLog = printSqlLog;
}
@Override
public String getVarModuleName() {
return VAR_NAME;
} }
private String getPageSql(String sql, int page, int size) { private String getPageSql(String sql, int page, int size) {
...@@ -83,7 +93,9 @@ public class DbVarModule { ...@@ -83,7 +93,9 @@ public class DbVarModule {
@Comment("查询所有的数据列表") @Comment("查询所有的数据列表")
public List<Map<String, Object>> selectAll(@Comment("sqlOrXml") String sqlOrXml) throws SQLException { public List<Map<String, Object>> selectAll(@Comment("sqlOrXml") String sqlOrXml) throws SQLException {
log.info("Enter selectAll() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter selectAll() function, SQL:{},params:{}", sqlOrXml, params);
}
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
...@@ -96,7 +108,9 @@ public class DbVarModule { ...@@ -96,7 +108,9 @@ public class DbVarModule {
@Comment("count所有数据的总数") @Comment("count所有数据的总数")
public Integer selectCount(@Comment("sqlOrXml") String sqlOrXml) { public Integer selectCount(@Comment("sqlOrXml") String sqlOrXml) {
log.info("Enter selectCount() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter selectCount() function, SQL:{},params:{}", sqlOrXml, params);
}
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
String countSql = String.format("select count(*) from (%s) a", sqlMeta.getSql()); String countSql = String.format("select count(*) from (%s) a", sqlMeta.getSql());
...@@ -110,7 +124,9 @@ public class DbVarModule { ...@@ -110,7 +124,9 @@ public class DbVarModule {
@Comment("查询单条结果,并传入变量信息,查不到返回null") @Comment("查询单条结果,并传入变量信息,查不到返回null")
public Map<String, Object> selectOne(@Comment("sqlOrXml") String sqlOrXml) { public Map<String, Object> selectOne(@Comment("sqlOrXml") String sqlOrXml) {
log.info("Enter selectOne() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter selectOne() function, SQL:{},params:{}", sqlOrXml, params);
}
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
...@@ -136,7 +152,9 @@ public class DbVarModule { ...@@ -136,7 +152,9 @@ public class DbVarModule {
@Comment("分页查询数据列表") @Comment("分页查询数据列表")
public List<Map<String, Object>> page(@Comment("sqlOrXml") String sqlOrXml) public List<Map<String, Object>> page(@Comment("sqlOrXml") String sqlOrXml)
throws SQLException { throws SQLException {
log.info("Enter page() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter page() function, SQL:{},params:{}", sqlOrXml, params);
}
int page = PageSizeUtils.getPageFromParams(params); int page = PageSizeUtils.getPageFromParams(params);
int size = PageSizeUtils.getSizeFromParams(params); int size = PageSizeUtils.getSizeFromParams(params);
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
...@@ -154,7 +172,9 @@ public class DbVarModule { ...@@ -154,7 +172,9 @@ public class DbVarModule {
@Comment("执行insert操作,返回插入主键") @Comment("执行insert操作,返回插入主键")
public Map<String, Object> insert(@Comment("sqlOrXml") String sqlOrXml) { public Map<String, Object> insert(@Comment("sqlOrXml") String sqlOrXml) {
log.info("Enter insert() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter insert() function, SQL:{},params:{}", sqlOrXml, params);
}
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
List<Object> parameters = sqlMeta.getParameter(); List<Object> parameters = sqlMeta.getParameter();
...@@ -176,7 +196,9 @@ public class DbVarModule { ...@@ -176,7 +196,9 @@ public class DbVarModule {
@Comment("执行update操作,返回受影响行数") @Comment("执行update操作,返回受影响行数")
public int update(@Comment("sqlOrXml") String sqlOrXml) { public int update(@Comment("sqlOrXml") String sqlOrXml) {
log.info("Enter update() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter update() function, SQL:{},params:{}", sqlOrXml, params);
}
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
List<Object> parameters = sqlMeta.getParameter(); List<Object> parameters = sqlMeta.getParameter();
...@@ -190,7 +212,9 @@ public class DbVarModule { ...@@ -190,7 +212,9 @@ public class DbVarModule {
@Comment("批量执行操作,返回受影响的行数") @Comment("批量执行操作,返回受影响的行数")
public int batchUpdate(@Comment("sqlList") List<String> sqlList) { public int batchUpdate(@Comment("sqlList") List<String> sqlList) {
log.info("Enter batchUpdate() function, SQL:{},params:{}", sqlList); if (printSqlLog) {
log.info("Enter batchUpdate() function, SQL:{},params:{}", sqlList);
}
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
return Arrays.stream(jdbcTemplate.batchUpdate(sqlList.toArray(new String[0]))).sum(); return Arrays.stream(jdbcTemplate.batchUpdate(sqlList.toArray(new String[0]))).sum();
...@@ -202,7 +226,9 @@ public class DbVarModule { ...@@ -202,7 +226,9 @@ public class DbVarModule {
@Comment("执行delete操作,返回受影响行数") @Comment("执行delete操作,返回受影响行数")
public int delete(@Comment("sqlOrXml") String sqlOrXml) { public int delete(@Comment("sqlOrXml") String sqlOrXml) {
log.info("Enter update() function, SQL:{},params:{}", sqlOrXml, params); if (printSqlLog) {
log.info("Enter update() function, SQL:{},params:{}", sqlOrXml, params);
}
XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml); XmlSqlTemplate template = new XmlSqlTemplate(sqlOrXml);
SqlMeta sqlMeta = template.process(params); SqlMeta sqlMeta = template.process(params);
List<Object> parameters = sqlMeta.getParameter(); List<Object> parameters = sqlMeta.getParameter();
......
...@@ -14,7 +14,7 @@ import com.zaxxer.hikari.HikariDataSource; ...@@ -14,7 +14,7 @@ import com.zaxxer.hikari.HikariDataSource;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import org.dromara.sqlrest.common.enums.NamingStrategyEnum; import org.dromara.sqlrest.common.enums.NamingStrategyEnum;
import org.dromara.sqlrest.common.enums.ProductTypeEnum; import org.dromara.sqlrest.common.service.VarModuleInterface;
import org.dromara.sqlrest.core.driver.DriverLoadService; import org.dromara.sqlrest.core.driver.DriverLoadService;
import org.dromara.sqlrest.core.exec.annotation.Comment; import org.dromara.sqlrest.core.exec.annotation.Comment;
import org.dromara.sqlrest.core.exec.annotation.Module; import org.dromara.sqlrest.core.exec.annotation.Module;
...@@ -22,20 +22,27 @@ import org.dromara.sqlrest.core.util.DataSourceUtils; ...@@ -22,20 +22,27 @@ import org.dromara.sqlrest.core.util.DataSourceUtils;
import org.dromara.sqlrest.persistence.dao.DataSourceDao; import org.dromara.sqlrest.persistence.dao.DataSourceDao;
import org.dromara.sqlrest.persistence.entity.DataSourceEntity; import org.dromara.sqlrest.persistence.entity.DataSourceEntity;
@Module("ds") @Module(DsVarModule.VAR_NAME)
public class DsVarModule { public class DsVarModule implements VarModuleInterface {
protected static final String VAR_NAME = "ds";
private DataSourceDao dataSourceDao = SpringUtil.getBean(DataSourceDao.class); private DataSourceDao dataSourceDao = SpringUtil.getBean(DataSourceDao.class);
private DriverLoadService driverLoadService = SpringUtil.getBean(DriverLoadService.class); private DriverLoadService driverLoadService = SpringUtil.getBean(DriverLoadService.class);
private Map<String, Object> params; private Map<String, Object> params;
private ProductTypeEnum productType;
private NamingStrategyEnum strategy; private NamingStrategyEnum strategy;
private boolean printSqlLog;
public DsVarModule(ProductTypeEnum productType, Map<String, Object> params, NamingStrategyEnum strategy) { public DsVarModule(Map<String, Object> params, NamingStrategyEnum strategy, boolean printSqlLog) {
this.productType = productType;
this.params = params; this.params = params;
this.strategy = strategy; this.strategy = strategy;
this.printSqlLog = printSqlLog;
}
@Override
public String getVarModuleName() {
return VAR_NAME;
} }
@Comment("根据数据源ID获取db模块") @Comment("根据数据源ID获取db模块")
...@@ -46,7 +53,7 @@ public class DsVarModule { ...@@ -46,7 +53,7 @@ public class DsVarModule {
} }
File driverPath = driverLoadService.getVersionDriverFile(dsEntity.getType(), dsEntity.getVersion()); File driverPath = driverLoadService.getVersionDriverFile(dsEntity.getType(), dsEntity.getVersion());
HikariDataSource dataSource = DataSourceUtils.getHikariDataSource(dsEntity, driverPath.getAbsolutePath()); HikariDataSource dataSource = DataSourceUtils.getHikariDataSource(dsEntity, driverPath.getAbsolutePath());
return new DbVarModule(dataSource, productType, params, strategy); return new DbVarModule(dataSource, dsEntity.getType(), params, strategy, printSqlLog);
} }
} }
...@@ -9,14 +9,17 @@ ...@@ -9,14 +9,17 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.exec.module; package org.dromara.sqlrest.core.exec.module;
import org.dromara.sqlrest.common.service.VarModuleInterface;
import org.dromara.sqlrest.core.exec.annotation.Comment; import org.dromara.sqlrest.core.exec.annotation.Comment;
import org.dromara.sqlrest.core.exec.annotation.Module; import org.dromara.sqlrest.core.exec.annotation.Module;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@Module("env") @Module(EnvVarModule.VAR_NAME)
public class EnvVarModule { public class EnvVarModule implements VarModuleInterface {
protected static final String VAR_NAME = "env";
private final Environment environment; private final Environment environment;
...@@ -24,6 +27,11 @@ public class EnvVarModule { ...@@ -24,6 +27,11 @@ public class EnvVarModule {
this.environment = environment; this.environment = environment;
} }
@Override
public String getVarModuleName() {
return VAR_NAME;
}
@Comment("获取配置") @Comment("获取配置")
public String get(@Comment("key") String key) { public String get(@Comment("key") String key) {
return environment.getProperty(key); return environment.getProperty(key);
......
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
package org.dromara.sqlrest.core.exec.module; package org.dromara.sqlrest.core.exec.module;
import java.util.Map; import java.util.Map;
import org.dromara.sqlrest.common.service.VarModuleInterface;
import org.dromara.sqlrest.core.exec.annotation.Comment; import org.dromara.sqlrest.core.exec.annotation.Comment;
import org.dromara.sqlrest.core.exec.annotation.Module; import org.dromara.sqlrest.core.exec.annotation.Module;
@Module("req") @Module(ReqVarModule.VAR_NAME)
public class ReqVarModule { public class ReqVarModule implements VarModuleInterface {
protected static final String VAR_NAME = "req";
private Map<String, Object> params; private Map<String, Object> params;
...@@ -22,6 +25,11 @@ public class ReqVarModule { ...@@ -22,6 +25,11 @@ public class ReqVarModule {
this.params = params; this.params = params;
} }
@Override
public String getVarModuleName() {
return VAR_NAME;
}
@Comment("设置一个请求参数,如果存在同名将被覆盖") @Comment("设置一个请求参数,如果存在同名将被覆盖")
public void setParam(@Comment("name") String name, @Comment("value") Object value) { public void setParam(@Comment("name") String name, @Comment("value") Object value) {
this.params.put(name, value); this.params.put(name, value);
......
...@@ -324,7 +324,7 @@ public class ApiAssignmentService { ...@@ -324,7 +324,7 @@ public class ApiAssignmentService {
SqlExecuteLogger.init(); SqlExecuteLogger.init();
HikariDataSource dataSource = DataSourceUtils.getHikariDataSource(dataSourceEntity, driverPath.getAbsolutePath()); HikariDataSource dataSource = DataSourceUtils.getHikariDataSource(dataSourceEntity, driverPath.getAbsolutePath());
List<Object> results = ApiExecutorEngineFactory List<Object> results = ApiExecutorEngineFactory
.getExecutor(request.getEngine(), dataSource, dataSourceEntity.getType()) .getExecutor(request.getEngine(), dataSource, dataSourceEntity.getType(), true)
.execute(scripts, params, request.getNamingStrategy()); .execute(scripts, params, request.getNamingStrategy());
Object answer = results.size() > 1 ? results : (1 == results.size()) ? results.get(0) : null; Object answer = results.size() > 1 ? results : (1 == results.size()) ? results.get(0) : null;
List<OutParam> types = JacksonUtils.parseFiledTypesAndFillNullAsString(results); List<OutParam> types = JacksonUtils.parseFiledTypesAndFillNullAsString(results);
...@@ -337,6 +337,7 @@ public class ApiAssignmentService { ...@@ -337,6 +337,7 @@ public class ApiAssignmentService {
respMap.put("types", types); respMap.put("types", types);
entity = ResultEntity.success(respMap); entity = ResultEntity.success(respMap);
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to debug for error:{}", e.getMessage(), e);
entity = ResultEntity.failed(ExceptionUtil.getMessage(e)); entity = ResultEntity.failed(ExceptionUtil.getMessage(e));
} finally { } finally {
SqlExecuteLogger.clear(); SqlExecuteLogger.clear();
......
// Copyright tang. All rights reserved.
// https://gitee.com/inrgihc/sqlrest
//
// Use of this source code is governed by a BSD-style license
//
// Author: tang (inrgihc@126.com)
// Date : 2024/3/31
// Location: beijing , china
/////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.servlet;
import org.dromara.sqlrest.common.consts.Constants;
import org.dromara.sqlrest.common.dto.ResultEntity;
import org.dromara.sqlrest.common.enums.HttpMethodEnum;
import org.dromara.sqlrest.core.exec.ApiExecuteService;
import org.dromara.sqlrest.core.util.JacksonUtils;
import org.dromara.sqlrest.persistence.dao.ApiAssignmentDao;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ApiServletService {
@Resource
private ApiAssignmentDao apiAssignmentDao;
@Resource
private ApiExecuteService apiExecuteService;
public void process(HttpMethodEnum method, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String path = request.getRequestURI().substring(Constants.API_PATH_PREFIX.length() + 2);
ApiAssignmentEntity apiConfigEntity = apiAssignmentDao.getByUk(method, path);
ResultEntity result = apiExecuteService.execute(apiConfigEntity, request);
String json = JacksonUtils.toJsonStr(result, apiConfigEntity.getResponseFormat());
response.getWriter().append(json);
}
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// Date : 2024/3/31 // Date : 2024/3/31
// Location: beijing , china // Location: beijing , china
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.core.filter; package org.dromara.sqlrest.core.servlet;
import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.thread.ExecutorBuilder; import cn.hutool.core.thread.ExecutorBuilder;
...@@ -33,11 +33,12 @@ import org.dromara.sqlrest.common.enums.HttpMethodEnum; ...@@ -33,11 +33,12 @@ import org.dromara.sqlrest.common.enums.HttpMethodEnum;
import org.dromara.sqlrest.common.exception.ResponseErrorCode; import org.dromara.sqlrest.common.exception.ResponseErrorCode;
import org.dromara.sqlrest.common.exception.UnAuthorizedException; import org.dromara.sqlrest.common.exception.UnAuthorizedException;
import org.dromara.sqlrest.common.exception.UnPermissionException; import org.dromara.sqlrest.common.exception.UnPermissionException;
import org.dromara.sqlrest.common.service.FlowControlManger;
import org.dromara.sqlrest.common.util.InetUtils; import org.dromara.sqlrest.common.util.InetUtils;
import org.dromara.sqlrest.common.util.TokenUtils; import org.dromara.sqlrest.common.util.TokenUtils;
import org.dromara.sqlrest.core.exec.ApiAssignmentCache;
import org.dromara.sqlrest.core.exec.logger.RequestParamLogger; import org.dromara.sqlrest.core.exec.logger.RequestParamLogger;
import org.dromara.sqlrest.core.executor.UnifyAlarmOpsService; import org.dromara.sqlrest.core.executor.UnifyAlarmOpsService;
import org.dromara.sqlrest.core.servlet.ClientTokenService;
import org.dromara.sqlrest.core.util.AlarmModelUtils; import org.dromara.sqlrest.core.util.AlarmModelUtils;
import org.dromara.sqlrest.core.util.ServletUtils; import org.dromara.sqlrest.core.util.ServletUtils;
import org.dromara.sqlrest.persistence.dao.ApiAssignmentDao; import org.dromara.sqlrest.persistence.dao.ApiAssignmentDao;
...@@ -54,6 +55,7 @@ public class AuthenticationFilter implements Filter { ...@@ -54,6 +55,7 @@ public class AuthenticationFilter implements Filter {
private static final ExecutorService alarmExecutor = ExecutorBuilder.create() private static final ExecutorService alarmExecutor = ExecutorBuilder.create()
.setCorePoolSize(Runtime.getRuntime().availableProcessors()) .setCorePoolSize(Runtime.getRuntime().availableProcessors())
.setMaxPoolSize(5 * Runtime.getRuntime().availableProcessors())
.useArrayBlockingQueue(8912) .useArrayBlockingQueue(8912)
.setHandler(new CallerRunsPolicy()) .setHandler(new CallerRunsPolicy())
.build(); .build();
...@@ -80,7 +82,7 @@ public class AuthenticationFilter implements Filter { ...@@ -80,7 +82,7 @@ public class AuthenticationFilter implements Filter {
HttpMethodEnum method = HttpMethodEnum.exists(request.getMethod()) HttpMethodEnum method = HttpMethodEnum.exists(request.getMethod())
? HttpMethodEnum.valueOf(request.getMethod().toUpperCase()) ? HttpMethodEnum.valueOf(request.getMethod().toUpperCase())
: HttpMethodEnum.GET; : HttpMethodEnum.GET;
ApiAssignmentEntity apiConfigEntity = apiAssignmentDao.getByUk(method, path, false); ApiAssignmentEntity apiConfigEntity = apiAssignmentDao.getByUk(method, path);
if (null == apiConfigEntity || !apiConfigEntity.getStatus()) { if (null == apiConfigEntity || !apiConfigEntity.getStatus()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
String message = String.format("/%s/%s[%s]", Constants.API_PATH_PREFIX, path, method.name()); String message = String.format("/%s/%s[%s]", Constants.API_PATH_PREFIX, path, method.name());
...@@ -90,13 +92,19 @@ public class AuthenticationFilter implements Filter { ...@@ -90,13 +92,19 @@ public class AuthenticationFilter implements Filter {
return; return;
} }
if (apiConfigEntity.getFlowStatus()) { try {
String resourceName = Constants.getResourceName(method.name(), path); ApiAssignmentCache.set(apiConfigEntity);
if (flowControlManger.checkFlowControl(resourceName, response)) {
if (apiConfigEntity.getFlowStatus()) {
String resourceName = Constants.getResourceName(method.name(), path);
if (flowControlManger.checkFlowControl(resourceName, response)) {
doAuthenticationFilter(chain, request, response, apiConfigEntity);
}
} else {
doAuthenticationFilter(chain, request, response, apiConfigEntity); doAuthenticationFilter(chain, request, response, apiConfigEntity);
} }
} else { } finally {
doAuthenticationFilter(chain, request, response, apiConfigEntity); ApiAssignmentCache.remove();
} }
} }
...@@ -165,17 +173,16 @@ public class AuthenticationFilter implements Filter { ...@@ -165,17 +173,16 @@ public class AuthenticationFilter implements Filter {
} }
} }
private void doRecord(ApiAssignmentEntity apiConfigEntity, AccessRecordEntity accessRecord, int httpStatus, private void doRecord(ApiAssignmentEntity config, AccessRecordEntity record, int status, long timestamp) {
long accessTimestamp) { accessRecordMapper.insert(record);
accessRecordMapper.insert(accessRecord); if (status == HttpServletResponse.SC_OK) {
if (httpStatus == HttpServletResponse.SC_OK) {
return; return;
} }
if (!apiConfigEntity.getAlarm()) { if (!config.getAlarm()) {
return; return;
} }
Map<String, String> dataModel = AlarmModelUtils.getBusinessModel(apiConfigEntity, accessRecord, accessTimestamp); Map<String, String> dataModel = AlarmModelUtils.getBusinessModel(config, record, timestamp);
unifyAlarmOpsService.triggerAlarm(dataModel); unifyAlarmOpsService.triggerAlarm(dataModel);
} }
......
...@@ -15,11 +15,6 @@ import com.fasterxml.jackson.databind.Module; ...@@ -15,11 +15,6 @@ import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.dromara.sqlrest.common.dto.OutParam;
import org.dromara.sqlrest.common.enums.DataTypeFormatEnum;
import org.dromara.sqlrest.common.enums.ParamTypeEnum;
import org.dromara.sqlrest.common.util.UuidUtils;
import org.dromara.sqlrest.core.serdes.DateTimeSerDesFactory;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Time; import java.sql.Time;
...@@ -33,6 +28,11 @@ import java.util.LinkedList; ...@@ -33,6 +28,11 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.dromara.sqlrest.common.dto.OutParam;
import org.dromara.sqlrest.common.enums.DataTypeFormatEnum;
import org.dromara.sqlrest.common.enums.ParamTypeEnum;
import org.dromara.sqlrest.common.util.UuidUtils;
import org.dromara.sqlrest.core.serdes.DateTimeSerDesFactory;
public final class JacksonUtils { public final class JacksonUtils {
...@@ -146,10 +146,12 @@ public final class JacksonUtils { ...@@ -146,10 +146,12 @@ public final class JacksonUtils {
if (isArray) { if (isArray) {
Collection collection = (Collection) value; Collection collection = (Collection) value;
Object item = collection.stream().findFirst().get(); if (collection.size() > 0) {
ParamTypeEnum subTypeEnum = parseValueType(item); Object item = collection.stream().findFirst().get();
if (null != subTypeEnum && subTypeEnum.isObject()) { ParamTypeEnum subTypeEnum = parseValueType(item);
parseFieldTypes(outParam, (Map) item, results); if (null != subTypeEnum && subTypeEnum.isObject()) {
parseFieldTypes(outParam, (Map) item, results);
}
} }
} else if (value instanceof Map) { } else if (value instanceof Map) {
parseFieldTypes(outParam, (Map) value, results); parseFieldTypes(outParam, (Map) value, results);
......
...@@ -39,7 +39,7 @@ public class SqlJdbcUtils { ...@@ -39,7 +39,7 @@ public class SqlJdbcUtils {
} }
public static Object execute(ProductTypeEnum productType, Connection connection, SqlMeta sqlMeta, public static Object execute(ProductTypeEnum productType, Connection connection, SqlMeta sqlMeta,
NamingStrategyEnum strategy, int page, int size) throws SQLException { NamingStrategyEnum strategy, int page, int size, boolean printSqlLog) throws SQLException {
List<Object> paramValues = sqlMeta.getParameter(); List<Object> paramValues = sqlMeta.getParameter();
boolean isQuerySql = sqlMeta.isQuerySQL(); boolean isQuerySql = sqlMeta.isQuerySQL();
String sql = isQuerySql String sql = isQuerySql
...@@ -55,7 +55,10 @@ public class SqlJdbcUtils { ...@@ -55,7 +55,10 @@ public class SqlJdbcUtils {
statement.setObject(i, paramValues.get(i - 1)); statement.setObject(i, paramValues.get(i - 1));
} }
log.info("ExecuteSQL:{}\n{}", sql, paramValues); if (printSqlLog) {
log.info("ExecuteSQL:{}\n{}", sql, paramValues);
}
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
Function<String, String> converter = getConverter(strategy); Function<String, String> converter = getConverter(strategy);
......
...@@ -22,7 +22,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; ...@@ -22,7 +22,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication( @SpringBootApplication(
scanBasePackages = { scanBasePackages = {
"org.dromara.sqlrest.persistence", "org.dromara.sqlrest.persistence",
"org.dromara.sqlrest.core.filter",
"org.dromara.sqlrest.core.driver", "org.dromara.sqlrest.core.driver",
"org.dromara.sqlrest.core.servlet", "org.dromara.sqlrest.core.servlet",
"org.dromara.sqlrest.core.exec", "org.dromara.sqlrest.core.exec",
......
...@@ -9,13 +9,14 @@ ...@@ -9,13 +9,14 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.executor.config; package org.dromara.sqlrest.executor.config;
import org.dromara.sqlrest.common.consts.Constants;
import org.dromara.sqlrest.core.filter.AuthenticationFilter;
import org.dromara.sqlrest.core.servlet.ApiServletService;
import org.dromara.sqlrest.executor.model.HttpApiServlet;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dromara.sqlrest.common.consts.Constants;
import org.dromara.sqlrest.core.exec.ApiExecuteService;
import org.dromara.sqlrest.core.servlet.AuthenticationFilter;
import org.dromara.sqlrest.executor.model.HttpApiServlet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -29,6 +30,9 @@ public class ExecutorServletConfig { ...@@ -29,6 +30,9 @@ public class ExecutorServletConfig {
private static final String URL_PATH_PATTERN = String.format("/%s/*", Constants.API_PATH_PREFIX); private static final String URL_PATH_PATTERN = String.format("/%s/*", Constants.API_PATH_PREFIX);
@Value("${sqlrest.executor.print-sql-log}")
private boolean printSqlLog;
@Resource @Resource
private AuthenticationFilter authenticationFilter; private AuthenticationFilter authenticationFilter;
...@@ -53,8 +57,8 @@ public class ExecutorServletConfig { ...@@ -53,8 +57,8 @@ public class ExecutorServletConfig {
* @return ServletRegistrationBean * @return ServletRegistrationBean
*/ */
@Bean @Bean
public ServletRegistrationBean apiServletRegistrationBean(ApiServletService apiServletService) { public ServletRegistrationBean apiServletRegistrationBean(ApiExecuteService apiExecuteService) {
HttpServlet httpServlet = new HttpApiServlet(apiServletService); HttpServlet httpServlet = new HttpApiServlet(apiExecuteService, printSqlLog);
return new ServletRegistrationBean(httpServlet, URL_PATH_PATTERN); return new ServletRegistrationBean(httpServlet, URL_PATH_PATTERN);
} }
} }
...@@ -21,7 +21,7 @@ import org.dromara.sqlrest.common.consts.Constants; ...@@ -21,7 +21,7 @@ import org.dromara.sqlrest.common.consts.Constants;
import org.dromara.sqlrest.common.dto.ResultEntity; import org.dromara.sqlrest.common.dto.ResultEntity;
import org.dromara.sqlrest.common.enums.HttpMethodEnum; import org.dromara.sqlrest.common.enums.HttpMethodEnum;
import org.dromara.sqlrest.common.exception.ResponseErrorCode; import org.dromara.sqlrest.common.exception.ResponseErrorCode;
import org.dromara.sqlrest.core.filter.FlowControlManger; import org.dromara.sqlrest.common.service.FlowControlManger;
import org.dromara.sqlrest.persistence.dao.ApiAssignmentDao; import org.dromara.sqlrest.persistence.dao.ApiAssignmentDao;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity; import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
import java.io.IOException; import java.io.IOException;
......
...@@ -9,49 +9,57 @@ ...@@ -9,49 +9,57 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package org.dromara.sqlrest.executor.model; package org.dromara.sqlrest.executor.model;
import org.dromara.sqlrest.common.enums.HttpMethodEnum;
import org.dromara.sqlrest.core.servlet.ApiServletService;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.dromara.sqlrest.common.dto.ResultEntity;
import org.dromara.sqlrest.core.exec.ApiAssignmentCache;
import org.dromara.sqlrest.core.exec.ApiExecuteService;
import org.dromara.sqlrest.core.util.JacksonUtils;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
public class HttpApiServlet extends HttpServlet { public class HttpApiServlet extends HttpServlet {
private ApiServletService apiServletService; private ApiExecuteService apiExecuteService;
private boolean printSqlLog;
public HttpApiServlet(ApiServletService apiServletService) { public HttpApiServlet(ApiExecuteService apiExecuteService, boolean printSqlLog) {
this.apiServletService = apiServletService; this.apiExecuteService = apiExecuteService;
this.printSqlLog = printSqlLog;
} }
private void doHandle(HttpMethodEnum method, HttpServletRequest request, HttpServletResponse response) private void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
throws ServletException, IOException { ApiAssignmentEntity apiConfigEntity = ApiAssignmentCache.get();
apiServletService.process(method, request, response); ResultEntity result = apiExecuteService.execute(apiConfigEntity, request, printSqlLog);
String json = JacksonUtils.toJsonStr(result, apiConfigEntity.getResponseFormat());
response.getWriter().append(json);
} }
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doHandle(HttpMethodEnum.GET, req, resp); process(req, resp);
} }
@Override @Override
protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doHandle(HttpMethodEnum.HEAD, req, resp); process(req, resp);
} }
@Override @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doHandle(HttpMethodEnum.POST, req, resp); process(req, resp);
} }
@Override @Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doHandle(HttpMethodEnum.PUT, req, resp); process(req, resp);
} }
@Override @Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doHandle(HttpMethodEnum.DELETE, req, resp); process(req, resp);
} }
} }
...@@ -9,6 +9,8 @@ spring: ...@@ -9,6 +9,8 @@ spring:
allow-bean-definition-overriding: false allow-bean-definition-overriding: false
sqlrest: sqlrest:
executor:
print-sql-log: false
cache: cache:
hazelcast: hazelcast:
enabled: true enabled: true
......
...@@ -641,7 +641,7 @@ ...@@ -641,7 +641,7 @@
</el-row> </el-row>
<el-row v-else <el-row v-else
:gutter="24"> :gutter="24">
<div style="display: inline-flex;justify-content: center;" <div style="display: inline-flex;flex-direction: row ;justify-content: left;align-items: center"
v-for="(arrayItemValue,arrayItemIndex) in scope.row.arrayValues" v-for="(arrayItemValue,arrayItemIndex) in scope.row.arrayValues"
:key="arrayItemIndex"> :key="arrayItemIndex">
<el-col :span="4"><button @click="delArrayValuesItem(scope.row.arrayValues,arrayItemIndex)">-</button></el-col> <el-col :span="4"><button @click="delArrayValuesItem(scope.row.arrayValues,arrayItemIndex)">-</button></el-col>
...@@ -649,7 +649,9 @@ ...@@ -649,7 +649,9 @@
:disabled="scope.row.type=='OBJECT'" :disabled="scope.row.type=='OBJECT'"
type="string"></el-input></el-col> type="string"></el-input></el-col>
</div> </div>
<el-col :span="4"><button @click="addArrayValuesItem(scope.row)">+</button></el-col> <div style="display: inline-flex;flex-direction: row ;justify-content: left;align-items: center">
<el-col :span="4"><button @click="addArrayValuesItem(scope.row)">+</button></el-col>
</div>
</el-row> </el-row>
</div> </div>
<div v-else> <div v-else>
...@@ -1660,7 +1662,6 @@ export default { ...@@ -1660,7 +1662,6 @@ export default {
if (0 === res.data.code) { if (0 === res.data.code) {
this.debugResponse = res.data.data.answer; this.debugResponse = res.data.data.answer;
this.debugConsoleLog = res.data.data.logs; this.debugConsoleLog = res.data.data.logs;
this.outputParams = [];
let arr = res.data.data.types; let arr = res.data.data.types;
if (Array.isArray(arr) && arr.length === 0) { if (Array.isArray(arr) && arr.length === 0) {
this.$alert("结果集内容为空", "提示信息", this.$alert("结果集内容为空", "提示信息",
...@@ -1670,14 +1671,31 @@ export default { ...@@ -1670,14 +1671,31 @@ export default {
} }
); );
} else { } else {
var paramNameRemarkMap = new Map();
for (let one of this.outputParams) {
paramNameRemarkMap.set(one.name, one.remark);
if (one.children) {
for (let subOne of one.children) {
paramNameRemarkMap.set(one.name + "." + subOne.name, subOne.remark);
}
}
}
this.outputParams = [];
for (let item of arr) { for (let item of arr) {
var remark = item.remark || paramNameRemarkMap.get(item.name);
if (item.children) {
for (let one of item.children) {
one.remark = one.remark || paramNameRemarkMap.get(item.name + "." + one.name);
}
}
this.outputParams.push( this.outputParams.push(
{ {
id: item.id, id: item.id,
name: item.name, name: item.name,
type: item.type, type: item.type,
isArray: item.isArray, isArray: item.isArray,
remark: item.remark, remark: remark,
children: item.children, children: item.children,
} }
) )
...@@ -1849,7 +1867,10 @@ export default { ...@@ -1849,7 +1867,10 @@ export default {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
} }
/deep/.el-table .cell .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner { /deep/.el-table
.cell
.el-checkbox__input.is-disabled.is-checked
.el-checkbox__inner {
background-color: #1464dd; background-color: #1464dd;
border-color: #f4f5f8; border-color: #f4f5f8;
} }
......
...@@ -15,6 +15,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; ...@@ -15,6 +15,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import io.modelcontextprotocol.server.McpSyncServerExchange;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
import org.dromara.sqlrest.common.consts.Constants; import org.dromara.sqlrest.common.consts.Constants;
import org.dromara.sqlrest.common.dto.BaseParam; import org.dromara.sqlrest.common.dto.BaseParam;
import org.dromara.sqlrest.common.dto.ItemParam; import org.dromara.sqlrest.common.dto.ItemParam;
...@@ -24,13 +31,6 @@ import org.dromara.sqlrest.core.exec.ApiExecuteService; ...@@ -24,13 +31,6 @@ import org.dromara.sqlrest.core.exec.ApiExecuteService;
import org.dromara.sqlrest.core.service.SystemParamService; import org.dromara.sqlrest.core.service.SystemParamService;
import org.dromara.sqlrest.core.util.JacksonUtils; import org.dromara.sqlrest.core.util.JacksonUtils;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity; import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
import com.google.common.collect.Lists;
import io.modelcontextprotocol.server.McpSyncServerExchange;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
/** /**
* https://mcp-docs.cn/docs/concepts/tools * https://mcp-docs.cn/docs/concepts/tools
...@@ -118,7 +118,7 @@ public class McpToolCallHandler { ...@@ -118,7 +118,7 @@ public class McpToolCallHandler {
public CallToolResult executeTool(McpSyncServerExchange exchange, Map<String, Object> arguments) { public CallToolResult executeTool(McpSyncServerExchange exchange, Map<String, Object> arguments) {
prepareArgumentsPageSizeParameter(arguments); prepareArgumentsPageSizeParameter(arguments);
try { try {
ResultEntity<Object> resultEntity = apiExecuteService.execute(config, arguments); ResultEntity<Object> resultEntity = apiExecuteService.execute(config, arguments, true);
String json = JacksonUtils.toJsonStr(resultEntity.getData(), config.getResponseFormat()); String json = JacksonUtils.toJsonStr(resultEntity.getData(), config.getResponseFormat());
McpSchema.TextContent content = new McpSchema.TextContent("操作成功,JSON格式的响应数据为:\n " + json); McpSchema.TextContent content = new McpSchema.TextContent("操作成功,JSON格式的响应数据为:\n " + json);
return new McpSchema.CallToolResult(Lists.newArrayList(content), false); return new McpSchema.CallToolResult(Lists.newArrayList(content), false);
......
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>SQLREST工具</title><link href=/static/css/app.b8caeaa64a37025bcd280cd6a618a45a.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.f896ba44da1bad38332d.js></script><script type=text/javascript src=/static/js/vendor.a6ebeac16c85a178c5e7.js></script><script type=text/javascript src=/static/js/app.2c1ec8f3a08d363c1c13.js></script></body></html> <!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>SQLREST工具</title><link href=/static/css/app.72ce71eacf4fdf5259993cb675dccd79.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.7ca5521c43f5be04d72c.js></script><script type=text/javascript src=/static/js/vendor.a6ebeac16c85a178c5e7.js></script><script type=text/javascript src=/static/js/app.2c1ec8f3a08d363c1c13.js></script></body></html>
\ No newline at end of file \ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
!function(e){var n=window.webpackJsonp;window.webpackJsonp=function(r,f,a){for(var o,d,b,i=0,u=[];i<r.length;i++)d=r[i],c[d]&&u.push(c[d][0]),c[d]=0;for(o in f)Object.prototype.hasOwnProperty.call(f,o)&&(e[o]=f[o]);for(n&&n(r,f,a);u.length;)u.shift()();if(a)for(i=0;i<a.length;i++)b=t(t.s=a[i]);return b};var r={},c={28:0};function t(n){if(r[n])return r[n].exports;var c=r[n]={i:n,l:!1,exports:{}};return e[n].call(c.exports,c,c.exports,t),c.l=!0,c.exports}t.e=function(e){var n=c[e];if(0===n)return new Promise(function(e){e()});if(n)return n[2];var r=new Promise(function(r,t){n=c[e]=[r,t]});n[2]=r;var f=document.getElementsByTagName("head")[0],a=document.createElement("script");a.type="text/javascript",a.charset="utf-8",a.async=!0,a.timeout=12e4,t.nc&&a.setAttribute("nonce",t.nc),a.src=t.p+"static/js/"+e+"."+{0:"1e9dbf4280bc4e974d1e",1:"e25df47f04ee43bfc49e",2:"7a542807ad5499534f0b",3:"776d791724a8de12ff9e",4:"f8494b8dd039413f79c8",5:"404ff5302fc6ee181ee9",6:"8f85de06573e2a5f9562",7:"061807fe4716131f26f8",8:"c4a2e9952c298efc080c",9:"313072ac394fc9349d2f",10:"0591dbe3e75f89e4c00e",11:"9ccf6e8ba19ce146e66b",12:"d26d5fe93a45bd5c6eaa",13:"0a3bfc86c8694e34b2b4",14:"b74db4e8e5c2f13b4c43",15:"d8a7cd9843e13fa1b5eb",16:"9a6082d7311beb531ffe",17:"ca3a537c0792f7b8e00f",18:"5096122498e2cfe23bfa",19:"492e3884353940300fa9",20:"7ac0693f49a00ab51b3e",21:"1056a6edefc50b64f16b",22:"0a5f684edcb8df816a5d",23:"93251b045354cc966a59",24:"61c786230b6da7b9ddc7",25:"b0986b0eaecd37184d01"}[e]+".js";var o=setTimeout(d,12e4);function d(){a.onerror=a.onload=null,clearTimeout(o);var n=c[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),c[e]=void 0)}return a.onerror=a.onload=d,f.appendChild(a),r},t.m=e,t.c=r,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="/",t.oe=function(e){throw console.error(e),e}}([]); !function(e){var n=window.webpackJsonp;window.webpackJsonp=function(r,a,f){for(var o,d,b,i=0,u=[];i<r.length;i++)d=r[i],c[d]&&u.push(c[d][0]),c[d]=0;for(o in a)Object.prototype.hasOwnProperty.call(a,o)&&(e[o]=a[o]);for(n&&n(r,a,f);u.length;)u.shift()();if(f)for(i=0;i<f.length;i++)b=t(t.s=f[i]);return b};var r={},c={28:0};function t(n){if(r[n])return r[n].exports;var c=r[n]={i:n,l:!1,exports:{}};return e[n].call(c.exports,c,c.exports,t),c.l=!0,c.exports}t.e=function(e){var n=c[e];if(0===n)return new Promise(function(e){e()});if(n)return n[2];var r=new Promise(function(r,t){n=c[e]=[r,t]});n[2]=r;var a=document.getElementsByTagName("head")[0],f=document.createElement("script");f.type="text/javascript",f.charset="utf-8",f.async=!0,f.timeout=12e4,t.nc&&f.setAttribute("nonce",t.nc),f.src=t.p+"static/js/"+e+"."+{0:"8750cbc69600454da2e0",1:"e25df47f04ee43bfc49e",2:"7a542807ad5499534f0b",3:"776d791724a8de12ff9e",4:"f8494b8dd039413f79c8",5:"404ff5302fc6ee181ee9",6:"8f85de06573e2a5f9562",7:"061807fe4716131f26f8",8:"c4a2e9952c298efc080c",9:"313072ac394fc9349d2f",10:"0591dbe3e75f89e4c00e",11:"9ccf6e8ba19ce146e66b",12:"d26d5fe93a45bd5c6eaa",13:"0a3bfc86c8694e34b2b4",14:"b74db4e8e5c2f13b4c43",15:"d8a7cd9843e13fa1b5eb",16:"9a6082d7311beb531ffe",17:"ca3a537c0792f7b8e00f",18:"5096122498e2cfe23bfa",19:"492e3884353940300fa9",20:"7ac0693f49a00ab51b3e",21:"1056a6edefc50b64f16b",22:"0a5f684edcb8df816a5d",23:"93251b045354cc966a59",24:"61c786230b6da7b9ddc7",25:"b0986b0eaecd37184d01"}[e]+".js";var o=setTimeout(d,12e4);function d(){f.onerror=f.onload=null,clearTimeout(o);var n=c[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),c[e]=void 0)}return f.onerror=f.onload=d,a.appendChild(f),r},t.m=e,t.c=r,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="/",t.oe=function(e){throw console.error(e),e}}([]);
//# sourceMappingURL=manifest.f896ba44da1bad38332d.js.map //# sourceMappingURL=manifest.7ca5521c43f5be04d72c.js.map
\ No newline at end of file \ No newline at end of file
...@@ -11,13 +11,13 @@ package org.dromara.sqlrest.persistence.dao; ...@@ -11,13 +11,13 @@ package org.dromara.sqlrest.persistence.dao;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import org.dromara.sqlrest.common.enums.HttpMethodEnum; import org.dromara.sqlrest.common.enums.HttpMethodEnum;
import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity; import org.dromara.sqlrest.persistence.entity.ApiAssignmentEntity;
import org.dromara.sqlrest.persistence.entity.ModuleAssignmentEntity; import org.dromara.sqlrest.persistence.entity.ModuleAssignmentEntity;
import org.dromara.sqlrest.persistence.mapper.ApiAssignmentMapper; import org.dromara.sqlrest.persistence.mapper.ApiAssignmentMapper;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -62,7 +62,7 @@ public class ApiAssignmentDao { ...@@ -62,7 +62,7 @@ public class ApiAssignmentDao {
return apiAssignmentMapper.selectBatchIds(ids); return apiAssignmentMapper.selectBatchIds(ids);
} }
public List<ModuleAssignmentEntity> getModuleAssignments(){ public List<ModuleAssignmentEntity> getModuleAssignments() {
return apiAssignmentMapper.getModuleAssignments(); return apiAssignmentMapper.getModuleAssignments();
} }
...@@ -102,18 +102,12 @@ public class ApiAssignmentDao { ...@@ -102,18 +102,12 @@ public class ApiAssignmentDao {
} }
public ApiAssignmentEntity getByUk(HttpMethodEnum method, String path) { public ApiAssignmentEntity getByUk(HttpMethodEnum method, String path) {
return getByUk(method, path, true);
}
public ApiAssignmentEntity getByUk(HttpMethodEnum method, String path, boolean withSql) {
QueryWrapper<ApiAssignmentEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<ApiAssignmentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ApiAssignmentEntity::getMethod, method.name()) queryWrapper.lambda().eq(ApiAssignmentEntity::getMethod, method.name())
.eq(ApiAssignmentEntity::getPath, path); .eq(ApiAssignmentEntity::getPath, path);
ApiAssignmentEntity apiConfigEntity = apiAssignmentMapper.selectOne(queryWrapper); ApiAssignmentEntity apiConfigEntity = apiAssignmentMapper.selectOne(queryWrapper);
if (withSql) { if (null != apiConfigEntity) {
if (null != apiConfigEntity) { apiConfigEntity.setContextList(apiContextDao.getByApiConfigId(apiConfigEntity.getId()));
apiConfigEntity.setContextList(apiContextDao.getByApiConfigId(apiConfigEntity.getId()));
}
} }
return apiConfigEntity; return apiConfigEntity;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment