feat(用例评审): 删除项目时删除用例评审资源

This commit is contained in:
guoyuqi 2023-12-04 18:25:34 +08:00 committed by 刘瑞斌
parent b4915df347
commit 106800e6cd
4 changed files with 64 additions and 21 deletions

View File

@ -1,19 +0,0 @@
package io.metersphere.functional.service;
import io.metersphere.system.service.CleanupProjectResourceService;
import io.metersphere.sdk.util.LogUtils;
import org.springframework.stereotype.Component;
@Component
public class CleanupCaseResourceService implements CleanupProjectResourceService {
@Override
public void deleteResources(String projectId) {
LogUtils.info("删除当前项目[" + projectId + "]相关功能用例资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关功能用例报告资源");
}
}

View File

@ -0,0 +1,46 @@
package io.metersphere.functional.service;
import io.metersphere.functional.domain.CaseReview;
import io.metersphere.functional.domain.CaseReviewExample;
import io.metersphere.functional.domain.CaseReviewModuleExample;
import io.metersphere.functional.mapper.CaseReviewMapper;
import io.metersphere.functional.mapper.CaseReviewModuleMapper;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.CleanupProjectResourceService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class CleanupCaseReviewResourceService implements CleanupProjectResourceService {
@Resource
private DeleteCaseReviewService deleteCaseReviewService;
@Resource
private CaseReviewModuleMapper caseReviewModuleMapper;
@Resource
private CaseReviewMapper caseReviewMapper;
@Override
public void deleteResources(String projectId) {
LogUtils.info("删除当前项目[" + projectId + "]相关用例评审资源");
CaseReviewExample caseReviewExample = new CaseReviewExample();
caseReviewExample.createCriteria().andProjectIdEqualTo(projectId);
List<CaseReview> caseReviews = caseReviewMapper.selectByExample(caseReviewExample);
List<String> ids = caseReviews.stream().map(CaseReview::getId).toList();
if (CollectionUtils.isNotEmpty(ids)) {
deleteCaseReviewService.deleteCaseReviewResource(ids, projectId);
}
//删除模块
CaseReviewModuleExample caseReviewModuleExample = new CaseReviewModuleExample();
caseReviewModuleExample.createCriteria().andProjectIdEqualTo(projectId);
caseReviewModuleMapper.deleteByExample(caseReviewModuleExample);
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关用例评审报告资源");
}
}

View File

@ -1,6 +1,6 @@
package io.metersphere.functional.controller;
import io.metersphere.functional.service.CleanupCaseResourceService;
import io.metersphere.functional.service.CleanupCaseReviewResourceService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@ -15,12 +17,14 @@ import org.springframework.boot.test.context.SpringBootTest;
@AutoConfigureMockMvc
public class CleanupResourceTests {
@Resource
private CleanupCaseResourceService resourceService;
private CleanupCaseReviewResourceService resourceService;
@Test
@Order(1)
@Sql(scripts = {"/dml/init_clean_review_resource_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void testCleanupResource() throws Exception {
resourceService.deleteResources("test");
resourceService.deleteResources("project_clean_gyq");
}
@Test

View File

@ -0,0 +1,12 @@
INSERT INTO case_review(id, num, name, module_id, project_id, status, review_pass_rule, pos, start_time, end_time, case_count, pass_rate, tags, description, create_time, create_user, update_time, update_user)
VALUES ('case_review_clean_id',1001,'case_review_clean','module_id','project_clean_gyq', 'PASS', 'SINGLE', 001, null,null,2,100.00,null,null, 1698058347559, 'admin',1698058347559,'admin');