From b2924b1a58345a0b0759741c96a5ee6d1ece1a44 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Thu, 2 Nov 2023 10:28:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84=E6=9B=B4=E6=96=B0=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=92=8C=E7=8A=B6=E6=80=81=E6=B5=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/BugStatusDefinitionType.java | 24 ++- .../main/resources/i18n/commons.properties | 1 + .../resources/i18n/commons_en_US.properties | 1 + .../resources/i18n/commons_zh_CN.properties | 1 + .../resources/i18n/commons_zh_TW.properties | 1 + .../ProjectStatusFlowSettingLogService.java | 6 +- .../ProjectStatusFlowSettingService.java | 15 +- ...rojectStatusFlowSettingControllerTest.java | 97 ++++----- .../handler/result/CommonResultCode.java | 3 +- .../StatusDefinitionUpdateRequest.java | 42 ++-- .../sdk/request/StatusFlowUpdateRequest.java | 42 ++-- .../service/BaseStatusDefinitionService.java | 20 ++ .../system/service/BaseStatusFlowService.java | 57 +++-- .../service/BaseStatusFlowSettingService.java | 106 +++++---- .../system/service/BaseStatusItemService.java | 9 +- ...ganizationStatusFlowSettingLogService.java | 6 +- .../OrganizationStatusFlowSettingService.java | 202 ++++++++++-------- ...zationStatusFlowSettingControllerTest.java | 202 +++++++++++++----- ...atusDefinitionUpdateRequestDefinition.java | 42 ++-- .../StatusFlowUpdateRequestDefinition.java | 42 ++-- 20 files changed, 492 insertions(+), 427 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/BugStatusDefinitionType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/BugStatusDefinitionType.java index 997aaab2b5..592763d651 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/BugStatusDefinitionType.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/BugStatusDefinitionType.java @@ -1,24 +1,36 @@ package io.metersphere.sdk.constants; -import io.metersphere.sdk.util.Translator; +import lombok.Getter; +import java.util.Arrays; + +@Getter public enum BugStatusDefinitionType { /** * 起始状态 */ - START("status_definition.type.start"), + START("status_definition.type.start", true), /** * 结束状态 */ - END("status_definition.type.end"); + END("status_definition.type.end", false); - BugStatusDefinitionType(String name) { + BugStatusDefinitionType(String name, Boolean isSingleChoice) { this.name = name; + this.isSingleChoice = isSingleChoice; } + /** + * 状态名 + */ private String name; + /** + * 是否是单选 + */ + private Boolean isSingleChoice; - public String getName() { - return Translator.get(name); + public static BugStatusDefinitionType getStatusDefinitionType(String type) { + return Arrays.stream(BugStatusDefinitionType.values()).filter(item -> item.name().equals(type)) + .findFirst().orElse(null); } } diff --git a/backend/framework/sdk/src/main/resources/i18n/commons.properties b/backend/framework/sdk/src/main/resources/i18n/commons.properties index 653487e9ac..d99e374b30 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons.properties @@ -407,6 +407,7 @@ internal_custom_field_permission_error=系统字段或模板无法删除! internal_template_permission_error=系统模板无法删除! default_template_permission_error=默认模板无法删除! field_validate_error={0}字段参数值不合法 +status_definition_required_error=该状态无法取消 #result message http_result_success=操作成功 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index e428c1a137..b11ea7c497 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -410,6 +410,7 @@ internal_custom_field_permission_error=System fields cannot be deleted! internal_template_permission_error=System template cannot be deleted! default_template_permission_error=Default templates cannot be deleted! field_validate_error=The field {0} value is invalid +status_definition_required_error=This status cannot be canceled #result message http_result_success=operate success diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index 58969041a9..d602872c9e 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -407,6 +407,7 @@ internal_custom_field_permission_error=系统字段或模板无法删除! internal_template_permission_error=系统模板无法删除! default_template_permission_error=默认模板无法删除! field_validate_error={0}字段参数值不合法 +status_definition_required_error=该状态无法取消 #result message http_result_success=操作成功 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 79f249aa48..724fd54f5a 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -406,6 +406,7 @@ internal_custom_field_permission_error=系統字段或模板無法刪除! internal_template_permission_error=系統模板無法刪除! default_template_permission_error=默认模板无法删除! field_validate_error={0}字段參數值不合法 +status_definition_required_error=該狀態無法取消 #result message http_result_success=操作成功 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingLogService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingLogService.java index 8019788896..e8461a638a 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingLogService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingLogService.java @@ -34,7 +34,8 @@ public class ProjectStatusFlowSettingLogService { public LogDTO updateStatusDefinitionLog(StatusDefinitionUpdateRequest request) { - return updateStatusFlowSettingLog(request.getScopeId(), request.getScene()); + StatusItem statusItem = statusItemMapper.selectByPrimaryKey(request.getStatusId()); + return updateStatusFlowSettingLog(statusItem.getScopeId(), statusItem.getScene()); } public LogDTO addStatusItemLog(StatusItemAddRequest request) { @@ -52,7 +53,8 @@ public class ProjectStatusFlowSettingLogService { } public LogDTO updateStatusFlowLog(StatusFlowUpdateRequest request) { - return updateStatusFlowSettingLog(request.getScopeId(), request.getScene()); + StatusItem statusItem = statusItemMapper.selectByPrimaryKey(request.getFromId()); + return updateStatusFlowSettingLog(statusItem.getScopeId(), statusItem.getScene()); } public LogDTO updateStatusFlowSettingLog(String scopeId, String scene) { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingService.java index fe825bcb98..19d821aafd 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectStatusFlowSettingService.java @@ -43,11 +43,11 @@ public class ProjectStatusFlowSettingService extends BaseStatusFlowSettingServic * 比如设置成项目 * @param request */ - @Override public void updateStatusDefinition(StatusDefinitionUpdateRequest request) { - ProjectService.checkResourceExist(request.getScopeId()); - projectTemplateService.checkProjectTemplateEnable(request.getScopeId(), request.getScene()); - super.updateStatusDefinition(request); + StatusItem statusItem = baseStatusItemService.getWithCheck(request.getStatusId()); + ProjectService.checkResourceExist(statusItem.getScopeId()); + projectTemplateService.checkProjectTemplateEnable(statusItem.getScopeId(), statusItem.getScene()); + super.updateStatusDefinition(statusItem, request); } /** @@ -105,8 +105,11 @@ public class ProjectStatusFlowSettingService extends BaseStatusFlowSettingServic * @param request */ public void updateStatusFlow(StatusFlowUpdateRequest request) { - ProjectService.checkResourceExist(request.getScopeId()); - projectTemplateService.checkProjectTemplateEnable(request.getScopeId(), request.getScene()); + StatusItem fromStatusItem = baseStatusItemService.getWithCheck(request.getFromId()); + StatusItem toStatusItem = baseStatusItemService.getWithCheck(request.getToId()); + ProjectService.checkResourceExist(fromStatusItem.getScopeId()); + ProjectService.checkResourceExist(toStatusItem.getScopeId()); + projectTemplateService.checkProjectTemplateEnable(fromStatusItem.getScopeId(), fromStatusItem.getScene()); super.updateStatusFlow(request); } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectStatusFlowSettingControllerTest.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectStatusFlowSettingControllerTest.java index 29842fcf8a..2a08fb2340 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectStatusFlowSettingControllerTest.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectStatusFlowSettingControllerTest.java @@ -34,8 +34,7 @@ import java.util.List; import java.util.stream.Collectors; import static io.metersphere.project.enums.result.ProjectResultCode.PROJECT_TEMPLATE_PERMISSION; -import static io.metersphere.system.controller.handler.result.CommonResultCode.STATUS_ITEM_EXIST; -import static io.metersphere.system.controller.handler.result.CommonResultCode.STATUS_ITEM_NOT_EXIST; +import static io.metersphere.system.controller.handler.result.CommonResultCode.*; import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND; import static io.metersphere.system.controller.result.SystemResultCode.ORGANIZATION_TEMPLATE_PERMISSION; @@ -58,6 +57,7 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { private static final String STATUS_FLOW_UPDATE = "status/flow/update"; private static StatusItem addStatusItem; + private static StatusItem anotherAddStatusItem; @Resource private StatusItemMapper statusItemMapper; @@ -124,7 +124,8 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { request.setName("test3"); request.setAllTransferTo(true); mvcResult = this.requestPostWithOkAndReturn(STATUS_ADD, request); - statusItemId = getResultData(mvcResult, StatusItem.class).getId(); + anotherAddStatusItem = getResultData(mvcResult, StatusItem.class); + statusItemId = anotherAddStatusItem.getId(); OrganizationStatusFlowSettingControllerTest.assertAllTransferTo(statusItemId, request.getScopeId()); // @@校验组织是否存在 @@ -178,21 +179,41 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { requestPostPermissionTest(PermissionConstants.PROJECT_TEMPLATE_UPDATE, STATUS_UPDATE, request); } - @Test @Order(3) public void updateStatusDefinition() throws Exception { StatusDefinitionUpdateRequest request = new StatusDefinitionUpdateRequest(); - request.setScene(TemplateScene.BUG.name()); - request.setScopeId(DEFAULT_PROJECT_ID); - StatusDefinitionUpdateRequest.StatusDefinitionRequest statusDefinition = new StatusDefinitionUpdateRequest.StatusDefinitionRequest(); - statusDefinition.setStatusId(addStatusItem.getId()); - statusDefinition.setDefinitionId(BugStatusDefinitionType.END.name()); - request.setStatusDefinitions(List.of(statusDefinition)); + request.setStatusId(addStatusItem.getId()); + request.setDefinitionId(BugStatusDefinitionType.END.name()); + request.setEnable(true); // @@校验请求成功 this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); - assertUpdateStatusDefinition(DEFAULT_PROJECT_ID); + OrganizationStatusFlowSettingControllerTest.assertUpdateStatusDefinition(request); + // 校验项目是否同步修改 + OrganizationStatusFlowSettingControllerTest.assertRefUpdateStatusDefinition(request); + + // 取消关联 + request.setEnable(false); + this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); + OrganizationStatusFlowSettingControllerTest.assertUpdateStatusDefinition(request); + + // @测试单选 + request.setStatusId(addStatusItem.getId()); + request.setDefinitionId(BugStatusDefinitionType.START.name()); + request.setEnable(true); + this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); + OrganizationStatusFlowSettingControllerTest.assertUpdateStatusDefinition(request); + // 校验单选 + OrganizationStatusFlowSettingControllerTest.assertSingleChoiceUpdateStatusDefinition(request); + // 校验单选禁止取消 + request.setEnable(false); + assertErrorCode(this.requestPost(STATUS_DEFINITION_UPDATE, request), STATUS_DEFINITION_REQUIRED_ERROR); + // 设置回来,避免其他地方校验出错 + StatusItem newStatusItem = OrganizationStatusFlowSettingControllerTest.getNewStatusItem(addStatusItem.getScopeId()); + request.setStatusId(newStatusItem.getId()); + request.setEnable(true); + this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); // @校验是否开启组织模板 changeOrgTemplateEnable(true); @@ -200,11 +221,7 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { changeOrgTemplateEnable(false); // @@状态不存在 - request.getStatusDefinitions().get(0).setStatusId("1111"); - assertErrorCode(this.requestPost(STATUS_DEFINITION_UPDATE, request), STATUS_ITEM_NOT_EXIST); - - // @@校验组织是否存在 - request.setScopeId("1111"); + request.setStatusId("1111"); assertErrorCode(this.requestPost(STATUS_DEFINITION_UPDATE, request), NOT_FOUND); // @@校验日志 @@ -215,34 +232,27 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { requestPostPermissionTest(PermissionConstants.PROJECT_TEMPLATE_UPDATE, STATUS_DEFINITION_UPDATE, request); } - private void assertUpdateStatusDefinition(String scopeId) { - List statusIds = baseStatusItemService.getByScopeIdAndScene(scopeId, TemplateScene.BUG.name()).stream().map(StatusItem::getId).toList(); - List statusDefinitions = baseStatusDefinitionService.getStatusDefinitions(statusIds); - Assertions.assertEquals(statusDefinitions.size(), 1); - Assertions.assertEquals(statusDefinitions.get(0).getDefinitionId(), BugStatusDefinitionType.END.name()); - } - @Test @Order(4) public void updateStatusFlow() throws Exception { StatusFlowUpdateRequest request = new StatusFlowUpdateRequest(); - request.setScopeId(DEFAULT_PROJECT_ID); - request.setScene(TemplateScene.BUG.name()); + request.setFromId(anotherAddStatusItem.getId()); + request.setToId(addStatusItem.getId()); - StatusFlowUpdateRequest.StatusFlowRequest statusFlow = new StatusFlowUpdateRequest.StatusFlowRequest(); - statusFlow.setFromId(addStatusItem.getId()); - StatusItemExample example = new StatusItemExample(); - example.createCriteria().andScopeIdEqualTo(DEFAULT_PROJECT_ID).andSceneEqualTo(TemplateScene.BUG.name()); - StatusItem targetStatusItem = statusItemMapper.selectByExample(example).stream() - .filter(item -> !StringUtils.equals(addStatusItem.getId(), item.getId())) - .findFirst() - .get(); - statusFlow.setToId(targetStatusItem.getId()); - request.setStatusFlows(List.of(statusFlow)); + request.setEnable(true); // @@校验请求成功 this.requestPostWithOkAndReturn(STATUS_FLOW_UPDATE, request); - assertUpdateStatusFlow(DEFAULT_PROJECT_ID, statusFlow); + OrganizationStatusFlowSettingControllerTest.assertUpdateStatusFlow(request); + // 校验项目是否同步修改 + OrganizationStatusFlowSettingControllerTest.assertRefUpdateStatusFlow(request); + + // @@校验取消 + request.setEnable(false); + this.requestPostWithOkAndReturn(STATUS_FLOW_UPDATE, request); + OrganizationStatusFlowSettingControllerTest.assertUpdateStatusFlow(request); + // 校验项目是否同步修改 + OrganizationStatusFlowSettingControllerTest.assertRefUpdateStatusFlow(request); // @校验是否开启组织模板 changeOrgTemplateEnable(true); @@ -250,11 +260,7 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { changeOrgTemplateEnable(false); // @@状态不存在 - request.getStatusFlows().get(0).setToId("1111"); - assertErrorCode(this.requestPost(STATUS_FLOW_UPDATE, request), STATUS_ITEM_NOT_EXIST); - - // @@校验组织是否存在 - request.setScopeId("1111"); + request.setToId("1111"); assertErrorCode(this.requestPost(STATUS_FLOW_UPDATE, request), NOT_FOUND); // @@校验日志 @@ -265,15 +271,6 @@ public class ProjectStatusFlowSettingControllerTest extends BaseTest { requestPostPermissionTest(PermissionConstants.PROJECT_TEMPLATE_UPDATE, STATUS_FLOW_UPDATE, request); } - private void assertUpdateStatusFlow(String scopeId, StatusFlowUpdateRequest.StatusFlowRequest statusFlow) { - List statusIds = baseStatusItemService.getByScopeIdAndScene(scopeId, TemplateScene.BUG.name()).stream() - .map(StatusItem::getId).toList(); - List statusFlows = baseStatusFlowService.getStatusFlows(statusIds); - Assertions.assertEquals(statusFlows.size(), 1); - Assertions.assertEquals(statusFlows.get(0).getFromId(), statusFlow.getFromId()); - Assertions.assertEquals(statusFlows.get(0).getToId(), statusFlow.getToId()); - } - @Test @Order(5) public void deleteStatusItem() throws Exception { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/handler/result/CommonResultCode.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/handler/result/CommonResultCode.java index 0dccf7297e..c4ab3123a0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/handler/result/CommonResultCode.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/handler/result/CommonResultCode.java @@ -27,7 +27,8 @@ public enum CommonResultCode implements IResultCode { DEFAULT_TEMPLATE_PERMISSION(100014, "default_template_permission_error"), STATUS_ITEM_NOT_EXIST(100015, "status_item.not.exist"), STATUS_ITEM_EXIST(100016, "status_item.exist"), - FIELD_VALIDATE_ERROR(100017, "field_validate_error"); + FIELD_VALIDATE_ERROR(100017, "field_validate_error"), + STATUS_DEFINITION_REQUIRED_ERROR(100018, "status_definition_required_error");; private int code; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusDefinitionUpdateRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusDefinitionUpdateRequest.java index c885d2b6cb..932d38ca65 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusDefinitionUpdateRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusDefinitionUpdateRequest.java @@ -1,46 +1,28 @@ package io.metersphere.system.dto.sdk.request; -import io.metersphere.sdk.constants.TemplateScene; -import io.metersphere.system.valid.EnumValue; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; import java.io.Serializable; -import java.util.List; @Data public class StatusDefinitionUpdateRequest implements Serializable { private static final long serialVersionUID = 1L; - @Schema(description = "组织ID或项目ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank - @Size(min = 1, max = 50) - private String scopeId; + @Schema(description = "状态ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_definition.status_id.not_blank}") + @Size(min = 1, max = 50, message = "{status_definition.status_id.length_range}") + private String statusId; - @Schema(description = "使用场景", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_item.scene.not_blank}") - @EnumValue(enumClass = TemplateScene.class) - private String scene; + @Schema(description = "状态定义ID(在代码中定义)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_definition.definition_id.not_blank}") + @Size(min = 1, max = 100, message = "{status_definition.definition_id.length_range}") + private String definitionId; - @NotBlank - @Valid - private List statusDefinitions; - - @Data - public static class StatusDefinitionRequest implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "状态ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_definition.status_id.not_blank}") - @Size(min = 1, max = 50, message = "{status_definition.status_id.length_range}") - private String statusId; - - @Schema(description = "状态定义ID(在代码中定义)", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_definition.definition_id.not_blank}") - @Size(min = 1, max = 100, message = "{status_definition.definition_id.length_range}") - private String definitionId; - } + @Schema(description = "启用或者禁用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull + private Boolean enable; } \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusFlowUpdateRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusFlowUpdateRequest.java index dfac0c4d6e..c41fc35dfe 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusFlowUpdateRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/StatusFlowUpdateRequest.java @@ -1,46 +1,28 @@ package io.metersphere.system.dto.sdk.request; -import io.metersphere.sdk.constants.TemplateScene; -import io.metersphere.system.valid.EnumValue; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; import java.io.Serializable; -import java.util.List; @Data public class StatusFlowUpdateRequest implements Serializable { private static final long serialVersionUID = 1L; - @Schema(description = "组织ID或项目ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank - @Size(min = 1, max = 50) - private String scopeId; + @Schema(description = "起始状态ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_flow.from_id.not_blank}") + @Size(min = 1, max = 50, message = "{status_flow.from_id.length_range}") + private String fromId; - @Schema(description = "使用场景", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_item.scene.not_blank}") - @EnumValue(enumClass = TemplateScene.class) - private String scene; + @Schema(description = "目的状态ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_flow.to_id.not_blank}") + @Size(min = 1, max = 50, message = "{status_flow.to_id.length_range}") + private String toId; - @NotBlank - @Valid - private List statusFlows; - - @Data - public static class StatusFlowRequest implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "起始状态ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_flow.from_id.not_blank}") - @Size(min = 1, max = 50, message = "{status_flow.from_id.length_range}") - private String fromId; - - @Schema(description = "目的状态ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_flow.to_id.not_blank}") - @Size(min = 1, max = 50, message = "{status_flow.to_id.length_range}") - private String toId; - } + @Schema(description = "启用或者禁用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull + private Boolean enable; } \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusDefinitionService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusDefinitionService.java index 4639365325..3bd133db87 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusDefinitionService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusDefinitionService.java @@ -38,6 +38,18 @@ public class BaseStatusDefinitionService { statusDefinitionMapper.deleteByExample(example); } + public void delete(String statusId, String definitionId) { + statusDefinitionMapper.deleteByPrimaryKey(statusId, definitionId); + } + + public void add(StatusDefinition statusDefinition) { + StatusDefinitionExample example = new StatusDefinitionExample(); + example.createCriteria() + .andStatusIdEqualTo(statusDefinition.getStatusId()) + .andDefinitionIdEqualTo(statusDefinition.getDefinitionId()); + statusDefinitionMapper.insert(statusDefinition); + } + public void deleteByStatusIds(List statusItemIds) { if (CollectionUtils.isEmpty(statusItemIds)) { return; @@ -54,4 +66,12 @@ public class BaseStatusDefinitionService { } statusDefinitionMapper.batchInsert(statusDefinitions); } + + public void deleteByStatusIdsAndDefinitionId(List statusIds, String definitionId) { + StatusDefinitionExample example = new StatusDefinitionExample(); + example.createCriteria() + .andStatusIdIn(statusIds) + .andDefinitionIdEqualTo(definitionId); + statusDefinitionMapper.deleteByExample(example); + } } \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowService.java index 3bd3ac21bc..d1a795fed0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowService.java @@ -1,7 +1,5 @@ package io.metersphere.system.service; -import io.metersphere.system.dto.sdk.request.StatusFlowUpdateRequest; -import io.metersphere.sdk.util.BeanUtils; import io.metersphere.system.domain.StatusFlow; import io.metersphere.system.domain.StatusFlowExample; import io.metersphere.system.mapper.StatusFlowMapper; @@ -11,10 +9,7 @@ import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; /** * @author jianxing @@ -40,34 +35,6 @@ public class BaseStatusFlowService { return statusFlowMapper.selectByExample(example); } - public void updateStatusFlow(List deleteStatusItemIds, List statusFlowRequests) { - // 先删除 - StatusFlowExample example = new StatusFlowExample(); - example.createCriteria().andFromIdIn(deleteStatusItemIds); - statusFlowMapper.deleteByExample(example); - example.clear(); - example.createCriteria().andToIdIn(deleteStatusItemIds); - statusFlowMapper.deleteByExample(example); - - // 再添加 - List statusFlows = statusFlowRequests.stream().map(request -> { - StatusFlow statusFlow = new StatusFlow(); - BeanUtils.copyBean(statusFlow, request); - statusFlow.setId(IDGenerator.nextStr()); - return statusFlow; - }).toList(); - statusFlowMapper.batchInsert(statusFlows); - } - - public static List getStatusIds(List statusFlows) { - Set statusIds = new HashSet<>(); - statusFlows.forEach(statusFlow -> { - statusIds.add(statusFlow.getFromId()); - statusIds.add(statusFlow.getToId()); - }); - return statusIds.stream().collect(Collectors.toList()); - } - public void deleteByStatusId(String statusId) { StatusFlowExample example = new StatusFlowExample(); example.createCriteria() @@ -100,4 +67,28 @@ public class BaseStatusFlowService { }); statusFlowMapper.batchInsert(statusFlows); } + + public void add(StatusFlow statusFlow) { + statusFlow.setId(IDGenerator.nextStr()); + statusFlowMapper.insert(statusFlow); + } + + public void delete(String fromId, String toId) { + StatusFlowExample example = new StatusFlowExample(); + example.createCriteria() + .andFromIdEqualTo(fromId) + .andToIdEqualTo(toId); + statusFlowMapper.deleteByExample(example); + } + + public void deleteByFromIdsAndToIds(List subProjectFromIds, List subProjectToIds) { + if (CollectionUtils.isEmpty(subProjectFromIds) || CollectionUtils.isEmpty(subProjectToIds)) { + return; + } + StatusFlowExample example = new StatusFlowExample(); + example.createCriteria() + .andFromIdIn(subProjectFromIds) + .andToIdIn(subProjectToIds); + statusFlowMapper.deleteByExample(example); + } } \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowSettingService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowSettingService.java index 85b72e0141..1cdd2b47ec 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowSettingService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusFlowSettingService.java @@ -1,22 +1,23 @@ package io.metersphere.system.service; -import io.metersphere.sdk.constants.DefaultBugStatusItem; import io.metersphere.sdk.constants.BugStatusDefinitionType; +import io.metersphere.sdk.constants.DefaultBugStatusItem; import io.metersphere.sdk.constants.TemplateScene; import io.metersphere.sdk.constants.TemplateScopeType; -import io.metersphere.system.dto.sdk.request.StatusDefinitionUpdateRequest; -import io.metersphere.system.dto.sdk.request.StatusFlowUpdateRequest; -import io.metersphere.system.dto.sdk.request.StatusItemAddRequest; +import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.system.controller.handler.result.CommonResultCode; import io.metersphere.system.domain.StatusDefinition; import io.metersphere.system.domain.StatusDefinitionExample; import io.metersphere.system.domain.StatusFlow; import io.metersphere.system.domain.StatusItem; import io.metersphere.system.dto.StatusItemDTO; +import io.metersphere.system.dto.sdk.request.StatusDefinitionUpdateRequest; +import io.metersphere.system.dto.sdk.request.StatusFlowUpdateRequest; +import io.metersphere.system.dto.sdk.request.StatusItemAddRequest; import io.metersphere.system.mapper.StatusDefinitionMapper; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -95,46 +96,42 @@ public class BaseStatusFlowSettingService { * * @param request */ - public void updateStatusDefinition(StatusDefinitionUpdateRequest request) { - List statusDefinitionsRequests = request.getStatusDefinitions(); - List statusDefinitions = statusDefinitionsRequests.stream() - .map(statusFlowRequest -> BeanUtils.copyBean(new StatusDefinition(), statusFlowRequest)) - .toList(); - List statusIds = getStatusIds(statusDefinitionsRequests); - // 校验状态项是否存在 - baseStatusItemService.checkStatusScope(request.getScopeId(), statusIds); - // 查询项目下所有的状态项 - List scopeStatusItemIds = baseStatusItemService.getByScopeIdAndScene(request.getScopeId(), request.getScene()) - .stream() - .map(StatusItem::getId) - .toList(); - updateStatusDefinition(scopeStatusItemIds, statusDefinitions); + protected void updateStatusDefinition(StatusItem statusItem, StatusDefinitionUpdateRequest request) { + handleSingleChoice(statusItem, request); + if (request.getEnable()) { + baseStatusDefinitionService.add(BeanUtils.copyBean(new StatusDefinition(), request)); + } else { + baseStatusDefinitionService.delete(request.getStatusId(), request.getDefinitionId()); + } } /** - * 设置状态定义 - * 比如设置成项目 - * - * @param scopeStatusItemIds - * @param statusDefinitions + * 处理单选的状态定义 + * @param statusItem + * @param request */ - public void updateStatusDefinition(List scopeStatusItemIds, List statusDefinitions) { - if (CollectionUtils.isEmpty(statusDefinitions)) { - return; + private void handleSingleChoice(StatusItem statusItem, StatusDefinitionUpdateRequest request) { + if (StringUtils.equals(statusItem.getScene(), TemplateScene.BUG.name())) { + BugStatusDefinitionType statusDefinitionType = BugStatusDefinitionType.getStatusDefinitionType(request.getDefinitionId()); + if (!statusDefinitionType.getIsSingleChoice()) { + return; + } + // 如果是单选,需要将其他状态取消勾选 + if (request.getEnable()) { + List statusIds = baseStatusItemService.getByScopeIdAndScene(statusItem.getScopeId(), statusItem.getScene()) + .stream() + .map(StatusItem::getId) + .toList(); + StatusDefinitionExample example = new StatusDefinitionExample(); + example.createCriteria() + .andStatusIdIn(statusIds) + .andDefinitionIdEqualTo(request.getDefinitionId()); + statusDefinitionMapper.deleteByExample(example); + } else { + // 单选默认必选,不能取消 + throw new MSException(CommonResultCode.STATUS_DEFINITION_REQUIRED_ERROR); + } } - // 先删除组织或项目下的所有定义 - StatusDefinitionExample example = new StatusDefinitionExample(); - example.createCriteria().andStatusIdIn(scopeStatusItemIds); - statusDefinitionMapper.deleteByExample(example); - // 再添加 - statusDefinitionMapper.batchInsert(statusDefinitions); - } - - private List getStatusIds(List statusDefinitions) { - List statusIds = statusDefinitions.stream() - .map(StatusDefinitionUpdateRequest.StatusDefinitionRequest::getStatusId) - .toList(); - return statusIds; } /** @@ -143,13 +140,11 @@ public class BaseStatusFlowSettingService { * @param request */ protected void updateStatusFlow(StatusFlowUpdateRequest request) { - List statusFlows = request.getStatusFlows(); - List statusIds = baseStatusFlowService.getStatusIds(statusFlows); - baseStatusItemService.checkStatusScope(request.getScopeId(), statusIds); - List statusItemIds = baseStatusItemService.getByScopeIdAndScene(request.getScopeId(), request.getScene()) - .stream() - .map(StatusItem::getId).toList(); - baseStatusFlowService.updateStatusFlow(statusItemIds, request.getStatusFlows()); + if (request.getEnable()) { + baseStatusFlowService.add(BeanUtils.copyBean(new StatusFlow(), request)); + } else { + baseStatusFlowService.delete(request.getFromId(), request.getToId()); + } } protected void deleteStatusItem(String id) { @@ -232,20 +227,17 @@ public class BaseStatusFlowSettingService { protected void handleAllTransferTo(StatusItemAddRequest request, String addStatusItemId) { if (BooleanUtils.isTrue(request.getAllTransferTo())) { List statusItems = baseStatusItemService.getByScopeIdAndScene(request.getScopeId(), request.getScene()); - List statusFlows = statusItems.stream() + List statusFlowUpdateRequests = statusItems.stream() // 过滤自己 .filter(item -> !StringUtils.equals(item.getId(), addStatusItemId)) .map(item -> { - StatusFlowUpdateRequest.StatusFlowRequest statusFlow = new StatusFlowUpdateRequest.StatusFlowRequest(); - statusFlow.setFromId(item.getId()); - statusFlow.setToId(addStatusItemId); - return statusFlow; + StatusFlowUpdateRequest statusFlowRequest = new StatusFlowUpdateRequest(); + statusFlowRequest.setFromId(item.getId()); + statusFlowRequest.setToId(addStatusItemId); + statusFlowRequest.setEnable(true); + return statusFlowRequest; }).toList(); - StatusFlowUpdateRequest statusFlowUpdateRequest = new StatusFlowUpdateRequest(); - statusFlowUpdateRequest.setScopeId(request.getScopeId()); - statusFlowUpdateRequest.setScene(request.getScene()); - statusFlowUpdateRequest.setStatusFlows(statusFlows); - updateStatusFlow(statusFlowUpdateRequest); + statusFlowUpdateRequests.forEach(this::updateStatusFlow); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusItemService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusItemService.java index c922187721..4a7200b50f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusItemService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseStatusItemService.java @@ -85,10 +85,8 @@ public class BaseStatusItemService { public StatusItem add(StatusItem statusItem) { checkAddExist(statusItem); statusItem.setInternal(false); - if (statusItem.getPos() == null) { - // 如果没有指定排序,就放到最后 - statusItem.setPos(getByScopeIdAndScene(statusItem.getScopeId(), statusItem.getScene()).size() + 1); - } + // 放到最后 + statusItem.setPos(getByScopeIdAndScene(statusItem.getScopeId(), statusItem.getScene()).size() + 1); return baseAdd(statusItem); } @@ -152,6 +150,9 @@ public class BaseStatusItemService { } public List getByScopeIdsAndScene(List scopeIds, String scene) { + if (CollectionUtils.isEmpty(scopeIds)) { + return List.of(); + } StatusItemExample example = new StatusItemExample(); example.createCriteria().andScopeIdIn(scopeIds).andSceneEqualTo(scene); return statusItemMapper.selectByExample(example); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingLogService.java index 1ad4b4efe1..6ff6b0784a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingLogService.java @@ -34,7 +34,8 @@ public class OrganizationStatusFlowSettingLogService { public LogDTO updateStatusDefinitionLog(StatusDefinitionUpdateRequest request) { - return updateStatusFlowSettingLog(request.getScopeId(), request.getScene()); + StatusItem statusItem = statusItemMapper.selectByPrimaryKey(request.getStatusId()); + return updateStatusFlowSettingLog(statusItem.getScopeId(), statusItem.getScene()); } public LogDTO addStatusItemLog(StatusItemAddRequest request) { @@ -52,7 +53,8 @@ public class OrganizationStatusFlowSettingLogService { } public LogDTO updateStatusFlowLog(StatusFlowUpdateRequest request) { - return updateStatusFlowSettingLog(request.getScopeId(), request.getScene()); + StatusItem statusItem = statusItemMapper.selectByPrimaryKey(request.getFromId()); + return updateStatusFlowSettingLog(statusItem.getScopeId(), statusItem.getScene()); } public LogDTO updateStatusFlowSettingLog(String scopeId, String scene) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingService.java index 9a9d262d5d..261f46ef2e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationStatusFlowSettingService.java @@ -1,17 +1,21 @@ package io.metersphere.system.service; +import io.metersphere.sdk.constants.BugStatusDefinitionType; +import io.metersphere.sdk.constants.TemplateScene; import io.metersphere.sdk.constants.TemplateScopeType; +import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.SubListUtils; +import io.metersphere.system.domain.StatusDefinition; +import io.metersphere.system.domain.StatusDefinitionExample; +import io.metersphere.system.domain.StatusFlow; +import io.metersphere.system.domain.StatusItem; +import io.metersphere.system.dto.StatusItemDTO; import io.metersphere.system.dto.sdk.request.StatusDefinitionUpdateRequest; import io.metersphere.system.dto.sdk.request.StatusFlowUpdateRequest; import io.metersphere.system.dto.sdk.request.StatusItemAddRequest; import io.metersphere.system.dto.sdk.request.StatusItemUpdateRequest; -import io.metersphere.sdk.util.BeanUtils; -import io.metersphere.sdk.util.SubListUtils; -import io.metersphere.system.domain.StatusDefinition; -import io.metersphere.system.domain.StatusFlow; -import io.metersphere.system.domain.StatusItem; -import io.metersphere.system.dto.StatusItemDTO; import io.metersphere.system.mapper.BaseProjectMapper; +import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -20,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -54,12 +59,13 @@ public class OrganizationStatusFlowSettingService extends BaseStatusFlowSettingS * * @param request */ - @Override public void updateStatusDefinition(StatusDefinitionUpdateRequest request) { - OrganizationService.checkResourceExist(request.getScopeId()); - organizationTemplateService.checkOrganizationTemplateEnable(request.getScopeId(), request.getScene()); - super.updateStatusDefinition(request); - updateRefProjectStatusDefinition(request); + StatusItem statusItem = baseStatusItemService.getWithCheck(request.getStatusId()); + OrganizationService.checkResourceExist(statusItem.getScopeId()); + organizationTemplateService.checkOrganizationTemplateEnable(statusItem.getScopeId(), statusItem.getScene()); + super.updateStatusDefinition(statusItem, request); + // 同步更新项目级别状态定义 + updateRefProjectStatusDefinition(statusItem, request); } /** @@ -68,49 +74,55 @@ public class OrganizationStatusFlowSettingService extends BaseStatusFlowSettingS * @param request * @return */ - public void updateRefProjectStatusDefinition(StatusDefinitionUpdateRequest request) { - String orgId = request.getScopeId(); - List orgStatusDefinitions = request.getStatusDefinitions(); - if (orgStatusDefinitions == null) { - return; - } - - List projectIds = baseProjectMapper.getProjectIdByOrgId(orgId); - SubListUtils.dealForSubList(projectIds, 200, (subProjectIds) -> { + public void updateRefProjectStatusDefinition(StatusItem orgStatusItem, StatusDefinitionUpdateRequest request) { + handleRefSingleChoice(orgStatusItem, request); + List statusItems = baseStatusItemService.getByRefId(request.getStatusId()); + SubListUtils.dealForSubList(statusItems, 200, (subStatusItems) -> { // 每次处理200条 - List statusDefinitions = new ArrayList<>(); - // 查询组织下所有项目的状态项 - List statusItems = baseStatusItemService.getByScopeIdsAndScene(subProjectIds, request.getScene()); - Map> projectStatusItemMap = statusItems - .stream() - .collect(Collectors.groupingBy(StatusItem::getScopeId)); - - for (String projectId : projectStatusItemMap.keySet()) { - List projectStatusItems = projectStatusItemMap.get(projectId); - // 构建map,键为组织状态ID,值为项目字状态ID - Map refFieldMap = projectStatusItems - .stream() - .collect(Collectors.toMap(StatusItem::getRefId, StatusItem::getId)); - // 根据组织状态ID,替换为项目状态ID - List projectStatusDefinitions = orgStatusDefinitions.stream() - .map(item -> { - StatusDefinition statusDefinition = BeanUtils.copyBean(new StatusDefinition(), item); - statusDefinition.setStatusId(refFieldMap.get(item.getStatusId())); - return statusDefinition; - }) - .filter(item -> StringUtils.isNotBlank(item.getStatusId())) + if (request.getEnable()) { + List projectStatusDefinitions = subStatusItems.stream().map(statusItem -> { + StatusDefinition statusDefinition = new StatusDefinition(); + statusDefinition.setStatusId(((StatusItem) statusItem).getId()); + statusDefinition.setDefinitionId(request.getDefinitionId()); + return statusDefinition; + }).toList(); + baseStatusDefinitionService.batchAdd(projectStatusDefinitions); + } else { + List projectStatusIds = subStatusItems.stream() + .map(statusItem -> ((StatusItem) statusItem).getId()) .toList(); - statusDefinitions.addAll(projectStatusDefinitions); + baseStatusDefinitionService.deleteByStatusIdsAndDefinitionId(projectStatusIds, request.getDefinitionId()); } - // 删除项目下的状态项 - List scopeStatusItemIds = statusItems - .stream() - .map(StatusItem::getId) - .toList(); - updateStatusDefinition(scopeStatusItemIds, statusDefinitions); }); } + + /** + * 处理单选的状态定义 + * + * @param request + */ + private void handleRefSingleChoice(StatusItem orgStatusItem, StatusDefinitionUpdateRequest request) { + if (StringUtils.equals(orgStatusItem.getScene(), TemplateScene.BUG.name())) { + BugStatusDefinitionType statusDefinitionType = BugStatusDefinitionType.getStatusDefinitionType(request.getDefinitionId()); + if (!statusDefinitionType.getIsSingleChoice()) { + return; + } + List projectIds = baseProjectMapper.getProjectIdByOrgId(orgStatusItem.getScopeId()); + SubListUtils.dealForSubList(projectIds, 200, (subProjectIds) -> { + // 查询组织下所有项目的状态项 + List statusItems = baseStatusItemService.getByScopeIdsAndScene(subProjectIds, orgStatusItem.getScene()); + List statusItemIds = statusItems.stream().map(StatusItem::getId).toList(); + StatusDefinitionExample example = new StatusDefinitionExample(); + example.createCriteria() + .andStatusIdIn(statusItemIds) + .andDefinitionIdEqualTo(request.getDefinitionId()); + // 如果是单选,需要将其他状态取消勾选 + statusDefinitionMapper.deleteByExample(example); + }); + } + } + /** * 添加状态选项 * @@ -207,14 +219,14 @@ public class OrganizationStatusFlowSettingService extends BaseStatusFlowSettingS */ public void deleteRefStatusItem(String orgStatusItemId) { // 删除关联的项目状态项 - baseStatusItemService.deleteByRefId(orgStatusItemId); List statusItemIds = baseStatusItemService.getStatusItemIdByRefId(orgStatusItemId); - SubListUtils.dealForSubList(statusItemIds, 100, (subProjectIds) -> { + SubListUtils.dealForSubList(statusItemIds, 100, (subStatusItemIds) -> { // 删除相关的状态定义 - baseStatusDefinitionService.deleteByStatusIds(statusItemIds); + baseStatusDefinitionService.deleteByStatusIds(subStatusItemIds); // 删除相关的状态流 - baseStatusFlowService.deleteByStatusIds(statusItemIds); + baseStatusFlowService.deleteByStatusIds(subStatusItemIds); }); + baseStatusItemService.deleteByRefId(orgStatusItemId); } /** @@ -223,10 +235,13 @@ public class OrganizationStatusFlowSettingService extends BaseStatusFlowSettingS * @param request */ public void updateStatusFlow(StatusFlowUpdateRequest request) { - OrganizationService.checkResourceExist(request.getScopeId()); - organizationTemplateService.checkOrganizationTemplateEnable(request.getScopeId(), request.getScene()); - // 同步添加项目级别状态流 + StatusItem fromStatusItem = baseStatusItemService.getWithCheck(request.getFromId()); + StatusItem toStatusItem = baseStatusItemService.getWithCheck(request.getToId()); + OrganizationService.checkResourceExist(fromStatusItem.getScopeId()); + OrganizationService.checkResourceExist(toStatusItem.getScopeId()); + organizationTemplateService.checkOrganizationTemplateEnable(fromStatusItem.getScopeId(), fromStatusItem.getScene()); super.updateStatusFlow(request); + // 同步添加项目级别状态流 updateRefProjectStatusFlow(request); } @@ -237,45 +252,50 @@ public class OrganizationStatusFlowSettingService extends BaseStatusFlowSettingS * @return */ public void updateRefProjectStatusFlow(StatusFlowUpdateRequest request) { - String orgId = request.getScopeId(); - List statusFlowRequests = request.getStatusFlows(); - if (statusFlowRequests == null) { - return; - } - List projectIds = baseProjectMapper.getProjectIdByOrgId(orgId); - SubListUtils.dealForSubList(projectIds, 100, (subProjectIds) -> { + // 获取from和to状态项 + List fromStatusItems = baseStatusItemService.getByRefId(request.getFromId()); + Map fromStatusItemMap = fromStatusItems.stream() + .collect(Collectors.toMap(StatusItem::getScopeId, Function.identity())); + List toStatusItems = baseStatusItemService.getByRefId(request.getToId()); + Map toStatusItemMap = toStatusItems.stream() + .collect(Collectors.toMap(StatusItem::getScopeId, Function.identity())); + + if (request.getEnable()) { + // 同步添加项目级别状态流 List statusFlows = new ArrayList<>(); - - // 查询组织下所有项目的状态项 - List statusItems = baseStatusItemService.getByScopeIdsAndScene(subProjectIds, request.getScene()); - Map> projectStatusItemMap = statusItems - .stream() - .collect(Collectors.groupingBy(StatusItem::getScopeId)); - List statusItemIds = statusItems.stream().map(StatusItem::getId).toList(); - - for (String projectId : projectStatusItemMap.keySet()) { - // 构建map,键为组织状态ID,值为项目字状态ID - Map refStatusItemMap = projectStatusItemMap.get(projectId) - .stream() - .collect(Collectors.toMap(StatusItem::getRefId, StatusItem::getId)); - // 根据组织状态ID,替换为项目状态ID - List projectStatusFlows = statusFlowRequests.stream() - .map(item -> { - StatusFlow statusFlow = new StatusFlow(); - statusFlow.setToId(refStatusItemMap.get(item.getToId())); - statusFlow.setFromId(refStatusItemMap.get(item.getFromId())); - return statusFlow; - }) - .filter(item -> item.getToId() != null && item.getFromId() != null) - .toList(); - statusFlows.addAll(projectStatusFlows); + for (String projectId : fromStatusItemMap.keySet()) { + String fromId = fromStatusItemMap.get(projectId).getId(); + String toId = toStatusItemMap.get(projectId).getId(); + if (StringUtils.isNotBlank(fromId) && StringUtils.isNotBlank(toId)) { + StatusFlow statusFlow = new StatusFlow(); + statusFlow.setFromId(fromId); + statusFlow.setToId(toId); + statusFlow.setId(IDGenerator.nextStr()); + statusFlows.add(statusFlow); + } } - // 先删除 - baseStatusFlowService.deleteByStatusIds(statusItemIds); - // 在添加 - baseStatusFlowService.batchAdd(statusFlows); - }); + SubListUtils.dealForSubList(statusFlows, 200, baseStatusFlowService::batchAdd); + } else { + // 同步删除项目级别状态流 + List subProjectFromIds = new ArrayList<>(); + List subProjectToIds = new ArrayList<>(); + for (String projectId : fromStatusItemMap.keySet()) { + String fromId = fromStatusItemMap.get(projectId).getId(); + String toId = toStatusItemMap.get(projectId).getId(); + if (StringUtils.isNotBlank(fromId) && StringUtils.isNotBlank(toId)) { + subProjectFromIds.add(fromId); + subProjectToIds.add(toId); + if (subProjectFromIds.size() > 100) { + // 分批删除 + baseStatusFlowService.deleteByFromIdsAndToIds(subProjectFromIds, subProjectToIds); + subProjectFromIds.clear(); + subProjectToIds.clear(); + } + } + } + baseStatusFlowService.deleteByFromIdsAndToIds(subProjectFromIds, subProjectToIds); + } } @Override diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationStatusFlowSettingControllerTest.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationStatusFlowSettingControllerTest.java index 86fbbeb4c6..2c5d0851d1 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationStatusFlowSettingControllerTest.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationStatusFlowSettingControllerTest.java @@ -17,6 +17,8 @@ import io.metersphere.system.domain.*; import io.metersphere.system.dto.StatusItemDTO; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.OrganizationParameterMapper; +import io.metersphere.system.mapper.StatusDefinitionMapper; +import io.metersphere.system.mapper.StatusFlowMapper; import io.metersphere.system.mapper.StatusItemMapper; import io.metersphere.system.service.BaseStatusDefinitionService; import io.metersphere.system.service.BaseStatusFlowService; @@ -33,10 +35,10 @@ import org.springframework.test.web.servlet.MvcResult; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; -import static io.metersphere.system.controller.handler.result.CommonResultCode.STATUS_ITEM_EXIST; -import static io.metersphere.system.controller.handler.result.CommonResultCode.STATUS_ITEM_NOT_EXIST; +import static io.metersphere.system.controller.handler.result.CommonResultCode.*; import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND; import static io.metersphere.system.controller.result.SystemResultCode.ORGANIZATION_TEMPLATE_PERMISSION; @@ -44,7 +46,7 @@ import static io.metersphere.system.controller.result.SystemResultCode.ORGANIZAT * @author jianxing * @date : 2023-10-9 */ -@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class OrganizationStatusFlowSettingControllerTest extends BaseTest { @@ -59,6 +61,7 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { private static final String STATUS_FLOW_UPDATE = "status/flow/update"; private static StatusItem addStatusItem; + private static StatusItem anotherAddStatusItem; @Resource private StatusItemMapper statusItemMapper; @@ -88,7 +91,7 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { requestGetPermissionTest(PermissionConstants.ORGANIZATION_TEMPLATE_READ, GET, DEFAULT_ORGANIZATION_ID, TemplateScene.BUG.name()); } - public static void assertDefaultStatusFlowSettingInit( List statusItemDTOS) { + public static void assertDefaultStatusFlowSettingInit(List statusItemDTOS) { Map nameIdMap = statusItemDTOS.stream() .collect(Collectors.toMap(StatusItem::getId, StatusItem::getName)); // 校验默认的状态定义是否初始化正确 @@ -155,7 +158,8 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { request.setName("test2"); request.setAllTransferTo(true); mvcResult = this.requestPostWithOkAndReturn(STATUS_ADD, request); - statusItemId = getResultData(mvcResult, StatusItem.class).getId(); + anotherAddStatusItem = getResultData(mvcResult, StatusItem.class); + statusItemId = anotherAddStatusItem.getId(); assertAllTransferTo(statusItemId, request.getScopeId()); assertRefAllTransferTo(statusItemId); @@ -185,6 +189,7 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { /** * 校验 allTransferTo + * * @param statusItemId */ public static void assertAllTransferTo(String statusItemId, String scopeId) { @@ -239,6 +244,11 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { Assertions.assertEquals(statusItem.getRemark(), request.getRemark()); assertRefStatusItem(statusItem); + // 提升覆盖率 + request.setName(null); + this.requestPostWithOkAndReturn(STATUS_UPDATE, request); + baseStatusItemService.getByScopeIdsAndScene(null, TemplateScene.BUG.name()); + // @校验是否开启组织模板 changeOrgTemplateEnable(false); assertErrorCode(this.requestPost(STATUS_UPDATE, request), ORGANIZATION_TEMPLATE_PERMISSION); @@ -260,23 +270,45 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { requestPostPermissionTest(PermissionConstants.ORGANIZATION_TEMPLATE_UPDATE, STATUS_UPDATE, request); } - @Test @Order(3) public void updateStatusDefinition() throws Exception { StatusDefinitionUpdateRequest request = new StatusDefinitionUpdateRequest(); - request.setScene(TemplateScene.BUG.name()); - request.setScopeId(DEFAULT_ORGANIZATION_ID); - StatusDefinitionUpdateRequest.StatusDefinitionRequest statusDefinition = new StatusDefinitionUpdateRequest.StatusDefinitionRequest(); - statusDefinition.setStatusId(addStatusItem.getId()); - statusDefinition.setDefinitionId(BugStatusDefinitionType.END.name()); - request.setStatusDefinitions(List.of(statusDefinition)); + request.setStatusId(addStatusItem.getId()); + request.setDefinitionId(BugStatusDefinitionType.END.name()); + request.setEnable(true); // @@校验请求成功 this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); - assertUpdateStatusDefinition(DEFAULT_ORGANIZATION_ID); + assertUpdateStatusDefinition(request); // 校验项目是否同步修改 - assertUpdateStatusDefinition(DEFAULT_PROJECT_ID); + assertRefUpdateStatusDefinition(request); + + // 取消关联 + request.setEnable(false); + this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); + assertUpdateStatusDefinition(request); + // 校验项目是否同步修改 + assertRefUpdateStatusDefinition(request); + + // @测试单选 + request.setStatusId(addStatusItem.getId()); + request.setDefinitionId(BugStatusDefinitionType.START.name()); + request.setEnable(true); + this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); + assertUpdateStatusDefinition(request); + // 校验项目是否同步修改 + assertRefUpdateStatusDefinition(request); + // 校验单选 + assertSingleChoiceUpdateStatusDefinition(request); + // 校验单选禁止取消 + request.setEnable(false); + assertErrorCode(this.requestPost(STATUS_DEFINITION_UPDATE, request), STATUS_DEFINITION_REQUIRED_ERROR); + // 设置回来,避免其他地方校验出错 + StatusItem newStatusItem = getNewStatusItem(addStatusItem.getScopeId()); + request.setStatusId(newStatusItem.getId()); + request.setEnable(true); + this.requestPostWithOkAndReturn(STATUS_DEFINITION_UPDATE, request); // @校验是否开启组织模板 changeOrgTemplateEnable(false); @@ -284,11 +316,7 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { changeOrgTemplateEnable(true); // @@状态不存在 - request.getStatusDefinitions().get(0).setStatusId("1111"); - assertErrorCode(this.requestPost(STATUS_DEFINITION_UPDATE, request), STATUS_ITEM_NOT_EXIST); - - // @@校验组织是否存在 - request.setScopeId("1111"); + request.setStatusId("1111"); assertErrorCode(this.requestPost(STATUS_DEFINITION_UPDATE, request), NOT_FOUND); // @@校验日志 @@ -299,39 +327,82 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { requestPostPermissionTest(PermissionConstants.ORGANIZATION_TEMPLATE_UPDATE, STATUS_DEFINITION_UPDATE, request); } - private void assertUpdateStatusDefinition(String scopeId) { - List statusIds = baseStatusItemService.getByScopeIdAndScene(scopeId, TemplateScene.BUG.name()).stream().map(StatusItem::getId).toList(); - List statusDefinitions = baseStatusDefinitionService.getStatusDefinitions(statusIds); - Assertions.assertEquals(statusDefinitions.size(), 1); - Assertions.assertEquals(statusDefinitions.get(0).getDefinitionId(), BugStatusDefinitionType.END.name()); + public static StatusItem getNewStatusItem(String scopeId) { + StatusItemExample example = new StatusItemExample(); + example.createCriteria() + .andNameEqualTo(DefaultBugStatusItemName.NEW) + .andScopeIdEqualTo(scopeId); + StatusItemMapper statusItemMapper = CommonBeanFactory.getBean(StatusItemMapper.class); + return statusItemMapper.selectByExample(example).get(0); + } + + public static void assertUpdateStatusDefinition(StatusDefinitionUpdateRequest request) { + StatusDefinitionExample example = new StatusDefinitionExample(); + example.createCriteria() + .andStatusIdEqualTo(request.getStatusId()) + .andDefinitionIdEqualTo(request.getDefinitionId()); + StatusDefinitionMapper statusDefinitionMapper = CommonBeanFactory.getBean(StatusDefinitionMapper.class); + List statusDefinitions = statusDefinitionMapper.selectByExample(example); + if (request.getEnable()) { + Assertions.assertTrue(statusDefinitions.size() == 1); + } else { + Assertions.assertTrue(statusDefinitions.size() == 0); + } + } + + public static void assertSingleChoiceUpdateStatusDefinition(StatusDefinitionUpdateRequest request) { + // 查询当前组织或项目下的状态项 + BaseStatusItemService baseStatusItemService = CommonBeanFactory.getBean(BaseStatusItemService.class); + StatusItem statusItem = baseStatusItemService.getWithCheck(request.getStatusId()); + List scopeStatusItemIds = baseStatusItemService.getByScopeIdAndScene(statusItem.getScopeId(), TemplateScene.BUG.name()) + .stream().map(StatusItem::getId).toList(); + + // 查询当前组织或项目下的该状态定义 + StatusDefinitionExample example = new StatusDefinitionExample(); + example.createCriteria() + .andStatusIdIn(scopeStatusItemIds) + .andDefinitionIdEqualTo(request.getDefinitionId()); + + StatusDefinitionMapper statusDefinitionMapper = CommonBeanFactory.getBean(StatusDefinitionMapper.class); + List statusDefinitions = statusDefinitionMapper.selectByExample(example); + if (request.getEnable()) { + Assertions.assertTrue(statusDefinitions.size() == 1); + } + } + + public static void assertRefUpdateStatusDefinition(StatusDefinitionUpdateRequest request) { + BaseStatusItemService baseStatusItemService = CommonBeanFactory.getBean(BaseStatusItemService.class); + List projectStatusItem = baseStatusItemService.getByRefId(request.getStatusId()); + StatusDefinitionUpdateRequest projectRequest = BeanUtils.copyBean(new StatusDefinitionUpdateRequest(), request); + projectStatusItem.forEach(statusItem -> { + projectRequest.setStatusId(statusItem.getId()); + assertUpdateStatusDefinition(projectRequest); + }); } @Test @Order(4) public void updateStatusFlow() throws Exception { StatusFlowUpdateRequest request = new StatusFlowUpdateRequest(); - request.setScopeId(DEFAULT_ORGANIZATION_ID); - request.setScene(TemplateScene.BUG.name()); - - StatusFlowUpdateRequest.StatusFlowRequest statusFlow = new StatusFlowUpdateRequest.StatusFlowRequest(); - statusFlow.setFromId(addStatusItem.getId()); - StatusItemExample example = new StatusItemExample(); - example.createCriteria().andScopeIdEqualTo(DEFAULT_ORGANIZATION_ID).andSceneEqualTo(TemplateScene.BUG.name()); - StatusItem targetStatusItem = statusItemMapper.selectByExample(example).stream() - .filter(item -> !StringUtils.equals(addStatusItem.getId(), item.getId())) - .findFirst() - .get(); - statusFlow.setToId(targetStatusItem.getId()); - request.setStatusFlows(List.of(statusFlow)); + request.setFromId(anotherAddStatusItem.getId()); + request.setToId(addStatusItem.getId()); + request.setEnable(true); // @@校验请求成功 this.requestPostWithOkAndReturn(STATUS_FLOW_UPDATE, request); - assertUpdateStatusFlow(DEFAULT_ORGANIZATION_ID, statusFlow); + assertUpdateStatusFlow(request); // 校验项目是否同步修改 - StatusFlowUpdateRequest.StatusFlowRequest projectStatusFlow = new StatusFlowUpdateRequest.StatusFlowRequest(); - projectStatusFlow.setFromId(baseStatusItemService.getByRefId(statusFlow.getFromId()).get(0).getId()); - projectStatusFlow.setToId(baseStatusItemService.getByRefId(statusFlow.getToId()).get(0).getId()); - assertUpdateStatusFlow(DEFAULT_PROJECT_ID, projectStatusFlow); + assertRefUpdateStatusFlow(request); + + // @@校验取消 + request.setEnable(false); + this.requestPostWithOkAndReturn(STATUS_FLOW_UPDATE, request); + assertUpdateStatusFlow(request); + // 校验项目是否同步修改 + assertRefUpdateStatusFlow(request); + + // 增加覆盖率 + baseStatusFlowService.deleteByFromIdsAndToIds(null, null); // @校验是否开启组织模板 changeOrgTemplateEnable(false); @@ -339,11 +410,7 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { changeOrgTemplateEnable(true); // @@状态不存在 - request.getStatusFlows().get(0).setToId("1111"); - assertErrorCode(this.requestPost(STATUS_FLOW_UPDATE, request), STATUS_ITEM_NOT_EXIST); - - // @@校验组织是否存在 - request.setScopeId("1111"); + request.setToId("1111"); assertErrorCode(this.requestPost(STATUS_FLOW_UPDATE, request), NOT_FOUND); // @@校验日志 @@ -354,13 +421,35 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { requestPostPermissionTest(PermissionConstants.ORGANIZATION_TEMPLATE_UPDATE, STATUS_FLOW_UPDATE, request); } - private void assertUpdateStatusFlow(String scopeId, StatusFlowUpdateRequest.StatusFlowRequest statusFlow) { - List statusIds = baseStatusItemService.getByScopeIdAndScene(scopeId, TemplateScene.BUG.name()).stream() - .map(StatusItem::getId).toList(); - List statusFlows = baseStatusFlowService.getStatusFlows(statusIds); - Assertions.assertEquals(statusFlows.size(), 1); - Assertions.assertEquals(statusFlows.get(0).getFromId(), statusFlow.getFromId()); - Assertions.assertEquals(statusFlows.get(0).getToId(), statusFlow.getToId()); + public static void assertUpdateStatusFlow(StatusFlowUpdateRequest request) { + StatusFlowExample example = new StatusFlowExample(); + example.createCriteria() + .andFromIdEqualTo(request.getFromId()) + .andToIdEqualTo(request.getToId()); + StatusFlowMapper statusFlowMapper = CommonBeanFactory.getBean(StatusFlowMapper.class); + List statusFlows = statusFlowMapper.selectByExample(example); + if (request.getEnable()) { + Assertions.assertTrue(statusFlows.size() == 1); + } else { + Assertions.assertTrue(statusFlows.size() == 0); + } + } + + public static void assertRefUpdateStatusFlow(StatusFlowUpdateRequest request) { + BaseStatusItemService baseStatusItemService = CommonBeanFactory.getBean(BaseStatusItemService.class); + List fromStatusItems = baseStatusItemService.getByRefId(request.getFromId()); + Map fromStatusItemMap = fromStatusItems.stream() + .collect(Collectors.toMap(StatusItem::getScopeId, Function.identity())); + List toStatusItems = baseStatusItemService.getByRefId(request.getToId()); + Map toStatusItemMap = toStatusItems.stream() + .collect(Collectors.toMap(StatusItem::getScopeId, Function.identity())); + + StatusFlowUpdateRequest projectRequest = BeanUtils.copyBean(new StatusFlowUpdateRequest(), request); + for (String projectId : fromStatusItemMap.keySet()) { + projectRequest.setFromId(fromStatusItemMap.get(projectId).getId()); + projectRequest.setToId(toStatusItemMap.get(projectId).getId()); + assertUpdateStatusFlow(projectRequest); + } } @Test @@ -372,11 +461,14 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { changeOrgTemplateEnable(true); // @@请求成功 + List projectStatusItemIds = baseStatusItemService.getStatusItemIdByRefId(addStatusItem.getId()); this.requestGetWithOk(STATUS_DELETE, addStatusItem.getId()); Assertions.assertNull(statusItemMapper.selectByPrimaryKey(addStatusItem.getId())); Assertions.assertTrue(CollectionUtils.isEmpty(baseStatusItemService.getStatusItemIdByRefId(addStatusItem.getId()))); Assertions.assertTrue(CollectionUtils.isEmpty(baseStatusDefinitionService.getStatusDefinitions(List.of(addStatusItem.getId())))); Assertions.assertTrue(CollectionUtils.isEmpty(baseStatusFlowService.getStatusFlows(List.of(addStatusItem.getId())))); + Assertions.assertTrue(CollectionUtils.isEmpty(baseStatusDefinitionService.getStatusDefinitions(projectStatusItemIds))); + Assertions.assertTrue(CollectionUtils.isEmpty(baseStatusFlowService.getStatusFlows(projectStatusItemIds))); // @@校验 NOT_FOUND 异常 assertErrorCode(this.requestGet(STATUS_DELETE, "1111"), NOT_FOUND); @@ -430,7 +522,7 @@ public class OrganizationStatusFlowSettingControllerTest extends BaseTest { public static void assertSortStatusItem(String scopeId, List statusIds) { BaseStatusItemService baseStatusItemService = CommonBeanFactory.getBean(BaseStatusItemService.class); - List statusItems = baseStatusItemService.getByScopeId(scopeId); + List statusItems = baseStatusItemService.getByScopeIdAndScene(scopeId, TemplateScene.BUG.name()); for (int i = 0; i < statusIds.size(); i++) { String statusId = statusIds.get(i); // 根据statusId 查询 diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusDefinitionUpdateRequestDefinition.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusDefinitionUpdateRequestDefinition.java index fb87134071..cf0c36f9d5 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusDefinitionUpdateRequestDefinition.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusDefinitionUpdateRequestDefinition.java @@ -1,45 +1,27 @@ package io.metersphere.system.controller.param; -import io.metersphere.sdk.constants.TemplateScene; -import io.metersphere.system.valid.EnumValue; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; import java.io.Serializable; -import java.util.List; @Data public class StatusDefinitionUpdateRequestDefinition implements Serializable { private static final long serialVersionUID = 1L; + @Schema(description = "状态ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_definition.status_id.not_blank}") + @Size(min = 1, max = 50, message = "{status_definition.status_id.length_range}") + private String statusId; - @Schema(description = "组织ID或项目ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank - @Size(min = 1, max = 50) - private String scopeId; - @Schema(description = "使用场景", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank - @EnumValue(enumClass = TemplateScene.class) - private String scene; + @Schema(description = "状态定义ID(在代码中定义)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_definition.definition_id.not_blank}") + @Size(min = 1, max = 100, message = "{status_definition.definition_id.length_range}") + private String definitionId; - @NotBlank - @Valid - private List statusDefinitions; - - @Data - public static class StatusDefinitionRequestStatusDefinition implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "状态ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_definition.status_id.not_blank}") - @Size(min = 1, max = 50, message = "{status_definition.status_id.length_range}") - private String statusId; - - @Schema(description = "状态定义ID(在代码中定义)", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_definition.definition_id.not_blank}") - @Size(min = 1, max = 100, message = "{status_definition.definition_id.length_range}") - private String definitionId; - } + @Schema(description = "启用或者禁用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull + private Boolean enable; } \ No newline at end of file diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusFlowUpdateRequestDefinition.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusFlowUpdateRequestDefinition.java index f35a1e366f..184534a731 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusFlowUpdateRequestDefinition.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/param/StatusFlowUpdateRequestDefinition.java @@ -1,46 +1,28 @@ package io.metersphere.system.controller.param; -import io.metersphere.sdk.constants.TemplateScene; -import io.metersphere.system.valid.EnumValue; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; import java.io.Serializable; -import java.util.List; @Data public class StatusFlowUpdateRequestDefinition implements Serializable { private static final long serialVersionUID = 1L; - @Schema(description = "组织ID或项目ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank - @Size(min = 1, max = 50) - private String scopeId; + @Schema(description = "起始状态ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_flow.from_id.not_blank}") + @Size(min = 1, max = 50, message = "{status_flow.from_id.length_range}") + private String fromId; - @Schema(description = "使用场景", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_item.scene.not_blank}") - @EnumValue(enumClass = TemplateScene.class) - private String scene; + @Schema(description = "目的状态ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{status_flow.to_id.not_blank}") + @Size(min = 1, max = 50, message = "{status_flow.to_id.length_range}") + private String toId; - @NotBlank - @Valid - private List statusFlows; - - @Data - public static class StatusFlowRequestDefinition implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "起始状态ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_flow.from_id.not_blank}") - @Size(min = 1, max = 50, message = "{status_flow.from_id.length_range}") - private String fromId; - - @Schema(description = "目的状态ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{status_flow.to_id.not_blank}") - @Size(min = 1, max = 50, message = "{status_flow.to_id.length_range}") - private String toId; - } + @Schema(description = "启用或者禁用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull + private Boolean enable; } \ No newline at end of file