refactor(项目管理): 菜单管理优化&创建/删除项目的默认定时任务资源处理
This commit is contained in:
parent
316526a0aa
commit
0cc274c2b8
|
@ -23,7 +23,7 @@ public class ProjectApplicationType {
|
|||
public enum UI{
|
||||
UI_CLEAN_REPORT,
|
||||
UI_SHARE_REPORT,
|
||||
UI_RESOURCE_POOL,
|
||||
UI_RESOURCE_POOL_ID,
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,8 @@ public class ProjectApplicationType {
|
|||
public enum PERFORMANCE_TEST{
|
||||
PERFORMANCE_TEST_CLEAN_REPORT,
|
||||
PERFORMANCE_TEST_SHARE_REPORT,
|
||||
PERFORMANCE_TEST_SCRIPT_REVIEWER
|
||||
PERFORMANCE_TEST_SCRIPT_REVIEWER_ENABLE,
|
||||
PERFORMANCE_TEST_SCRIPT_REVIEWER_ID,
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,8 +42,9 @@ public class ProjectApplicationType {
|
|||
API_URL_REPEATABLE,
|
||||
API_CLEAN_REPORT,
|
||||
API_SHARE_REPORT,
|
||||
API_RESOURCE_POOL,
|
||||
API_SCRIPT_REVIEWER,
|
||||
API_RESOURCE_POOL_ID,
|
||||
API_SCRIPT_REVIEWER_ENABLE,
|
||||
API_SCRIPT_REVIEWER_ID,
|
||||
API_ERROR_REPORT_RULE,
|
||||
API_SYNC_CASE
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/test-plan")
|
||||
@Operation(summary = "测试计划-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_TEST_PLAN_READ)
|
||||
public List<ProjectApplication> getTestPlan(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
public Map<String, Object> getTestPlan(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.TEST_PLAN.values()).stream().map(ProjectApplicationType.TEST_PLAN::name).collect(Collectors.toList());
|
||||
return projectApplicationService.get(request, types);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/ui")
|
||||
@Operation(summary = "UI测试-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_UI_READ)
|
||||
public List<ProjectApplication> getUI(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
public Map<String, Object> getUI(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.UI.values()).stream().map(ProjectApplicationType.UI::name).collect(Collectors.toList());
|
||||
return projectApplicationService.get(request, types);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/performance-test")
|
||||
@Operation(summary = "性能测试-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_READ)
|
||||
public List<ProjectApplication> getPerformanceTest(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
public Map<String, Object> getPerformanceTest(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.values()).stream().map(ProjectApplicationType.PERFORMANCE_TEST::name).collect(Collectors.toList());
|
||||
return projectApplicationService.get(request, types);
|
||||
}
|
||||
|
@ -130,9 +130,12 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/api")
|
||||
@Operation(summary = "接口测试-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ)
|
||||
public List<ProjectApplication> getApi(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
public Map<String, Object> getApi(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.API.values()).stream().map(ProjectApplicationType.API::name).collect(Collectors.toList());
|
||||
return projectApplicationService.get(request, types);
|
||||
Map<String, Object> configMap = projectApplicationService.get(request, types);
|
||||
int errorNum = projectApplicationService.getFakeErrorList(request.getProjectId());
|
||||
configMap.put("FAKE_ERROR_NUM", errorNum);
|
||||
return configMap;
|
||||
}
|
||||
|
||||
@GetMapping("/api/user/{projectId}")
|
||||
|
@ -167,9 +170,9 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/case")
|
||||
@Operation(summary = "用例管理-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
|
||||
public List<ProjectApplication> getCase(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
public Map<String, Object> getCase(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.CASE.values()).stream().map(ProjectApplicationType.CASE::name).collect(Collectors.toList());
|
||||
types.add(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name());
|
||||
types.add(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name());
|
||||
return projectApplicationService.get(request, types);
|
||||
}
|
||||
|
||||
|
@ -221,7 +224,7 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/workstation")
|
||||
@Operation(summary = "工作台-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_WORKSTATION_READ)
|
||||
public List<ProjectApplication> getWorkstation(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
public Map<String, Object> getWorkstation(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.WORKSTATION.values()).stream().map(ProjectApplicationType.WORKSTATION::name).collect(Collectors.toList());
|
||||
return projectApplicationService.get(request, types);
|
||||
}
|
||||
|
@ -242,8 +245,8 @@ public class ProjectApplicationController {
|
|||
@PostMapping("/bug")
|
||||
@Operation(summary = "缺陷管理-获取配置")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ)
|
||||
public List<ProjectApplication> getBug(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name());
|
||||
public Map<String, Object> getBug(@Validated @RequestBody ProjectApplicationRequest request) {
|
||||
List<String> types = Arrays.asList(ProjectApplicationType.BUG.BUG_SYNC.name() + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name());
|
||||
return projectApplicationService.get(request, types);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
</select>
|
||||
|
||||
<select id="getProjectUserList" resultType="io.metersphere.system.domain.User">
|
||||
SELECT u.id,
|
||||
SELECT distinct
|
||||
u.id,
|
||||
u.NAME
|
||||
FROM `user` u
|
||||
LEFT JOIN user_role_relation urr ON u.id = urr.user_id
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.sechedule.ScheduleService;
|
||||
import io.metersphere.system.service.CleanupProjectResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Component
|
||||
public class CleanupApplicationResourceService implements CleanupProjectResourceService {
|
||||
|
||||
@Resource
|
||||
private ScheduleService scheduleService;
|
||||
|
||||
@Override
|
||||
public void deleteResources(String projectId) {
|
||||
scheduleService.deleteByProjectId(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanReportResources(String projectId) {
|
||||
LogUtils.info("清理当前项目[" + projectId + "]相关报告资源");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.job.CleanUpReportJob;
|
||||
import io.metersphere.sdk.constants.ScheduleType;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
import io.metersphere.system.sechedule.ScheduleService;
|
||||
import io.metersphere.system.service.CreateProjectResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Component
|
||||
public class CreateApplicationResourceService implements CreateProjectResourceService {
|
||||
|
||||
|
||||
@Resource
|
||||
private ScheduleService scheduleService;
|
||||
|
||||
@Override
|
||||
public void createResources(String projectId) {
|
||||
//初始化清理报告定时任务
|
||||
Schedule request = new Schedule();
|
||||
request.setName("Clean Report Job");
|
||||
request.setResourceId(projectId);
|
||||
request.setKey(projectId);
|
||||
request.setProjectId(projectId);
|
||||
request.setEnable(true);
|
||||
request.setCreateUser("admin");
|
||||
request.setType(ScheduleType.CRON.name());
|
||||
// 每天凌晨2点执行清理任务
|
||||
request.setValue("0 0 2 * * ?");
|
||||
request.setJob(CleanUpReportJob.class.getName());
|
||||
scheduleService.addSchedule(request);
|
||||
scheduleService.addOrUpdateCronJob(request,
|
||||
CleanUpReportJob.getJobKey(projectId),
|
||||
CleanUpReportJob.getTriggerKey(projectId),
|
||||
CleanUpReportJob.class);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package io.metersphere.project.service;
|
|||
|
||||
import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin;
|
||||
import io.metersphere.plugin.platform.spi.Platform;
|
||||
import io.metersphere.project.domain.FakeErrorExample;
|
||||
import io.metersphere.project.domain.ProjectApplication;
|
||||
import io.metersphere.project.domain.ProjectApplicationExample;
|
||||
import io.metersphere.project.dto.ModuleDTO;
|
||||
|
@ -9,6 +10,7 @@ import io.metersphere.project.job.CleanUpReportJob;
|
|||
import io.metersphere.project.job.BugSyncJob;
|
||||
import io.metersphere.project.mapper.ExtProjectMapper;
|
||||
import io.metersphere.project.mapper.ExtProjectUserRoleMapper;
|
||||
import io.metersphere.project.mapper.FakeErrorMapper;
|
||||
import io.metersphere.project.mapper.ProjectApplicationMapper;
|
||||
import io.metersphere.project.request.ProjectApplicationRequest;
|
||||
import io.metersphere.project.utils.ModuleSortUtils;
|
||||
|
@ -70,6 +72,9 @@ public class ProjectApplicationService {
|
|||
@Resource
|
||||
private PlatformPluginService platformPluginService;
|
||||
|
||||
@Resource
|
||||
private FakeErrorMapper fakeErrorMapper;
|
||||
|
||||
/**
|
||||
* 更新配置信息
|
||||
*
|
||||
|
@ -153,14 +158,16 @@ public class ProjectApplicationService {
|
|||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public List<ProjectApplication> get(ProjectApplicationRequest request, List<String> types) {
|
||||
public Map<String, Object> get(ProjectApplicationRequest request, List<String> types) {
|
||||
Map<String, Object> configMap = new HashMap<>();
|
||||
ProjectApplicationExample projectApplicationExample = new ProjectApplicationExample();
|
||||
projectApplicationExample.createCriteria().andProjectIdEqualTo(request.getProjectId()).andTypeIn(types);
|
||||
List<ProjectApplication> applicationList = projectApplicationMapper.selectByExample(projectApplicationExample);
|
||||
if (CollectionUtils.isNotEmpty(applicationList)) {
|
||||
return applicationList;
|
||||
configMap = applicationList.stream().collect(Collectors.toMap(ProjectApplication::getType, ProjectApplication::getTypeValue));
|
||||
return configMap;
|
||||
}
|
||||
return new ArrayList<ProjectApplication>();
|
||||
return configMap;
|
||||
}
|
||||
|
||||
|
||||
|
@ -506,4 +513,10 @@ public class ProjectApplicationService {
|
|||
return platformPluginService.getPlatform(pluginId, serviceIntegrations.get(0).getOrganizationId(), new String(serviceIntegrations.get(0).getConfiguration()));
|
||||
}
|
||||
|
||||
public int getFakeErrorList(String projectId) {
|
||||
FakeErrorExample example = new FakeErrorExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId);
|
||||
long l = fakeErrorMapper.countByExample(example);
|
||||
return (int) l;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.service.CleanupApplicationResourceService;
|
||||
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 CleanupApplicationResourceTests {
|
||||
|
||||
@Resource
|
||||
private CleanupApplicationResourceService resourceService;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testCleanupResource() throws Exception {
|
||||
resourceService.deleteResources("test_project_id");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.service.CreateApplicationResourceService;
|
||||
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 CreateApplicationResourceTests {
|
||||
|
||||
@Resource
|
||||
private CreateApplicationResourceService resourceService;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testCleanupResource() throws Exception {
|
||||
resourceService.createResources("test_project_id");
|
||||
}
|
||||
}
|
|
@ -136,7 +136,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(5)
|
||||
public void testUiResourcePool() throws Exception {
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.UI.UI_RESOURCE_POOL.name()), "local");
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.UI.UI_RESOURCE_POOL_ID.name()), "local");
|
||||
this.requestPost(UI_UPDATE_URL, request);
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
|
|||
@Order(9)
|
||||
public void testPerformanceReviewer() throws Exception {
|
||||
//新增
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.PERFORMANCE_TEST_SCRIPT_REVIEWER.name()), "admin");
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.PERFORMANCE_TEST_SCRIPT_REVIEWER_ENABLE.name()), "admin");
|
||||
this.requestPost(PERFORMANCE_UPDATE_URL, request);
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(15)
|
||||
public void testApiResourcePool() throws Exception {
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_RESOURCE_POOL.name()), "local");
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_RESOURCE_POOL_ID.name()), "local");
|
||||
this.requestPost(API_UPDATE_URL, request);
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(16)
|
||||
public void testApiReviewer() throws Exception {
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_SCRIPT_REVIEWER.name()), "admin");
|
||||
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_SCRIPT_REVIEWER_ENABLE.name()), "admin");
|
||||
this.requestPost(API_UPDATE_URL, request);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue