Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
wangjiahao 2022-07-28 17:37:20 +08:00
commit 39f01c2ba6
9 changed files with 98 additions and 53 deletions

View File

@ -95,22 +95,30 @@ public class JdbcProvider extends DefaultJdbcProvider {
while (resultSet.next()) {
String tableName = resultSet.getString("TABLE_NAME");
String database;
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name()) || datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.impala.name())) {
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.pg.name()) ||datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name()) || datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.impala.name())) {
database = resultSet.getString("TABLE_SCHEM");
} else {
database = resultSet.getString("TABLE_CAT");
}
if (database != null) {
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) {
TableField tableField = getTableFiled(resultSet, datasourceRequest);
list.add(tableField);
}
} else {
if (tableName.equals(datasourceRequest.getTable())) {
TableField tableField = getTableFiled(resultSet, datasourceRequest);
list.add(tableField);
}
}
if(datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.pg.name())){
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDsSchema(datasourceRequest))) {
TableField tableField = getTableFiled(resultSet, datasourceRequest);
list.add(tableField);
}
}else {
if (database != null) {
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) {
TableField tableField = getTableFiled(resultSet, datasourceRequest);
list.add(tableField);
}
} else {
if (tableName.equals(datasourceRequest.getTable())) {
TableField tableField = getTableFiled(resultSet, datasourceRequest);
list.add(tableField);
}
}
}
}
resultSet.close();
} catch (SQLException e) {
@ -191,6 +199,11 @@ public class JdbcProvider extends DefaultJdbcProvider {
}
}
private String getDsSchema(DatasourceRequest datasourceRequest) {
JdbcConfiguration jdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class);
return jdbcConfiguration.getSchema();
}
@Override
public List<TableField> fetchResultField(DatasourceRequest datasourceRequest) throws Exception {
JdbcConfiguration jdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class);

View File

@ -78,7 +78,7 @@ public class CKQueryProvider extends QueryProvider {
case "UINT64":
return 2;// 整型
case "FLOAT32":
case "Float64":
case "FLOAT64":
case "DECIMAL":
return 3;// 浮点
case "BIT":

View File

@ -57,6 +57,7 @@ import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SubSelect;
import net.sf.jsqlparser.statement.select.WithItem;
import net.sf.jsqlparser.util.deparser.ExpressionDeParser;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
@ -1027,7 +1028,22 @@ public class DataSetTableService {
expr.accept(getExpressionDeParser(stringBuilder));
}
plainSelect.setWhere(CCJSqlParserUtil.parseCondExpression(stringBuilder.toString()));
return plainSelect.toString();
StringBuilder builder = new StringBuilder();
if (CollectionUtils.isNotEmpty(select.getWithItemsList())) {
builder.append("WITH");
builder.append(" ");
}
for (Iterator<WithItem> iter = select.getWithItemsList().iterator(); iter.hasNext();) {
WithItem withItem = iter.next();
builder.append(withItem.toString());
if (iter.hasNext()) {
builder.append(",");
}
}
builder.append(plainSelect);
return builder.toString();
}
public Map<String, Object> getSQLPreview(DataSetTableRequest dataSetTableRequest) throws Exception {
@ -2569,8 +2585,12 @@ public class DataSetTableService {
@Override
public void visit(ExpressionList expressionList) {
for (Expression expression : expressionList.getExpressions()) {
for (Iterator<Expression> iter = expressionList.getExpressions().iterator(); iter.hasNext();) {
Expression expression = iter.next();
expression.accept(this);
if (iter.hasNext()) {
buffer.append(", ");
}
}
}

View File

@ -123,18 +123,24 @@ public class PermissionService {
dataSetRowPermissionsDTO.setAuthTargetIds(Collections.singletonList(userId));
dataSetRowPermissionsDTO.setAuthTargetType("user");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
dataSetRowPermissionsDTO.setAuthTargetIds(roleIds);
dataSetRowPermissionsDTO.setAuthTargetType("role");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
dataSetRowPermissionsDTO.setAuthTargetIds(Collections.singletonList(deptId));
dataSetRowPermissionsDTO.setAuthTargetType("dept");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
if(CollectionUtils.isNotEmpty(roleIds)){
dataSetRowPermissionsDTO.setAuthTargetIds(roleIds);
dataSetRowPermissionsDTO.setAuthTargetType("role");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
}
if(deptId != null){
dataSetRowPermissionsDTO.setAuthTargetIds(Collections.singletonList(deptId));
dataSetRowPermissionsDTO.setAuthTargetType("dept");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
}
dataSetRowPermissionsDTO.setAuthTargetType("sysParams");
dataSetRowPermissionsDTO.setAuthTargetIds(null);
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
values.put("${sysParams.userId}", userEntity.getUsername());
values.put("${sysParams.userName}", userEntity.getNickName());
values.put("${sysParams.userEmail}", userEntity.getEmail());
@ -170,28 +176,33 @@ public class PermissionService {
dataSetColumnPermissionsDTO.setAuthTargetType("user");
datasetColumnPermissions.addAll(columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO));
dataSetColumnPermissionsDTO.setAuthTargetIds(roleIds);
dataSetColumnPermissionsDTO.setAuthTargetType("role");
List<DataSetColumnPermissionsDTO> roleColumnPermissionsDTOS = new ArrayList<>();
for (DataSetColumnPermissionsDTO columnPermissionsDTO : columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO)) {
columnPermissionsDTO.getWhiteListUser();
List<Long> userIdList = new Gson().fromJson(columnPermissionsDTO.getWhiteListUser(), new TypeToken<List<Long>>() {}.getType());
if(!userIdList.contains(userId)){
roleColumnPermissionsDTOS.add(columnPermissionsDTO);
if(CollectionUtils.isNotEmpty(roleIds)){
dataSetColumnPermissionsDTO.setAuthTargetIds(roleIds);
dataSetColumnPermissionsDTO.setAuthTargetType("role");
List<DataSetColumnPermissionsDTO> roleColumnPermissionsDTOS = new ArrayList<>();
for (DataSetColumnPermissionsDTO columnPermissionsDTO : columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO)) {
columnPermissionsDTO.getWhiteListUser();
List<Long> userIdList = new Gson().fromJson(columnPermissionsDTO.getWhiteListUser(), new TypeToken<List<Long>>() {}.getType());
if(!userIdList.contains(userId)){
roleColumnPermissionsDTOS.add(columnPermissionsDTO);
}
}
datasetColumnPermissions.addAll(roleColumnPermissionsDTOS);
}
datasetColumnPermissions.addAll(roleColumnPermissionsDTOS);
dataSetColumnPermissionsDTO.setAuthTargetIds(Collections.singletonList(deptId));
dataSetColumnPermissionsDTO.setAuthTargetType("dept");
List<DataSetColumnPermissionsDTO> deptColumnPermissionsDTOS = new ArrayList<>();
for (DataSetColumnPermissionsDTO columnPermissionsDTO : columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO)) {
List<Long> userIdList = new Gson().fromJson(columnPermissionsDTO.getWhiteListUser(), new TypeToken<List<Long>>() {}.getType());
if(!userIdList.contains(userId)){
deptColumnPermissionsDTOS.add(columnPermissionsDTO);
if(deptId != null){
dataSetColumnPermissionsDTO.setAuthTargetIds(Collections.singletonList(deptId));
dataSetColumnPermissionsDTO.setAuthTargetType("dept");
List<DataSetColumnPermissionsDTO> deptColumnPermissionsDTOS = new ArrayList<>();
for (DataSetColumnPermissionsDTO columnPermissionsDTO : columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO)) {
List<Long> userIdList = new Gson().fromJson(columnPermissionsDTO.getWhiteListUser(), new TypeToken<List<Long>>() {}.getType());
if(!userIdList.contains(userId)){
deptColumnPermissionsDTOS.add(columnPermissionsDTO);
}
}
datasetColumnPermissions.addAll(deptColumnPermissionsDTOS);
}
datasetColumnPermissions.addAll(deptColumnPermissionsDTOS);
return datasetColumnPermissions;
}

View File

@ -1,9 +1,7 @@
package io.dataease.service.datasource;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
@ -61,7 +59,6 @@ import java.util.*;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class DatasourceService {
@Resource
@ -91,6 +88,7 @@ public class DatasourceService {
}
@DeCleaner(DePermissionType.DATASOURCE)
@Transactional(rollbackFor = Exception.class)
public Datasource addDatasource(Datasource datasource) throws Exception {
if (!types().stream().map(DataSourceType::getType).collect(Collectors.toList()).contains(datasource.getType())) {
throw new Exception("Datasource type not supported.");
@ -298,12 +296,12 @@ public class DatasourceService {
if (datasource == null) {
return ResultHolder.error("Can not find datasource: " + datasourceId);
}
String datasourceStatus = null;
try {
Provider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(datasource);
String datasourceStatus = datasourceProvider.checkStatus(datasourceRequest);
datasource.setStatus(datasourceStatus);
datasourceStatus = datasourceProvider.checkStatus(datasourceRequest);
if (datasource.getType().equalsIgnoreCase("api")) {
List<ApiDefinition> apiDefinitionList = new Gson().fromJson(datasource.getConfiguration(), new TypeToken<List<ApiDefinition>>() {
@ -328,10 +326,14 @@ public class DatasourceService {
return ResultHolder.success("Success");
} catch (Exception e) {
datasource.setStatus("Error");
datasourceStatus = "Error";
return ResultHolder.error("Datasource is invalid: " + e.getMessage());
} finally {
datasourceMapper.updateByPrimaryKey(datasource);
Datasource record = new Datasource();
record.setStatus(datasourceStatus);
DatasourceExample example = new DatasourceExample();
example.createCriteria().andIdEqualTo(datasource.getId());
datasourceMapper.updateByExampleSelective(record, example);
}
}
@ -461,15 +463,14 @@ public class DatasourceService {
datasourceRequest.setDatasource(datasource);
String status = datasourceProvider.checkStatus(datasourceRequest);
record.setStatus(status);
datasourceMapper.updateByExampleSelective(datasource, example);
datasourceMapper.updateByExampleSelective(record, example);
} catch (Exception e) {
Datasource temp = datasourceMapper.selectByPrimaryKey(datasource.getId());
record.setStatus("Error");
if (!StringUtils.equals(temp.getStatus(), "Error")) {
sendWebMsg(datasource);
datasourceMapper.updateByExampleSelective(datasource, example);
datasourceMapper.updateByExampleSelective(record, example);
}
}
}

View File

@ -57,7 +57,7 @@
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1 && item.deType !== 5" :command="beforeSummary('stddev_pop')">{{ $t('chart.stddev_pop') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1 && item.deType !== 5" :command="beforeSummary('var_pop')">{{ $t('chart.var_pop') }}</el-dropdown-item>
<el-dropdown-item :command="beforeSummary('count')">{{ $t('chart.count') }}</el-dropdown-item>
<el-dropdown-item :command="beforeSummary('count_distinct')">{{ $t('chart.count_distinct') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count'" :command="beforeSummary('count_distinct')">{{ $t('chart.count_distinct') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>

View File

@ -57,7 +57,7 @@
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1 && item.deType !== 5" :command="beforeSummary('stddev_pop')">{{ $t('chart.stddev_pop') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1 && item.deType !== 5" :command="beforeSummary('var_pop')">{{ $t('chart.var_pop') }}</el-dropdown-item>
<el-dropdown-item :command="beforeSummary('count')">{{ $t('chart.count') }}</el-dropdown-item>
<el-dropdown-item :command="beforeSummary('count_distinct')">{{ $t('chart.count_distinct') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count'" :command="beforeSummary('count_distinct')">{{ $t('chart.count_distinct') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>

View File

@ -68,7 +68,7 @@
<span>
<svg-icon v-if="fieldItem.field.deType === 0" icon-class="field_text" class="field-icon-text" />
<svg-icon v-if="fieldItem.field.deType === 1" icon-class="field_time" class="field-icon-time" />
<svg-icon v-if="fieldItem.field.deType === 2 || fieldItem.field.value === 3" icon-class="field_value" class="field-icon-value" />
<svg-icon v-if="fieldItem.field.deType === 2 || fieldItem.field.deType === 3" icon-class="field_value" class="field-icon-value" />
<svg-icon v-if="fieldItem.field.deType === 5" icon-class="field_location" class="field-icon-location" />
</span>
<span :title="fieldItem.field.name" class="field-text">{{ fieldItem.field.name }}</span>

View File

@ -16,7 +16,7 @@
<svg-icon v-if="fieldOption.deType === 0" icon-class="field_text" class="field-icon-text" />
<svg-icon v-if="fieldOption.deType === 1" icon-class="field_time" class="field-icon-time" />
<svg-icon
v-if="fieldOption.deType === 2 || fieldOption.value === 3"
v-if="fieldOption.deType === 2 || fieldOption.deType === 3"
icon-class="field_value"
class="field-icon-value"
/>