|
@@ -1,7 +1,7 @@
|
|
|
package com.usoftchina.bi.server.service.dataSource;
|
|
package com.usoftchina.bi.server.service.dataSource;
|
|
|
|
|
|
|
|
|
|
+import com.usoftchina.bi.core.exception.MyException;
|
|
|
import com.usoftchina.bi.core.utils.GetTokenDataUtil;
|
|
import com.usoftchina.bi.core.utils.GetTokenDataUtil;
|
|
|
-import com.usoftchina.bi.core.utils.JsonUtils;
|
|
|
|
|
import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
|
|
import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
|
|
|
import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
|
|
import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
|
|
|
import com.usoftchina.bi.server.dao.user.UserMapper;
|
|
import com.usoftchina.bi.server.dao.user.UserMapper;
|
|
@@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.usoftchina.bi.server.model.bo.BaseToDataInfo;
|
|
import com.usoftchina.bi.server.model.bo.BaseToDataInfo;
|
|
|
import com.usoftchina.bi.server.model.bo.ColumnConfigAndSql;
|
|
import com.usoftchina.bi.server.model.bo.ColumnConfigAndSql;
|
|
|
-import com.usoftchina.bi.server.model.bo.DatabaseConfig;
|
|
|
|
|
import com.usoftchina.bi.server.model.bo.GroupUpdateId;
|
|
import com.usoftchina.bi.server.model.bo.GroupUpdateId;
|
|
|
import com.usoftchina.bi.server.model.po.BaseConfig;
|
|
import com.usoftchina.bi.server.model.po.BaseConfig;
|
|
|
import com.usoftchina.bi.server.model.po.DataConnector;
|
|
import com.usoftchina.bi.server.model.po.DataConnector;
|
|
@@ -20,6 +19,7 @@ import com.usoftchina.bi.core.base.RepEntity;
|
|
|
import com.usoftchina.bi.core.base.TestPage;
|
|
import com.usoftchina.bi.core.base.TestPage;
|
|
|
import com.usoftchina.bi.server.model.vo.configVo.*;
|
|
import com.usoftchina.bi.server.model.vo.configVo.*;
|
|
|
import com.usoftchina.bi.server.model.vo.dataVo.ColumnValuesInfo;
|
|
import com.usoftchina.bi.server.model.vo.dataVo.ColumnValuesInfo;
|
|
|
|
|
+import com.usoftchina.bi.server.model.vo.dataVo.DataSourceCopyInfo;
|
|
|
import com.usoftchina.bi.server.service.chart.GetChartsDataUtilService;
|
|
import com.usoftchina.bi.server.service.chart.GetChartsDataUtilService;
|
|
|
import com.usoftchina.bi.server.service.strategy.StrategysService;
|
|
import com.usoftchina.bi.server.service.strategy.StrategysService;
|
|
|
import com.usoftchina.bi.server.service.chart.ChartsUtilService;
|
|
import com.usoftchina.bi.server.service.chart.ChartsUtilService;
|
|
@@ -30,7 +30,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
|
|
+import org.springframework.dao.DataAccessException;
|
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -57,6 +58,8 @@ public class DataConnectorService {
|
|
|
ChartsUtilService chartsUtilService;
|
|
ChartsUtilService chartsUtilService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
GetChartsDataUtilService getChartsDataUtilService;
|
|
GetChartsDataUtilService getChartsDataUtilService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DataConnectorService.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(DataConnectorService.class);
|
|
|
|
|
|
|
@@ -349,4 +352,51 @@ public class DataConnectorService {
|
|
|
return new RepEntity(RepCode.success, columnValuesInfo);
|
|
return new RepEntity(RepCode.success, columnValuesInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 数据源复制
|
|
|
|
|
+ * @param token
|
|
|
|
|
+ * @param dataSourceCopyInfo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public RepEntity copyDataSource(String token, DataSourceCopyInfo dataSourceCopyInfo){
|
|
|
|
|
+ Map<String, String> resultMap = GetTokenDataUtil.getTokenData(token);
|
|
|
|
|
+ int userId = Integer.parseInt(resultMap.get("id"));
|
|
|
|
|
+ String userName = resultMap.get("name");
|
|
|
|
|
+
|
|
|
|
|
+ int dataSourceId = dataSourceCopyInfo.getDataSourceId(),
|
|
|
|
|
+ dataConnectionId = dataSourceCopyInfo.getDataConnectionId();
|
|
|
|
|
+ DataConnector dataConnector = dataConnectorMapper.getOneData(dataSourceId);
|
|
|
|
|
+ String loadObject = dataConnector.getLoadObject();
|
|
|
|
|
+ //校验SQL语句是否可正确在目标数据库执行
|
|
|
|
|
+ enableCopy(loadObject, dataConnectionId);
|
|
|
|
|
+ //复制数据源,开启事务
|
|
|
|
|
+ dataConnector.setDataName(dataConnector.getDataName() + "_副本");
|
|
|
|
|
+ dataConnector.setCreateBy(userName);
|
|
|
|
|
+ dataConnector.setCreateId(userId);
|
|
|
|
|
+ dataConnector.setDbConId(String.valueOf(dataConnectionId));
|
|
|
|
|
+ dataConnectorMapper.insertDataConnector(dataConnector);
|
|
|
|
|
+ int dataId = dataConnector.getDataId();
|
|
|
|
|
+ return new RepEntity(RepCode.success, dataId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验SQL在新数据连接中是否可以正确执行
|
|
|
|
|
+ * @param loadObject
|
|
|
|
|
+ * @param dataConnectionId
|
|
|
|
|
+ */
|
|
|
|
|
+ private void enableCopy(String loadObject, int dataConnectionId){
|
|
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(String.valueOf(dataConnectionId));
|
|
|
|
|
+ if (!loadObject.toUpperCase().startsWith("SELECT")) {
|
|
|
|
|
+ loadObject = "SELECT * FROM " + loadObject;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.queryForRowSet(loadObject);
|
|
|
|
|
+ } catch (DataAccessException e) {
|
|
|
|
|
+ throw new MyException(e.getCause().getMessage());
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ DynamicDataSourceContextHolder.clearDataSourceType();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|