refactor(接口测试): 优化接口定时清理报告的逻辑

This commit is contained in:
wxg0103 2024-01-29 14:51:18 +08:00 committed by wxg0103
parent 15fc7e84ae
commit 25fc319557
32 changed files with 268 additions and 322 deletions

View File

@ -33,8 +33,8 @@ public class ApiDefinitionModuleController {
@Operation(summary = "接口测试-接口管理-模块-查找模块")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
@CheckOwner(resourceId = "#request.projectId", resourceType = "project")
public List<BaseTreeNode> getTree(@RequestBody @Validated ApiModuleRequest request) {
return apiDefinitionModuleService.getTree(request, false);
public List<BaseTreeNode> getTreeAndRequest(@RequestBody @Validated ApiModuleRequest request) {
return apiDefinitionModuleService.getTree(request, false, true);
}
@PostMapping("/add")
@ -97,4 +97,12 @@ public class ApiDefinitionModuleController {
public EnvApiTreeDTO envTree(@RequestBody @Validated EnvApiModuleRequest request) {
return apiDefinitionModuleService.envTree(request);
}
@PostMapping("/only/tree")
@Operation(summary = "接口测试-接口管理-模块-不包含请求数据的模块树")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
@CheckOwner(resourceId = "#request.projectId", resourceType = "project")
public List<BaseTreeNode> getTree(@RequestBody @Validated ApiModuleRequest request) {
return apiDefinitionModuleService.getTree(request, false, false);
}
}

View File

@ -40,7 +40,7 @@ public class ApiReportShareService {
@Resource
private ApiScenarioReportMapper apiScenarioReportMapper;
private static final Long DEFAULT = 1000L * 60 * 60 * 24 * 30;
private static final Long DEFAULT = 1000L * 60 * 60 * 24;
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void validateExpired(ShareInfo shareInfo) {

View File

@ -0,0 +1,95 @@
package io.metersphere.api.service;
import io.metersphere.api.domain.*;
import io.metersphere.api.mapper.*;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.BaseCleanUpReport;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import static io.metersphere.sdk.util.ShareUtil.getCleanDate;
@Component
@Transactional(rollbackFor = Exception.class)
public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
@Resource
private ApiReportMapper apiReportMapper;
@Resource
private ExtApiReportMapper extApiReportMapper;
@Resource
private ApiReportStepMapper apiReportStepMapper;
@Resource
private ApiReportDetailMapper apiReportDetailMapper;
@Resource
private ApiReportLogMapper apiReportLogMapper;
@Resource
private ApiScenarioReportMapper apiScenarioReportMapper;
@Resource
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
@Resource
private ApiScenarioReportStepMapper apiScenarioReportStepMapper;
@Resource
private ApiScenarioReportDetailMapper apiScenarioReportDetailMapper;
@Resource
private ApiScenarioReportLogMapper apiScenarioReportLogMapper;
@Override
public void cleanReport(Map<String, String> map, String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关接口测试报告");
String expr = map.get(ProjectApplicationType.API.API_CLEAN_REPORT.name());
long timeMills = getCleanDate(expr);
int apiReportCount = extApiReportMapper.selectApiReportByTime(timeMills, projectId);
while (apiReportCount > 0) {
List<String> ids = extApiReportMapper.selectApiReportByProjectIdAndTime(timeMills, projectId);
ApiReportExample reportExample = new ApiReportExample();
reportExample.createCriteria().andIdIn(ids);
ApiReport report = new ApiReport();
report.setDeleted(true);
apiReportMapper.updateByExampleSelective(report, reportExample);
deleteApiReport(ids);
apiReportCount = extApiReportMapper.selectApiReportByTime(timeMills, projectId);
}
int scenarioReportCount = extApiScenarioReportMapper.selectScenarioReportByTime(timeMills, projectId);
while (scenarioReportCount > 0) {
List<String> ids = extApiScenarioReportMapper.selectApiReportByProjectIdAndTime(timeMills, projectId);
ApiScenarioReportExample reportExample = new ApiScenarioReportExample();
reportExample.createCriteria().andIdIn(ids);
ApiScenarioReport report = new ApiScenarioReport();
report.setDeleted(true);
apiScenarioReportMapper.updateByExampleSelective(report, reportExample);
deleteScenarioReport(ids);
scenarioReportCount = extApiScenarioReportMapper.selectScenarioReportByTime(timeMills, projectId);
}
}
private void deleteApiReport(List<String> ids) {
ApiReportStepExample stepExample = new ApiReportStepExample();
stepExample.createCriteria().andReportIdIn(ids);
apiReportStepMapper.deleteByExample(stepExample);
ApiReportDetailExample detailExample = new ApiReportDetailExample();
detailExample.createCriteria().andReportIdIn(ids);
apiReportDetailMapper.deleteByExample(detailExample);
ApiReportLogExample logExample = new ApiReportLogExample();
logExample.createCriteria().andReportIdIn(ids);
apiReportLogMapper.deleteByExample(logExample);
}
private void deleteScenarioReport(List<String> ids) {
ApiScenarioReportStepExample stepExample = new ApiScenarioReportStepExample();
stepExample.createCriteria().andReportIdIn(ids);
apiScenarioReportStepMapper.deleteByExample(stepExample);
ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample();
detailExample.createCriteria().andReportIdIn(ids);
apiScenarioReportDetailMapper.deleteByExample(detailExample);
ApiScenarioReportLogExample logExample = new ApiScenarioReportLogExample();
logExample.createCriteria().andReportIdIn(ids);
apiScenarioReportLogMapper.deleteByExample(logExample);
}
}

View File

@ -3,12 +3,8 @@ package io.metersphere.api.service;
import io.metersphere.api.domain.*;
import io.metersphere.api.mapper.*;
import io.metersphere.api.service.schedule.SwaggerUrlImportJob;
import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.domain.ShareInfoExample;
import io.metersphere.sdk.mapper.ShareInfoMapper;
import io.metersphere.sdk.util.LogUtils;
@ -28,12 +24,9 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
import static io.metersphere.sdk.util.ShareUtil.getCleanDate;
@Component
@Transactional(rollbackFor = Exception.class)
public class CleanupApiResourceService implements CleanupProjectResourceService {
public class CleanupApiResourceServiceImpl implements CleanupProjectResourceService {
@Resource
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
@ -88,12 +81,8 @@ public class CleanupApiResourceService implements CleanupProjectResourceService
@Resource
private ShareInfoMapper shareInfoMapper;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
@Resource
private ApiDefinitionSwaggerMapper apiDefinitionSwaggerMapper;
private static final String DEFAULT = "30D";
@Async
@Override
@ -119,46 +108,6 @@ public class CleanupApiResourceService implements CleanupProjectResourceService
shareInfoMapper.deleteByExample(example);
}
@Async
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关接口测试报告资源");
//只是删除报告的详情 但是会保存执行历史
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andProjectIdEqualTo(projectId).andTypeEqualTo(ProjectApplicationType.API.API_CLEAN_REPORT.name());
List<ProjectApplication> projectApplications = projectApplicationMapper.selectByExample(example);
long timeMills = 0;
if (CollectionUtils.isNotEmpty(projectApplications)) {
String expr = projectApplications.getFirst().getTypeValue();
timeMills = getCleanDate(expr);
} else {
timeMills = getCleanDate(DEFAULT);
}
int apiReportCount = extApiReportMapper.selectApiReportByTime(timeMills, projectId);
while (apiReportCount > 0) {
List<String> ids = extApiReportMapper.selectApiReportByProjectIdAndTime(timeMills, projectId);
ApiReportExample reportExample = new ApiReportExample();
reportExample.createCriteria().andIdIn(ids);
ApiReport report = new ApiReport();
report.setDeleted(true);
apiReportMapper.updateByExampleSelective(report, reportExample);
deleteApiReport(ids);
apiReportCount = extApiReportMapper.selectApiReportByTime(timeMills, projectId);
}
int scenarioReportCount = extApiScenarioReportMapper.selectScenarioReportByTime(timeMills, projectId);
while (scenarioReportCount > 0) {
List<String> ids = extApiScenarioReportMapper.selectApiReportByProjectIdAndTime(timeMills, projectId);
ApiScenarioReportExample reportExample = new ApiScenarioReportExample();
reportExample.createCriteria().andIdIn(ids);
ApiScenarioReport report = new ApiScenarioReport();
report.setDeleted(true);
apiScenarioReportMapper.updateByExampleSelective(report, reportExample);
deleteScenarioReport(ids);
scenarioReportCount = extApiScenarioReportMapper.selectScenarioReportByTime(timeMills, projectId);
}
}
private void delScenarioModule(String projectId) {
ApiScenarioModuleExample apiScenarioModuleExample = new ApiScenarioModuleExample();
apiScenarioModuleExample.createCriteria().andProjectIdEqualTo(projectId);

View File

@ -61,10 +61,13 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
@Resource
private ApiTestCaseService apiTestCaseService;
public List<BaseTreeNode> getTree(ApiModuleRequest request, boolean deleted) {
public List<BaseTreeNode> getTree(ApiModuleRequest request, boolean deleted, boolean containRequest) {
//接口的树结构是 模块子模块+接口 接口为非delete状态的
List<BaseTreeNode> fileModuleList = extApiDefinitionModuleMapper.selectBaseByRequest(request);
List<BaseTreeNode> baseTreeNodes = super.buildTreeAndCountResource(fileModuleList, true, Translator.get(UNPLANNED_API));
if (!containRequest) {
return baseTreeNodes;
}
List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted);
return apiDebugModuleService.getBaseTreeNodes(apiTreeNodeList, baseTreeNodes);

View File

@ -59,6 +59,7 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
private static final String URL_FILE_MODULE_COUNT = "/api/definition/module/count";
private static final String URL_MODULE_TRASH_TREE = "/api/definition/module/trash/tree";
private static final String URL_MODULE_TRASH_COUNT = "/api/definition/module/trash/count";
private static final String URL_MODULE_ONLY_TREE = "/api/definition/module/only/tree";
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
private static Project project;
@ -953,6 +954,10 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
this.setProtocol("HTTP");
this.setProjectId(project.getId());
}});
this.requestPostWithOkAndReturn(URL_MODULE_ONLY_TREE, new ApiModuleRequest() {{
this.setProtocol("HTTP");
this.setProjectId(project.getId());
}});
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);

View File

@ -2,12 +2,11 @@ package io.metersphere.api.controller;
import io.metersphere.api.domain.*;
import io.metersphere.api.mapper.*;
import io.metersphere.api.service.CleanupApiResourceService;
import io.metersphere.api.service.CleanupApiReportServiceImpl;
import io.metersphere.api.service.CleanupApiResourceServiceImpl;
import io.metersphere.api.service.definition.ApiReportService;
import io.metersphere.api.service.scenario.ApiScenarioReportService;
import io.metersphere.api.service.schedule.SwaggerUrlImportJob;
import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.sdk.constants.ApiReportStatus;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.constants.ScheduleType;
@ -25,7 +24,9 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ -34,7 +35,7 @@ import java.util.List;
public class CleanupApiTests {
private final ProjectServiceInvoker serviceInvoker;
@Resource
private CleanupApiResourceService cleanupApiResourceService;
private CleanupApiResourceServiceImpl cleanupApiResourceServiceImpl;
@Resource
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
@Resource
@ -52,11 +53,7 @@ public class CleanupApiTests {
@Resource
private ScheduleMapper scheduleMapper;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
@Resource
private ApiReportMapper apiReportMapper;
@Resource
private ApiScenarioReportMapper apiScenarioReportMapper;
private CleanupApiReportServiceImpl cleanupApiReportServiceImpl;
@Autowired
public CleanupApiTests(ProjectServiceInvoker serviceInvoker) {
@ -144,7 +141,7 @@ public class CleanupApiTests {
initReportData("test");
initScheduleData();
serviceInvoker.invokeServices("test");
cleanupApiResourceService.deleteResources("test");
cleanupApiResourceServiceImpl.deleteResources("test");
}
private void initScheduleData() {
@ -169,21 +166,9 @@ public class CleanupApiTests {
@Order(2)
public void testCleanupReport() throws Exception {
initReportData("test-clean-project");
cleanupApiResourceService.cleanReportResources("test-clean-project");
ApiReportExample apiReportExample = new ApiReportExample();
apiReportExample.createCriteria().andProjectIdEqualTo("test-clean-project");
apiReportMapper.deleteByExample(apiReportExample);
ApiScenarioReportExample apiScenarioReportExample = new ApiScenarioReportExample();
apiScenarioReportExample.createCriteria().andProjectIdEqualTo("test-clean-project");
apiScenarioReportMapper.deleteByExample(apiScenarioReportExample);
// 清理报告有数据
ProjectApplication projectApplication = new ProjectApplication();
projectApplication.setProjectId("test-clean-project-report");
projectApplication.setType(ProjectApplicationType.API.API_CLEAN_REPORT.name());
projectApplication.setTypeValue("1D");
projectApplicationMapper.insert(projectApplication);
initReportData("test-clean-project1");
cleanupApiResourceService.cleanReportResources("test-clean-project1");
Map<String, String> map = new HashMap<>();
map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), "1D");
cleanupApiReportServiceImpl.cleanReport(map, "test-clean-project");
}
private void initReportData(String projectId) {

View File

@ -1,31 +0,0 @@
package io.metersphere.api.controller;
import io.metersphere.api.service.CleanupApiResourceService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
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;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class CleanupResourceTests {
@Resource
private CleanupApiResourceService resourceService;
@Test
@Order(1)
public void testCleanupResource() throws Exception {
resourceService.deleteResources("test");
}
@Test
@Order(1)
public void testCleanupReportResource() throws Exception {
resourceService.cleanReportResources("test");
}
}

View File

@ -17,96 +17,90 @@ import java.util.List;
@Component
public class CleanupBugResourceService implements CleanupProjectResourceService {
@Resource
private BugMapper bugMapper;
@Resource
private BugContentMapper bugContentMapper;
@Resource
private BugFollowerMapper bugFollowerMapper;
@Resource
private BugLocalAttachmentMapper bugLocalAttachmentMapper;
@Resource
private BugCommentMapper bugCommentMapper;
@Resource
private BugCustomFieldMapper bugCustomFieldMapper;
@Resource
private BugRelationCaseMapper bugRelationCaseMapper;
@Resource
private BugMapper bugMapper;
@Resource
private BugContentMapper bugContentMapper;
@Resource
private BugFollowerMapper bugFollowerMapper;
@Resource
private BugLocalAttachmentMapper bugLocalAttachmentMapper;
@Resource
private BugCommentMapper bugCommentMapper;
@Resource
private BugCustomFieldMapper bugCustomFieldMapper;
@Resource
private BugRelationCaseMapper bugRelationCaseMapper;
@Async
@Override
public void deleteResources(String projectId) {
LogUtils.info("删除当前项目[" + projectId + "]相关缺陷测试资源");
List<String> deleteIds = getBugIds(projectId);
if (CollectionUtils.isNotEmpty(deleteIds)) {
// 清理缺陷
deleteBug(deleteIds);
// 清理缺陷内容
deleteBugContent(deleteIds);
// 清理缺陷关注人信息
deleteBugFollower(deleteIds);
// 清理缺陷本地附件
deleteBugLocalAttachment(deleteIds);
// 清理缺陷评论
deleteBugComment(deleteIds);
// 清理缺陷自定义字段
deleteBugCustomField(deleteIds);
// 清理缺陷关联用例
deleteBugRelateCase(deleteIds);
}
}
@Async
@Override
public void deleteResources(String projectId) {
LogUtils.info("删除当前项目[" + projectId + "]相关缺陷测试资源");
List<String> deleteIds = getBugIds(projectId);
if (CollectionUtils.isNotEmpty(deleteIds)) {
// 清理缺陷
deleteBug(deleteIds);
// 清理缺陷内容
deleteBugContent(deleteIds);
// 清理缺陷关注人信息
deleteBugFollower(deleteIds);
// 清理缺陷本地附件
deleteBugLocalAttachment(deleteIds);
// 清理缺陷评论
deleteBugComment(deleteIds);
// 清理缺陷自定义字段
deleteBugCustomField(deleteIds);
// 清理缺陷关联用例
deleteBugRelateCase(deleteIds);
}
}
@Async
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关缺陷测试报告资源");
}
private List<String> getBugIds(String projectId) {
BugExample example = new BugExample();
example.createCriteria().andProjectIdEqualTo(projectId);
List<Bug> bugs = bugMapper.selectByExample(example);
return bugs.stream().map(Bug::getId).toList();
}
private List<String> getBugIds(String projectId) {
BugExample example = new BugExample();
example.createCriteria().andProjectIdEqualTo(projectId);
List<Bug> bugs = bugMapper.selectByExample(example);
return bugs.stream().map(Bug::getId).toList();
}
private void deleteBug(List<String> bugIds) {
BugExample example = new BugExample();
example.createCriteria().andIdIn(bugIds);
bugMapper.deleteByExample(example);
}
private void deleteBug(List<String> bugIds) {
BugExample example = new BugExample();
example.createCriteria().andIdIn(bugIds);
bugMapper.deleteByExample(example);
}
private void deleteBugContent(List<String> bugIds) {
BugContentExample example = new BugContentExample();
example.createCriteria().andBugIdIn(bugIds);
bugContentMapper.deleteByExample(example);
}
private void deleteBugContent(List<String> bugIds) {
BugContentExample example = new BugContentExample();
example.createCriteria().andBugIdIn(bugIds);
bugContentMapper.deleteByExample(example);
}
private void deleteBugFollower(List<String> bugIds) {
BugFollowerExample example = new BugFollowerExample();
example.createCriteria().andBugIdIn(bugIds);
bugFollowerMapper.deleteByExample(example);
}
private void deleteBugFollower(List<String> bugIds) {
BugFollowerExample example = new BugFollowerExample();
example.createCriteria().andBugIdIn(bugIds);
bugFollowerMapper.deleteByExample(example);
}
private void deleteBugLocalAttachment(List<String> bugIds) {
BugLocalAttachmentExample example = new BugLocalAttachmentExample();
example.createCriteria().andBugIdIn(bugIds);
bugLocalAttachmentMapper.deleteByExample(example);
}
private void deleteBugLocalAttachment(List<String> bugIds) {
BugLocalAttachmentExample example = new BugLocalAttachmentExample();
example.createCriteria().andBugIdIn(bugIds);
bugLocalAttachmentMapper.deleteByExample(example);
}
private void deleteBugComment(List<String> bugIds) {
BugCommentExample example = new BugCommentExample();
example.createCriteria().andBugIdIn(bugIds);
bugCommentMapper.deleteByExample(example);
}
private void deleteBugComment(List<String> bugIds) {
BugCommentExample example = new BugCommentExample();
example.createCriteria().andBugIdIn(bugIds);
bugCommentMapper.deleteByExample(example);
}
private void deleteBugCustomField(List<String> bugIds) {
BugCustomFieldExample example = new BugCustomFieldExample();
example.createCriteria().andBugIdIn(bugIds);
bugCustomFieldMapper.deleteByExample(example);
}
private void deleteBugCustomField(List<String> bugIds) {
BugCustomFieldExample example = new BugCustomFieldExample();
example.createCriteria().andBugIdIn(bugIds);
bugCustomFieldMapper.deleteByExample(example);
}
private void deleteBugRelateCase(List<String> bugIds) {
BugRelationCaseExample example = new BugRelationCaseExample();
example.createCriteria().andBugIdIn(bugIds);
bugRelationCaseMapper.deleteByExample(example);
}
private void deleteBugRelateCase(List<String> bugIds) {
BugRelationCaseExample example = new BugRelationCaseExample();
example.createCriteria().andBugIdIn(bugIds);
bugRelationCaseMapper.deleteByExample(example);
}
}

View File

@ -13,27 +13,25 @@ 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)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CleanBugResourceServiceTests extends BaseTest {
private final ProjectServiceInvoker serviceInvoker;
@Resource
private CleanupBugResourceService cleanupBugResourceService;
private final ProjectServiceInvoker serviceInvoker;
@Resource
private CleanupBugResourceService cleanupBugResourceService;
@Autowired
public CleanBugResourceServiceTests(ProjectServiceInvoker serviceInvoker) {
this.serviceInvoker = serviceInvoker;
}
@Autowired
public CleanBugResourceServiceTests(ProjectServiceInvoker serviceInvoker) {
this.serviceInvoker = serviceInvoker;
}
@Test
@Order(1)
@Sql(scripts = {"/dml/init_bug_clean_resource.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
void test() {
serviceInvoker.invokeServices("default-project-for-clean-resource");
serviceInvoker.invokeServices("default-project-for-clean-resource-not-exist");
cleanupBugResourceService.cleanReportResources("default-project-for-clean-resource");
cleanupBugResourceService.cleanReportResources("default-project-for-clean-resource-not-exist");
}
@Test
@Order(1)
@Sql(scripts = {"/dml/init_bug_clean_resource.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
void test() {
serviceInvoker.invokeServices("default-project-for-clean-resource");
serviceInvoker.invokeServices("default-project-for-clean-resource-not-exist");
}
}

View File

@ -38,9 +38,4 @@ public class CleanupCaseReviewResourceService implements CleanupProjectResourceS
caseReviewModuleMapper.deleteByExample(caseReviewModuleExample);
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关用例评审报告资源");
}
}

View File

@ -3,7 +3,6 @@ package io.metersphere.functional.service;
import io.metersphere.functional.domain.FunctionalCaseModuleExample;
import io.metersphere.functional.mapper.ExtFunctionalCaseMapper;
import io.metersphere.functional.mapper.FunctionalCaseModuleMapper;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.CleanupProjectResourceService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
@ -39,9 +38,5 @@ public class CleanupFunctionalCaseResourceService implements CleanupProjectResou
functionalCaseModuleExample.createCriteria().andProjectIdEqualTo(projectId);
functionalCaseModuleMapper.deleteByExample(functionalCaseModuleExample);
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关报告资源");
}
}

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class CleanupResourceTests {
@ -27,9 +27,4 @@ public class CleanupResourceTests {
resourceService.deleteResources("project_clean_gyq");
}
@Test
@Order(2)
public void testCleanupReportResource() throws Exception {
resourceService.cleanReportResources("test");
}
}

View File

@ -2,7 +2,6 @@ package io.metersphere.project.service;
import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.service.CleanupProjectResourceService;
import jakarta.annotation.Resource;
@ -27,8 +26,4 @@ public class CleanupApplicationResourceService implements CleanupProjectResource
projectApplicationMapper.deleteByExample(example);
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关报告资源");
}
}

View File

@ -47,9 +47,4 @@ public class CleanupEnvironmentResourceService implements CleanupProjectResource
}
@Override
public void cleanReportResources(String projectId) {
}
}

View File

@ -36,8 +36,4 @@ public class CleanupMessageTaskService implements CleanupProjectResourceService
LogUtils.info("删除当前项目[" + projectId + "]相关消息管理资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关消息管理报告资源");
}
}

View File

@ -2,8 +2,8 @@ package io.metersphere.project.service;
import io.metersphere.project.domain.ProjectRobotExample;
import io.metersphere.project.mapper.ProjectRobotMapper;
import io.metersphere.system.service.CleanupProjectResourceService;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.CleanupProjectResourceService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
@ -20,9 +20,4 @@ public class CleanupRobotResourceService implements CleanupProjectResourceServic
robotMapper.deleteByExample(projectExample);
LogUtils.info("删除当前项目[" + projectId + "]相关消息机器人资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关消息机器人报告资源");
}
}

View File

@ -21,6 +21,7 @@ public class CleanupVersionResourceService implements CleanupProjectResourceServ
private ProjectVersionMapper projectVersionMapper;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
@Override
public void deleteResources(String projectId) {
// 删除所有项目版本
@ -32,8 +33,4 @@ public class CleanupVersionResourceService implements CleanupProjectResourceServ
LogUtils.info("清理当前项目[" + projectId + "]相关版本资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关报告资源");
}
}

View File

@ -159,6 +159,7 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje
fileModuleRepositoryMapper.deleteByExample(repositoryExample);
}
public void deleteModule(List<String> deleteIds) {
if (CollectionUtils.isEmpty(deleteIds)) {
return;
@ -199,7 +200,6 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje
/**
* 查找当前项目下模块每个节点对应的资源统计
*
*/
public Map<String, Long> getModuleCountMap(String projectId, String storage, List<ModuleCountDTO> moduleCountDTOList) {
@ -242,10 +242,6 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje
}
}
@Override
public void cleanReportResources(String projectId) {
// nothing to do
}
public Map<String, String> getModuleNameMapByIds(List<String> moduleIds) {
if (CollectionUtils.isEmpty(moduleIds)) {

View File

@ -16,7 +16,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class CleanupEnvironmentTests {
@ -27,6 +27,7 @@ public class CleanupEnvironmentTests {
private EnvironmentGroupMapper environmentGroupMapper;
@Resource
private EnvironmentGroupRelationMapper environmentGroupRelationMapper;
@Autowired
public CleanupEnvironmentTests(ProjectServiceInvoker serviceInvoker) {
this.serviceInvoker = serviceInvoker;
@ -52,7 +53,6 @@ public class CleanupEnvironmentTests {
environmentGroupRelation.setProjectId("test");
environmentGroupRelationMapper.insert(environmentGroupRelation);
serviceInvoker.invokeServices("test");
cleanupEnvironmentResourceService.cleanReportResources("test");
}
}

View File

@ -1,7 +1,6 @@
package io.metersphere.project.controller;
import io.metersphere.project.domain.ProjectRobot;
import io.metersphere.project.service.CleanupRobotResourceService;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.util.JSON;
@ -45,12 +44,7 @@ public class CleanupRobotResourceTests extends BaseTest {
List<ProjectRobot> projectRobotAfters = getList();
Assertions.assertTrue(CollectionUtils.isEmpty(projectRobotAfters));
}
@Test
@Order(2)
public void testCleanupReportResource() throws Exception {
resourceService.cleanReportResources("test");
}
private List<ProjectRobot> getList() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_LIST + "test")

View File

@ -8,7 +8,10 @@ import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
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.http.MediaType;
@ -24,7 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class CleanupMessageTaskResourceTests extends BaseTest {
@ -41,18 +44,6 @@ public class CleanupMessageTaskResourceTests extends BaseTest {
}
}
@Test
@Order(2)
public void testCleanupResourceNoMessage() throws Exception {
resourceService.cleanReportResources("test1");
}
@Test
@Order(3)
public void testCleanupReportResource() throws Exception {
resourceService.cleanReportResources("test");
}
private List<MessageTaskDTO> getList() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/test")
.header(SessionConstants.HEADER_TOKEN, sessionId)

View File

@ -106,4 +106,13 @@ public class OperationLogModule {
//测试计划
public static final String TEST_PLAN = "TEST_PLAN";
public static final String TEST_PLAN_MODULE = "TEST_PLAN_MODULE";
// 个人信息-基本信息
public static final String PERSONAL_INFORMATION_BASE_INFO = "PERSONAL_INFORMATION_BASE_INFO";
// 个人信息-密码设置
public static final String PERSONAL_INFORMATION_PSW = "PERSONAL_INFORMATION_PSW";
// 个人信息-本地执行
public static final String PERSONAL_INFORMATION_LOCAL_EXECUTE = "PERSONAL_INFORMATION_LOCAL_EXECUTE";
// 个人信息-三方平台账号
public static final String PERSONAL_INFORMATION_TRIPARTITE = "PERSONAL_INFORMATION_TRIPARTITE";
}

View File

@ -7,9 +7,4 @@ public interface CleanupProjectResourceService {
void deleteResources(String projectId);
/**
* 清理报告资源
* @param projectId
*/
void cleanReportResources(String projectId);
}

View File

@ -11,6 +11,7 @@ public class CleanupTemplateResourceService implements CleanupProjectResourceSer
private BaseCustomFieldService baseCustomFieldService;
@Resource
private BaseStatusFlowSettingService baseStatusFlowSettingService;
@Override
public void deleteResources(String projectId) {
baseTemplateService.deleteByScopeId(projectId);
@ -18,6 +19,4 @@ public class CleanupTemplateResourceService implements CleanupProjectResourceSer
baseStatusFlowSettingService.deleteByScopeId(projectId);
}
@Override
public void cleanReportResources(String projectId) {}
}

View File

@ -46,7 +46,7 @@ public class UserLocalConfigService {
.projectId(OperationLogConstants.SYSTEM)
.organizationId(OperationLogConstants.SYSTEM)
.type(OperationLogType.ADD.name())
.module(OperationLogModule.PERSONAL_INFORMATION_LOCAL_CONFIG)
.module(OperationLogModule.PERSONAL_INFORMATION_LOCAL_EXECUTE)
.method(HttpMethodConstants.POST.name())
.path("/user/local/config/add")
.sourceId(userLocalConfig.getId())
@ -111,5 +111,16 @@ public class UserLocalConfigService {
UserLocalConfig userLocalConfig = checkResourceById(request.getId());
userLocalConfig.setUserUrl(request.getUserUrl());
userLocalConfigMapper.updateByPrimaryKeySelective(userLocalConfig);
LogDTO dto = LogDTOBuilder.builder()
.projectId(OperationLogConstants.SYSTEM)
.organizationId(OperationLogConstants.SYSTEM)
.type(OperationLogType.UPDATE.name())
.module(OperationLogModule.PERSONAL_INFORMATION_LOCAL_EXECUTE)
.method(HttpMethodConstants.POST.name())
.path("/user/local/config/update")
.sourceId(userLocalConfig.getId())
.originalValue(JSON.toJSONBytes(userLocalConfig))
.build().getLogDTO();
operationLogService.add(dto);
}
}

View File

@ -91,7 +91,7 @@ public class UserLogService {
.projectId(OperationLogConstants.SYSTEM)
.organizationId(OperationLogConstants.SYSTEM)
.type(OperationLogType.UPDATE.name())
.module(OperationLogModule.PERSONAL_INFORMATION_PERSONAL_SETTINGS)
.module(OperationLogModule.PERSONAL_INFORMATION_PSW)
.method(HttpMethodConstants.POST.name())
.path("/personal/update-password")
.sourceId(request.getId())
@ -122,7 +122,7 @@ public class UserLogService {
.projectId(OperationLogConstants.SYSTEM)
.organizationId(OperationLogConstants.SYSTEM)
.type(OperationLogType.UPDATE.name())
.module(OperationLogModule.PERSONAL_INFORMATION_PERSONAL_SETTINGS)
.module(OperationLogModule.PERSONAL_INFORMATION_BASE_INFO)
.method(HttpMethodConstants.POST.name())
.path("/personal/update-info")
.sourceId(request.getId())
@ -262,6 +262,7 @@ public class UserLogService {
}
operationLogService.batchAdd(logs);
}
public void batchAddOrgLog(UserRoleBatchRelationRequest request, String operator) {
List<LogDTO> logs = new ArrayList<>();
List<String> userIds = userToolService.getBatchUserIds(request);

View File

@ -68,7 +68,7 @@ public class UserPlatformAccountService {
userExtend.setId(userId);
userExtend.setPlatformInfo(JSON.toJSONBytes(platformInfo));
userExtendMapper.insertSelective(userExtend);
} else if (userExtend.getPlatformInfo() == null){
} else if (userExtend.getPlatformInfo() == null) {
userExtend.setPlatformInfo(JSON.toJSONBytes(platformInfo));
userExtendMapper.updateByPrimaryKeySelective(userExtend);
} else {
@ -82,7 +82,7 @@ public class UserPlatformAccountService {
.projectId(OperationLogConstants.SYSTEM)
.organizationId(OperationLogConstants.SYSTEM)
.type(OperationLogType.UPDATE.name())
.module(OperationLogModule.PERSONAL_INFORMATION_APIKEYS)
.module(OperationLogModule.PERSONAL_INFORMATION_TRIPARTITE)
.method(HttpMethodConstants.GET.name())
.path("/user/platform/save")
.sourceId(userId)
@ -93,8 +93,9 @@ public class UserPlatformAccountService {
/**
* 获取个人三方平台账号
*
* @param userId 用户ID
* @param orgId 组织ID
* @param orgId 组织ID
* @return 三方平台账号
*/
public Map<String, Object> get(String userId, String orgId) {

View File

@ -1,7 +1,7 @@
package io.metersphere.system.mock;
import io.metersphere.system.service.CleanupProjectResourceService;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.CleanupProjectResourceService;
import org.springframework.stereotype.Component;
@Component
@ -12,8 +12,4 @@ public class CleanupTestResourceService implements CleanupProjectResourceService
LogUtils.info("删除当前项目[" + projectId + "]TEST资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]TEST报告资源");
}
}

View File

@ -12,8 +12,4 @@ public class CleanupPlanResourceService implements CleanupProjectResourceService
LogUtils.info("删除当前项目[" + projectId + "]相关测试计划资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关测试计划报告资源");
}
}

View File

@ -50,7 +50,7 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
return super.buildTreeAndCountResource(fileModuleList, true, Translator.get("default.module"));
}
public List<BaseTreeNode> getTreeOnlyIdsAndResourceCount(String projectId, List<ModuleCountDTO> moduleCountDTOList) {
public List<BaseTreeNode> getTreeOnlyIdsAndResourceCount(String projectId, List<ModuleCountDTO> moduleCountDTOList) {
//节点内容只有Id和parentId
List<BaseTreeNode> fileModuleList = extTestPlanModuleMapper.selectIdAndParentIdByProjectId(projectId);
return super.buildTreeAndCountResource(fileModuleList, moduleCountDTOList, true, Translator.get("default.module"));
@ -70,7 +70,7 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
testPlanModule.setUpdateUser(operator);
testPlanModuleMapper.insert(testPlanModule);
//记录日志
testPlanModuleLogService.saveAddLog(testPlanModule, operator,requestUrl,requestMethod);
testPlanModuleLogService.saveAddLog(testPlanModule, operator, requestUrl, requestMethod);
return testPlanModule.getId();
}
@ -111,7 +111,7 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
example.clear();
}
public void update(TestPlanModuleUpdateRequest request, String userId,String requestUrl,String requestMethod) {
public void update(TestPlanModuleUpdateRequest request, String userId, String requestUrl, String requestMethod) {
TestPlanModule module = testPlanModuleMapper.selectByPrimaryKey(request.getId());
TestPlanModule updateModule = new TestPlanModule();
updateModule.setId(request.getId());
@ -123,7 +123,7 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
testPlanModuleMapper.updateByPrimaryKeySelective(updateModule);
TestPlanModule newModule = testPlanModuleMapper.selectByPrimaryKey(request.getId());
//记录日志
testPlanModuleLogService.saveUpdateLog(module, newModule, module.getProjectId(), userId,requestUrl,requestMethod);
testPlanModuleLogService.saveUpdateLog(module, newModule, module.getProjectId(), userId, requestUrl, requestMethod);
}
@ -154,7 +154,7 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
}
}
public void moveNode(NodeMoveRequest request, String currentUser,String requestUrl,String requestMethod) {
public void moveNode(NodeMoveRequest request, String currentUser, String requestUrl, String requestMethod) {
NodeSortDTO nodeSortDTO = super.getNodeSortDTO(request,
extTestPlanModuleMapper::selectBaseModuleById,
@ -171,12 +171,11 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
}
super.sort(nodeSortDTO);
//记录日志
testPlanModuleLogService.saveMoveLog(nodeSortDTO, currentUser,requestUrl,requestMethod);
testPlanModuleLogService.saveMoveLog(nodeSortDTO, currentUser, requestUrl, requestMethod);
}
/**
* 查找当前项目下模块每个节点对应的资源统计
*
*/
public Map<String, Long> getModuleCountMap(String projectId, List<ModuleCountDTO> moduleCountDTOList) {
@ -219,11 +218,6 @@ public class TestPlanModuleService extends ModuleTreeService implements CleanupP
}
}
@Override
public void cleanReportResources(String projectId) {
// nothing to do
}
public String getNameById(String id) {
return extTestPlanModuleMapper.selectNameById(id);
}

View File

@ -10,7 +10,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class CleanupResourceTests {
@ -22,10 +22,4 @@ public class CleanupResourceTests {
public void testCleanupResource() throws Exception {
resourceService.deleteResources("test");
}
@Test
@Order(2)
public void testCleanupReportResource() throws Exception {
resourceService.cleanReportResources("test");
}
}