提交 40598b84 authored 作者: taojinlong's avatar taojinlong

fix: 拋出数据源链接异常

上级 5632153f
......@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -73,14 +74,18 @@ public class DataSetTableFieldController {
@ApiOperation("值枚举")
@PostMapping("fieldValues/{fieldId}")
public List<Object> fieldValues(@PathVariable String fieldId) {
public List<Object> fieldValues(@PathVariable String fieldId) throws Exception{
return dataSetFieldService.fieldValues(fieldId);
}
@ApiOperation("多字段值枚举")
@PostMapping("multFieldValues")
public List<Object> multFieldValues(@RequestBody List<String> fieldIds) {
List<Object> results = fieldIds.stream().map(fieldId -> dataSetFieldService.fieldValues(fieldId)).flatMap(list -> list.stream()).distinct().collect(Collectors.toList());
public List<Object> multFieldValues(@RequestBody List<String> fieldIds) throws Exception{
List<Object> results = new ArrayList<>();
for (String fieldId : fieldIds) {
results.addAll(dataSetFieldService.fieldValues(fieldId));
}
results.stream().distinct().collect(Collectors.toList());
return results;
}
}
......@@ -79,9 +79,9 @@ public class JdbcProvider extends DatasourceProvider {
}
} catch (SQLException e) {
DataEaseException.throwException(e);
DataEaseException.throwException(Translator.get("i18n_sql_error") + e.getMessage());
} catch (Exception e) {
DataEaseException.throwException(e);
DataEaseException.throwException(Translator.get("i18n_datasource_connect_error") + e.getMessage());
}
return list;
}
......
......@@ -5,5 +5,5 @@ import java.util.List;
public interface DataSetFieldService {
List<Object> fieldValues(String fieldId);
List<Object> fieldValues(String fieldId) throws Exception;
}
......@@ -5,8 +5,8 @@ import io.dataease.base.domain.DatasetTable;
import io.dataease.base.domain.DatasetTableField;
import io.dataease.base.domain.Datasource;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.dto.chart.ChartCustomFilterDTO;
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
import io.dataease.i18n.Translator;
import io.dataease.provider.datasource.DatasourceProvider;
import io.dataease.provider.ProviderFactory;
import io.dataease.controller.request.datasource.DatasourceRequest;
......@@ -42,7 +42,7 @@ public class DirectFieldService implements DataSetFieldService {
private DataSetTableUnionService dataSetTableUnionService;
@Override
public List<Object> fieldValues(String fieldId) {
public List<Object> fieldValues(String fieldId) throws Exception{
List<DatasetTableField> list = dataSetTableFieldsService.getListByIds(new ArrayList<String>() {{
add(fieldId);
}});
......@@ -65,6 +65,9 @@ public class DirectFieldService implements DataSetFieldService {
if (datasetTable.getMode() == 0) {// 直连
if (StringUtils.isEmpty(datasetTable.getDataSourceId())) return null;
Datasource ds = datasourceService.get(datasetTable.getDataSourceId());
if(ds.getStatus().equalsIgnoreCase("Error")){
throw new Exception(Translator.get("i18n_invalid_ds"));
}
datasourceProvider = ProviderFactory.getProvider(ds.getType());
datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(ds);
......@@ -97,13 +100,8 @@ public class DirectFieldService implements DataSetFieldService {
datasourceRequest.setQuery(qp.createQuerySQL(tableName, Collections.singletonList(field), true, null, customFilter));
}
try {
List<String[]> rows = datasourceProvider.getData(datasourceRequest);
List<Object> results = rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList());
return results;
} catch (Exception e) {
e.printStackTrace();
}
return null;
List<String[]> rows = datasourceProvider.getData(datasourceRequest);
List<Object> results = rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList());
return results;
}
}
......@@ -290,4 +290,7 @@ i18n_no_trigger=The current setting does not trigger task generation.
i18n_dataset_field_delete=Union field deleted,please set again and redo.
i18n_es_limit=Elasticsearch version cannot be less than 6.3
i18n_ds_error=Preview fail:Execute SQL error。Cause field、table、dataset changed,please check
i18n_union_ds_no_checked=This union dataset no checked field,please edit
\ No newline at end of file
i18n_union_ds_no_checked=This union dataset no checked field,please edit
i18n_auth_row_permission=Row Permission
i18n_sql_error=SQL Error:
i18n_invalid_ds=Invalid Datasource
\ No newline at end of file
......@@ -290,4 +290,6 @@ i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重
i18n_es_limit=Elasticsearch 版本不能小于6.3
i18n_ds_error=预览数据错误:执行SQL失败。可能因相关字段、表、数据集等元素发生变更,请检查
i18n_union_ds_no_checked=当前关联数据集,无选中字段,请重新编辑
i18n_auth_row_permission=行权限
\ No newline at end of file
i18n_auth_row_permission=行权限
i18n_sql_error=SQL 错误:
i18n_invalid_ds=无效数据源
\ No newline at end of file
......@@ -292,4 +292,7 @@ i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任
i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集
i18n_es_limit=Elasticsearch 版本不能小於6.3
i18n_ds_error=預覽數據錯誤:執行SQL失敗。可能因相關字段、表、數據集等元素發生變更,請檢查
i18n_union_ds_no_checked=當前關聯數據集,無選中字段,請重新編輯
\ No newline at end of file
i18n_union_ds_no_checked=當前關聯數據集,無選中字段,請重新編輯
i18n_auth_row_permission=行權限
i18n_sql_error=SQL 錯誤:
i18n_invalid_ds=無效數據源
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论