From df63b29908c48905b404cc33a0cabc8d1ae51a3a Mon Sep 17 00:00:00 2001
From: q1279335527 <1279335527@qq.com>
Date: Fri, 11 Apr 2025 21:06:34 +0800
Subject: [PATCH] executor
---
.../apis/client/controller/DataTypeApi.java | 3 +-
.../apis/client/controller/FileApi.java | 8 --
commons/pom.xml | 1 -
...ot.autoconfigure.AutoConfiguration.imports | 1 -
executor/pom.xml | 33 +++++++
.../viewer-executor-core}/pom.xml | 4 +-
.../core/CoreExecutorAutoConfiguration.java | 13 +++
.../executor/core/base/AbstractExecutor.java | 27 ++++++
.../executor/core/base/DataContext.java | 17 ++++
.../core}/constants/TypeConstants.java | 2 +-
.../executor/core}/dao/QueryBodyDao.java | 4 +-
.../executor/core}/dao/QueryParamDao.java | 4 +-
.../executor/core}/entity/QueryBody.java | 2 +-
.../executor/core}/entity/QueryParam.java | 2 +-
.../core/factory/ExecutorManager.java | 48 ++++++++++
.../core/factory/ExecutorRegistry.java | 32 +++++++
.../core}/service/QueryBodyService.java | 4 +-
.../core}/service/QueryBodyServiceImpl.java | 12 +--
.../main/resources/META-INF/spring.factories | 2 +-
...ot.autoconfigure.AutoConfiguration.imports | 1 +
executor/viewer-executor-mybatis/pom.xml | 27 ++++++
.../MybatisExecutorAutoConfiguration.java | 6 +-
.../factory/MybatisTypeQueryExecutor.java | 22 ++++-
.../main/resources/META-INF/spring.factories | 1 +
...ot.autoconfigure.AutoConfiguration.imports | 1 +
.../api/constants/ApiParamTypeConstant.java | 2 +
.../api/controller/BaseApiController.java | 89 +++++++++++++++++++
.../api/controller/EasyQueryController.java | 46 +---------
.../viewer/modules/api/entity/ApiInfo.java | 10 +++
.../viewer/modules/api/entity/ApiParam.java | 3 +-
.../ds/core/service/DsConfigServiceImpl.java | 2 +-
.../core/service/LinkerConfigServiceImpl.java | 2 +-
modules/viewer-modules-step/pom.xml | 8 ++
.../step/executor/SimpleBlockExecutor.java | 60 ++++++++-----
pom.xml | 12 +++
35 files changed, 407 insertions(+), 104 deletions(-)
delete mode 100644 commons/viewer-common-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
create mode 100644 executor/pom.xml
rename {commons/viewer-common-executor => executor/viewer-executor-core}/pom.xml (87%)
create mode 100644 executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/CoreExecutorAutoConfiguration.java
create mode 100644 executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/AbstractExecutor.java
create mode 100644 executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/DataContext.java
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/constants/TypeConstants.java (94%)
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/dao/QueryBodyDao.java (61%)
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/dao/QueryParamDao.java (61%)
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/entity/QueryBody.java (93%)
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/entity/QueryParam.java (87%)
create mode 100644 executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorManager.java
create mode 100644 executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorRegistry.java
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/service/QueryBodyService.java (55%)
rename {modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step => executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core}/service/QueryBodyServiceImpl.java (88%)
rename {commons/viewer-common-executor => executor/viewer-executor-core}/src/main/resources/META-INF/spring.factories (64%)
create mode 100644 executor/viewer-executor-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
create mode 100644 executor/viewer-executor-mybatis/pom.xml
rename commons/viewer-common-executor/src/main/java/xyz/thoughtset/viewer/common/executor/CommonExecutorAutoConfiguration.java => executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/MybatisExecutorAutoConfiguration.java (73%)
rename modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleQueryExecutor.java => executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/factory/MybatisTypeQueryExecutor.java (89%)
create mode 100644 executor/viewer-executor-mybatis/src/main/resources/META-INF/spring.factories
create mode 100644 executor/viewer-executor-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
create mode 100644 modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/BaseApiController.java
diff --git a/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/DataTypeApi.java b/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/DataTypeApi.java
index f41239c..b2982bc 100644
--- a/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/DataTypeApi.java
+++ b/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/DataTypeApi.java
@@ -8,9 +8,8 @@ import xyz.thoughtset.viewer.common.api.controller.BaseController;
import xyz.thoughtset.viewer.common.connector.linker.LinkerHelper;
import xyz.thoughtset.viewer.modules.ds.core.entity.LinkerConfig;
import xyz.thoughtset.viewer.modules.ds.core.service.LinkerConfigService;
-import xyz.thoughtset.viewer.modules.step.constants.TypeConstants;
+import xyz.thoughtset.viewer.executor.core.constants.TypeConstants;
-import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
diff --git a/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/FileApi.java b/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/FileApi.java
index 5556863..980b2eb 100644
--- a/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/FileApi.java
+++ b/apis/viewer-apis-client/src/main/java/xyz/thoughtset/viewer/apis/client/controller/FileApi.java
@@ -6,15 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.thoughtset.viewer.common.api.controller.BaseController;
-import xyz.thoughtset.viewer.common.connector.linker.LinkerHelper;
-import xyz.thoughtset.viewer.modules.ds.core.entity.LinkerConfig;
-import xyz.thoughtset.viewer.modules.ds.core.service.LinkerConfigService;
import xyz.thoughtset.viewer.modules.excel.service.ExportDataInfoService;
-import xyz.thoughtset.viewer.modules.step.constants.TypeConstants;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
@RestController
@RequestMapping("/file/")
diff --git a/commons/pom.xml b/commons/pom.xml
index 12b65ca..995bbd1 100644
--- a/commons/pom.xml
+++ b/commons/pom.xml
@@ -17,7 +17,6 @@
viewer-common-crud
viewer-common-connector
viewer-common-envvar
- viewer-common-executor
diff --git a/commons/viewer-common-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/commons/viewer-common-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
deleted file mode 100644
index 9a4d0f1..0000000
--- a/commons/viewer-common-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ /dev/null
@@ -1 +0,0 @@
-xyz.thoughtset.viewer.common.executor.CommonExecutorAutoConfiguration
\ No newline at end of file
diff --git a/executor/pom.xml b/executor/pom.xml
new file mode 100644
index 0000000..9c65edd
--- /dev/null
+++ b/executor/pom.xml
@@ -0,0 +1,33 @@
+
+
+ 4.0.0
+
+ xyz.thoughtset.viewer
+ Viewer
+ ${revision}
+
+
+ executor
+ pom
+
+ viewer-executor-mybatis
+ viewer-executor-core
+
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+ xyz.thoughtset.viewer
+ viewer-modules-ds-core
+
+
+
+
\ No newline at end of file
diff --git a/commons/viewer-common-executor/pom.xml b/executor/viewer-executor-core/pom.xml
similarity index 87%
rename from commons/viewer-common-executor/pom.xml
rename to executor/viewer-executor-core/pom.xml
index a738e34..3acfa07 100644
--- a/commons/viewer-common-executor/pom.xml
+++ b/executor/viewer-executor-core/pom.xml
@@ -5,11 +5,11 @@
4.0.0
xyz.thoughtset.viewer
- commons
+ executor
${revision}
- viewer-common-executor
+ viewer-executor-core
17
diff --git a/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/CoreExecutorAutoConfiguration.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/CoreExecutorAutoConfiguration.java
new file mode 100644
index 0000000..c45149f
--- /dev/null
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/CoreExecutorAutoConfiguration.java
@@ -0,0 +1,13 @@
+package xyz.thoughtset.viewer.executor.core;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ComponentScan
+@EnableConfigurationProperties
+@MapperScan(basePackages = "xyz.thoughtset.viewer.executor.core.dao")
+public class CoreExecutorAutoConfiguration {
+}
diff --git a/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/AbstractExecutor.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/AbstractExecutor.java
new file mode 100644
index 0000000..20b1f1f
--- /dev/null
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/AbstractExecutor.java
@@ -0,0 +1,27 @@
+package xyz.thoughtset.viewer.executor.core.base;
+
+import lombok.Getter;
+import xyz.thoughtset.viewer.executor.core.entity.QueryBody;
+import xyz.thoughtset.viewer.executor.core.factory.ExecutorRegistry;
+import xyz.thoughtset.viewer.executor.core.service.QueryBodyService;
+
+import java.util.Map;
+
+public abstract class AbstractExecutor {
+ @Getter
+ protected final String supportType;
+ @Getter
+ protected final boolean innerExecutor;
+ protected AbstractExecutor(String supportType, boolean innerExecutor){
+ this.supportType = supportType;
+ this.innerExecutor = innerExecutor;
+ ExecutorRegistry.register(this);
+ }
+
+ public Object execute(QueryBody queryBody, Map param){
+ return exec(queryBody,param);
+ }
+
+ abstract protected Object exec(QueryBody queryBody,Map dataContext);
+
+}
diff --git a/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/DataContext.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/DataContext.java
new file mode 100644
index 0000000..449a377
--- /dev/null
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/base/DataContext.java
@@ -0,0 +1,17 @@
+package xyz.thoughtset.viewer.executor.core.base;
+
+import lombok.Data;
+
+import java.util.HashMap;
+
+@Data
+public class DataContext {
+ private HashMap dataMap;
+ private String nextBodyId;
+
+ public DataContext() {
+ this.dataMap = new HashMap<>();
+ }
+
+
+}
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/constants/TypeConstants.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/constants/TypeConstants.java
similarity index 94%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/constants/TypeConstants.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/constants/TypeConstants.java
index ab0c6cb..135d8b3 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/constants/TypeConstants.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/constants/TypeConstants.java
@@ -1,4 +1,4 @@
-package xyz.thoughtset.viewer.modules.step.constants;
+package xyz.thoughtset.viewer.executor.core.constants;
import com.google.common.collect.ImmutableMap;
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/dao/QueryBodyDao.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/dao/QueryBodyDao.java
similarity index 61%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/dao/QueryBodyDao.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/dao/QueryBodyDao.java
index 66c8a7e..b69e59c 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/dao/QueryBodyDao.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/dao/QueryBodyDao.java
@@ -1,7 +1,7 @@
-package xyz.thoughtset.viewer.modules.step.dao;
+package xyz.thoughtset.viewer.executor.core.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import xyz.thoughtset.viewer.modules.step.entity.QueryBody;
+import xyz.thoughtset.viewer.executor.core.entity.QueryBody;
import org.apache.ibatis.annotations.Mapper;
@Mapper
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/dao/QueryParamDao.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/dao/QueryParamDao.java
similarity index 61%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/dao/QueryParamDao.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/dao/QueryParamDao.java
index 029a911..074625f 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/dao/QueryParamDao.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/dao/QueryParamDao.java
@@ -1,7 +1,7 @@
-package xyz.thoughtset.viewer.modules.step.dao;
+package xyz.thoughtset.viewer.executor.core.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import xyz.thoughtset.viewer.modules.step.entity.QueryParam;
+import xyz.thoughtset.viewer.executor.core.entity.QueryParam;
import org.apache.ibatis.annotations.Mapper;
@Mapper
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/entity/QueryBody.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/entity/QueryBody.java
similarity index 93%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/entity/QueryBody.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/entity/QueryBody.java
index 9f99632..6453cd1 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/entity/QueryBody.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/entity/QueryBody.java
@@ -1,4 +1,4 @@
-package xyz.thoughtset.viewer.modules.step.entity;
+package xyz.thoughtset.viewer.executor.core.entity;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/entity/QueryParam.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/entity/QueryParam.java
similarity index 87%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/entity/QueryParam.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/entity/QueryParam.java
index ca3284c..f44eea7 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/entity/QueryParam.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/entity/QueryParam.java
@@ -1,4 +1,4 @@
-package xyz.thoughtset.viewer.modules.step.entity;
+package xyz.thoughtset.viewer.executor.core.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
diff --git a/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorManager.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorManager.java
new file mode 100644
index 0000000..66348bb
--- /dev/null
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorManager.java
@@ -0,0 +1,48 @@
+package xyz.thoughtset.viewer.executor.core.factory;
+
+import cn.hutool.core.convert.Convert;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import xyz.thoughtset.viewer.executor.core.base.AbstractExecutor;
+import xyz.thoughtset.viewer.executor.core.base.DataContext;
+import xyz.thoughtset.viewer.executor.core.constants.TypeConstants;
+import xyz.thoughtset.viewer.executor.core.entity.QueryBody;
+import xyz.thoughtset.viewer.executor.core.entity.QueryParam;
+import xyz.thoughtset.viewer.executor.core.service.QueryBodyService;
+
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Component
+public class ExecutorManager {
+ @Autowired
+ private QueryBodyService queryBodyService;
+
+ public Object execute(String bodyId, Map tmpParam){
+ QueryBody queryBody = queryBodyService.getById(bodyId);
+ Map queryMap = queryBody.getParams()
+ .stream()
+ .collect(Collectors.toMap(QueryParam::getId, Function.identity(), (existing, replacement) -> existing));
+// QueryParam queryParam = queryMap.get(blockParam.getQpId());
+// tmpParamsMap.put(queryParam.getTitle(),
+// Convert.convert(TypeConstants.TYPE_MAP.get(queryParam.getDataType()),value));
+ Map paramsMap = new HashMap<>();
+ for(Map.Entry entry: queryMap.entrySet()){
+ String key = entry.getKey();
+ QueryParam queryParam = entry.getValue();
+ Object value = tmpParam.get(key);
+ if (Objects.isNull(value)) value = queryParam.getDefaultVal();
+ paramsMap.put(queryParam.getTitle(),
+ Convert.convert(TypeConstants.TYPE_MAP.get(queryParam.getDataType()),value));
+ }
+ AbstractExecutor executor = ExecutorRegistry.findExecutor(queryBody.getDsId());
+ return executor.execute(queryBody,paramsMap);
+ }
+
+}
diff --git a/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorRegistry.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorRegistry.java
new file mode 100644
index 0000000..6d21f8e
--- /dev/null
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/factory/ExecutorRegistry.java
@@ -0,0 +1,32 @@
+package xyz.thoughtset.viewer.executor.core.factory;
+
+import lombok.Getter;
+import xyz.thoughtset.viewer.executor.core.base.AbstractExecutor;
+import xyz.thoughtset.viewer.executor.core.base.DataContext;
+
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+public class ExecutorRegistry {
+ private static AbstractExecutor DEFAULT = null;
+ private static final ConcurrentHashMap Executor_Map = new ConcurrentHashMap<>();
+ @Getter
+ private static final LinkedHashSet Executor_Keys = new LinkedHashSet<>();
+
+ public static void register(AbstractExecutor executor) {
+ if (DEFAULT==null) DEFAULT = executor;
+ Executor_Map.put(executor.getSupportType(), executor);
+ Executor_Keys.add(executor.getSupportType());
+ }
+
+ public static AbstractExecutor findExecutor(String supportType){
+ AbstractExecutor executor = Executor_Map.get(supportType);
+ if (executor == null) {
+ return DEFAULT;
+ }
+ return executor;
+ }
+
+}
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/service/QueryBodyService.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/service/QueryBodyService.java
similarity index 55%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/service/QueryBodyService.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/service/QueryBodyService.java
index dea97d5..fd58d7e 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/service/QueryBodyService.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/service/QueryBodyService.java
@@ -1,8 +1,8 @@
-package xyz.thoughtset.viewer.modules.step.service;
+package xyz.thoughtset.viewer.executor.core.service;
import xyz.thoughtset.viewer.common.crud.core.service.BaseService;
-import xyz.thoughtset.viewer.modules.step.entity.QueryBody;
+import xyz.thoughtset.viewer.executor.core.entity.QueryBody;
public interface QueryBodyService extends BaseService {
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/service/QueryBodyServiceImpl.java b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/service/QueryBodyServiceImpl.java
similarity index 88%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/service/QueryBodyServiceImpl.java
rename to executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/service/QueryBodyServiceImpl.java
index 08c2572..64b62ce 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/service/QueryBodyServiceImpl.java
+++ b/executor/viewer-executor-core/src/main/java/xyz/thoughtset/viewer/executor/core/service/QueryBodyServiceImpl.java
@@ -1,11 +1,11 @@
-package xyz.thoughtset.viewer.modules.step.service;
+package xyz.thoughtset.viewer.executor.core.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import xyz.thoughtset.viewer.common.crud.core.service.BaseServiceImpl;
-import xyz.thoughtset.viewer.modules.step.dao.QueryBodyDao;
-import xyz.thoughtset.viewer.modules.step.dao.QueryParamDao;
-import xyz.thoughtset.viewer.modules.step.entity.QueryBody;
-import xyz.thoughtset.viewer.modules.step.entity.QueryParam;
+import xyz.thoughtset.viewer.executor.core.dao.QueryBodyDao;
+import xyz.thoughtset.viewer.executor.core.dao.QueryParamDao;
+import xyz.thoughtset.viewer.executor.core.entity.QueryBody;
+import xyz.thoughtset.viewer.executor.core.entity.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -17,7 +17,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;
-@Service()
+@Service
@Transactional
public class QueryBodyServiceImpl extends BaseServiceImpl implements QueryBodyService {
diff --git a/commons/viewer-common-executor/src/main/resources/META-INF/spring.factories b/executor/viewer-executor-core/src/main/resources/META-INF/spring.factories
similarity index 64%
rename from commons/viewer-common-executor/src/main/resources/META-INF/spring.factories
rename to executor/viewer-executor-core/src/main/resources/META-INF/spring.factories
index 5efd276..102bf9a 100644
--- a/commons/viewer-common-executor/src/main/resources/META-INF/spring.factories
+++ b/executor/viewer-executor-core/src/main/resources/META-INF/spring.factories
@@ -1 +1 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=xyz.thoughtset.viewer.common.executor
\ No newline at end of file
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=xyz.thoughtset.viewer.executor.core
\ No newline at end of file
diff --git a/executor/viewer-executor-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/executor/viewer-executor-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000..2dee881
--- /dev/null
+++ b/executor/viewer-executor-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+xyz.thoughtset.viewer.executor.core.CoreExecutorAutoConfiguration
\ No newline at end of file
diff --git a/executor/viewer-executor-mybatis/pom.xml b/executor/viewer-executor-mybatis/pom.xml
new file mode 100644
index 0000000..556a6f1
--- /dev/null
+++ b/executor/viewer-executor-mybatis/pom.xml
@@ -0,0 +1,27 @@
+
+
+ 4.0.0
+
+ xyz.thoughtset.viewer
+ executor
+ ${revision}
+
+
+ viewer-executor-mybatis
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ xyz.thoughtset.viewer
+ viewer-executor-core
+
+
+
+
\ No newline at end of file
diff --git a/commons/viewer-common-executor/src/main/java/xyz/thoughtset/viewer/common/executor/CommonExecutorAutoConfiguration.java b/executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/MybatisExecutorAutoConfiguration.java
similarity index 73%
rename from commons/viewer-common-executor/src/main/java/xyz/thoughtset/viewer/common/executor/CommonExecutorAutoConfiguration.java
rename to executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/MybatisExecutorAutoConfiguration.java
index 7aa0b29..a172206 100644
--- a/commons/viewer-common-executor/src/main/java/xyz/thoughtset/viewer/common/executor/CommonExecutorAutoConfiguration.java
+++ b/executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/MybatisExecutorAutoConfiguration.java
@@ -1,4 +1,4 @@
-package xyz.thoughtset.viewer.common.executor;
+package xyz.thoughtset.viewer.executor.mybatis;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
@@ -7,5 +7,5 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
@EnableConfigurationProperties
-public class CommonExecutorAutoConfiguration {
-}
+public class MybatisExecutorAutoConfiguration {
+}
\ No newline at end of file
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleQueryExecutor.java b/executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/factory/MybatisTypeQueryExecutor.java
similarity index 89%
rename from modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleQueryExecutor.java
rename to executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/factory/MybatisTypeQueryExecutor.java
index 7ad91fd..63109da 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleQueryExecutor.java
+++ b/executor/viewer-executor-mybatis/src/main/java/xyz/thoughtset/viewer/executor/mybatis/factory/MybatisTypeQueryExecutor.java
@@ -1,4 +1,4 @@
-package xyz.thoughtset.viewer.modules.step.executor;
+package xyz.thoughtset.viewer.executor.mybatis.factory;
import lombok.SneakyThrows;
import org.apache.ibatis.mapping.BoundSql;
@@ -15,7 +15,12 @@ import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeException;
import org.apache.ibatis.type.TypeHandler;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
+import xyz.thoughtset.viewer.executor.core.base.AbstractExecutor;
+import xyz.thoughtset.viewer.executor.core.base.DataContext;
+import xyz.thoughtset.viewer.executor.core.entity.QueryBody;
+import xyz.thoughtset.viewer.executor.core.service.QueryBodyService;
import xyz.thoughtset.viewer.modules.ds.core.service.DsConfigService;
import javax.sql.DataSource;
@@ -26,15 +31,24 @@ import java.util.List;
import java.util.Map;
@Component
-public class SimpleQueryExecutor {
+public class MybatisTypeQueryExecutor extends AbstractExecutor {
+
+ public MybatisTypeQueryExecutor() {
+ super("MybatisType", true);
+// this.dsConfigService = dsConfigService;
+ }
+
private final Configuration configuration = new Configuration();
@Autowired
private DsConfigService dsConfigService;
- public List doQuery(String sqlText,Object param,String dsId) {
- return doQuery(sqlText,param,dsConfigService.buildDataSource(dsId));
+
+ @Override
+ protected Object exec(QueryBody queryBody, Map param) {
+ return doQuery(queryBody.getQuery(),param,dsConfigService.buildDataSource(queryBody.getDsId()));
}
+
@SneakyThrows
public List doQuery(String sqlText, Object param, DataSource ds) {
XPathParser parser = new XPathParser(sqlText);
diff --git a/executor/viewer-executor-mybatis/src/main/resources/META-INF/spring.factories b/executor/viewer-executor-mybatis/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..eb37a7b
--- /dev/null
+++ b/executor/viewer-executor-mybatis/src/main/resources/META-INF/spring.factories
@@ -0,0 +1 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=xyz.thoughtset.viewer.executor.mybatis
\ No newline at end of file
diff --git a/executor/viewer-executor-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/executor/viewer-executor-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000..54d7e55
--- /dev/null
+++ b/executor/viewer-executor-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+xyz.thoughtset.viewer.executor.mybatis.MybatisExecutorAutoConfiguration
\ No newline at end of file
diff --git a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/constants/ApiParamTypeConstant.java b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/constants/ApiParamTypeConstant.java
index 3bedb18..926ec76 100644
--- a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/constants/ApiParamTypeConstant.java
+++ b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/constants/ApiParamTypeConstant.java
@@ -3,4 +3,6 @@ package xyz.thoughtset.viewer.modules.api.constants;
public class ApiParamTypeConstant {
public static final Integer INPUT = 0;
public static final Integer OUTPUT = 1;
+ public static final Integer INNER = 2;
+
}
diff --git a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/BaseApiController.java b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/BaseApiController.java
new file mode 100644
index 0000000..8ea813e
--- /dev/null
+++ b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/BaseApiController.java
@@ -0,0 +1,89 @@
+package xyz.thoughtset.viewer.modules.api.controller;
+
+
+import cn.idev.excel.ExcelWriter;
+import cn.idev.excel.FastExcel;
+import cn.idev.excel.write.metadata.WriteSheet;
+import jakarta.servlet.http.HttpServletResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.*;
+import xyz.thoughtset.viewer.common.api.controller.BaseController;
+import xyz.thoughtset.viewer.common.core.constants.FolderNameConstant;
+import xyz.thoughtset.viewer.modules.api.constants.ApiParamTypeConstant;
+import xyz.thoughtset.viewer.modules.api.entity.ApiInfo;
+import xyz.thoughtset.viewer.modules.api.entity.ApiParam;
+import xyz.thoughtset.viewer.modules.api.service.ApiInfoService;
+import xyz.thoughtset.viewer.modules.excel.entity.ExportDataInfo;
+import xyz.thoughtset.viewer.modules.excel.service.ExportDataInfoService;
+import xyz.thoughtset.viewer.modules.step.executor.SimpleBlockExecutor;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.*;
+import java.util.stream.Collectors;
+
+
+public class BaseApiController extends BaseController {
+
+ @Autowired
+ protected ApiInfoService apiInfoService;
+ @Autowired
+ protected SimpleBlockExecutor simpleBlockExecutor;
+ @Autowired
+ protected ExportDataInfoService exportDataService;
+
+
+ protected Map doQuery(LinkedHashMap searchMap, ApiInfo apiInfo) {
+ if (apiInfo == null) {
+ throw new NullPointerException("api not found");
+ }
+ Map> apiParamMap = apiInfo.groupParams();
+ Map paramMap = beforeQuery(searchMap, apiInfo,apiParamMap);
+ Map result = simpleBlockExecutor.executeQuery(apiInfo.getId(),paramMap);
+ return afterQuery(result, apiInfo,apiParamMap);
+ }
+
+ protected Map beforeQuery(LinkedHashMap searchMap, ApiInfo apiInfo, Map> apiParamMap) {
+ if (apiInfo == null) {
+ throw new NullPointerException("api not found");
+ }
+ //过滤入参+临时变量
+ Map paramMap = new HashMap<>();
+ List inputParams = apiParamMap.get(ApiParamTypeConstant.INPUT);
+ if(!ObjectUtils.isEmpty(inputParams) && !ObjectUtils.isEmpty(searchMap)){
+ paramMap = new LinkedHashMap<>();
+ for(ApiParam param : inputParams) {
+ String key = param.getTitle();
+ Object paramValue = searchMap.get(key);
+ if (paramValue == null) {
+ paramValue = param.getDefaultVal();
+ }
+ paramMap.put(key, paramValue);
+ }
+ }
+ List innerParams = apiParamMap.get(ApiParamTypeConstant.INNER);
+ if (!ObjectUtils.isEmpty(innerParams)){
+ for (ApiParam param : innerParams) {
+ String key = param.getTitle();
+ Object paramValue = param.getDefaultVal();
+ paramMap.put(key, paramValue);
+ }
+ }
+ return paramMap;
+ }
+ protected Map afterQuery(Map result, ApiInfo apiInfo, Map> apiParamMap) {
+ List resultParams = apiParamMap.get(ApiParamTypeConstant.OUTPUT);
+ if(!ObjectUtils.isEmpty(resultParams)){
+ Map resultMap = new HashMap<>();
+ for (ApiParam resultParam : resultParams) {
+ resultMap.put(resultParam.getTitle(),result.get(resultParam.getTitle()));
+ }
+ return resultMap;
+ }
+ return result;
+ }
+
+
+
+}
diff --git a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/EasyQueryController.java b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/EasyQueryController.java
index c8a6d40..b120caf 100644
--- a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/EasyQueryController.java
+++ b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/controller/EasyQueryController.java
@@ -26,53 +26,15 @@ import java.util.*;
@RestController
@RequestMapping("/eq/")
-public class EasyQueryController extends BaseController {
+public class EasyQueryController extends BaseApiController {
- @Autowired
- private ApiInfoService apiInfoService;
- @Autowired
- private SimpleBlockExecutor simpleBlockExecutor;
- @Autowired
- private ExportDataInfoService exportDataService;
@GetMapping(value = "{subject}")
@ResponseBody
- public Object doQuery(@RequestParam(required = false) LinkedHashMap searchMap
+ public Object query(@RequestParam(required = false) LinkedHashMap searchMap
, @PathVariable("subject") String subject) {
ApiInfo apiInfo = apiInfoService.getById(subject);
- if (apiInfo == null) {
- throw new NullPointerException("api not found");
- }
- List apiParams = apiInfo.getApiParams();
- boolean hasParams = !ObjectUtils.isEmpty(apiParams);
- //过滤入参+临时变量
- Map paramMap = searchMap;
- List resultParams = null;
- if(hasParams){
- paramMap = new LinkedHashMap<>();
- for (ApiParam param : apiParams) {
- if (param.getParamType().equals(ApiParamTypeConstant.INPUT)) {
- paramMap.put(param.getTitle(),searchMap.get(param.getTitle()));
- }else if (ApiParamTypeConstant.OUTPUT.equals(param.getParamType())){
- if (resultParams == null) {
- resultParams = new ArrayList<>();
- }
- resultParams.add(param);
- }else{
- paramMap.put(param.getTitle(), param.getDefaultVal());
- }
- }
- }
-
- Map result = simpleBlockExecutor.executeQuery(subject,paramMap);
- if(!ObjectUtils.isEmpty(resultParams)){
- Map resultMap = new LinkedHashMap<>();
- for (ApiParam resultParam : resultParams) {
- resultMap.put(resultParam.getTitle(),result.get(resultParam.getTitle()));
- }
- return resultMap;
- }
- return result;
+ return doQuery(searchMap, apiInfo);
}
@@ -84,7 +46,7 @@ public class EasyQueryController extends BaseController {
if (exportDataInfo == null) {
throw new NullPointerException("exportData not found");
}
- Map data = (Map) doQuery(searchMap, exportDataInfo.getBodyId());
+ Map data = (Map) query(searchMap, exportDataInfo.getBodyId());
String fileName = exportDataInfo.getFileName();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
diff --git a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiInfo.java b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiInfo.java
index 53bc7d3..daaa81c 100644
--- a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiInfo.java
+++ b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiInfo.java
@@ -2,6 +2,7 @@ package xyz.thoughtset.viewer.modules.api.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
+import org.springframework.util.ObjectUtils;
import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;
import lombok.AllArgsConstructor;
@@ -9,6 +10,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
+import java.util.Map;
@TableName
@Data
@@ -24,5 +26,13 @@ public class ApiInfo extends BaseMeta {
@TableField(exist = false)
private List apiParams;
+ public Map> groupParams(){
+ if (ObjectUtils.isEmpty(apiParams)) {
+ return Map.of();
+ }
+ return apiParams.parallelStream()
+ .collect(java.util.stream.Collectors.groupingBy(ApiParam::getParamType));
+ }
+
}
diff --git a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiParam.java b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiParam.java
index 55f3be8..f523eca 100644
--- a/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiParam.java
+++ b/modules/viewer-modules-api/src/main/java/xyz/thoughtset/viewer/modules/api/entity/ApiParam.java
@@ -5,6 +5,7 @@ import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
+import xyz.thoughtset.viewer.modules.api.constants.ApiParamTypeConstant;
@TableName
@Data
@@ -14,6 +15,6 @@ public class ApiParam extends BaseMeta {
private String dataType;
private String defaultVal;
private String dataExp;
- private Integer paramType;
+ private Integer paramType = ApiParamTypeConstant.INNER;
}
diff --git a/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/DsConfigServiceImpl.java b/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/DsConfigServiceImpl.java
index 1b4bb21..b4df07e 100644
--- a/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/DsConfigServiceImpl.java
+++ b/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/DsConfigServiceImpl.java
@@ -14,7 +14,7 @@ import java.util.LinkedHashMap;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
-@Service()
+@Service
@Transactional
public class DsConfigServiceImpl extends BaseServiceImpl implements DsConfigService {
private ConcurrentHashMap DS_CACHE = new ConcurrentHashMap<>();
diff --git a/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/LinkerConfigServiceImpl.java b/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/LinkerConfigServiceImpl.java
index 50e2c24..ce1a599 100644
--- a/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/LinkerConfigServiceImpl.java
+++ b/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/service/LinkerConfigServiceImpl.java
@@ -10,7 +10,7 @@ import xyz.thoughtset.viewer.modules.ds.core.entity.LinkerConfig;
import java.util.LinkedHashMap;
import java.util.Objects;
-@Service
+@Service("linkerConfigService")
@Transactional
public class LinkerConfigServiceImpl extends BaseServiceImpl implements LinkerConfigService{
diff --git a/modules/viewer-modules-step/pom.xml b/modules/viewer-modules-step/pom.xml
index 7fd9f83..6817d32 100644
--- a/modules/viewer-modules-step/pom.xml
+++ b/modules/viewer-modules-step/pom.xml
@@ -22,6 +22,14 @@
xyz.thoughtset.viewer
viewer-modules-ds-core
+
+
+
+
+
+ xyz.thoughtset.viewer
+ viewer-executor-mybatis
+
\ No newline at end of file
diff --git a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleBlockExecutor.java b/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleBlockExecutor.java
index d1ea377..5f1638c 100644
--- a/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleBlockExecutor.java
+++ b/modules/viewer-modules-step/src/main/java/xyz/thoughtset/viewer/modules/step/executor/SimpleBlockExecutor.java
@@ -1,13 +1,5 @@
package xyz.thoughtset.viewer.modules.step.executor;
-import cn.hutool.core.convert.Convert;
-import xyz.thoughtset.viewer.modules.step.constants.TypeConstants;
-import xyz.thoughtset.viewer.modules.step.entity.BlockParam;
-import xyz.thoughtset.viewer.modules.step.entity.QueryBlock;
-import xyz.thoughtset.viewer.modules.step.entity.QueryBody;
-import xyz.thoughtset.viewer.modules.step.entity.QueryParam;
-import xyz.thoughtset.viewer.modules.step.service.QueryBlockService;
-import xyz.thoughtset.viewer.modules.step.service.QueryBodyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -15,10 +7,15 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
+import xyz.thoughtset.viewer.executor.core.factory.ExecutorManager;
+import xyz.thoughtset.viewer.modules.step.entity.BlockParam;
+import xyz.thoughtset.viewer.modules.step.entity.QueryBlock;
+import xyz.thoughtset.viewer.modules.step.service.QueryBlockService;
-import java.util.*;
-import java.util.function.Function;
-import java.util.stream.Collectors;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
@Component
public class SimpleBlockExecutor {
@@ -27,9 +24,8 @@ public class SimpleBlockExecutor {
@Autowired
private QueryBlockService queryBlockService;
@Autowired
- private QueryBodyService queryBodyService;
- @Autowired
- private SimpleQueryExecutor simpleQueryExecutor;
+ private ExecutorManager executorManager;
+
public Map executeQuery(String apiId,Map params){
Map contentMap = new HashMap(params);
@@ -45,16 +41,38 @@ public class SimpleBlockExecutor {
return contentMap;
}
+// private List blockQuery(QueryBlock block,Map contentMap){
+// QueryBody queryBody = queryBodyService.getById(block.getBodyId());
+// Map tmpParamsMap = new HashMap();
+// List blockParams = queryBlockService.blockParams(block.getId());
+// if (Objects.nonNull(blockParams)){
+// StandardEvaluationContext context = new StandardEvaluationContext();
+// context.setVariable("p", contentMap);
+// Map queryMap = queryBody.getParams()
+// .stream()
+// .collect(Collectors.toMap(QueryParam::getId, Function.identity(), (existing, replacement) -> existing));
+// for (BlockParam blockParam : blockParams){
+// if(!StringUtils.hasText(blockParam.getDataExp())){
+// continue;
+// }
+// String exp =blockParam.getDataExp();
+// exp = blockParam.getDataExp().startsWith("['")?exp:"['"+exp;
+// exp = blockParam.getDataExp().endsWith("']")?exp:exp+"']";
+// Object value = parser.parseExpression("#p"+exp).getValue(context);
+// QueryParam queryParam = queryMap.get(blockParam.getQpId());
+// tmpParamsMap.put(queryParam.getTitle(),
+// Convert.convert(TypeConstants.TYPE_MAP.get(queryParam.getDataType()),value));
+// }
+// }
+// return simpleQueryExecutor.doQuery(queryBody.getQuery(),tmpParamsMap,queryBody.getDsId());
+// }
+
private List blockQuery(QueryBlock block,Map contentMap){
- QueryBody queryBody = queryBodyService.getById(block.getBodyId());
Map tmpParamsMap = new HashMap();
List blockParams = queryBlockService.blockParams(block.getId());
if (Objects.nonNull(blockParams)){
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("p", contentMap);
- Map queryMap = queryBody.getParams()
- .stream()
- .collect(Collectors.toMap(QueryParam::getId, Function.identity(), (existing, replacement) -> existing));
for (BlockParam blockParam : blockParams){
if(!StringUtils.hasText(blockParam.getDataExp())){
continue;
@@ -63,12 +81,10 @@ public class SimpleBlockExecutor {
exp = blockParam.getDataExp().startsWith("['")?exp:"['"+exp;
exp = blockParam.getDataExp().endsWith("']")?exp:exp+"']";
Object value = parser.parseExpression("#p"+exp).getValue(context);
- QueryParam queryParam = queryMap.get(blockParam.getQpId());
- tmpParamsMap.put(queryParam.getTitle(),
- Convert.convert(TypeConstants.TYPE_MAP.get(queryParam.getDataType()),value));
+ tmpParamsMap.put(blockParam.getQpId(),value);
}
}
- return simpleQueryExecutor.doQuery(queryBody.getQuery(),tmpParamsMap,queryBody.getDsId());
+ return (List) executorManager.execute(block.getBodyId(),tmpParamsMap);
}
diff --git a/pom.xml b/pom.xml
index bf67d1a..63ba05d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,6 +27,7 @@
apis
commons
modules
+ executor
@@ -164,6 +165,11 @@
viewer-common-crud-api
${revision}
+
+ xyz.thoughtset.viewer
+ viewer-executor-core
+ ${revision}
+
xyz.thoughtset.viewer
viewer-modules-ds-core
@@ -209,6 +215,12 @@
viewer-common-envvar
${revision}
+
+
+ xyz.thoughtset.viewer
+ viewer-executor-mybatis
+ ${revision}
+
--
Gitee