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 b ON brc.bug_id = b.id
INNER JOIN bug_content bc ON brc.bug_id = bc.bug_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 left join test_plan tp on brc.test_plan_id = tp.id
where b.deleted = false <where>
<include refid="queryWhereConditionByProvider"/> <include refid="queryWhereConditionByProvider"/>
<include refid="filter"/> <include refid="filter"/>
order by order by
<if test="sort != null and sort != ''"> <if test="sort != null and sort != ''">
brc.${sort} brc.${sort}
</if> </if>
<if test="sort == null or sort == ''"> <if test="sort == null or sort == ''">
brc.create_time desc brc.create_time desc
</if> </if>
</where>
</select> </select>
<select id="countByCaseId" resultType="java.lang.Long"> <select id="countByCaseId" resultType="java.lang.Long">

View File

@ -39,28 +39,29 @@
</if> </if>
LEFT JOIN `user` u ON fc.create_user = u.id LEFT JOIN `user` u ON fc.create_user = u.id
LEFT JOIN project_version pv ON pv.id = fc.version_id LEFT JOIN project_version pv ON pv.id = fc.version_id
WHERE <where>
fc.deleted = false <if test="request.type != null and request.type != ''">
<if test="request.type != null and request.type != ''"> <choose>
<choose> <when test="request.type == 'PRE'">
<when test="request.type == 'PRE'"> AND fcre.source_id = #{request.id}
AND fcre.source_id = #{request.id} </when>
</when> <when test="request.type == 'POST'">
<when test="request.type == 'POST'"> AND fcre.target_id = #{request.id}
AND fcre.target_id = #{request.id} </when>
</when> </choose>
</choose> </if>
</if> <if test="request.keyword != null and request.keyword != ''">
<if test="request.keyword != null and request.keyword != ''"> and fc.name like concat('%', #{request.keyword},'%')
and fc.name like concat('%', #{request.keyword},'%') </if>
</if> order by
order by <if test="sort != null and sort != ''">
<if test="sort != null and sort != ''"> fc.${sort}
fc.${sort} </if>
</if> <if test="sort == null or sort == ''">
<if test="sort == null or sort == ''"> fcre.create_time desc
fcre.create_time desc </if>
</if> </where>
</select> </select>
<select id="getGraphId" resultType="io.metersphere.system.dto.RelationshipEdgeDTO" parameterType="java.lang.String"> <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.FileCenter;
import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.utils.RelationshipEdgeUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -37,6 +39,10 @@ public class DeleteFunctionalCaseService {
private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper; private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper;
@Resource @Resource
private FunctionalCaseAttachmentMapper functionalCaseAttachmentMapper; private FunctionalCaseAttachmentMapper functionalCaseAttachmentMapper;
@Resource
private FunctionalCaseRelationshipEdgeMapper functionalCaseRelationshipEdgeMapper;
@Resource
private ExtFunctionalCaseRelationshipEdgeMapper extFunctionalCaseRelationshipEdgeMapper;
public void deleteFunctionalCaseResource(List<String> ids, String projectId) { public void deleteFunctionalCaseResource(List<String> ids, String projectId) {
@ -49,6 +55,26 @@ public class DeleteFunctionalCaseService {
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample(); FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdIn(ids); functionalCaseDemandExample.createCriteria().andCaseIdIn(ids);
functionalCaseDemandMapper.deleteByExample(functionalCaseDemandExample); 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.删除关联评审 //5.删除关联评审
CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andCaseIdIn(ids); caseReviewFunctionalCaseExample.createCriteria().andCaseIdIn(ids);
@ -72,7 +98,7 @@ public class DeleteFunctionalCaseService {
request.setFolder(DefaultRepositoryDir.getFunctionalCasePreviewDir(projectId, id)); request.setFolder(DefaultRepositoryDir.getFunctionalCasePreviewDir(projectId, id));
FileCenter.getDefaultRepository().deleteFolder(request); FileCenter.getDefaultRepository().deleteFolder(request);
} catch (Exception e) { } catch (Exception e) {
LogUtils.error("彻底删除功能用例,文件删除失败:{}",e); LogUtils.error("彻底删除功能用例,文件删除失败:{}", e);
} }
} }
//10.自定义字段 //10.自定义字段