refactor(用例评审): 评审详情列表查询

This commit is contained in:
WangXu10 2024-01-30 19:10:54 +08:00 committed by Craftsman
parent 55a6ecae3b
commit c978deefc0
2 changed files with 123 additions and 83 deletions

View File

@ -35,7 +35,7 @@
crfc.case_id as caseId, crfc.case_id as caseId,
crfc.`status` as status, crfc.`status` as status,
crfc.create_time as createTime, crfc.create_time as createTime,
crfc.create_user as createUser, functional_case.create_user as createUser,
user.name as createUserName, user.name as createUserName,
functional_case.version_id as versionId, functional_case.version_id as versionId,
functional_case.module_id as moduleId, functional_case.module_id as moduleId,
@ -45,23 +45,14 @@
FROM FROM
case_review_functional_case crfc case_review_functional_case crfc
LEFT JOIN functional_case ON crfc.case_id = functional_case.id LEFT JOIN functional_case ON crfc.case_id = functional_case.id
LEFT JOIN user ON crfc.create_user = user.id LEFT JOIN user ON functional_case.create_user = user.id
WHERE WHERE
review_id = #{request.reviewId} review_id = #{request.reviewId}
AND functional_case.deleted = #{deleted} AND functional_case.deleted = #{deleted}
<if test="userId != null and userId != ''"> <if test="userId != null and userId != ''">
AND crfc.case_id in (select case_id from case_review_functional_case_user crfcu where crfcu.review_id = #{request.reviewId} and crfcu.user_id = #{userId}) AND crfc.case_id in (select case_id from case_review_functional_case_user crfcu where crfcu.review_id = #{request.reviewId} and crfcu.user_id = #{userId})
</if> </if>
<choose> <include refid="queryWhereCondition"/>
<when test='request.searchMode == "AND"'>
AND <include refid="queryWhereCondition"/>
</when>
<when test='request.searchMode == "OR"'>
and (
<include refid="queryWhereCondition"/>
)
</when>
</choose>
order by order by
<if test="sort != null and sort != ''"> <if test="sort != null and sort != ''">
functional_case.${sort} functional_case.${sort}
@ -75,35 +66,31 @@
<sql id="queryWhereCondition"> <sql id="queryWhereCondition">
<if test="request.moduleIds != null and request.moduleIds.size() > 0"> <if test="request.moduleIds != null and request.moduleIds.size() > 0">
functional_case.module_id in and functional_case.module_id in
<foreach collection="request.moduleIds" item="moduleId" separator="," open="(" close=")"> <foreach collection="request.moduleIds" item="moduleId" separator="," open="(" close=")">
#{moduleId} #{moduleId}
</foreach> </foreach>
<include refid="queryType">
<property name="searchMode" value="request.searchMode"/>
</include>
</if> </if>
<if test="request.keyword != null"> <if test="request.keyword != null">
( and (
functional_case.name like concat('%', #{request.keyword},'%') functional_case.name like concat('%', #{request.keyword},'%')
or functional_case.num like concat('%', #{request.keyword},'%') or functional_case.num like concat('%', #{request.keyword},'%')
or JSON_CONTAINS(tags, concat('["',#{request.keyword},'"]')) or JSON_CONTAINS(tags, concat('["',#{request.keyword},'"]'))
) )
<include refid="queryType">
<property name="searchMode" value="request.searchMode"/>
</include>
</if> </if>
<include refid="filters"> <include refid="filters">
<property name="filter" value="request.filter"/> <property name="filter" value="request.filter"/>
<property name="searchMode" value="request.searchMode"/>
</include> </include>
<if test="request.combine != null"> <choose>
<include refid="combine"> <when test='request.searchMode == "AND"'>
<property name="condition" value="request.combine"/> AND <include refid="queryCombine"/>
<property name="searchMode" value="request.searchMode"/> </when>
</include> <when test='request.searchMode == "OR"'>
</if> and (
1=1 <include refid="queryCombine"/>
)
</when>
</choose>
</sql> </sql>
@ -113,52 +100,34 @@
<if test="values != null and values.size() > 0"> <if test="values != null and values.size() > 0">
<choose> <choose>
<when test="key=='status'"> <when test="key=='status'">
crfc.status in and crfc.status in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/> <include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</when> </when>
<when test="key=='last_execute_result'"> <when test="key=='last_execute_result'">
functional_case.last_execute_result in and functional_case.last_execute_result in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/> <include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</when> </when>
<when test="key=='version_id'"> <when test="key=='version_id'">
functional_case.version_id in and functional_case.version_id in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/> <include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</when> </when>
<when test="key.startsWith('custom_single')"> <when test="key.startsWith('custom_single')">
test_case.id in ( and functional_case.id in (
select resource_id from custom_field_test_case where concat('custom_single-',field_id) = select resource_id from custom_field_test_case where concat('custom_single-',field_id) =
#{key} #{key}
and trim(both '"' from `value`) in and trim(both '"' from `value`) in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/> <include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
) )
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</when> </when>
<when test="key.startsWith('custom_multiple')"> <when test="key.startsWith('custom_multiple')">
test_case.id in ( and functional_case.id in (
select resource_id from custom_field_test_case where concat('custom_multiple-',field_id) = select resource_id from custom_field_test_case where concat('custom_multiple-',field_id) =
#{key} #{key}
and JSON_CONTAINS(`value`, json_array(#{value})) and JSON_CONTAINS(`value`, json_array(#{value}))
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</when> </when>
<when test="key=='create_user'"> <when test="key=='create_user'">
functional_case.create_user in and functional_case.create_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/> <include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</when> </when>
</choose> </choose>
</if> </if>
@ -166,7 +135,18 @@
</if> </if>
</sql> </sql>
<sql id="queryCombine">
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="searchMode" value="request.searchMode"/>
</include>
</if>
1=1
</sql>
<sql id="combine"> <sql id="combine">
<!-- 名称 -->
<if test='${condition}.name != null'> <if test='${condition}.name != null'>
functional_case.name functional_case.name
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
@ -176,6 +156,7 @@
<property name="searchMode" value="${searchMode}"/> <property name="searchMode" value="${searchMode}"/>
</include> </include>
</if> </if>
<!-- id -->
<if test='${condition}.id != null'> <if test='${condition}.id != null'>
functional_case.num functional_case.num
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
@ -185,6 +166,63 @@
<property name="searchMode" value="${searchMode}"/> <property name="searchMode" value="${searchMode}"/>
</include> </include>
</if> </if>
<!-- 所属模块 -->
<if test='${condition}.moduleId != null'>
functional_case.moduleId
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.moduleId"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 创建人 -->
<if test='${condition}.createUser != null'>
functional_case.create_user
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.createUser"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 创建时间 -->
<if test='${condition}.createTime != null'>
functional_case.create_time
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.createTime"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 更新人 -->
<if test='${condition}.updateUser != null'>
functional_case.update_user
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.updateUser"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 更新时间 -->
<if test='${condition}.updateTime != null'>
functional_case.update_time
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.updateTime"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 标签 -->
<if test='${condition}.tags != null'>
<include refid="queryTag">
<property name="searchMode" value="${searchMode}"/>
<property name="combineTag" value="${condition}.tags"/>
</include>
</if>
<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="">
functional_case.id ${custom.operator} ( functional_case.id ${custom.operator} (
@ -225,6 +263,37 @@
</choose> </choose>
</sql> </sql>
<sql id="queryTag">
<!-- 不包含 -->
<if test='${combineTag}.value.size() > 0 and ${combineTag}.operator == "not like"'>
(
functional_case.tags is null or functional_case.tags = '[]' or
<foreach collection="${combineTag}.value" item="tag" separator="and" open="(" close=")">
!JSON_CONTAINS(functional_case.tags, JSON_ARRAY(#{tag}))
</foreach>
)
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 包含 -->
<if test='${combineTag}.value.size() > 0 and ${combineTag}.operator == "like"'>
<foreach collection="${combineTag}.value" item="tag" separator="or" open="(" close=")">
JSON_CONTAINS(functional_case.tags, JSON_ARRAY(#{tag}))
</foreach>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!---->
<if test='${combineTag}.operator == "is null"'>
(functional_case.tags is null or functional_case.tags = '[]')
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
</sql>
<select id="getIds" resultType="java.lang.String"> <select id="getIds" resultType="java.lang.String">
SELECT SELECT
crfc.id as id crfc.id as id
@ -391,16 +460,7 @@
<if test="userId != null and userId != ''"> <if test="userId != null and userId != ''">
AND crfc.case_id in (select crfcu.case_id from case_review_functional_case_user crfcu where crfcu.review_id = #{request.reviewId} and crfcu.user_id = #{userId}) AND crfc.case_id in (select crfcu.case_id from case_review_functional_case_user crfcu where crfcu.review_id = #{request.reviewId} and crfcu.user_id = #{userId})
</if> </if>
<choose> <include refid="queryWhereCondition"/>
<when test='request.searchMode == "AND"'>
AND <include refid="queryWhereCondition"/>
</when>
<when test='request.searchMode == "OR"'>
and (
<include refid="queryWhereCondition"/>
)
</when>
</choose>
GROUP BY module_id GROUP BY module_id
</select> </select>
@ -413,16 +473,7 @@
<if test="userId != null and userId != ''"> <if test="userId != null and userId != ''">
AND crfc.case_id in (select case_id from case_review_functional_case_user crfcu where crfcu.review_id = #{request.reviewId} and crfcu.user_id = #{userId}) AND crfc.case_id in (select case_id from case_review_functional_case_user crfcu where crfcu.review_id = #{request.reviewId} and crfcu.user_id = #{userId})
</if> </if>
<choose> <include refid="queryWhereCondition"/>
<when test='request.searchMode == "AND"'>
AND <include refid="queryWhereCondition"/>
</when>
<when test='request.searchMode == "OR"'>
and (
<include refid="queryWhereCondition"/>
)
</when>
</choose>
</select> </select>

View File

@ -462,17 +462,6 @@
</if> </if>
</sql> </sql>
<sql id="prefixMode">
<choose>
<when test='${searchMode} == "AND"'>
1 = 1
</when>
<when test='${searchMode} == "OR"'>
1 = 2
</when>
</choose>
</sql>
<sql id="queryType"> <sql id="queryType">
<choose> <choose>
<when test='${searchMode} == "AND"'> <when test='${searchMode} == "AND"'>