diff --git a/README.md b/README.md
index c01d8699084f73e8bc1940a168fe9a7f059f8470..17618a8e083c6acda83be49731d34950d4ba58d1 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,7 @@
## 🚀 项目简介
-
-Viewer 是一个基于SpringBoot的**零代码API开发平台**,开发者只需通过可视化界面编写MyBatis风格的标准SQL语句,即可快速生成完整的HTTP RESTful API接口,无需编写任何Java业务代码。
+Viewer 是一款基于SpringBoot构建的API敏捷开发平台,突破传统编码范式,提供从SQL到API的一站式数据服务能力。通过可视化SQL工作台,开发者无需编写Java代码即可发布标准RESTful接口,针对查询、大屏场景提供快速迭代方案,助力企业快速构建高性能数据决策系统。
## ✨ 核心特性
@@ -16,7 +15,7 @@ Viewer 是一个基于SpringBoot的**零代码API开发平台**,开发者只
- **MyBatis SQL支持**:直接使用熟悉的SQL语法开发接口
- **可视化操作**:通过Web界面完成API开发全流程
- **自动生成**:根据SQL自动生成Swagger文档和参数校验
-- **多数据源**:支持MySQL/Oracle/PostgreSQL等主流数据库
+- **多数据源**:支持MySQL/Oracle/PostgreSQL等主流数据库,在一次请求中可跨数据源查询
- **高性能**:基于SpringBoot的轻量级架构
- **实时生效**:支持动态创建、修改API;动态创建、修改数据源。热部署全程无感。
diff --git a/commons/pom.xml b/commons/pom.xml
index 995bbd15c33b2c0d5c9ab47b0a93dcdaebd84b0c..8c106d3a743265614390fad7f81b24aa8243abcb 100644
--- a/commons/pom.xml
+++ b/commons/pom.xml
@@ -17,6 +17,7 @@
viewer-common-crud
viewer-common-connector
viewer-common-envvar
+ viewer-common-exc
diff --git a/commons/viewer-common-api/pom.xml b/commons/viewer-common-api/pom.xml
index 435ad01c6f2666e6c1cb7a6c2b4dfaeb6aff2e70..88440ad389ac069d19896aec4a729358414dcdb8 100644
--- a/commons/viewer-common-api/pom.xml
+++ b/commons/viewer-common-api/pom.xml
@@ -22,6 +22,11 @@
xyz.thoughtset.viewer
viewer-common-core
+
+
+ xyz.thoughtset.viewer
+ viewer-common-exc
+
\ No newline at end of file
diff --git a/commons/viewer-common-api/src/main/java/xyz/thoughtset/viewer/common/api/advice/ExceptionAdvice.java b/commons/viewer-common-api/src/main/java/xyz/thoughtset/viewer/common/api/advice/ExceptionAdvice.java
index 4994d0df4dd675c8964bf20b934e5e31fe01abf5..05601fa3d2d521031400afac8742138428e7bde8 100644
--- a/commons/viewer-common-api/src/main/java/xyz/thoughtset/viewer/common/api/advice/ExceptionAdvice.java
+++ b/commons/viewer-common-api/src/main/java/xyz/thoughtset/viewer/common/api/advice/ExceptionAdvice.java
@@ -1,12 +1,17 @@
package xyz.thoughtset.viewer.common.api.advice;
+import org.apache.catalina.core.ApplicationContext;
+import org.springframework.context.ApplicationEventPublisher;
import xyz.thoughtset.viewer.common.api.result.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
+import xyz.thoughtset.viewer.common.exc.event.ExcMsgEvent;
+import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;
+import xyz.thoughtset.viewer.common.exc.service.ExcInfoService;
@Slf4j
//@RestControllerAdvice(basePackageClasses = {
@@ -17,7 +22,18 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
public class ExceptionAdvice {
@Autowired
private ObjectMapper mapper;
+ @Autowired
+ private ExcInfoService excInfoService;
+ @Autowired
+ private ApplicationEventPublisher eventPublisher;
+ @ExceptionHandler({ExecException.class})
+ public Result> handle(ExecException ex) {
+ log.error(ex.toString(), ex);
+ eventPublisher.publishEvent(new ExcMsgEvent(this,ex));
+ return Result.failed(ex.getMessage());
+ }
+
@ExceptionHandler({Exception.class})
public Result> handle(Exception ex) {
log.error(ex.toString(), ex);
diff --git a/commons/viewer-common-envvar/pom.xml b/commons/viewer-common-envvar/pom.xml
index 94742b9e138f8c2671e169b14d7cad904ac13315..94738568b7026d677c11ba59b82c3ec635f0b488 100644
--- a/commons/viewer-common-envvar/pom.xml
+++ b/commons/viewer-common-envvar/pom.xml
@@ -17,4 +17,11 @@
UTF-8
+
+
+ xyz.thoughtset.viewer
+ viewer-common-crud-core
+
+
+
\ No newline at end of file
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/constants/EnvVarDataTypeConstant.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/constants/EnvVarDataTypeConstant.java
new file mode 100644
index 0000000000000000000000000000000000000000..845236bf0ba4169bcdea919885c456914fe4f2d3
--- /dev/null
+++ b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/constants/EnvVarDataTypeConstant.java
@@ -0,0 +1,8 @@
+package xyz.thoughtset.viewer.common.envvar.constants;
+
+public class EnvVarDataTypeConstant {
+ public static final Integer OBJ = 0;
+ public static final Integer MAP = 1;
+
+
+}
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/dao/EnvVarsDao.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/dao/EnvVarsDao.java
new file mode 100644
index 0000000000000000000000000000000000000000..de8ec23d69c96ba5a52f7e3c7be21e0484cecb11
--- /dev/null
+++ b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/dao/EnvVarsDao.java
@@ -0,0 +1,10 @@
+package xyz.thoughtset.viewer.common.envvar.dao;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import xyz.thoughtset.viewer.common.envvar.entity.EnvVars;
+
+@Mapper
+public interface EnvVarsDao extends BaseMapper {
+}
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/entity/BaseEnvMeta.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/entity/BaseEnvMeta.java
deleted file mode 100644
index 374af3bd40daf2226ae4172f875168a0977efc4d..0000000000000000000000000000000000000000
--- a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/entity/BaseEnvMeta.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package xyz.thoughtset.viewer.common.envvar.entity;
-
-public class BaseEnvMeta {
-
-
-
-}
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/entity/EnvVars.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/entity/EnvVars.java
new file mode 100644
index 0000000000000000000000000000000000000000..efdb836df6e30ab89f08ea2aa12b9b7c629bdeef
--- /dev/null
+++ b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/entity/EnvVars.java
@@ -0,0 +1,22 @@
+package xyz.thoughtset.viewer.common.envvar.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
+import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;
+
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+@TableName
+@ApiCRUDPower(insert = false,update = false,list = true)
+public class EnvVars extends BaseMeta {
+ protected String type;
+ protected String topic;
+ protected String payload;
+
+
+}
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/factory/EnvPropSignFactory.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/factory/EnvPropSignFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..f87f7c8be87cdcce7e77ddd018b2ad552a7cc02f
--- /dev/null
+++ b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/factory/EnvPropSignFactory.java
@@ -0,0 +1,73 @@
+package xyz.thoughtset.viewer.common.envvar.factory;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.annotation.PostConstruct;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.type.filter.AnnotationTypeFilter;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+import xyz.thoughtset.viewer.common.envvar.annotation.EnvPropSign;
+import xyz.thoughtset.viewer.common.envvar.constants.EnvVarDataTypeConstant;
+import xyz.thoughtset.viewer.common.envvar.entity.EnvVars;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+@Component
+public class EnvPropSignFactory {
+ @Value("${scan.package}")
+ private String scanPackage;
+ @Autowired
+ protected ObjectMapper objectMapper;
+ @Autowired
+ protected ApplicationContext applicationContext;
+
+ private Map signMap = new HashMap<>();
+
+ @PostConstruct
+ public void init() {
+ // 创建扫描器,false 表示不检查父类
+ ClassPathScanningCandidateComponentProvider scanner =
+ new ClassPathScanningCandidateComponentProvider(false);
+ scanner.addIncludeFilter(new AnnotationTypeFilter(EnvPropSign.class));
+ // 扫描指定包
+ Set beanDefinitions = scanner.findCandidateComponents(scanPackage);
+ for (BeanDefinition beanDefinition : beanDefinitions) {
+ try {
+ Class> clazz = Class.forName(beanDefinition.getBeanClassName());
+ String key = StringUtils.uncapitalize(clazz.getSimpleName());
+ signMap.put(key,clazz);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public Class getSignType(String key) {
+ return signMap.get(key);
+ }
+
+ public EnvPropSign getSignInfo(String key) {
+ return (EnvPropSign) signMap.get(key).getAnnotation(EnvPropSign.class);
+ }
+
+ public Object getTargetData(String key,Object payload) {
+ Class clazz = getSignType(key);
+ return objectMapper.convertValue(payload,clazz);
+ }
+
+ public Object loadData(EnvVars data) {
+ if (!(EnvVarDataTypeConstant.OBJ.equals(data.getType()))) {
+ return data.getPayload();
+ }
+ return objectMapper.convertValue(data.getPayload(),getSignType(data.getTopic()));
+ }
+
+
+
+}
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/service/EnvVarsService.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/service/EnvVarsService.java
new file mode 100644
index 0000000000000000000000000000000000000000..a2bde5c44672be23d5948aca9e494f396debd13b
--- /dev/null
+++ b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/service/EnvVarsService.java
@@ -0,0 +1,12 @@
+package xyz.thoughtset.viewer.common.envvar.service;
+
+
+import xyz.thoughtset.viewer.common.crud.core.service.BaseService;
+import xyz.thoughtset.viewer.common.envvar.entity.EnvVars;
+
+public interface EnvVarsService extends BaseService {
+
+ Object loadData(String varId);
+ T loadSingleData(Class tarType);
+
+}
diff --git a/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/service/EnvVarsServiceImpl.java b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/service/EnvVarsServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec6072819cc3a899d12ce0e7bf23783de2123bfb
--- /dev/null
+++ b/commons/viewer-common-envvar/src/main/java/xyz/thoughtset/viewer/common/envvar/service/EnvVarsServiceImpl.java
@@ -0,0 +1,52 @@
+package xyz.thoughtset.viewer.common.envvar.service;
+
+import lombok.SneakyThrows;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import xyz.thoughtset.viewer.common.crud.core.service.BaseServiceImpl;
+import xyz.thoughtset.viewer.common.envvar.constants.EnvVarDataTypeConstant;
+import xyz.thoughtset.viewer.common.envvar.dao.EnvVarsDao;
+import xyz.thoughtset.viewer.common.envvar.entity.EnvVars;
+import xyz.thoughtset.viewer.common.envvar.factory.EnvPropSignFactory;
+
+import java.util.LinkedHashMap;
+
+@Service
+@Transactional
+public class EnvVarsServiceImpl extends BaseServiceImpl implements EnvVarsService {
+ private static final String TARGET_DATA_KEY = "payload";
+
+ @Autowired
+ private EnvPropSignFactory envSignFactory;
+
+ @SneakyThrows
+ @Override
+ public Object saveData(LinkedHashMap baseMap) {
+ Object targetData = baseMap.remove(TARGET_DATA_KEY);
+ EnvVars data = convertValue(baseMap);
+ String topic = data.getTopic();
+ if (EnvVarDataTypeConstant.OBJ.equals(data.getType())) {
+ targetData = envSignFactory.getTargetData(topic, targetData);
+ }
+ data.setPayload(mapper.writeValueAsString(targetData));
+ if (envSignFactory.getSignInfo(topic).single()){
+ data.setId(topic);
+ }
+ saveOrUpdate(data);
+ return data;
+ }
+
+ @Override
+ public Object loadData(String varId) {
+ EnvVars vars = baseMapper.selectById(varId);
+ return envSignFactory.loadData(vars);
+ }
+
+ @Override
+ public T loadSingleData(Class tarType) {
+// QueryWrapper queryWrapper = new QueryWrapper<>();
+// queryWrapper.lambda().eq(EnvVars::getTopic,tarType.getSimpleName());
+ return (T) loadData(tarType.getSimpleName());
+ }
+}
diff --git a/commons/viewer-common-exc/pom.xml b/commons/viewer-common-exc/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c50ae627b738e67b31267e02d116e7a4d97c7978
--- /dev/null
+++ b/commons/viewer-common-exc/pom.xml
@@ -0,0 +1,35 @@
+
+
+ 4.0.0
+
+ xyz.thoughtset.viewer
+ commons
+ ${revision}
+
+
+ viewer-common-exc
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ xyz.thoughtset.viewer
+ viewer-common-core
+
+
+ xyz.thoughtset.viewer
+ viewer-common-crud-core
+
+
+ xyz.thoughtset.viewer
+ viewer-common-envvar
+
+
+
+
\ No newline at end of file
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/CommonExcAutoConfiguration.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/CommonExcAutoConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..5b8448acd4767b0a0a56e74dcfa27f04c426b2c4
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/CommonExcAutoConfiguration.java
@@ -0,0 +1,11 @@
+package xyz.thoughtset.viewer.common.exc;
+
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ComponentScan
+@EnableConfigurationProperties
+public class CommonExcAutoConfiguration {
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/config/ExcInfoExConfig.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/config/ExcInfoExConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..eba88b48616d124d5fb8bc12e48542938a9b436f
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/config/ExcInfoExConfig.java
@@ -0,0 +1,43 @@
+package xyz.thoughtset.viewer.common.exc.config;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import xyz.thoughtset.viewer.common.exc.constant.ExcInfoExConstant;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+public class ExcInfoExConfig {
+
+ @Bean
+ @ConditionalOnMissingBean(name = ExcInfoExConstant.EX_NAME)
+ public Executor saveExcExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ executor.setCorePoolSize(2);
+ executor.setMaxPoolSize(16);
+ executor.setQueueCapacity(128);
+ executor.setKeepAliveSeconds(60);
+ executor.setThreadNamePrefix(ExcInfoExConstant.EX_NAME+"-"); // 线程名称前缀
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+ executor.initialize();
+ return executor;
+ }
+
+// @Bean
+// @ConditionalOnMissingBean(name = ExcInfoExConstant.EX_CHECK)
+// public Executor countFilePageExecutor() {
+// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+// executor.setCorePoolSize(1);
+// executor.setMaxPoolSize(16);
+// executor.setQueueCapacity(128);
+// executor.setKeepAliveSeconds(60);
+// executor.setThreadNamePrefix(ExcInfoExConstant.EX_CHECK+"-"); // 线程名称前缀
+// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+// executor.initialize();
+// return executor;
+// }
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/constant/ExcInfoExConstant.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/constant/ExcInfoExConstant.java
new file mode 100644
index 0000000000000000000000000000000000000000..eca6a3005809c24ced5b59b9ef985483af7331cf
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/constant/ExcInfoExConstant.java
@@ -0,0 +1,7 @@
+package xyz.thoughtset.viewer.common.exc.constant;
+
+public class ExcInfoExConstant {
+ public static final String EX_NAME = "EXC_EX_NAME";
+ public static final String EX_CHECK = "EXC_EX_CHECK";
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/dao/ExcInfoDao.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/dao/ExcInfoDao.java
new file mode 100644
index 0000000000000000000000000000000000000000..b4b05f32a271697474d2169a0510491e1c470b2f
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/dao/ExcInfoDao.java
@@ -0,0 +1,10 @@
+package xyz.thoughtset.viewer.common.exc.dao;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import xyz.thoughtset.viewer.common.exc.entity.ExcInfo;
+
+@Mapper
+public interface ExcInfoDao extends BaseMapper {
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/entity/ExcEnvVar.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/entity/ExcEnvVar.java
new file mode 100644
index 0000000000000000000000000000000000000000..84981bc8e560f648d774a50e17ce3e46d0a205ee
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/entity/ExcEnvVar.java
@@ -0,0 +1,25 @@
+package xyz.thoughtset.viewer.common.exc.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
+import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;
+import xyz.thoughtset.viewer.common.envvar.annotation.EnvPropSign;
+import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+@EnvPropSign(single = true)
+public class ExcEnvVar {
+ protected Integer saveNums = -1;//异常条数保存条数
+ protected Integer saveTimes = -1;//异常条数保存时长
+ protected boolean useSave = true;
+
+ public boolean needCheck() {
+ return !(-1 == saveNums && -1 == saveTimes);
+ }
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/entity/ExcInfo.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/entity/ExcInfo.java
new file mode 100644
index 0000000000000000000000000000000000000000..054681adf59a779340b023846a91789168171c69
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/entity/ExcInfo.java
@@ -0,0 +1,35 @@
+package xyz.thoughtset.viewer.common.exc.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
+import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;
+import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;
+
+import java.util.Map;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+@TableName
+@ApiCRUDPower(searchOnly = true,list = true)
+public class ExcInfo extends BaseMeta {
+ protected String funId;
+ protected String errMsg;
+ protected String apiId;
+ protected String blockId;
+ protected String paramStr;
+// protected Integer
+
+ public ExcInfo(Exception exc){
+ this.errMsg = exc.getMessage();
+ }
+
+ public static ExecException buildAndThrowExc(Exception exc, Map params){
+ ExcInfo e = new ExcInfo(exc);
+ return new ExecException(e);
+ }
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/event/ExcMsgEvent.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/event/ExcMsgEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..5037ab35bdf6f97d2d52f113ec2dc01d3bac5693
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/event/ExcMsgEvent.java
@@ -0,0 +1,17 @@
+package xyz.thoughtset.viewer.common.exc.event;
+
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+import xyz.thoughtset.viewer.common.exc.entity.ExcInfo;
+import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;
+
+@Getter
+public class ExcMsgEvent extends ApplicationEvent {
+ private ExcInfo excInfo;
+
+ public ExcMsgEvent(Object source, ExecException exception) {
+ super(source);
+ this.excInfo = exception.getExcInfo();
+ }
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/exceptions/ExecException.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/exceptions/ExecException.java
new file mode 100644
index 0000000000000000000000000000000000000000..ef8c167f5c07e3a8d75df777e7427df7eb0d8f5d
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/exceptions/ExecException.java
@@ -0,0 +1,25 @@
+package xyz.thoughtset.viewer.common.exc.exceptions;
+
+import lombok.Data;
+import xyz.thoughtset.viewer.common.exc.entity.ExcInfo;
+
+@Data
+public class ExecException extends RuntimeException {
+ protected ExcInfo excInfo;
+
+
+ public ExecException(ExcInfo exc){
+ super(exc.getErrMsg());
+ this.excInfo = exc;
+ }
+
+ public ExecException addApiId(String apiId){
+ excInfo.setApiId(apiId);
+ return this;
+ }
+ public ExecException addBlockId(String blockId){
+ excInfo.setBlockId(blockId);
+ return this;
+ }
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/listener/ExcInfoListener.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/listener/ExcInfoListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..b78f34fc41c7130b0b3b1b04ca8927c24f0f11f3
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/listener/ExcInfoListener.java
@@ -0,0 +1,32 @@
+package xyz.thoughtset.viewer.common.exc.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+import xyz.thoughtset.viewer.common.envvar.service.EnvVarsService;
+import xyz.thoughtset.viewer.common.exc.constant.ExcInfoExConstant;
+import xyz.thoughtset.viewer.common.exc.entity.ExcEnvVar;
+import xyz.thoughtset.viewer.common.exc.event.ExcMsgEvent;
+import xyz.thoughtset.viewer.common.exc.service.ExcInfoService;
+
+@Slf4j
+@Component
+public class ExcInfoListener implements ApplicationListener {
+ @Autowired
+ private ExcInfoService excInfoService;
+ @Autowired
+ private EnvVarsService envVarsService;
+
+
+ @Async(ExcInfoExConstant.EX_NAME)
+ @Override
+ public void onApplicationEvent(ExcMsgEvent event) {
+ ExcEnvVar envVar = envVarsService.loadSingleData(ExcEnvVar.class);
+ if (!envVar.isUseSave()) {return;}
+ excInfoService.save(event.getExcInfo());
+ if (!envVar.needCheck()) {return;}
+ }
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/service/ExcInfoService.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/service/ExcInfoService.java
new file mode 100644
index 0000000000000000000000000000000000000000..76efd84ca519bfee20f7e69372f5bce176535a2a
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/service/ExcInfoService.java
@@ -0,0 +1,9 @@
+package xyz.thoughtset.viewer.common.exc.service;
+
+
+import xyz.thoughtset.viewer.common.crud.core.service.BaseService;
+import xyz.thoughtset.viewer.common.exc.entity.ExcInfo;
+
+public interface ExcInfoService extends BaseService {
+
+}
diff --git a/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/service/ExcInfoServiceImpl.java b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/service/ExcInfoServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..670077a1cfc8d59f76dec94e380e2c9032837dac
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/java/xyz/thoughtset/viewer/common/exc/service/ExcInfoServiceImpl.java
@@ -0,0 +1,17 @@
+package xyz.thoughtset.viewer.common.exc.service;
+
+import lombok.SneakyThrows;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import xyz.thoughtset.viewer.common.crud.core.service.BaseServiceImpl;
+import xyz.thoughtset.viewer.common.exc.dao.ExcInfoDao;
+import xyz.thoughtset.viewer.common.exc.entity.ExcInfo;
+
+import java.util.LinkedHashMap;
+
+@Service
+public class ExcInfoServiceImpl extends BaseServiceImpl implements ExcInfoService {
+
+
+}
diff --git a/commons/viewer-common-exc/src/main/resources/META-INF/spring.factories b/commons/viewer-common-exc/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000000000000000000000000000000000000..87a92842b9597d9b646902f9815be3352227e7fa
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/resources/META-INF/spring.factories
@@ -0,0 +1 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=xyz.thoughtset.viewer.common.exc
\ No newline at end of file
diff --git a/commons/viewer-common-exc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/commons/viewer-common-exc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000000000000000000000000000000000000..57aed7b48385f9e20a1d2ca771b563790bddc1a5
--- /dev/null
+++ b/commons/viewer-common-exc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+xyz.thoughtset.viewer.common.exc.CommonExcAutoConfiguration
\ No newline at end of file
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
index 449a377aa3e981cff631885b7508eaa4e1dc3139..4a4ba49e37a00ea92f61d524c85043ab2f253365 100644
--- 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
@@ -7,7 +7,9 @@ import java.util.HashMap;
@Data
public class DataContext {
private HashMap dataMap;
- private String nextBodyId;
+ private String bodyId;
+ private String apiId;
+ private String funId;
public DataContext() {
this.dataMap = new HashMap<>();
diff --git a/modules/pom.xml b/modules/pom.xml
index 33dbba3761be01d2e771504397f533c58ea71995..84f322af79fdb18e92c5177e7c3fb83540a1c69a 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -34,6 +34,11 @@
xyz.thoughtset.viewer
viewer-common-crud-core
+
+
+ xyz.thoughtset.viewer
+ viewer-common-exc
+
\ No newline at end of file
diff --git a/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/factory/ExecutorManager.java b/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/factory/ExecutorManager.java
index 6ba51d024a31977ddd343031c67c52509bfcfd6a..6fae2fa2a3af750ccb9404f7073a067281faf368 100644
--- a/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/factory/ExecutorManager.java
+++ b/modules/viewer-modules-ds/viewer-modules-ds-core/src/main/java/xyz/thoughtset/viewer/modules/ds/core/factory/ExecutorManager.java
@@ -8,6 +8,8 @@ import xyz.thoughtset.viewer.common.connector.entity.bo.Linker;
import xyz.thoughtset.viewer.common.connector.linker.ConnBuilder;
import xyz.thoughtset.viewer.common.connector.linker.LinkerBuilder;
import xyz.thoughtset.viewer.common.connector.linker.LinkerHelper;
+import xyz.thoughtset.viewer.common.exc.entity.ExcInfo;
+import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;
import xyz.thoughtset.viewer.executor.core.base.AbstractExecutor;
import xyz.thoughtset.viewer.executor.core.base.DataContext;
import xyz.thoughtset.viewer.executor.core.constants.TypeConstants;
@@ -55,7 +57,17 @@ public class ExecutorManager {
DsConfig dsConfig = dsConfigDao.selectById(queryBody.getDsId());
ConnBuilder connBuilder = connectFactory.findConnBuilder(dsConfig);
AbstractExecutor executor = ExecutorRegistry.findExecutor(connBuilder.getDataLinker().getLinkerType());
- return executor.execute(queryBody,paramsMap);
+ try{
+ return executor.execute(queryBody,paramsMap);
+ }catch (ExecException e){
+ throw e;
+ }catch (Exception e){
+ ExecException exc = ExcInfo.buildAndThrowExc(e,paramsMap);
+ ExcInfo excInfo = exc.getExcInfo();
+ excInfo.setFunId(bodyId);
+ throw exc;
+ }
+
}
}
diff --git a/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/ModuleSettingAutoConfiguration.java b/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/ModuleSettingAutoConfiguration.java
index fad95ca87d9d387e0dae3b6f9b18a94ceef99e41..2116c2af36b460014eef9eb53f6adc3a1ffbe4d8 100644
--- a/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/ModuleSettingAutoConfiguration.java
+++ b/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/ModuleSettingAutoConfiguration.java
@@ -8,6 +8,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
@EnableConfigurationProperties
-@MapperScan(basePackages = "xyz.thoughtset.viewer.modules.setting")
+//@MapperScan(basePackages = "xyz.thoughtset.viewer.modules.setting")
public class ModuleSettingAutoConfiguration {
}
diff --git a/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/service/EnvVarsServiceImpl.java b/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/service/EnvVarsServiceImpl.java
index 19097663251ca3bd4db36f1f48dbae1f2dc9c67a..b212c3f7890cfe343edb436415111c930bec9730 100644
--- a/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/service/EnvVarsServiceImpl.java
+++ b/modules/viewer-modules-setting/src/main/java/xyz/thoughtset/viewer/modules/setting/service/EnvVarsServiceImpl.java
@@ -19,7 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-@Service
+//@Service
@Transactional
public class EnvVarsServiceImpl extends BaseServiceImpl implements EnvVarsService {
private static final String TARGET_DATA_KEY = "payload";
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 0ef8748a5177ac518410fa89bf12d662cfe8bdb9..710bc8cdc932d4577147f13b80eaf6fefb6e136c 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
@@ -7,6 +7,8 @@ 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.common.exc.entity.ExcInfo;
+import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;
import xyz.thoughtset.viewer.modules.ds.core.factory.ExecutorManager;
import xyz.thoughtset.viewer.modules.step.entity.BlockParam;
import xyz.thoughtset.viewer.modules.step.entity.QueryBlock;
@@ -28,7 +30,17 @@ public class SimpleBlockExecutor {
Map contentMap = new HashMap(params);
List blocks = queryBlockService.listByPId(apiId);
for (QueryBlock block : blocks) {
- Object queryResult = blockQuery(block,contentMap);
+ Object queryResult;
+ try{
+ queryResult = blockQuery(block,contentMap);
+ }catch (ExecException e){
+ throw e.addApiId(apiId);
+ }catch (Exception e){
+ ExecException exc = ExcInfo.buildAndThrowExc(e,params);
+ exc.addBlockId(block.getId());
+ exc.addApiId(apiId);
+ throw exc;
+ }
String key = block.getTitle();
Object val = queryResult;
if (block.resultWasSingle() && !ObjectUtils.isEmpty(queryResult)){
diff --git a/pom.xml b/pom.xml
index 9067546740d7ce859484631631e889f16b942a68..c06edd1f6361882818a592866788d8d1cc234c94 100644
--- a/pom.xml
+++ b/pom.xml
@@ -222,6 +222,11 @@
viewer-common-envvar
${revision}
+
+ xyz.thoughtset.viewer
+ viewer-common-exc
+ ${revision}
+
xyz.thoughtset.viewer
viewer-modules-ds-http-core