Merge pull request #4117 from dataease/pr@dev@params

feat: 过滤组件绑定参数优化,可直接展示数据集中的参数
This commit is contained in:
taojinlong 2022-12-16 16:24:18 +08:00 committed by GitHub
commit 34857162e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 115 additions and 38 deletions

View File

@ -247,6 +247,12 @@ public class DataSetTableController {
return dataSetTableService.paramsWithIds(type, viewIds);
}
@ApiOperation("数据集的SQL变量")
@PostMapping("/params/{id}/{type}")
List<SqlVariableDetails> paramsWithIds(@PathVariable String type, @PathVariable String id) {
return dataSetTableService.datasetParams(type, id);
}
@ApiOperation("根据数据集文件夹ID查询数据集名称")
@PostMapping("/getDatasetNameFromGroup/{sceneId}")
public List<String> getDatasetNameFromGroup(@PathVariable String sceneId) {

View File

@ -48,7 +48,7 @@ public class DatasourceController {
positionIndex = 0, positionKey = "type",
value = "id"
)
public Datasource addDatasource(@RequestBody Datasource datasource) throws Exception {
public Datasource addDatasource(@RequestBody DatasourceDTO datasource) throws Exception {
return datasourceService.addDatasource(datasource);
}
@ -61,7 +61,7 @@ public class DatasourceController {
@ApiIgnore
@PostMapping("/validate")
public ResultHolder validate(@RequestBody Datasource datasource) throws Exception {
public ResultHolder validate(@RequestBody DatasourceDTO datasource) throws Exception {
return datasourceService.validate(datasource);
}
@ -129,7 +129,7 @@ public class DatasourceController {
@ApiIgnore
@PostMapping("/getSchema")
public List<String> getSchema(@RequestBody Datasource datasource) throws Exception {
public List<String> getSchema(@RequestBody DatasourceDTO datasource) throws Exception {
return datasourceService.getSchema(datasource);
}

View File

@ -15,4 +15,5 @@ public class UpdataDsRequest {
private String type;
@ApiModelProperty(value = "配置详情", required = true)
private String configuration;
private boolean configurationEncryption = false;
}

View File

@ -1,6 +1,6 @@
package io.dataease.controller.request.panel;
import io.dataease.plugins.common.base.domain.Datasource;
import io.dataease.dto.DatasourceDTO;
import lombok.Data;
import java.util.List;
@ -33,5 +33,5 @@ public class PanelAppTemplateApplyRequest {
private String datasourceHistoryId;
private List<Datasource> datasourceList;
private List<DatasourceDTO> datasourceList;
}

View File

@ -22,4 +22,5 @@ public class DatasourceDTO extends Datasource {
private String apiConfigurationStr;
private String typeDesc;
private DatasourceCalculationMode calculationMode;
private boolean isConfigurationEncryption = false;
}

View File

@ -967,26 +967,15 @@ public class DataSetTableService {
return map;
}
public List<SqlVariableDetails> paramsWithIds(String type, List<String> viewIds) {
if (CollectionUtils.isEmpty(viewIds)) {
return new ArrayList<>();
}
public List<SqlVariableDetails> datasetParams(String type, String id) {
if (!Arrays.asList("DATE", "TEXT", "NUM").contains(type)) {
return new ArrayList<>();
}
ChartViewExample chartViewExample = new ChartViewExample();
chartViewExample.createCriteria().andIdIn(viewIds);
List<String> datasetIds = chartViewMapper.selectByExample(chartViewExample).stream().map(ChartView::getTableId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(datasetIds)) {
return new ArrayList<>();
}
DatasetTableExample datasetTableExample = new DatasetTableExample();
datasetTableExample.createCriteria().andIdIn(datasetIds);
List<DatasetTable> datasetTables = datasetTableMapper.selectByExample(datasetTableExample);
if (CollectionUtils.isEmpty(datasetTables)) {
return new ArrayList<>();
}
DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(id);
return getSqlVariableDetails(type, Arrays.asList(datasetTable));
}
private List<SqlVariableDetails> getSqlVariableDetails(String type, List<DatasetTable> datasetTables) {
List<SqlVariableDetails> sqlVariableDetails = new ArrayList<>();
for (DatasetTable datasetTable : datasetTables) {
if (StringUtils.isNotEmpty(datasetTable.getSqlVariableDetails())) {
@ -999,6 +988,7 @@ public class DataSetTableService {
}
}
}
switch (type) {
case "DATE":
sqlVariableDetails = sqlVariableDetails.stream().filter(item -> item.getType().get(0).contains("DATETIME")).collect(Collectors.toList());
@ -1022,6 +1012,29 @@ public class DataSetTableService {
return sqlVariableDetails;
}
public List<SqlVariableDetails> paramsWithIds(String type, List<String> viewIds) {
if (CollectionUtils.isEmpty(viewIds)) {
return new ArrayList<>();
}
if (!Arrays.asList("DATE", "TEXT", "NUM").contains(type)) {
return new ArrayList<>();
}
ChartViewExample chartViewExample = new ChartViewExample();
chartViewExample.createCriteria().andIdIn(viewIds);
List<String> datasetIds = chartViewMapper.selectByExample(chartViewExample).stream().map(ChartView::getTableId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(datasetIds)) {
return new ArrayList<>();
}
DatasetTableExample datasetTableExample = new DatasetTableExample();
datasetTableExample.createCriteria().andIdIn(datasetIds);
List<DatasetTable> datasetTables = datasetTableMapper.selectByExample(datasetTableExample);
if (CollectionUtils.isEmpty(datasetTables)) {
return new ArrayList<>();
}
return getSqlVariableDetails(type, datasetTables);
}
public void checkVariable(final String sql, String dsType) throws Exception {
String tmpSql = removeVariables(sql, dsType);

View File

@ -104,11 +104,13 @@ public class DatasourceService {
@DeCleaner(DePermissionType.DATASOURCE)
@Transactional(rollbackFor = Exception.class)
public Datasource addDatasource(Datasource datasource) throws Exception {
public Datasource addDatasource(DatasourceDTO datasource) throws Exception {
if (!types().stream().map(DataSourceType::getType).collect(Collectors.toList()).contains(datasource.getType())) {
throw new Exception("Datasource type not supported.");
}
datasource.setConfiguration(new String(java.util.Base64.getDecoder().decode(datasource.getConfiguration())));
if(datasource.isConfigurationEncryption()){
datasource.setConfiguration(new String(java.util.Base64.getDecoder().decode(datasource.getConfiguration())));
}
Provider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
datasourceProvider.checkConfiguration(datasource);
@ -261,7 +263,12 @@ public class DatasourceService {
if (!types().stream().map(DataSourceType::getType).collect(Collectors.toList()).contains(updataDsRequest.getType())) {
throw new Exception("Datasource type not supported.");
}
updataDsRequest.setConfiguration(new String(java.util.Base64.getDecoder().decode(updataDsRequest.getConfiguration())));
System.out.println(updataDsRequest.getConfiguration());
System.out.println(updataDsRequest.isConfigurationEncryption());
if(updataDsRequest.isConfigurationEncryption()){
updataDsRequest.setConfiguration(new String(java.util.Base64.getDecoder().decode(updataDsRequest.getConfiguration())));
}
System.out.println(updataDsRequest.getConfiguration());
checkName(updataDsRequest.getName(), updataDsRequest.getType(), updataDsRequest.getId());
Datasource datasource = new Datasource();
datasource.setName(updataDsRequest.getName());
@ -292,8 +299,10 @@ public class DatasourceService {
}
}
public ResultHolder validate(Datasource datasource) throws Exception {
datasource.setConfiguration(new String(java.util.Base64.getDecoder().decode(datasource.getConfiguration())));
public ResultHolder validate(DatasourceDTO datasource) throws Exception {
if(datasource.isConfigurationEncryption()){
datasource.setConfiguration(new String(java.util.Base64.getDecoder().decode(datasource.getConfiguration())));
}
DatasourceDTO datasourceDTO = new DatasourceDTO();
BeanUtils.copyBean(datasourceDTO, datasource);
try {
@ -381,8 +390,10 @@ public class DatasourceService {
}
}
public List<String> getSchema(Datasource datasource) throws Exception {
datasource.setConfiguration(new String(java.util.Base64.getDecoder().decode(datasource.getConfiguration())));
public List<String> getSchema(DatasourceDTO datasource) throws Exception {
if(datasource.isConfigurationEncryption()){
datasource.setConfiguration(new String(java.util.Base64.getDecoder().decode(datasource.getConfiguration())));
}
Provider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(datasource);

View File

@ -11,6 +11,7 @@ import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.controller.request.panel.PanelAppTemplateApplyRequest;
import io.dataease.controller.request.panel.PanelAppTemplateRequest;
import io.dataease.controller.request.panel.PanelGroupRequest;
import io.dataease.dto.DatasourceDTO;
import io.dataease.ext.ExtPanelAppTemplateMapper;
import io.dataease.plugins.common.base.domain.*;
import io.dataease.plugins.common.base.mapper.PanelAppTemplateMapper;
@ -142,9 +143,9 @@ public class PanelAppTemplateService {
if (PanelConstants.APP_DATASOURCE_FROM.HISTORY.equals(request.getDatasourceFrom())) {
datasourceRealMap.put(oldDatasourceList.get(0).getId(), request.getDatasourceHistoryId());
} else {
List<Datasource> newDatasourceList = request.getDatasourceList();
List<DatasourceDTO> newDatasourceList = request.getDatasourceList();
for (int i = 0; i < newDatasourceList.size(); i++) {
Datasource datasource = newDatasourceList.get(0);
DatasourceDTO datasource = newDatasourceList.get(0);
datasource.setId(null);
Datasource newDatasource = datasourceService.addDatasource(datasource);
datasourceRealMap.put(oldDatasourceList.get(i).getId(), newDatasource.getId());
@ -392,7 +393,7 @@ public class PanelAppTemplateService {
}
@Transactional(rollbackFor = Exception.class)
public void editDatasource(List<Datasource> updateDatasourceList) throws Exception {
public void editDatasource(List<DatasourceDTO> updateDatasourceList) throws Exception {
for (int i = 0; i < updateDatasourceList.size(); i++) {
UpdataDsRequest updataDsRequest = new UpdataDsRequest();
BeanUtils.copyBean(updataDsRequest, updateDatasourceList.get(i));

View File

@ -128,6 +128,14 @@ export function fieldListWithPermission(id, showLoading = true) {
})
}
export function datasetParams(id, type, showLoading = true) {
return request({
url: '/dataset/table/params/' + id + '/' + type,
loading: showLoading,
method: 'post'
})
}
export function fieldListDQ(id, showLoading = true) {
return request({
url: '/dataset/field/listByDQ/' + id,

View File

@ -274,6 +274,7 @@
:widget="widget"
:control-attrs="myAttrs"
:child-views="childViews"
:dataset-params="datasetParams"
/>
<filter-foot :element="currentElement" />
@ -296,10 +297,7 @@ import { queryAuthModel } from '@/api/authModel/authModel'
import {
mapState
} from 'vuex'
import {
groupTree,
fieldListWithPermission
} from '@/api/dataset/dataset'
import { groupTree, fieldListWithPermission, datasetParams } from '@/api/dataset/dataset'
import {
paramsWithIds,
viewsWithIds
@ -386,6 +384,7 @@ export default {
viewInfos: [],
datasetParams: []
},
datasetParams: [],
currentElement: null,
tempTreeData: null,
showTips: false
@ -735,6 +734,18 @@ export default {
this.fieldData = JSON.parse(JSON.stringify(data))
})
},
loadDatasetParams(tableId) {
var type = 'TEXT'
if (this.widgetInfo.name.indexOf('time') !== -1) {
type = 'DATE'
}
if (this.widgetInfo.name === 'numberSelectWidget') {
type = 'NUM'
}
datasetParams(tableId, type).then(res => {
this.datasetParams = res.data
})
},
comLoadField(tableId) {
fieldListWithPermission(tableId).then(res => {
let data = res.data
@ -751,6 +762,7 @@ export default {
this.addQueue(row)
this.fieldsParent = row
this.loadField(row.id)
this.loadDatasetParams(row.id)
},
showNextGroup(row) {
this.tempTreeData = JSON.parse(JSON.stringify(row.children))

View File

@ -184,7 +184,7 @@
@change="val => {changeDynamicParams(val, item.name)}"
>
<el-checkbox
v-for="(ele ) in childViews.datasetParams"
v-for="(ele ) in allParams"
:key="ele.id"
:label="ele.id"
:disabled="attrs[tabsOption[(index + 1)%2].name + 'Parameters'] && attrs[tabsOption[(index + 1)%2].name + 'Parameters'].includes(ele.id)"
@ -276,6 +276,10 @@ export default {
element: {
type: Object,
default: null
},
datasetParams: {
type: Array,
default: []
}
},
data() {
@ -296,7 +300,8 @@ export default {
{ id: 'HH', name: 'HH' },
{ id: 'HH:mm', name: 'HH:mm' },
{ id: 'HH:mm:ss', name: 'HH:mm:ss' }
]
],
allParams: []
}
},
computed: {
@ -322,6 +327,21 @@ export default {
}
this.attrs.parameters = parameters
}
this.allParams = this.childViews.datasetParams
}
},
'datasetParams': {
handler(newName, oldName) {
if (this.datasetParams.length > 0) {
this.allParams = this.childViews.datasetParams
for (var j = 0; j < this.datasetParams.length; j++) {
for (var i = 0; i < this.childViews.datasetParams.length; i++) {
if (this.childViews.datasetParams[i].id.split('|DE|')[0] !== this.datasetParams[j].id.split('|DE|')[0]) {
this.allParams.push(this.datasetParams[j])
}
}
}
}
}
}
},

View File

@ -712,6 +712,7 @@ export default {
} else {
data.configuration = Base64.encode(JSON.stringify(data.configuration))
}
data.configurationEncryption = true
if (data.showModel === 'show' && !this.canEdit) {
validateDsById(data.id).then(res => {
if (res.success) {

View File

@ -982,6 +982,7 @@ export default {
} else {
form.configuration = Base64.encode(JSON.stringify(form.configuration))
}
form.configurationEncryption = true
const isAppMarket = this.positionCheck('appMarket')
let appApplyForm
if (isAppMarket) {
@ -1063,6 +1064,7 @@ export default {
if (valid) {
const data = JSON.parse(JSON.stringify(this.form))
data.configuration = Base64.encode(JSON.stringify(data.configuration))
data.configurationEncryption = true
getSchema(data).then((res) => {
this.schemas = res.data
this.openMessageSuccess('commons.success')
@ -1117,6 +1119,7 @@ export default {
} else {
data.configuration = Base64.encode(JSON.stringify(data.configuration))
}
data.configurationEncryption = true
if (data.showModel === 'show' && !this.canEdit) {
validateDsById(data.id).then((res) => {
if (res.success) {