refactor(项目设置): 版本功能添加开启配置项
This commit is contained in:
parent
0247634c34
commit
9836c40f80
|
@ -591,5 +591,8 @@ INSERT INTO message_task_blob(id, template) VALUES (@schedule_close_id, 'message
|
|||
SET @load_report_id = UUID_SHORT();
|
||||
INSERT INTO schedule(`id`, `key`, `type`, `value`, `job`, `enable`, `resource_id`, `create_user`, `create_time`, `update_time`, `project_id`, `name`, `config`)
|
||||
VALUES (@load_report_id, '100001100001', 'CRON', '0 0 2 * * ?', 'io.metersphere.project.job.CleanUpReportJob', true, '100001100001', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, '100001100001', 'Clean Report Job', NULL);
|
||||
|
||||
-- 初始化默认项目版本配置项
|
||||
INSERT INTO project_application (`project_id`, `type`, `type_value`) VALUES ('100001100001', 'VERSION_ENABLE', 'FALSE');
|
||||
-- set innodb lock wait timeout to default
|
||||
SET SESSION innodb_lock_wait_timeout = DEFAULT;
|
||||
|
|
|
@ -76,4 +76,9 @@ public class ProjectApplicationType {
|
|||
MECHANISM,
|
||||
}
|
||||
|
||||
// 版本管理-配置项
|
||||
public enum VERSION{
|
||||
VERSION_ENABLE
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -145,6 +145,8 @@ permission.project_log.name=Operation log
|
|||
# project version
|
||||
project.version.exist=Version exist
|
||||
project.version.not_exist=Version not exist
|
||||
project.version.resource_exist=There is resource data associated with the version, please delete the data first
|
||||
project.version.only=Can be closed when there is only one version
|
||||
#environment datasource
|
||||
environment_datasource.id.not_blank=ID is required
|
||||
environment_datasource.driver.not_blank=Driver is required
|
||||
|
|
|
@ -145,6 +145,8 @@ permission.project_log.name=日志
|
|||
# project version
|
||||
project.version.exist=版本已存在
|
||||
project.version.not_exist=版本不存在
|
||||
project.version.resource_exist=版本号下存在业务数据,请先删除该版本的业务数据
|
||||
project.version.only=只有一个版本号时可关闭
|
||||
#environment datasource
|
||||
environment_datasource.id.not_blank=ID不能为空
|
||||
environment_datasource.driver.not_blank=驱动不能为空
|
||||
|
|
|
@ -145,6 +145,8 @@ permission.project_log.name=日誌
|
|||
# project version
|
||||
project.version.exist=版本已存在
|
||||
project.version.not_exist=版本不存在
|
||||
project.version.resource_exist=版本號下存在業務數據,請先刪除該版本的業務數據
|
||||
project.version.only=只有一個版本號時可關閉
|
||||
#environment datasource
|
||||
environment_datasource.id.not_blank=ID不能為空
|
||||
environment_datasource.driver.not_blank=驅動不能為空
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.domain.ProjectVersionExample;
|
||||
import io.metersphere.project.mapper.ProjectApplicationMapper;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.sdk.constants.ProjectApplicationType;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.service.CleanupProjectResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -17,12 +19,16 @@ public class CleanupVersionResourceService implements CleanupProjectResourceServ
|
|||
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
@Resource
|
||||
private ProjectApplicationMapper projectApplicationMapper;
|
||||
@Override
|
||||
public void deleteResources(String projectId) {
|
||||
// 删除所有项目版本
|
||||
ProjectVersionExample example = new ProjectVersionExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId);
|
||||
projectVersionMapper.deleteByExample(example);
|
||||
// 删除项目版本配置项
|
||||
projectApplicationMapper.deleteByPrimaryKey(projectId, ProjectApplicationType.VERSION.VERSION_ENABLE.name());
|
||||
LogUtils.info("清理当前项目[" + projectId + "]相关版本资源");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.domain.ProjectApplication;
|
||||
import io.metersphere.project.domain.ProjectVersion;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.sdk.constants.InternalUserRole;
|
||||
import io.metersphere.sdk.constants.ProjectApplicationType;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.service.CreateProjectResourceService;
|
||||
import io.metersphere.system.uid.UUID;
|
||||
|
@ -22,10 +24,12 @@ public class CreateVersionResourceService implements CreateProjectResourceServic
|
|||
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
@Resource
|
||||
private ProjectApplicationService projectApplicationService;
|
||||
|
||||
@Override
|
||||
public void createResources(String projectId) {
|
||||
// 初始化版本V1.0
|
||||
// 初始化版本V1.0, 初始化版本配置项
|
||||
ProjectVersion defaultVersion = new ProjectVersion();
|
||||
defaultVersion.setId(UUID.randomUUID().toString());
|
||||
defaultVersion.setProjectId(projectId);
|
||||
|
@ -35,6 +39,11 @@ public class CreateVersionResourceService implements CreateProjectResourceServic
|
|||
defaultVersion.setCreateTime(System.currentTimeMillis());
|
||||
defaultVersion.setCreateUser(InternalUserRole.ADMIN.getValue());
|
||||
projectVersionMapper.insert(defaultVersion);
|
||||
ProjectApplication projectApplication = new ProjectApplication();
|
||||
projectApplication.setProjectId(projectId);
|
||||
projectApplication.setType(ProjectApplicationType.VERSION.VERSION_ENABLE.name());
|
||||
projectApplication.setTypeValue("FALSE");
|
||||
projectApplicationService.update(projectApplication, "");
|
||||
LogUtils.info("初始化当前项目[" + projectId + "]相关版本资源");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ package io.metersphere.project.controller;
|
|||
import io.metersphere.project.domain.ProjectVersion;
|
||||
import io.metersphere.project.domain.ProjectVersionExample;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.project.request.ProjectApplicationRequest;
|
||||
import io.metersphere.project.service.ProjectApplicationService;
|
||||
import io.metersphere.sdk.constants.ProjectApplicationType;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -12,6 +15,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
|
@ -24,6 +28,8 @@ public class ProjectVersionResourceTests extends BaseTest {
|
|||
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
@Resource
|
||||
private ProjectApplicationService projectApplicationService;
|
||||
|
||||
@Autowired
|
||||
public ProjectVersionResourceTests(ProjectServiceInvoker serviceInvoker) {
|
||||
|
@ -38,13 +44,19 @@ public class ProjectVersionResourceTests extends BaseTest {
|
|||
// 默认为空
|
||||
List<ProjectVersion> projectVersions = projectVersionMapper.selectByExample(example);
|
||||
Assertions.assertTrue(projectVersions.isEmpty());
|
||||
// 项目资源初始化版本, 默认为一条版本记录
|
||||
// 初始化项目版本资源{默认为一条版本记录V1.0, 并生成一条项目版本配置项}
|
||||
serviceInvoker.invokeCreateServices(TEST_PROJECT_ID);
|
||||
List<ProjectVersion> createVersions = projectVersionMapper.selectByExample(example);
|
||||
Assertions.assertEquals(1, createVersions.size());
|
||||
// 项目资源清理版本, 为空
|
||||
ProjectApplicationRequest request = new ProjectApplicationRequest();
|
||||
request.setProjectId(TEST_PROJECT_ID);
|
||||
Map<String, Object> configMap = projectApplicationService.get(request, List.of(ProjectApplicationType.VERSION.VERSION_ENABLE.name()));
|
||||
Assertions.assertTrue(configMap.containsKey(ProjectApplicationType.VERSION.VERSION_ENABLE.name()));
|
||||
// 清空项目版本资源{版本记录为空, 配置项为空}
|
||||
serviceInvoker.invokeServices(TEST_PROJECT_ID);
|
||||
List<ProjectVersion> cleanUpVersions = projectVersionMapper.selectByExample(example);
|
||||
Assertions.assertTrue(cleanUpVersions.isEmpty());
|
||||
Map<String, Object> cleanConfig = projectApplicationService.get(request, List.of(ProjectApplicationType.VERSION.VERSION_ENABLE.name()));
|
||||
Assertions.assertFalse(cleanConfig.containsKey(ProjectApplicationType.VERSION.VERSION_ENABLE.name()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue