fix(系统设置): 删除项目后缺陷表未清理

--bug=1032572 --user=宋昌昌 [系统设置]github#27384MS删除项目后,issue表里的数据没有删除 https://www.tapd.cn/55049933/s/1435389
This commit is contained in:
song-cc-rock 2023-11-10 18:04:15 +08:00 committed by 刘瑞斌
parent e5ee006b66
commit 2e55d11e80
2 changed files with 11 additions and 2 deletions

View File

@ -4,13 +4,14 @@ import io.metersphere.commons.constants.KafkaTopicConstants;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.plan.service.TestPlanProjectService; import io.metersphere.plan.service.TestPlanProjectService;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.service.IssuesService;
import io.metersphere.service.TestCaseService; import io.metersphere.service.TestCaseService;
import jakarta.annotation.Resource;
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener; import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import jakarta.annotation.Resource;
import java.util.List; import java.util.List;
@Component @Component
@ -23,6 +24,8 @@ public class ProjectDeletedListener {
private TestPlanService testPlanService; private TestPlanService testPlanService;
@Resource @Resource
private TestCaseService testCaseService; private TestCaseService testCaseService;
@Resource
private IssuesService issuesService;
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_DELETED_TOPIC, groupId = "${spring.application.name}") @KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_DELETED_TOPIC, groupId = "${spring.application.name}")
public void consume(ConsumerRecord<?, String> record) { public void consume(ConsumerRecord<?, String> record) {
@ -39,5 +42,6 @@ public class ProjectDeletedListener {
}); });
} }
testCaseService.deleteTestCaseByProjectId(projectId); testCaseService.deleteTestCaseByProjectId(projectId);
issuesService.deleteIssueByProjectId(projectId);
} }
} }

View File

@ -55,7 +55,6 @@ import io.metersphere.service.remote.project.TrackIssueTemplateService;
import io.metersphere.service.wapper.TrackProjectService; import io.metersphere.service.wapper.TrackProjectService;
import io.metersphere.service.wapper.UserService; import io.metersphere.service.wapper.UserService;
import io.metersphere.utils.DistinctKeyUtil; import io.metersphere.utils.DistinctKeyUtil;
import io.metersphere.xpack.track.dto.AttachmentRequest;
import io.metersphere.xpack.track.dto.PlatformStatusDTO; import io.metersphere.xpack.track.dto.PlatformStatusDTO;
import io.metersphere.xpack.track.dto.PlatformUser; import io.metersphere.xpack.track.dto.PlatformUser;
import io.metersphere.xpack.track.dto.*; import io.metersphere.xpack.track.dto.*;
@ -608,6 +607,12 @@ public class IssuesService {
testCaseIssuesMapper.deleteByExample(example); testCaseIssuesMapper.deleteByExample(example);
} }
public void deleteIssueByProjectId(String projectId) {
IssuesExample example = new IssuesExample();
example.createCriteria().andProjectIdEqualTo(projectId);
issuesMapper.deleteByExample(example);
}
public void deleteIssueRelate(IssuesRequest request) { public void deleteIssueRelate(IssuesRequest request) {
String caseResourceId = request.getCaseResourceId(); String caseResourceId = request.getCaseResourceId();
String id = request.getId(); String id = request.getId();