fix(测试跟踪 ): 修复公共用例库批量复制用例到模块后,再次批量复制到同一模块会报错

--bug=1009848 --user=王孝刚 公共用例库 批量复制用例到模块后,再次批量复制到同一模块会报错
https://www.tapd.cn/55049933/s/1096183
This commit is contained in:
wxg0103 2022-01-22 14:26:28 +08:00
parent e7c7ca9d10
commit f9ee1c5f89
4 changed files with 94 additions and 68 deletions

View File

@ -67,8 +67,11 @@ public interface ExtTestCaseMapper {
List<String> selectIds(@Param("request") BaseQueryRequest condition);
List<String> selectPublicIds(@Param("request") BaseQueryRequest condition);
/**
* 按照用例等级统计
*
* @param projectId 项目ID
* @return 统计结果
*/

View File

@ -82,7 +82,6 @@
<update id="updateTestCaseCustomNumByProjectId">
update test_case set custom_num = num where (custom_num is null or custom_num = '') and project_id = #{projectId}
</update>
<select id="getTestCaseByNotInReview" resultType="io.metersphere.track.dto.TestCaseDTO">
select
test_case.id,
@ -282,76 +281,21 @@
test_case.other_test_name, test_case.review_status, test_case.tags,
test_case.demand_id, test_case.demand_name, test_case.`status`,
test_case.custom_num, test_case.step_model, test_case.create_user,u.name as createName,
test_case.custom_fields,test_case.case_public , project.name as projectName ,test_case.ref_id
test_case.custom_fields,test_case.case_public ,
project.workspace_id , project.name as projectName ,test_case.ref_id ,test_case.`order`
</if>
from test_case left join user u on test_case.create_user=u.id
left join (select id,workspace_id,NAME from project where workspace_id =#{request.workspaceId})
project on test_case.project_id = project.id
project on test_case.project_id = project.id
left join project_version on project.id = project_version.project_id and project_version.id =
test_case.version_id
<where>
<include refid="filters"/>
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
<property name="objectKey" value="request.combine.tags"/>
</include>
</if>
<if test="request.statusIsNot != null">
and (test_case.status is null or test_case.status != #{request.statusIsNot})
</if>
<if test="request.notEqStatus != null">
and (test_case.status is null or test_case.status != #{request.notEqStatus})
</if>
<if test="request.name != null">
and (test_case.name like CONCAT('%', #{request.name},'%')
or test_case.num like CONCAT('%', #{request.name},'%')
or test_case.tags like CONCAT('%', #{request.name},'%')
or test_case.custom_num like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.ids != null">
and test_case.id in
<foreach collection="request.ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
<if test="request.relevanceCreateTime >0">
and test_case.id in (select test_case_id from test_case_test where test_case_test.create_time >=
#{request.createTime})
</if>
<if test="request.createTime >0">
and test_case.create_time >= #{request.createTime}
</if>
<if test="request.nodeIds != null and request.nodeIds.size() > 0">
and test_case.node_id in
<foreach collection="request.nodeIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<if test="request.workspaceId != null">
AND test_case.project_id in (select id from project where workspace_id=#{request.workspaceId})
</if>
and test_case.case_public = TRUE
<include refid="filters"/>
<if test="request.caseCoverage == 'uncoverage' ">
and test_case.id not in (select distinct test_case_test.test_case_id from test_case_test)
</if>
<if test="request.caseCoverage == 'coverage' ">
and test_case.id in (select distinct test_case_test.test_case_id from test_case_test)
</if>
</where>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>) test_case right join
(select
max(test_case.update_time) update_time , ref_id
from test_case left join user u on test_case.create_user=u.id
) test_case right join
(select
max(test_case.update_time) update_time , ref_id
from test_case
left join (select id,workspace_id,NAME from project where workspace_id =#{request.workspaceId})
project on test_case.project_id = project.id
left join project_version on project.id = project_version.project_id and project_version.id =
test_case.version_id
project on test_case.project_id = project.id group by test_case.ref_id
) tmp on test_case.update_time = tmp.update_time and test_case.ref_id = tmp.ref_id
<where>
<include refid="filters"/>
<if test="request.combine != null">
@ -406,8 +350,8 @@
and test_case.id in (select distinct test_case_test.test_case_id from test_case_test)
</if>
</where>
group by test_case.ref_id
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>) tmp on test_case.update_time = tmp.update_time and test_case.ref_id = tmp.ref_id
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
@ -516,6 +460,83 @@
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<select id="selectPublicIds" resultType="java.lang.String">
select test_case.id from
(select
test_case.id,test_case.update_time, test_case.ref_id , test_case.`status` , test_case.case_public ,
test_case.project_id
from test_case left join project on test_case.project_id = project.id) test_case
right join (select
max(test_case.update_time) update_time , ref_id
from test_case
left join (select id,workspace_id,NAME from project where workspace_id =#{request.workspaceId})
project on test_case.project_id = project.id
where (test_case.STATUS IS NULL OR test_case.STATUS != 'Trash') and test_case.case_public=true GROUP BY ref_id)
tmp on test_case.update_time = tmp.update_time and test_case.ref_id = tmp.ref_id
<where>
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
<property name="objectKey" value="request.combine.tags"/>
</include>
</if>
<if test="request.statusIsNot != null">
and (test_case.status is null or test_case.status != #{request.statusIsNot})
</if>
<if test="request.notEqStatus != null">
and (test_case.status is null or test_case.status != #{request.notEqStatus})
</if>
<if test="request.name != null">
and (test_case.name like CONCAT('%', #{request.name},'%')
or test_case.num like CONCAT('%', #{request.name},'%')
or test_case.tags like CONCAT('%', #{request.name},'%')
or test_case.custom_num like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.ids != null">
and test_case.id in
<foreach collection="request.ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
<if test="request.relevanceCreateTime >0">
and test_case.id in (select test_case_id from test_case_test where test_case_test.create_time >=
#{request.createTime})
</if>
<if test="request.createTime >0">
and test_case.create_time >= #{request.createTime}
</if>
<if test="request.nodeIds != null and request.nodeIds.size() > 0">
and test_case.node_id in
<foreach collection="request.nodeIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<if test="request.workspaceId != null">
AND test_case.project_id in (select id from project where workspace_id=#{request.workspaceId})
</if>
<if test="request.projectId != null">
and test_case.project_id = #{request.projectId}
</if>
<include refid="filters"/>
<if test="request.caseCoverage == 'uncoverage' ">
and test_case.id not in (select distinct test_case_test.test_case_id from test_case_test)
</if>
<if test="request.caseCoverage == 'coverage' ">
and test_case.id in (select distinct test_case_test.test_case_id from test_case_test)
</if>
<if test="request.versionId != null">
and test_case.version_id = #{request.versionId}
</if>
<if test="request.refId != null">
and test_case.ref_id = #{request.refId}
</if>
and test_case.case_public = TRUE
</where>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<sql id="filters">
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">

View File

@ -1466,7 +1466,7 @@ public class TestCaseService {
public void copyTestCaseBathPublic(TestCaseBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extTestCaseMapper.selectIds(query));
(query) -> extTestCaseMapper.selectPublicIds(query));
List<String> ids = request.getIds();
if (CollectionUtils.isEmpty(ids)) {
return;

View File

@ -1158,6 +1158,8 @@ export default {
copyPublic(param) {
param.condition = this.condition;
param.projectId = this.projectId;
param.condition.projectId = null;
param.condition.ids = null;
this.page.result = this.$post('/test/case/batch/copy/public', param, () => {
this.$success(this.$t('commons.save_success'));
this.$refs.testBatchMove.close();