feat: sql变量 支持 时间类型

This commit is contained in:
taojinlong 2022-09-07 10:21:45 +08:00
parent 1fce18141e
commit 7cc270c2c0
10 changed files with 186 additions and 133 deletions

View File

@ -211,8 +211,8 @@ public class DataSetTableController {
}
@ApiOperation("根据仪表板视图ID查询数据集变量")
@PostMapping("/paramsWithIds")
List<SqlVariableDetails> paramsWithIds(@RequestBody List<String> viewIds){
return dataSetTableService.paramsWithIds(viewIds);
@PostMapping("/paramsWithIds/{type}")
List<SqlVariableDetails> paramsWithIds(@PathVariable String type, @RequestBody List<String> viewIds){
return dataSetTableService.paramsWithIds(type, viewIds);
};
}

View File

@ -930,10 +930,14 @@ public class DataSetTableService {
return map;
}
public List<SqlVariableDetails> paramsWithIds(List<String> viewIds) {
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());
@ -946,11 +950,9 @@ public class DataSetTableService {
if (CollectionUtils.isEmpty(datasetTables)) {
return new ArrayList<>();
}
List<SqlVariableDetails> sqlVariableDetails = new ArrayList<>();
List<String> sqlVariableNames = new ArrayList<>();
datasetTables.forEach(datasetTable -> {
for (DatasetTable datasetTable : datasetTables) {
if (StringUtils.isNotEmpty(datasetTable.getSqlVariableDetails())) {
List<SqlVariableDetails> sqlVariables = new Gson().fromJson(datasetTable.getSqlVariableDetails(), new TypeToken<List<SqlVariableDetails>>() {
}.getType());
@ -961,7 +963,21 @@ public class DataSetTableService {
}
}
}
});
}
switch (type){
case "DATE":
sqlVariableDetails = sqlVariableDetails.stream().filter(item -> item.getType().get(0).contains("DATETIME")).collect(Collectors.toList());
sqlVariableDetails.forEach(item -> {item.setAlias(item.getVariableName() + "[" + item.getType().get(1) + "]");});
break;
case "TEXT":
sqlVariableDetails = sqlVariableDetails.stream().filter(item -> item.getType().get(0).contains("TEXT")).collect(Collectors.toList());
sqlVariableDetails.forEach(item -> {item.setAlias(item.getVariableName());});
break;
case "NUM":
sqlVariableDetails = sqlVariableDetails.stream().filter(item -> item.getType().get(0).contains("LONG") || item.getType().get(0).contains("DOUBLE")).collect(Collectors.toList());
sqlVariableDetails.forEach(item -> {item.setAlias(item.getVariableName());});
break;
}
return sqlVariableDetails;
}

View File

@ -17,9 +17,9 @@ export function viewsWithIds(data) {
})
}
export function paramsWithIds(data) {
export function paramsWithIds(type, data) {
return request({
url: '/dataset/table/paramsWithIds',
url: '/dataset/table/paramsWithIds/' + type,
method: 'post',
loading: true,
data

View File

@ -17,6 +17,7 @@ const dialogPanel = {
placeholder: 'dedate.placeholder',
viewIds: [],
fieldId: '',
parameters: [],
dragItems: [],
default: {
isDynamic: false,

View File

@ -15,6 +15,7 @@ const dialogPanel = {
placeholder: 'deyearmonth.placeholder',
viewIds: [],
fieldId: '',
parameters: [],
dragItems: [],
default: {
isDynamic: false,

View File

@ -13,6 +13,7 @@ const dialogPanel = {
},
value: ''
},
parameters: [],
defaultClass: 'time-filter',
component: 'de-quarter'
}

View File

@ -15,6 +15,7 @@ const dialogPanel = {
placeholder: 'deyear.placeholder',
viewIds: [],
fieldId: '',
parameters: [],
dragItems: [],
default: {
isDynamic: false,

View File

@ -249,35 +249,35 @@ export default {
{ label: this.$t('dataset.text'), value: 'TEXT' },
{ label: this.$t('dataset.value'), value: 'LONG' },
{ label: this.$t('dataset.value') + '(' + this.$t('dataset.float') + ')', value: 'DOUBLE' },
// { label: this.$t('dataset.time_year'), value: 'DATETIME-YEAR' },
// { label: this.$t('dataset.time_year_month'), value: 'DATETIME-YEAR-MONTH',
// children: [{
// value: 'yyyy-MM',
// label: 'YYYY-MM'
// }, {
// value: 'yyyy/MM',
// label: 'YYYY/MM'
// }]
// },
// { label: this.$t('dataset.time_year_month_day'), value: 'DATETIME-YEAR-MONTH-DAY',
// children: [{
// value: 'yyyy-MM-dd',
// label: 'YYYY-MM-DD'
// }, {
// value: 'yyyy/MM/dd',
// label: 'YYYY/MM/DD'
// }]
// },
// { label: this.$t('dataset.time_all'), value: 'DATETIME',
// children: [{
// value: 'yyyy-MM-dd HH:mm:ss',
// label: 'YYYY-MM-DD HH:MI:SS'
// }, {
// value: 'yyyy/MM/dd HH:mm:ss',
// label: 'YYYY/MM/DD HH:MI:SS'
// }
// ]
// }
{ label: this.$t('dataset.time_year'), value: 'DATETIME-YEAR' },
{ label: this.$t('dataset.time_year_month'), value: 'DATETIME-YEAR-MONTH',
children: [{
value: 'yyyy-MM',
label: 'YYYY-MM'
}, {
value: 'yyyy/MM',
label: 'YYYY/MM'
}]
},
{ label: this.$t('dataset.time_year_month_day'), value: 'DATETIME-YEAR-MONTH-DAY',
children: [{
value: 'yyyy-MM-dd',
label: 'YYYY-MM-DD'
}, {
value: 'yyyy/MM/dd',
label: 'YYYY/MM/DD'
}]
},
{ label: this.$t('dataset.time_all'), value: 'DATETIME',
children: [{
value: 'yyyy-MM-dd HH:mm:ss',
label: 'YYYY-MM-DD HH:MI:SS'
}, {
value: 'yyyy/MM/dd HH:mm:ss',
label: 'YYYY/MM/DD HH:MI:SS'
}
]
}
],
}
},

View File

@ -480,7 +480,14 @@ export default {
this.viewInfos = datas
this.childViews.viewInfos = datas
})
viewIds && viewIds.length > 0 && paramsWithIds(viewIds).then(res => {
var type = 'TEXT'
if(this.widgetInfo.name.indexOf('time') !== -1){
type = 'DATE'
}
if(this.widgetInfo.name === 'numberSelectWidget'){
type = 'NUM'
}
viewIds && viewIds.length > 0 && paramsWithIds(type, viewIds).then(res => {
const datas = res.data
this.childViews.datasetParams = datas

View File

@ -50,7 +50,8 @@
</el-checkbox>
<el-popover v-model="titlePopovervisible" placement="bottom-end" :disabled="!attrs.showTitle" width="200">
<div style="width: 100%;overflow-y: auto;overflow-x: hidden;word-break: break-all;position: relative;">
<el-input v-model="attrs.title" :placeholder="$t('panel.input_title')" type="textarea" maxlength="15" show-word-limit />
<el-input v-model="attrs.title" :placeholder="$t('panel.input_title')" type="textarea" maxlength="15"
show-word-limit/>
</div>
<i
@ -74,7 +75,7 @@
class="de-checkbox"
>
<div class="span-div">
<svg-icon :icon-class="item.type" class="chart-icon" />
<svg-icon :icon-class="item.type" class="chart-icon"/>
<span v-if="item.name && item.name.length <= 7" style="margin-left: 6px">{{ item.name }}</span>
<el-tooltip v-else class="item" effect="dark" :content="item.name" placement="left">
<span style="margin-left: 6px">{{ item.name }}</span>
@ -92,7 +93,7 @@
/>
</el-popover>
</span>
<span v-if="element.component === 'de-select'" style="padding-left: 10px;">
<span v-if="showParams" style="padding-left: 10px;">
<el-checkbox v-model="attrs.enableParameters" @change="enableParametersChange"><span>
{{ $t('panel.binding_parameters') }} </span> </el-checkbox>
@ -106,9 +107,10 @@
class="de-checkbox"
>
<div class="span-div">
<span v-if="item.variableName && item.variableName.length <= 7" style="margin-left: 6px">{{ item.variableName }}</span>
<el-tooltip v-else class="item" effect="dark" :content="item.variableName" placement="left">
<span style="margin-left: 6px">{{ item.variableName }}</span>
<span v-if="item.alias && item.alias.length <= 7"
style="margin-left: 6px">{{ item.alias }}</span>
<el-tooltip v-else class="item" effect="dark" :content="item.alias" placement="left">
<span style="margin-left: 6px">{{ item.alias }}</span>
</el-tooltip>
</div>
@ -145,7 +147,8 @@ export default {
childViews: {
type: Object,
default: () => {}
default: () => {
}
},
element: {
type: Object,
@ -154,120 +157,143 @@ export default {
},
data() {
return {
showParams: false,
attrs: null,
titlePopovervisible: false,
popovervisible: false,
parametersVisible: false,
timePopovervisible: false,
accuracyOptions: [
{ id: 'HH', name: 'HH' },
{ id: 'HH:mm', name: 'HH:mm' },
{ id: 'HH:mm:ss', name: 'HH:mm:ss' }
{id: 'HH', name: 'HH'},
{id: 'HH:mm', name: 'HH:mm'},
{id: 'HH:mm:ss', name: 'HH:mm:ss'}
]
}
},
computed: {
},
computed: {},
created() {
console.log(this.element)
console.log(this.widget)
this.attrs = this.controlAttrs
},
methods: {
multipleChange(value) {
this.fillAttrs2Filter()
},
showTimeChange(value) {
this.attrs.accuracy = this.accuracyOptions[1].id
this.attrs.default.isDynamic = false
this.fillAttrs2Filter()
},
checkedViewsChange(values) {
this.fillAttrs2Filter()
},
enableRangeChange(value) {
if (!value) {
this.attrs.viewIds = []
}
this.fillAttrs2Filter()
},
enableParametersChange(value) {
if (!value) {
this.attrs.parameters = []
}
this.fillAttrs2Filter()
},
showTitleChange(value) {
if (!value) {
this.attrs.title = ''
this.element.style.backgroundColor = ''
}
this.fillAttrs2Filter()
},
showVisualChange(value) {
this.fillAttrs2Filter()
},
fillAttrs2Filter() {}
console.log(this.childViews.datasetParams.length)
if ('timeYearWidget,timeMonthWidget,timeDateWidget,textSelectWidget,numberSelectWidget'.indexOf(this.widget.name) !== -1) {
this.showParams = true
}
}
,
methods: {
multipleChange(value)
{
this.fillAttrs2Filter()
}
,
showTimeChange(value)
{
this.attrs.accuracy = this.accuracyOptions[1].id
this.attrs.default.isDynamic = false
this.fillAttrs2Filter()
}
,
checkedViewsChange(values)
{
this.fillAttrs2Filter()
}
,
enableRangeChange(value)
{
if (!value) {
this.attrs.viewIds = []
}
this.fillAttrs2Filter()
}
,
enableParametersChange(value)
{
console.log(this.childViews.datasetParams.length)
if (!value) {
this.attrs.parameters = []
}
this.fillAttrs2Filter()
}
,
showTitleChange(value)
{
if (!value) {
this.attrs.title = ''
this.element.style.backgroundColor = ''
}
this.fillAttrs2Filter()
}
,
showVisualChange(value)
{
this.fillAttrs2Filter()
}
,
fillAttrs2Filter()
{
}
}
}
</script>
<style lang="scss" scoped>
.filter-options-left {
align-items: center;
display: flex;
flex-direction: row;
justify-content: flex-start;
flex-wrap: nowrap;
height: 50px;
}
.filter-options-left {
align-items: center;
display: flex;
flex-direction: row;
justify-content: flex-start;
flex-wrap: nowrap;
height: 50px;
}
.filter-options-right {
align-items: center;
display: flex;
flex-direction: row;
justify-content: flex-end;
flex-wrap: nowrap;
height: 50px;
}
.filter-options-right {
align-items: center;
display: flex;
flex-direction: row;
justify-content: flex-end;
flex-wrap: nowrap;
height: 50px;
}
.i-filter {
text-align: center;
margin-left: 5px;
margin-top: 1px;
}
.i-filter {
text-align: center;
margin-left: 5px;
margin-top: 1px;
}
.i-filter-inactive {
color: #9ea6b2 !important;
cursor: not-allowed !important;
}
.i-filter-inactive {
color: #9ea6b2 !important;
cursor: not-allowed !important;
}
.i-filter-active {
cursor: pointer !important;
}
.i-filter-active {
cursor: pointer !important;
}
.view-container-class {
.view-container-class {
min-height: 150px;
max-height: 200px;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
word-break: break-all;
position: relative;
min-height: 150px;
max-height: 200px;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
word-break: break-all;
position: relative;
}
}
.span-div {
width: 135px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.span-div {
width: 135px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.de-ul li {
margin: 5px 2px;