Skip to content

Commit

Permalink
#95 fix bug: show mapping fields in query insertion helper when index…
Browse files Browse the repository at this point in the history
… version exist [vip:platform/pallas#927]
  • Loading branch information
NathanChan committed Jul 8, 2019
1 parent 90272e9 commit f683e5a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
</div>
<div v-if="isTemplateInsertVisible">
<template-insert-dialog
:metadata-list="metadataList"
:field-list="fieldList"
@insert-template-content="insertTemplateContent"
@close-dialog="closeTemplateInsertDialog">
</template-insert-dialog>
Expand All @@ -174,7 +174,7 @@ import TemplateConfigDialog from './template_config_dialog';
import TemplateInsertDialog from './template_insert_dialog';
export default {
props: ['indexId', 'indexName', 'metadataList', 'clusters', 'isAllPrivilege', 'templateInfo', 'macroList', 'temPanelHeight'],
props: ['indexId', 'indexName', 'metadataList', 'fieldList', 'clusters', 'isAllPrivilege', 'templateInfo', 'macroList', 'temPanelHeight'],
data() {
return {
loading: false,
Expand Down Expand Up @@ -478,7 +478,7 @@ export default {
return this.$http.post('/index/loadDbList.json', { indexId: this.indexId }).then((data) => {
if (data) {
this.datasourceList = data;
if (this.datasourceList.length !== 0) {
if (!this.datasourceList && this.datasourceList.length !== 0) {
this.datasourceId = Object.entries(data)[0][0];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<el-col :span="23">
<el-form-item label-width="30px">
<el-table border :data="metadatas" :max-height="320" v-if="info.field === 'query'">
<el-table-column prop="dbFieldName" label="字段名" width="130" show-overflow-tooltip></el-table-column>
<el-table-column prop="field" label="字段名" width="130" show-overflow-tooltip></el-table-column>
<el-table-column label="查询方式">
<template slot-scope="scope">
<el-radio class="radio" v-model="scope.row.queryWay" label="term">term</el-radio>
Expand All @@ -61,7 +61,7 @@

<script>
export default {
props: ['metadataList'],
props: ['fieldList'],
data() {
return {
loading: false,
Expand Down Expand Up @@ -116,42 +116,42 @@ export default {
}
switch (ele.queryWay) {
case 'term':
this.resultContent += `${frontSpace}{{#${ele.dbFieldName}}}\n`
this.resultContent += `${frontSpace}{{#${ele.field}}}\n`
+ ' ,{\n'
+ ` "term":{"${ele.dbFieldName}":"{{${ele.dbFieldName}}}"}\n`
+ ` "term":{"${ele.field}":"{{${ele.field}}}"}\n`
+ ' }\n'
+ ` {{/${ele.dbFieldName}}}${endNewline}`;
+ ` {{/${ele.field}}}${endNewline}`;
break;
case 'multiTerm':
this.resultContent += `${frontSpace}{{#${ele.dbFieldName}}}\n`
this.resultContent += `${frontSpace}{{#${ele.field}}}\n`
+ ' ,{\n'
+ ` "terms":{ "${ele.dbFieldName}":{{#toJson}}${ele.dbFieldName}.list{{/toJson}} }\n`
+ ` "terms":{ "${ele.field}":{{#toJson}}${ele.field}.list{{/toJson}} }\n`
+ ' }\n'
+ ` {{/${ele.dbFieldName}}}${endNewline}`;
+ ` {{/${ele.field}}}${endNewline}`;
break;
case 'range':
this.resultContent += `${frontSpace}{{#${ele.dbFieldName}_min}}\n`
this.resultContent += `${frontSpace}{{#${ele.field}_min}}\n`
+ ' ,{\n'
+ ' "range": {\n'
+ ` "${ele.dbFieldName}": {\n`
+ ` "from": "{{${ele.dbFieldName}_min}}",\n`
+ ` "to": "{{${ele.dbFieldName}_max}}"\n`
+ ` "${ele.field}": {\n`
+ ` "from": "{{${ele.field}_min}}",\n`
+ ` "to": "{{${ele.field}_max}}"\n`
+ ' }\n'
+ ' }\n'
+ ' }\n'
+ ` {{/${ele.dbFieldName}_min}}${endNewline}`;
+ ` {{/${ele.field}_min}}${endNewline}`;
break;
case 'script':
this.resultContent += `${frontSpace}{{#${ele.dbFieldName}}}\n`
this.resultContent += `${frontSpace}{{#${ele.field}}}\n`
+ ' ,{\n'
+ ' "script": {\n'
+ ' "script": {\n'
+ ' "lang": "painless",\n'
+ ` "inline": "return doc['${ele.dbFieldName}'].value > 0"\n`
+ ` "inline": "return doc['${ele.field}'].value > 0"\n`
+ ' }\n'
+ ' }\n'
+ ' }\n'
+ ` {{/${ele.dbFieldName}}${endNewline}`;
+ ` {{/${ele.field}}${endNewline}`;
break;
default:
break;
Expand All @@ -173,7 +173,7 @@ export default {
},
},
created() {
this.metadatas = this.metadataList.map((obj) => {
this.metadatas = this.fieldList.map((obj) => {
const rObj = { ...obj };
rObj.queryWay = '';
return rObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div class="template-warning" v-if="!isEditable"><i class="el-icon-warning"></i>请选择模板</div>
<div v-for="template in templateList" :key="template.templateName" class="template-body">
<template-edit v-if="templateInfo.templateName === template.templateName" :tem-panel-height="temPanelHeight" :metadata-list="metadataList" :clusters="clusters" :index-id="indexId" :index-name="indexName" :is-all-privilege="isAllPrivilege" :template-info="templateInfo" :macro-list="macroList" @close-delete="closeDelete" @close-edit="closeEdit"></template-edit>
<template-edit v-if="templateInfo.templateName === template.templateName" :tem-panel-height="temPanelHeight" :metadata-list="metadataList" :field-list="fieldList" :clusters="clusters" :index-id="indexId" :index-name="indexName" :is-all-privilege="isAllPrivilege" :template-info="templateInfo" :macro-list="macroList" @close-delete="closeDelete" @close-edit="closeEdit"></template-edit>
</div>
</div>
<div v-if="isTemplateAddVisible">
Expand Down Expand Up @@ -80,6 +80,7 @@ export default {
},
clusters: [],
metadataList: [],
fieldList: [],
temPanelHeight: {
height: document.body.clientHeight - 210,
},
Expand Down Expand Up @@ -191,6 +192,7 @@ export default {
return this.$http.post('/index/version/metadata.json', { indexId: this.indexId }).then((data) => {
this.clusters = data.clusters;
this.metadataList = data.list;
this.fieldList = data.schema;
});
},
init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
import static java.util.stream.Collectors.toList;

import java.sql.SQLException;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;

import javax.annotation.Resource;

import com.vip.pallas.bean.DBSchema;
import com.vip.pallas.console.vo.TemplateFieldVO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
Expand Down Expand Up @@ -69,7 +66,21 @@ public Map<String, Object> metadata(@RequestBody Map<String, Object> params) thr
}

Map<String, Object> resultMap = new HashMap<>();
resultMap.put("list", indexVersionService.getMetaDataFromDB(indexId));
List<DBSchema> dbList = indexVersionService.getMetaDataFromDB(indexId);
resultMap.put("list", dbList);
com.vip.pallas.bean.IndexVersion version = indexVersionService.findUsedOrLastIndexVersoinByIndexId(indexId);

List<TemplateFieldVO> schema;
if (null == version){
schema = dbList.stream().map(filed->new TemplateFieldVO(filed.getDbFieldName())).collect(toList());
}else {
schema = new ArrayList<>();
version.getSchema().stream().filter(field -> field.getFieldType()!="nested"&&field.getFieldType()!="object"&&(field.getMultiField()==null||field.getMultiField().size()==0)).forEach(field -> {
schema.add(new TemplateFieldVO(field.getFieldName()));
});
}
resultMap.put("schema",schema);

resultMap.put("clusters", getClusters(indexId));
resultMap.put("isLogical", indexService.isLogicalIndex(indexId));
return resultMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.vip.pallas.console.vo;

public class TemplateFieldVO {
private String field;

public TemplateFieldVO(String field) {
this.field = field;
}

public String getField() {
return field;
}

public void setField(String field) {
this.field = field;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public interface IndexVersionRepository {

IndexVersion findUsedIndexVersionByIndexId(@Param("indexId") Long indexId);

IndexVersion findUsedOrLastIndexVersoinByIndexId(@Param("indexId") Long indexId);

List<IndexVersion> findAllByIndexId(@Param("indexId") Long indexId);

void enableThisVersionAndDisableOthers(@Param("indexId") Long indexId, @Param("id") Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,8 @@ public IndexVersion findUsedIndexVersionByIndexId(Long indexId) {
return indexVersionRepository.findUsedIndexVersionByIndexId(indexId);
}

public com.vip.pallas.bean.IndexVersion findUsedOrLastIndexVersoinByIndexId(Long indexId) throws PallasException, SQLException {
IndexVersion version = indexVersionRepository.findUsedOrLastIndexVersoinByIndexId(indexId);
return null==version?null:findVersionById(version.getId());
}
}
8 changes: 8 additions & 0 deletions pallas-core/src/main/resources/mapper/IndexVersionMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@
where index_id = #{indexId,jdbcType=BIGINT} and is_used = 1
</select>

<select id="findUsedOrLastIndexVersoinByIndexId" resultType="com.vip.pallas.mybatis.entity.IndexVersion">
select
<include refid="Base_Column_List" />
from index_version
where index_id = #{indexId,jdbcType=BIGINT}
ORDER BY is_used DESC,id DESC LIMIT 1
</select>

<select id="findRampupByVersionId" parameterType="java.lang.Long" resultType="java.lang.String">
select `ramp_up`
from index_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@
where index_id = #{indexId,jdbcType=BIGINT} and is_used = 1
</select>

<select id="findUsedOrLastIndexVersoinByIndexId" resultType="com.vip.pallas.mybatis.entity.IndexVersion">
select
<include refid="Base_Column_List" />
from index_version
where index_id = #{indexId,jdbcType=BIGINT}
ORDER BY is_used DESC,id DESC LIMIT 1
</select>

<select id="findRampupByVersionId" parameterType="java.lang.Long" resultType="java.lang.String">
select `ramp_up`
from index_version
Expand Down

0 comments on commit f683e5a

Please sign in to comment.