forked from github/dataease
Merge pull request #9576 from dataease/pr@dev-v2@fix_outer-params
fix(仪表板): 修复默认数据源不兼容外部指定数据源问题
This commit is contained in:
commit
0deb2c50c6
@ -3,6 +3,7 @@ package io.dataease.datasource.manage;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDeEngine;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDeEngineMapper;
|
||||
import io.dataease.datasource.provider.EngineProvider;
|
||||
import io.dataease.datasource.provider.ProviderUtil;
|
||||
@ -21,7 +22,9 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -33,6 +36,9 @@ public class EngineManage {
|
||||
@Resource
|
||||
private CoreDeEngineMapper deEngineMapper;
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper datasourceMapper;
|
||||
|
||||
|
||||
public CoreDeEngine info() throws DEException {
|
||||
List<CoreDeEngine> deEngines = deEngineMapper.selectList(null);
|
||||
@ -89,6 +95,7 @@ public class EngineManage {
|
||||
}
|
||||
|
||||
public void initSimpleEngine() throws Exception {
|
||||
initLocalDataSource();
|
||||
QueryWrapper<CoreDeEngine> queryWrapper = new QueryWrapper<>();
|
||||
if (ModelUtils.isDesktop()) {
|
||||
queryWrapper.eq("type", engineType.h2.name());
|
||||
@ -147,4 +154,39 @@ public class EngineManage {
|
||||
return alias;
|
||||
}
|
||||
}
|
||||
|
||||
public void initLocalDataSource(){
|
||||
QueryWrapper<CoreDatasource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id",985188400292302848L);
|
||||
if(!datasourceMapper.exists(queryWrapper) && !ModelUtils.isDesktop()){
|
||||
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)\\?(.*)");
|
||||
Matcher matcher = WITH_SQL_FRAGMENT.matcher(env.getProperty("spring.datasource.url"));
|
||||
if (!matcher.find()) {
|
||||
return;
|
||||
}
|
||||
Map configuration = new HashMap<>();
|
||||
configuration.put("dataBase",matcher.group(3));
|
||||
configuration.put("username",env.getProperty("spring.datasource.username"));
|
||||
configuration.put("password",env.getProperty("spring.datasource.password"));
|
||||
configuration.put("host",matcher.group(1));
|
||||
configuration.put("port",Integer.valueOf(matcher.group(2)));
|
||||
configuration.put("extraParams","");
|
||||
|
||||
CoreDatasource initDatasource = new CoreDatasource();
|
||||
initDatasource.setId(985188400292302848L);
|
||||
initDatasource.setName("Demo");
|
||||
initDatasource.setType("mysql");
|
||||
initDatasource.setPid(0L);
|
||||
initDatasource.setConfiguration(JsonUtil.toJSONString(configuration).toString());
|
||||
initDatasource.setCreateTime(System.currentTimeMillis());
|
||||
initDatasource.setUpdateTime(System.currentTimeMillis());
|
||||
initDatasource.setCreateBy("1");
|
||||
initDatasource.setUpdateBy(1L);
|
||||
initDatasource.setStatus("success");
|
||||
initDatasource.setTaskStatus("WaitingForExecution");
|
||||
datasourceMapper.deleteById(985188400292302848L);
|
||||
datasourceMapper.insert(initDatasource);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ set
|
||||
where a.id = b.id and a.type = 'table-pivot';
|
||||
|
||||
|
||||
INSERT INTO `core_datasource` (`id`, `name`, `description`, `type`, `pid`, `edit_type`, `configuration`, `create_time`, `update_time`, `update_by`, `create_by`, `status`, `qrtz_instance`, `task_status`) VALUES (985188400292302848, 'Demo', '', 'mysql', 0, NULL, '{\"dataBase\":\"dataease\",\"extraParams\":\"\",\"username\":\"root\",\"password\":\"Password123@mysql\",\"host\":\"mysql-de\",\"authMethod\":\"\",\"port\":3306,\"initialPoolSize\":5,\"minPoolSize\":5,\"maxPoolSize\":5,\"queryTimeout\":30}', 1715053684176, 1715100309074, 1, '1', 'Success', NULL, 'WaitingForExecution');
|
||||
INSERT INTO `core_dataset_table` (`id`, `name`, `table_name`, `datasource_id`, `dataset_group_id`, `type`, `info`, `sql_variable_details`) VALUES (7193457660727922688, NULL, 'demo_tea_material', 985188400292302848, 985189703189925888, 'db', '{\"table\":\"demo_tea_material\",\"sql\":\"\"}', NULL);
|
||||
INSERT INTO `core_dataset_table` (`id`, `name`, `table_name`, `datasource_id`, `dataset_group_id`, `type`, `info`, `sql_variable_details`) VALUES (7193537020143079424, NULL, 'demo_tea_order', 985188400292302848, 985189053949415424, 'db', '{\"table\":\"demo_tea_order\",\"sql\":\"\"}', NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user