fix(用例管理): 前后置用例删除与彻底删除问题

--bug=1036173 --user=王旭 【用例查看】-依赖关系-删除用例的前后置依赖用例,用例依赖标签数量错误 https://www.tapd.cn/55049933/s/1506308
This commit is contained in:
WangXu10 2024-04-23 11:42:56 +08:00 committed by 刘瑞斌
parent 341ed433ea
commit e92aea49e0
3 changed files with 61 additions and 33 deletions

View File

@ -83,16 +83,17 @@
INNER JOIN bug b ON brc.bug_id = b.id
INNER JOIN bug_content bc ON brc.bug_id = bc.bug_id
left join test_plan tp on brc.test_plan_id = tp.id
where b.deleted = false
<include refid="queryWhereConditionByProvider"/>
<include refid="filter"/>
order by
<if test="sort != null and sort != ''">
brc.${sort}
</if>
<if test="sort == null or sort == ''">
brc.create_time desc
</if>
<where>
<include refid="queryWhereConditionByProvider"/>
<include refid="filter"/>
order by
<if test="sort != null and sort != ''">
brc.${sort}
</if>
<if test="sort == null or sort == ''">
brc.create_time desc
</if>
</where>
</select>
<select id="countByCaseId" resultType="java.lang.Long">

View File

@ -39,28 +39,29 @@
</if>
LEFT JOIN `user` u ON fc.create_user = u.id
LEFT JOIN project_version pv ON pv.id = fc.version_id
WHERE
fc.deleted = false
<if test="request.type != null and request.type != ''">
<choose>
<when test="request.type == 'PRE'">
AND fcre.source_id = #{request.id}
</when>
<when test="request.type == 'POST'">
AND fcre.target_id = #{request.id}
</when>
</choose>
</if>
<if test="request.keyword != null and request.keyword != ''">
and fc.name like concat('%', #{request.keyword},'%')
</if>
order by
<if test="sort != null and sort != ''">
fc.${sort}
</if>
<if test="sort == null or sort == ''">
fcre.create_time desc
</if>
<where>
<if test="request.type != null and request.type != ''">
<choose>
<when test="request.type == 'PRE'">
AND fcre.source_id = #{request.id}
</when>
<when test="request.type == 'POST'">
AND fcre.target_id = #{request.id}
</when>
</choose>
</if>
<if test="request.keyword != null and request.keyword != ''">
and fc.name like concat('%', #{request.keyword},'%')
</if>
order by
<if test="sort != null and sort != ''">
fc.${sort}
</if>
<if test="sort == null or sort == ''">
fcre.create_time desc
</if>
</where>
</select>
<select id="getGraphId" resultType="io.metersphere.system.dto.RelationshipEdgeDTO" parameterType="java.lang.String">

View File

@ -6,7 +6,9 @@ import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.utils.RelationshipEdgeUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -37,6 +39,10 @@ public class DeleteFunctionalCaseService {
private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper;
@Resource
private FunctionalCaseAttachmentMapper functionalCaseAttachmentMapper;
@Resource
private FunctionalCaseRelationshipEdgeMapper functionalCaseRelationshipEdgeMapper;
@Resource
private ExtFunctionalCaseRelationshipEdgeMapper extFunctionalCaseRelationshipEdgeMapper;
public void deleteFunctionalCaseResource(List<String> ids, String projectId) {
@ -49,6 +55,26 @@ public class DeleteFunctionalCaseService {
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdIn(ids);
functionalCaseDemandMapper.deleteByExample(functionalCaseDemandExample);
//4.删除依赖关系
FunctionalCaseRelationshipEdgeExample relationshipEdgeExample = new FunctionalCaseRelationshipEdgeExample();
relationshipEdgeExample.createCriteria()
.andSourceIdIn(ids);
relationshipEdgeExample.or(
relationshipEdgeExample.createCriteria()
.andTargetIdIn(ids)
);
List<FunctionalCaseRelationshipEdge> edgeList = functionalCaseRelationshipEdgeMapper.selectByExample(relationshipEdgeExample);
if (CollectionUtils.isNotEmpty(edgeList)) {
List<String> edgeIds = edgeList.stream().map(FunctionalCaseRelationshipEdge::getId).toList();
edgeIds.forEach(id -> {
RelationshipEdgeUtils.updateGraphId(id, extFunctionalCaseRelationshipEdgeMapper::getGraphId, extFunctionalCaseRelationshipEdgeMapper::getEdgeByGraphId, extFunctionalCaseRelationshipEdgeMapper::update);
});
relationshipEdgeExample.clear();
relationshipEdgeExample.createCriteria().andIdIn(edgeIds);
functionalCaseRelationshipEdgeMapper.deleteByExample(relationshipEdgeExample);
}
//5.删除关联评审
CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andCaseIdIn(ids);
@ -72,7 +98,7 @@ public class DeleteFunctionalCaseService {
request.setFolder(DefaultRepositoryDir.getFunctionalCasePreviewDir(projectId, id));
FileCenter.getDefaultRepository().deleteFolder(request);
} catch (Exception e) {
LogUtils.error("彻底删除功能用例,文件删除失败:{}",e);
LogUtils.error("彻底删除功能用例,文件删除失败:{}", e);
}
}
//10.自定义字段