fix(高级搜索): 多选成员类型搜索问题

story 1004114
This commit is contained in:
shiziyuan9527 2022-05-23 11:51:23 +08:00 committed by shiziyuan9527
parent 2730922faa
commit aabb8f426c
6 changed files with 67 additions and 19 deletions

View File

@ -248,11 +248,28 @@
<if test="${condition}.customs != null and ${condition}.customs.size() > 0"> <if test="${condition}.customs != null and ${condition}.customs.size() > 0">
<foreach collection="${condition}.customs" item="custom" separator="" open="" close=""> <foreach collection="${condition}.customs" item="custom" separator="" open="" close="">
and issues.id in ( and issues.id in (
select resource_id from custom_field_issues where field_id = #{custom.id} select resource_id from custom_field_issues where field_id = #{custom.id}
and trim(both '"' from value) <choose>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition"> <when test="custom.type == 'multipleMember'">
<property name="object" value="custom"/> <foreach item="item" collection='custom.value.split(",")' open="" separator="" close="">
</include>) and left(`value`, 1) = '['
and find_in_set(#{item}, replace(replace(`value`, ']', ''), '[', ''))
</foreach>
</when>
<when test="custom.type == 'date' or custom.type == 'datetime'">
and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13)
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition">
<property name="object" value="custom"/>
</include>
</when>
<otherwise>
and trim(both '"' from value)
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition">
<property name="object" value="custom"/>
</include>
</otherwise>
</choose>
)
</foreach> </foreach>
</if> </if>
</sql> </sql>

View File

@ -82,16 +82,27 @@
<foreach collection="${condition}.customs" item="custom" separator="" open="" close=""> <foreach collection="${condition}.customs" item="custom" separator="" open="" close="">
and test_case.id in ( and test_case.id in (
select resource_id from custom_field_test_case where field_id = #{custom.id} select resource_id from custom_field_test_case where field_id = #{custom.id}
<if test="custom.type == 'multipleMember'"> <choose>
and `value` = #{custom.value} <when test="custom.type == 'multipleMember'">
</if> <foreach item="item" collection='custom.value.split(",")' open="" separator="" close="">
<if test="custom.type != 'multipleMember'"> and left(`value`, 1) = '['
and trim(both '"' from value) and find_in_set(#{item}, replace(replace(`value`, ']', ''), '[', ''))
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition"> </foreach>
<property name="object" value="custom"/> </when>
</include> <when test="custom.type == 'date' or custom.type == 'datetime'">
</if> and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13)
) <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition">
<property name="object" value="custom"/>
</include>
</when>
<otherwise>
and trim(both '"' from value)
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition">
<property name="object" value="custom"/>
</include>
</otherwise>
</choose>
)
</foreach> </foreach>
</if> </if>
</sql> </sql>

View File

@ -117,10 +117,19 @@ export default {
if (!condition.customs) { if (!condition.customs) {
condition['customs'] = []; condition['customs'] = [];
} }
let value = component.value;
if (component.type === "multipleMember") {
try {
let str = JSON.stringify(component.value);
value = str.substring(1, str.length - 1);
} catch (e) {
// nothing
}
}
condition['customs'].push({ condition['customs'].push({
id: component.key, id: component.key,
operator: component.operator.value, operator: component.operator.value,
value: component.type === "multipleMember" ? JSON.stringify(component.value) : component.value, value: value,
type: component.type type: component.type
}); });
} }

View File

@ -633,6 +633,7 @@ export default {
this.testCaseTemplate = template; this.testCaseTemplate = template;
this.fields = getTableHeaderWithCustomFields('TRACK_TEST_CASE', this.testCaseTemplate.customFields, this.members); this.fields = getTableHeaderWithCustomFields('TRACK_TEST_CASE', this.testCaseTemplate.customFields, this.members);
// todo // todo
this.condition.components = this.condition.components.filter(item => item.custom !== true);
let comp = getAdvSearchCustomField(this.condition, this.testCaseTemplate.customFields); let comp = getAdvSearchCustomField(this.condition, this.testCaseTemplate.customFields);
this.condition.components.push(...comp); this.condition.components.push(...comp);
this.setTestCaseDefaultValue(template); this.setTestCaseDefaultValue(template);
@ -672,6 +673,9 @@ export default {
return value ? value : ''; return value ? value : '';
}, },
getCustomFieldFilter(field) { getCustomFieldFilter(field) {
if (field.type === 'multipleMember') {
return null;
}
return Array.isArray(field.options) ? return Array.isArray(field.options) ?
(field.options.length > 0 ? field.options : null) : null; (field.options.length > 0 ? field.options : null) : null;
}, },

View File

@ -128,7 +128,7 @@
</ms-table-column> </ms-table-column>
<ms-table-column v-for="field in issueTemplate.customFields" :key="field.id" <ms-table-column v-for="field in issueTemplate.customFields" :key="field.id"
:filters="Array.isArray(field.options) ? (field.options.length > 0 ? field.options : null) : null" :filters="getCustomFieldFilter(field)"
:field="item" :field="item"
:fields-width="fieldsWidth" :fields-width="fieldsWidth"
:label="field.system ? $t(systemNameMap[field.name]) :field.name" :label="field.system ? $t(systemNameMap[field.name]) :field.name"
@ -272,6 +272,13 @@ export default {
getCustomFieldValue(row, field) { getCustomFieldValue(row, field) {
return getCustomFieldValue(row, field, this.members); return getCustomFieldValue(row, field, this.members);
}, },
getCustomFieldFilter(field) {
if (field.type === 'multipleMember') {
return null;
}
return Array.isArray(field.options) ?
(field.options.length > 0 ? field.options : null) : null;
},
initFields(template) { initFields(template) {
this.issueTemplate = template; this.issueTemplate = template;
if (this.issueTemplate.platform === LOCAL) { if (this.issueTemplate.platform === LOCAL) {
@ -279,7 +286,7 @@ export default {
} else { } else {
this.isThirdPart = true; this.isThirdPart = true;
} }
this.fields = getTableHeaderWithCustomFields('ISSUE_LIST', this.issueTemplate.customFields); this.fields = getTableHeaderWithCustomFields('ISSUE_LIST', this.issueTemplate.customFields, this.members);
if (!this.isThirdPart) { if (!this.isThirdPart) {
for (let i = 0; i < this.fields.length; i++) { for (let i = 0; i < this.fields.length; i++) {
if (this.fields[i].id === 'platformStatus') { if (this.fields[i].id === 'platformStatus') {

View File

@ -525,7 +525,7 @@ export function getCustomFieldValue(row, field, members) {
val += i + ' '; val += i + ' ';
}); });
return val; return val;
} else if (field.type === 'datetime') { } else if (field.type === 'datetime' || field.type === 'date') {
return timestampFormatDate(item.value); return timestampFormatDate(item.value);
} else if (['richText', 'textarea'].indexOf(field.type) > -1) { } else if (['richText', 'textarea'].indexOf(field.type) > -1) {
return item.textValue; return item.textValue;