From 9836c40f8029ea0742c67a9a4a212edecb3cf1fd Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 19 Oct 2023 10:52:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E7=89=88=E6=9C=AC=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration/3.0.0/dml/V3.0.0_11_1__data.sql | 3 +++ .../sdk/constants/ProjectApplicationType.java | 5 +++++ .../main/resources/i18n/project_en_US.properties | 2 ++ .../main/resources/i18n/project_zh_CN.properties | 2 ++ .../main/resources/i18n/project_zh_TW.properties | 2 ++ .../service/CleanupVersionResourceService.java | 6 ++++++ .../service/CreateVersionResourceService.java | 11 ++++++++++- .../controller/ProjectVersionResourceTests.java | 16 ++++++++++++++-- 8 files changed, 44 insertions(+), 3 deletions(-) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql index 180bd28ed0..450a761bd6 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql @@ -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; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java index c7ccc96f84..7dd43683b0 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java @@ -76,4 +76,9 @@ public class ProjectApplicationType { MECHANISM, } + // 版本管理-配置项 + public enum VERSION{ + VERSION_ENABLE + } + } diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index 16069eb7a8..f3271e4c58 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -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 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index c739dfa28a..e22059f312 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -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=驱动不能为空 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index ae1607a46c..5a4d5202f2 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -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=驅動不能為空 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupVersionResourceService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupVersionResourceService.java index e72c03fb51..dea6d11a02 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupVersionResourceService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupVersionResourceService.java @@ -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 + "]相关版本资源"); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateVersionResourceService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateVersionResourceService.java index b41d16c323..545aacdbac 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateVersionResourceService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateVersionResourceService.java @@ -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 + "]相关版本资源"); } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectVersionResourceTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectVersionResourceTests.java index 7e6bb620d7..df444e7fe3 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectVersionResourceTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectVersionResourceTests.java @@ -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 projectVersions = projectVersionMapper.selectByExample(example); Assertions.assertTrue(projectVersions.isEmpty()); - // 项目资源初始化版本, 默认为一条版本记录 + // 初始化项目版本资源{默认为一条版本记录V1.0, 并生成一条项目版本配置项} serviceInvoker.invokeCreateServices(TEST_PROJECT_ID); List createVersions = projectVersionMapper.selectByExample(example); Assertions.assertEquals(1, createVersions.size()); - // 项目资源清理版本, 为空 + ProjectApplicationRequest request = new ProjectApplicationRequest(); + request.setProjectId(TEST_PROJECT_ID); + Map 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 cleanUpVersions = projectVersionMapper.selectByExample(example); Assertions.assertTrue(cleanUpVersions.isEmpty()); + Map cleanConfig = projectApplicationService.get(request, List.of(ProjectApplicationType.VERSION.VERSION_ENABLE.name())); + Assertions.assertFalse(cleanConfig.containsKey(ProjectApplicationType.VERSION.VERSION_ENABLE.name())); } }