diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql index e0f4011f80..59fc65a817 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql @@ -34,6 +34,7 @@ CREATE INDEX idx_module_id ON functional_case(module_id); CREATE INDEX idx_project_id_pos ON functional_case(project_id,pos); CREATE INDEX idx_public_case_pos ON functional_case(public_case,pos); CREATE INDEX idx_ref_id ON functional_case(ref_id); +CREATE INDEX idx_project_id ON functional_case(project_id); CREATE INDEX idx_version_id ON functional_case(version_id); CREATE INDEX idx_create_time ON functional_case(create_time); CREATE INDEX idx_delete_time ON functional_case(delete_time); diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleConstants.java index 8797153dc7..7f7b31e57d 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ModuleConstants.java @@ -3,8 +3,8 @@ package io.metersphere.sdk.constants; public class ModuleConstants { //未规划节点的ID public static final String DEFAULT_NODE_ID = "root"; - //没有父类的节点,parent_id为none - public static final String ROOT_NODE_PARENT_ID = "none"; + //没有父类的节点,parent_id为NONE + public static final String ROOT_NODE_PARENT_ID = "NONE"; //默认节点类型 public static final String NODE_TYPE_DEFAULT = "module"; //Git节点类型 diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java index 54263613e8..2e23fae19a 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java @@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.Map; /** * @author wx @@ -52,7 +53,7 @@ public class FunctionalCaseController { @GetMapping("/default/template/field/{projectId}") - @Operation(summary = "功能用例-获取默认模板自定义字段") + @Operation(summary = "用例管理-功能用例-获取默认模板自定义字段") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_ADD) public TemplateDTO getDefaultTemplateField(@PathVariable String projectId) { TemplateDTO defaultTemplateDTO = projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.FUNCTIONAL.name()); @@ -61,7 +62,7 @@ public class FunctionalCaseController { @PostMapping("/add") - @Operation(summary = "功能用例-新增用例") + @Operation(summary = "用例管理-功能用例-新增用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_ADD) @Log(type = OperationLogType.ADD, expression = "#msClass.addFunctionalCaseLog(#request, #files)", msClass = FunctionalCaseLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainFunctionalCaseDTO(#request.name, #request.caseEditType, #request.projectId, #request.customFields)", targetClass = FunctionalCaseNoticeService.class) @@ -72,7 +73,7 @@ public class FunctionalCaseController { @GetMapping("/detail/{id}") - @Operation(summary = "功能用例-查看用例详情") + @Operation(summary = "用例管理-功能用例-查看用例详情") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) public FunctionalCaseDetailDTO getFunctionalCaseDetail(@PathVariable String id) { String userId = SessionUtils.getUserId(); @@ -81,7 +82,7 @@ public class FunctionalCaseController { @PostMapping("/update") - @Operation(summary = "功能用例-更新用例") + @Operation(summary = "用例管理-功能用例-更新用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateFunctionalCaseLog(#request, #files)", msClass = FunctionalCaseLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getMainFunctionalCaseDTO(#request.name, #request.caseEditType, #request.projectId, #request.customFields)", targetClass = FunctionalCaseNoticeService.class) @@ -92,7 +93,7 @@ public class FunctionalCaseController { @PostMapping("/edit/follower") - @Operation(summary = "功能用例-关注/取消关注用例") + @Operation(summary = "用例管理-功能用例-关注/取消关注用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE) public void editFollower(@Validated @RequestBody FunctionalCaseFollowerRequest request) { String userId = SessionUtils.getUserId(); @@ -101,7 +102,7 @@ public class FunctionalCaseController { @GetMapping("/version/{id}") - @Operation(summary = "功能用例-版本信息(用例是否存在多版本)") + @Operation(summary = "用例管理-功能用例-版本信息(用例是否存在多版本)") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) public List getVersion(@PathVariable @NotBlank(message = "{functional_case.id.not_blank}") String id) { return functionalCaseService.getFunctionalCaseVersion(id); @@ -109,7 +110,7 @@ public class FunctionalCaseController { @PostMapping("/delete") - @Operation(summary = "功能用例-删除用例") + @Operation(summary = "用例管理-功能用例-删除用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteFunctionalCaseLog(#request)", msClass = FunctionalCaseLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getDeleteFunctionalCaseDTO(#request.id)", targetClass = FunctionalCaseNoticeService.class) @@ -120,7 +121,7 @@ public class FunctionalCaseController { @PostMapping("/page") - @Operation(summary = "功能用例-用例列表查询") + @Operation(summary = "用例管理-功能用例-用例列表查询") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) public Pager> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), @@ -128,9 +129,15 @@ public class FunctionalCaseController { return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false)); } + @PostMapping("/module/count") + @Operation(summary = "用例管理-功能用例-表格分页查询文件") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) + public Map moduleCount(@Validated @RequestBody FunctionalCasePageRequest request) { + return functionalCaseService.moduleCount(request, false); + } @PostMapping("/batch/delete-to-gc") - @Operation(summary = "功能用例-批量删除用例") + @Operation(summary = "用例管理-功能用例-批量删除用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) @Log(type = OperationLogType.DELETE, expression = "#msClass.batchDeleteFunctionalCaseLog(#request)", msClass = FunctionalCaseLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchDeleteFunctionalCaseDTO(#request)", targetClass = FunctionalCaseNoticeService.class) @@ -140,14 +147,14 @@ public class FunctionalCaseController { } @GetMapping("/custom/field/{projectId}") - @Operation(summary = "功能用例-获取表头自定义字段(高级搜索中的自定义字段)") + @Operation(summary = "用例管理-功能用例-获取表头自定义字段(高级搜索中的自定义字段)") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) public List getTableCustomField(@PathVariable String projectId) { return projectTemplateService.getTableCustomField(projectId, TemplateScene.FUNCTIONAL.name()); } @PostMapping("/batch/move") - @Operation(summary = "功能用例-批量移动用例") + @Operation(summary = "用例管理-功能用例-批量移动用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE) public void batchMoveFunctionalCase(@Validated @RequestBody FunctionalCaseBatchMoveRequest request) { String userId = SessionUtils.getUserId(); @@ -156,7 +163,7 @@ public class FunctionalCaseController { @PostMapping("/batch/copy") - @Operation(summary = "功能用例-批量复制用例") + @Operation(summary = "用例管理-功能用例-批量复制用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE) public void batchCopyFunctionalCase(@Validated @RequestBody FunctionalCaseBatchMoveRequest request) { String userId = SessionUtils.getUserId(); @@ -165,7 +172,7 @@ public class FunctionalCaseController { @PostMapping("/batch/edit") - @Operation(summary = "功能用例-批量编辑用例") + @Operation(summary = "用例管理-功能用例-批量编辑用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchEditFunctionalCaseLog(#request)", msClass = FunctionalCaseLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getBatchEditFunctionalCaseDTO(#request)", targetClass = FunctionalCaseNoticeService.class) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java index 32caf27ce8..5669796b6c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java @@ -1,19 +1,29 @@ package io.metersphere.functional.controller; +import com.alibaba.excel.util.StringUtils; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.metersphere.functional.dto.FunctionalCasePageDTO; +import io.metersphere.functional.request.FunctionalCaseBatchRequest; +import io.metersphere.functional.request.FunctionalCasePageRequest; import io.metersphere.functional.service.FunctionalCaseLogService; +import io.metersphere.functional.service.FunctionalCaseService; import io.metersphere.functional.service.FunctionalCaseTrashService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.utils.PageUtils; +import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.SessionUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; @Tag(name = "用例管理-功能用例-回收站") @RestController @@ -22,6 +32,25 @@ public class FunctionalCaseTrashController { @Resource private FunctionalCaseTrashService functionalCaseTrashService; + @Resource + private FunctionalCaseService functionalCaseService; + + @PostMapping("/page") + @Operation(summary = "用例管理-功能用例-回收站-用例列表查询") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) + public Pager> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, true)); + } + + @PostMapping("/module/count") + @Operation(summary = "用例管理-功能用例-回收站-表格分页查询文件") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) + public Map moduleCount(@Validated @RequestBody FunctionalCasePageRequest request) { + return functionalCaseService.moduleCount(request, true); + } + @GetMapping("/recover/{id}") @Operation(summary = "用例管理-功能用例-回收站-恢复用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) @@ -30,6 +59,14 @@ public class FunctionalCaseTrashController { functionalCaseTrashService.recoverCase(id, SessionUtils.getUserId()); } + @PostMapping("/batch/recover") + @Operation(summary = "用例管理-功能用例-回收站-批量恢复用例") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) + @Log(type = OperationLogType.RECOVER, expression = "#msClass.batchRecoverLog(#request)", msClass = FunctionalCaseLogService.class) + public void batchRecoverCase(@Validated @RequestBody FunctionalCaseBatchRequest request) { + functionalCaseTrashService.batchRecoverCase(request, SessionUtils.getUserId()); + } + @GetMapping("/delete/{id}") @Operation(summary = "用例管理-功能用例-回收站-彻底删除用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) @@ -38,4 +75,12 @@ public class FunctionalCaseTrashController { functionalCaseTrashService.deleteCase(id); } + @PostMapping("/batch/delete") + @Operation(summary = "用例管理-功能用例-回收站-批量彻底删除用例") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) + @Log(type = OperationLogType.DELETE, expression = "#msClass.batchDeleteTrashCaseLog(#request)", msClass = FunctionalCaseLogService.class) + public void batchDeleteCase(@Validated @RequestBody FunctionalCaseBatchRequest request) { + functionalCaseTrashService.batchDeleteCase(request); + } + } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java index a1cb201a5f..1a4a8e6737 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java @@ -6,6 +6,7 @@ import io.metersphere.functional.dto.FunctionalCasePageDTO; import io.metersphere.functional.dto.FunctionalCaseVersionDTO; import io.metersphere.functional.request.FunctionalCaseBatchMoveRequest; import io.metersphere.functional.request.FunctionalCasePageRequest; +import io.metersphere.project.dto.ModuleCountDTO; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -36,9 +37,9 @@ public interface ExtFunctionalCaseMapper { void batchDelete(@Param("ids") List ids, @Param("userId") String userId); - List getLogInfo(@Param("ids") List ids); + List getLogInfo(@Param("ids") List ids, @Param("deleted") boolean deleted); - List getRefIds(@Param("ids") List ids); + List getRefIds(@Param("ids") List ids, @Param("deleted") boolean deleted); void batchMoveModule(@Param("request") FunctionalCaseBatchMoveRequest request, @Param("ids") List ids, @Param("userId") String userId); @@ -46,4 +47,11 @@ public interface ExtFunctionalCaseMapper { void batchUpdate(@Param("functionalCase") FunctionalCase functionalCase, @Param("ids") List ids); + + void recoverCaseByRefIds(@Param("refIds") List refIds, @Param("userId") String userId, @Param("time") long time); + + List countModuleIdByKeywordAndFileType(@Param("request") FunctionalCasePageRequest request, @Param("deleted") boolean deleted); + + long caseCount(@Param("request") FunctionalCasePageRequest request, @Param("deleted") boolean deleted); + } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml index 8a69955b26..842bec00e5 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml @@ -111,6 +111,19 @@ + + UPDATE functional_case + SET deleted = false, + update_user = #{userId}, + update_time = #{time}, + delete_user = null, + delete_time = null + WHERE ref_id IN + + #{refId} + + + functional_case.module_id in @@ -422,7 +435,7 @@ #{id} - and deleted = false + and deleted = #{deleted} group by ref_id @@ -450,7 +463,7 @@ #{id} - and deleted = false + and deleted = #{deleted} @@ -498,4 +511,40 @@ and deleted = false and project_id = #{functionalCase.projectId} + + + + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.java index cf7c2471d3..70183f861c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.java @@ -21,4 +21,7 @@ public interface ExtFunctionalCaseModuleMapper { BaseModule selectBaseModuleById(String dragNodeId); BaseModule selectModuleByParentIdAndPosOperator(NodeSortQueryParam nodeSortQueryParam); + + List selectIdAndParentIdByProjectId(String projectId); + } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.xml index 3688660476..563bfd766b 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseModuleMapper.xml @@ -55,4 +55,10 @@ FROM functional_case_module WHERE id = #{0} + + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java index c85ab351a6..0767ac9e81 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java @@ -1,6 +1,7 @@ package io.metersphere.functional.service; import io.metersphere.functional.domain.FunctionalCase; +import io.metersphere.functional.dto.BaseFunctionalCaseBatchDTO; import io.metersphere.functional.mapper.ExtFunctionalCaseMapper; import io.metersphere.functional.mapper.FunctionalCaseMapper; import io.metersphere.functional.request.*; @@ -139,7 +140,7 @@ public class FunctionalCaseLogService { List ids = functionalCaseService.doSelectIds(request, request.getProjectId()); List dtoList = new ArrayList<>(); if (CollectionUtils.isNotEmpty(ids)) { - List functionalCases = extFunctionalCaseMapper.getLogInfo(ids); + List functionalCases = extFunctionalCaseMapper.getLogInfo(ids, false); functionalCases.forEach(functionalCase -> { LogDTO dto = new LogDTO( functionalCase.getProjectId(), @@ -182,6 +183,36 @@ public class FunctionalCaseLogService { return null; } + /** + * 恢复项目 + * + * @param request 接口请求参数 + * @return 日志详情 + */ + public List batchRecoverLog(FunctionalCaseBatchRequest request) { + List ids = getSelectIdsByTrash(request, request.getProjectId()); + List dtoList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(ids)) { + List functionalCases = extFunctionalCaseMapper.getLogInfo(ids, true); + functionalCases.forEach(functionalCase -> { + LogDTO dto = new LogDTO( + functionalCase.getProjectId(), + "", + functionalCase.getId(), + functionalCase.getCreateUser(), + OperationLogType.RECOVER.name(), + OperationLogModule.FUNCTIONAL_CASE, + functionalCase.getName()); + + dto.setPath("/functional/case/batch/recover"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(functionalCase)); + dtoList.add(dto); + }); + } + return dtoList; + } + /** * 彻底删除 * @@ -213,7 +244,7 @@ public class FunctionalCaseLogService { List ids = functionalCaseService.doSelectIds(request, request.getProjectId()); List dtoList = new ArrayList<>(); if (CollectionUtils.isNotEmpty(ids)) { - List functionalCases = extFunctionalCaseMapper.getLogInfo(ids); + List functionalCases = extFunctionalCaseMapper.getLogInfo(ids, false); functionalCases.forEach(functionalCase -> { LogDTO dto = new LogDTO( functionalCase.getProjectId(), @@ -232,4 +263,41 @@ public class FunctionalCaseLogService { } return dtoList; } + + public List batchDeleteTrashCaseLog(FunctionalCaseBatchRequest request) { + List ids = getSelectIdsByTrash(request, request.getProjectId()); + List dtoList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(ids)) { + List functionalCases = extFunctionalCaseMapper.getLogInfo(ids, true); + functionalCases.forEach(functionalCase -> { + LogDTO dto = new LogDTO( + functionalCase.getProjectId(), + null, + functionalCase.getId(), + functionalCase.getCreateUser(), + OperationLogType.DELETE.name(), + OperationLogModule.FUNCTIONAL_CASE, + functionalCase.getName()); + + dto.setPath("/functional/case/batch/delete"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(functionalCase)); + dtoList.add(dto); + }); + } + return dtoList; + } + + public List getSelectIdsByTrash(T dto, String projectId) { + BaseFunctionalCaseBatchDTO request = (BaseFunctionalCaseBatchDTO) dto; + if (request.isSelectAll()) { + List ids = extFunctionalCaseMapper.getIds(request, projectId, true); + if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { + ids.removeAll(request.getExcludeIds()); + } + return ids; + } else { + return request.getSelectIds(); + } + } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseModuleService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseModuleService.java index f4e6674dab..cd15fa24c7 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseModuleService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseModuleService.java @@ -17,13 +17,20 @@ import io.metersphere.functional.mapper.FunctionalCaseMapper; import io.metersphere.functional.mapper.FunctionalCaseModuleMapper; import io.metersphere.functional.request.FunctionalCaseModuleCreateRequest; import io.metersphere.functional.request.FunctionalCaseModuleUpdateRequest; +import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.dto.NodeSortDTO; import io.metersphere.project.service.ModuleTreeService; +import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.request.NodeMoveRequest; +import io.metersphere.system.log.constants.OperationLogModule; +import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.log.dto.LogDTO; +import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; @@ -38,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; @Service @@ -54,7 +62,7 @@ public class FunctionalCaseModuleService extends ModuleTreeService { @Resource private FunctionalCaseMapper functionalCaseMapper; @Resource - private FunctionalCaseLogService functionalCaseLogService; + private OperationLogService operationLogService; public List getTree(String projectId) { List fileModuleList = extFunctionalCaseModuleMapper.selectBaseByProjectId(projectId); @@ -113,10 +121,30 @@ public class FunctionalCaseModuleService extends ModuleTreeService { FunctionalCaseModule deleteModule = functionalCaseModuleMapper.selectByPrimaryKey(moduleId); if (deleteModule != null) { List functionalCases = this.deleteModuleByIds(Collections.singletonList(moduleId), new ArrayList<>()); - functionalCaseLogService.batchDelLog(functionalCases, deleteModule.getProjectId()); + batchDelLog(functionalCases, deleteModule.getProjectId()); } } + public void batchDelLog(List functionalCases, String projectId) { + List dtoList = new ArrayList<>(); + functionalCases.forEach(item -> { + LogDTO dto = new LogDTO( + projectId, + "", + item.getId(), + item.getCreateUser(), + OperationLogType.DELETE.name(), + OperationLogModule.FUNCTIONAL_CASE, + item.getName()); + + dto.setPath("/functional/case/module/delete/"); + dto.setMethod(HttpMethodConstants.GET.name()); + dto.setOriginalValue(JSON.toJSONBytes(item)); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } + public List deleteModuleByIds(ListdeleteIds, ListfunctionalCases){ if (CollectionUtils.isEmpty(deleteIds)) { return functionalCases; @@ -145,6 +173,24 @@ public class FunctionalCaseModuleService extends ModuleTreeService { } } + /** + * 查找当前项目下模块每个节点对应的资源统计 + * + */ + public Map getModuleCountMap(String projectId, List moduleCountDTOList) { + + //构建模块树,并计算每个节点下的所有数量(包含子节点) + List treeNodeList = this.getTreeOnlyIdsAndResourceCount(projectId, moduleCountDTOList); + //通过广度遍历的方式构建返回值 + return super.getIdCountMapByBreadth(treeNodeList); + } + + public List getTreeOnlyIdsAndResourceCount(String projectId, List moduleCountDTOList) { + //节点内容只有Id和parentId + List fileModuleList = extFunctionalCaseModuleMapper.selectIdAndParentIdByProjectId(projectId); + return super.buildTreeAndCountResource(fileModuleList, moduleCountDTOList, true, Translator.get("default.module")); + } + /** * 检查数据的合法性 */ diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index f6e21037fe..3ed86af964 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -5,6 +5,7 @@ import io.metersphere.functional.dto.*; import io.metersphere.functional.mapper.*; import io.metersphere.functional.request.*; import io.metersphere.functional.result.FunctionalCaseResultCode; +import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.project.service.ProjectTemplateService; import io.metersphere.sdk.constants.ApplicationNumScope; @@ -74,6 +75,11 @@ public class FunctionalCaseService { @Resource private FunctionalCaseModuleMapper functionalCaseModuleMapper; + @Resource + private FunctionalCaseModuleService functionalCaseModuleService; + + private static final String CASE_MODULE_COUNT_ALL = "all"; + private static final String ADD_FUNCTIONAL_CASE_FILE_LOG_URL = "/functional/case/add"; private static final String UPDATE_FUNCTIONAL_CASE_FILE_LOG_URL = "/functional/case/update"; @@ -98,7 +104,7 @@ public class FunctionalCaseService { /** * 添加功能用例 * - * @param request + * @param request request */ private FunctionalCase addCase(String caseId, FunctionalCaseAddRequest request, String userId) { FunctionalCase functionalCase = new FunctionalCase(); @@ -143,8 +149,8 @@ public class FunctionalCaseService { /** * 查看用例获取详情 * - * @param functionalCaseId - * @return + * @param functionalCaseId functionalCaseId + * @return FunctionalCaseDetailDTO */ public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId, String userId) { FunctionalCase functionalCase = checkFunctionalCase(functionalCaseId); @@ -185,8 +191,8 @@ public class FunctionalCaseService { /** * 校验用例是否存在 * - * @param functionalCaseId - * @return + * @param functionalCaseId functionalCaseId + * @return FunctionalCase */ private FunctionalCase checkFunctionalCase(String functionalCaseId) { FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); @@ -202,7 +208,7 @@ public class FunctionalCaseService { /** * 获取模板自定义字段 * - * @param functionalCase + * @param functionalCase functionalCase */ private FunctionalCaseDetailDTO checkTemplateCustomField(FunctionalCaseDetailDTO functionalCaseDetailDTO, FunctionalCase functionalCase) { TemplateDTO templateDTO = projectTemplateService.getTemplateDTOById(functionalCase.getTemplateId(), functionalCase.getProjectId(), TemplateScene.FUNCTIONAL.name()); @@ -224,10 +230,10 @@ public class FunctionalCaseService { /** * 更新用例 基本信息 * - * @param request - * @param files - * @param userId - * @return + * @param request request + * @param files files + * @param userId userId + * @return FunctionalCase */ public FunctionalCase updateFunctionalCase(FunctionalCaseEditRequest request, List files, String userId) { FunctionalCase checked = checkFunctionalCase(request.getId()); @@ -270,8 +276,8 @@ public class FunctionalCaseService { /** * 多版本所属模块更新处理 * - * @param refId - * @param moduleId + * @param refId refId + * @param moduleId moduleId */ private void updateFunctionalCaseModule(String refId, String moduleId) { extFunctionalCaseMapper.updateFunctionalCaseModule(refId, moduleId); @@ -296,8 +302,8 @@ public class FunctionalCaseService { /** * 关注/取消关注用例 * - * @param functionalCaseId - * @param userId + * @param functionalCaseId functionalCaseId + * @param userId userId */ public void editFollower(String functionalCaseId, String userId) { checkFunctionalCase(functionalCaseId); @@ -317,17 +323,17 @@ public class FunctionalCaseService { /** * 删除用例 * - * @param request - * @param userId + * @param request request + * @param userId userId */ public void deleteFunctionalCase(FunctionalCaseDeleteRequest request, String userId) { - handDeleteFunctionalCase(Arrays.asList(request.getId()), request.getDeleteAll(), userId); + handDeleteFunctionalCase(Collections.singletonList(request.getId()), request.getDeleteAll(), userId); } private void handDeleteFunctionalCase(List ids, Boolean deleteAll, String userId) { if (deleteAll) { //全部删除 进入回收站 - List refId = extFunctionalCaseMapper.getRefIds(ids); + List refId = extFunctionalCaseMapper.getRefIds(ids, false); extFunctionalCaseMapper.batchDelete(refId, userId); } else { //列表删除 需要判断是否存在多个版本问题 @@ -335,7 +341,7 @@ public class FunctionalCaseService { List versionDTOList = getFunctionalCaseVersion(id); if (versionDTOList.size() > 1) { String projectId = versionDTOList.get(0).getProjectId(); - deleteFunctionalCaseService.deleteFunctionalCaseResource(Arrays.asList(id), projectId); + deleteFunctionalCaseService.deleteFunctionalCaseResource(Collections.singletonList(id), projectId); } else { //只有一个版本 直接放入回收站 doDelete(id, userId); @@ -358,20 +364,19 @@ public class FunctionalCaseService { /** * 根据用例id 获取用例是否存在多个版本 * - * @param functionalCaseId - * @return + * @param functionalCaseId functionalCaseId + * @return List */ public List getFunctionalCaseVersion(String functionalCaseId) { FunctionalCase functionalCase = checkFunctionalCase(functionalCaseId); - List list = extFunctionalCaseMapper.getFunctionalCaseByRefId(functionalCase.getRefId()); - return list; + return extFunctionalCaseMapper.getFunctionalCaseByRefId(functionalCase.getRefId()); } /** * 列表查询 * - * @param request - * @return + * @param request request + * @return List */ public List getFunctionalCasePage(FunctionalCasePageRequest request, Boolean deleted) { List functionalCaseLists = extFunctionalCaseMapper.list(request, deleted); @@ -418,13 +423,13 @@ public class FunctionalCaseService { /** * 批量移动用例 * - * @param request - * @param userId + * @param request request + * @param userId userId */ public void batchMoveFunctionalCase(FunctionalCaseBatchMoveRequest request, String userId) { List ids = doSelectIds(request, request.getProjectId()); if (CollectionUtils.isNotEmpty(ids)) { - List refId = extFunctionalCaseMapper.getRefIds(ids); + List refId = extFunctionalCaseMapper.getRefIds(ids, false); extFunctionalCaseMapper.batchMoveModule(request, refId, userId); } } @@ -432,8 +437,8 @@ public class FunctionalCaseService { /** * 批量复制用例 * - * @param request - * @param userId + * @param request request + * @param userId userId */ public void batchCopyFunctionalCase(FunctionalCaseBatchMoveRequest request, String userId) { List ids = doSelectIds(request, request.getProjectId()); @@ -479,7 +484,7 @@ public class FunctionalCaseService { }); if (CollectionUtils.isNotEmpty(caseAttachments)) { - caseAttachments.stream().forEach(attachment -> { + caseAttachments.forEach(attachment -> { attachment.setId(IDGenerator.nextStr()); attachment.setCaseId(id); attachment.setCreateUser(userId); @@ -489,7 +494,7 @@ public class FunctionalCaseService { } if (CollectionUtils.isNotEmpty(customFields)) { - customFields.stream().forEach(customField -> { + customFields.forEach(customField -> { customField.setCaseId(id); }); functionalCaseCustomFieldService.batchSaveCustomField(customFields); @@ -519,24 +524,22 @@ public class FunctionalCaseService { FunctionalCaseBlobExample blobExample = new FunctionalCaseBlobExample(); blobExample.createCriteria().andIdIn(ids); List functionalCaseBlobs = functionalCaseBlobMapper.selectByExampleWithBLOBs(blobExample); - Map functionalCaseBlobMap = functionalCaseBlobs.stream().collect(Collectors.toMap(FunctionalCaseBlob::getId, functionalCaseBlob -> functionalCaseBlob)); - return functionalCaseBlobMap; + return functionalCaseBlobs.stream().collect(Collectors.toMap(FunctionalCaseBlob::getId, functionalCaseBlob -> functionalCaseBlob)); } public Map copyBaseInfo(String projectId, List ids) { FunctionalCaseExample example = new FunctionalCaseExample(); example.createCriteria().andProjectIdEqualTo(projectId).andDeletedEqualTo(false).andIdIn(ids); List functionalCaseLists = functionalCaseMapper.selectByExample(example); - Map functionalMap = functionalCaseLists.stream().collect(Collectors.toMap(FunctionalCase::getId, functionalCase -> functionalCase)); - return functionalMap; + return functionalCaseLists.stream().collect(Collectors.toMap(FunctionalCase::getId, functionalCase -> functionalCase)); } /** * 批量编辑 * - * @param request - * @param userId + * @param request request + * @param userId userId */ public void batchEditFunctionalCase(FunctionalCaseBatchEditRequest request, String userId) { List ids = doSelectIds(request, request.getProjectId()); @@ -599,4 +602,15 @@ public class FunctionalCaseService { } } + + public Map moduleCount(FunctionalCasePageRequest request, boolean delete) { + //查出每个模块节点下的资源数量。 不需要按照模块进行筛选 + List moduleCountDTOList = extFunctionalCaseMapper.countModuleIdByKeywordAndFileType(request, delete); + Map moduleCountMap = functionalCaseModuleService.getModuleCountMap(request.getProjectId(), moduleCountDTOList); + //查出全部文件和我的文件的数量 + long allCount = extFunctionalCaseMapper.caseCount(request, delete); + moduleCountMap.put(CASE_MODULE_COUNT_ALL, allCount); + return moduleCountMap; + + } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseTrashService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseTrashService.java index 7400001e79..5868b37fca 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseTrashService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseTrashService.java @@ -7,6 +7,7 @@ import io.metersphere.functional.domain.FunctionalCaseExample; import io.metersphere.functional.mapper.ExtFunctionalCaseMapper; import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper; import io.metersphere.functional.mapper.FunctionalCaseMapper; +import io.metersphere.functional.request.FunctionalCaseBatchRequest; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.CustomField; @@ -14,6 +15,7 @@ import io.metersphere.system.domain.CustomFieldExample; import io.metersphere.system.mapper.CustomFieldMapper; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -38,6 +40,7 @@ public class FunctionalCaseTrashService { @Resource private DeleteFunctionalCaseService deleteFunctionalCaseService; + /** * 从回收站恢复用例 * @param id 用例ID @@ -50,7 +53,17 @@ public class FunctionalCaseTrashService { throw new MSException(Translator.get("case_comment.case_is_null")); } List ids = getIdsByRefId(functionalCase.getRefId()); - //检查自定义字段是否还存在,不存在,删除关联关系 + //检查自定义字段是否还存在,不存在,删除关联关系(与恢复流程没关系可异步执行) + delCustomFields(ids); + extFunctionalCaseMapper.recoverCase(ids,userId,System.currentTimeMillis()); + } + + @Async + public void delCustomFields(List ids) { + doDeleteCustomFields(ids); + } + + private void doDeleteCustomFields(List ids) { FunctionalCaseCustomFieldExample functionalCaseCustomFieldExample = new FunctionalCaseCustomFieldExample(); functionalCaseCustomFieldExample.createCriteria().andCaseIdIn(ids); List functionalCaseCustomFields = functionalCaseCustomFieldMapper.selectByExample(functionalCaseCustomFieldExample); @@ -68,7 +81,15 @@ public class FunctionalCaseTrashService { functionalCaseCustomFieldExample.createCriteria().andFieldIdIn(delIds); functionalCaseCustomFieldMapper.deleteByExample(functionalCaseCustomFieldExample); } - extFunctionalCaseMapper.recoverCase(ids,userId,System.currentTimeMillis()); + } + + @Async + public void delCustomFieldsByRefIds(List refIds) { + FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andRefIdIn(refIds); + List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); + List ids = functionalCases.stream().map(FunctionalCase::getId).toList(); + doDeleteCustomFields(ids); } /** @@ -90,4 +111,94 @@ public class FunctionalCaseTrashService { List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); return functionalCases.stream().map(FunctionalCase::getId).toList(); } + + /** + * 从回收站批量回复用例(恢复就是恢复所有版本) + * @param request request + * @param userId userId + */ + public void batchRecoverCase(FunctionalCaseBatchRequest request, String userId) { + List refIds; + if (request.isSelectAll()) { + //回收站全部恢复 + List ids = getIds(request); + if (ids == null) return; + refIds = extFunctionalCaseMapper.getRefIds(ids, true); + } else { + if (CollectionUtils.isEmpty(request.getSelectIds())) { + return; + } + FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andIdIn(request.getSelectIds()); + List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); + refIds = functionalCases.stream().map(FunctionalCase::getRefId).distinct().toList(); + } + if (CollectionUtils.isNotEmpty(refIds)) { + extFunctionalCaseMapper.recoverCaseByRefIds(refIds, userId, System.currentTimeMillis()); + delCustomFieldsByRefIds(refIds); + } + } + + /** + * 获取实际的选择ID + * @param request request + * @return List + */ + private List getIds(FunctionalCaseBatchRequest request) { + List ids = extFunctionalCaseMapper.getIds(request, request.getProjectId(), true); + if (CollectionUtils.isEmpty(ids)) { + return null; + } + if(CollectionUtils.isNotEmpty(request.getExcludeIds())){ + ids.removeAll(request.getExcludeIds()); + if (CollectionUtils.isEmpty(ids)) { + return null; + } + } + return ids; + } + + + /** + * 批量彻底删除,也分当前版本和全部版本 + * @param request request + */ + public void batchDeleteCase(FunctionalCaseBatchRequest request) { + List refIds; + if (request.isSelectAll()) { + //判断是否全部删除 + List ids = getIds(request); + if (ids == null) return; + if (request.getDeleteAll()) { + //回收站全部版本全都删除 + refIds = extFunctionalCaseMapper.getRefIds(ids, true); + deleteByRefIds(request, refIds); + }else { + //只删除当前选择的数据 + deleteFunctionalCaseService.deleteFunctionalCaseResource(ids, request.getProjectId()); + } + } else { + if (CollectionUtils.isEmpty(request.getSelectIds())) { + return; + } + if (request.getDeleteAll()) { + FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andIdIn(request.getSelectIds()); + List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); + refIds = functionalCases.stream().map(FunctionalCase::getRefId).distinct().toList(); + deleteByRefIds(request, refIds); + } else { + //只删除当前选择的数据 + deleteFunctionalCaseService.deleteFunctionalCaseResource(request.getSelectIds(), request.getProjectId()); + } + } + } + + private void deleteByRefIds(FunctionalCaseBatchRequest request, List refIds) { + FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andRefIdIn(refIds).andDeletedEqualTo(true); + List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); + List deleteIds = functionalCases.stream().map(FunctionalCase::getId).toList(); + deleteFunctionalCaseService.deleteFunctionalCaseResource(deleteIds, request.getProjectId()); + } } diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java index 103a4d6677..ee88154950 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java @@ -1,7 +1,7 @@ package io.metersphere.functional.controller; -import com.jayway.jsonpath.JsonPath; import io.metersphere.sdk.constants.SessionConstants; +import io.metersphere.system.base.BaseTest; import jakarta.annotation.Resource; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -9,39 +9,19 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class CaseReviewControllerTests { +public class CaseReviewControllerTests extends BaseTest { @Resource private MockMvc mockMvc; - private static String sessionId; - private static String csrfToken; - - - @Test - @Order(0) - public void login() throws Exception { - MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login") - .content("{\"username\":\"admin\",\"password\":\"metersphere\"}") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); - sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId"); - csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken"); - } - @Test @Order(1) public void testGetCaseReview() throws Exception { diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java index 2c1f6d5879..6d98882400 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java @@ -2,6 +2,7 @@ package io.metersphere.functional.controller; import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.dto.CaseCustomFieldDTO; +import io.metersphere.functional.dto.FunctionalCasePageDTO; import io.metersphere.functional.request.*; import io.metersphere.functional.result.FunctionalCaseResultCode; import io.metersphere.functional.utils.FileBaseUtils; @@ -17,6 +18,7 @@ import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.CustomField; import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.notice.constants.NoticeConstants; +import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -43,6 +45,7 @@ public class FunctionalCaseControllerTests extends BaseTest { public static final String FUNCTIONAL_CASE_EDIT_FOLLOWER_URL = "/functional/case/edit/follower"; public static final String FUNCTIONAL_CASE_DELETE_URL = "/functional/case/delete"; public static final String FUNCTIONAL_CASE_LIST_URL = "/functional/case/page"; + public static final String FUNCTIONAL_CASE_MODULE_COUNT = "/functional/case/module/count"; public static final String FUNCTIONAL_CASE_BATCH_DELETE_URL = "/functional/case/batch/delete-to-gc"; public static final String FUNCTIONAL_CASE_TABLE_URL = "/functional/case/custom/field/"; public static final String FUNCTIONAL_CASE_BATCH_MOVE_URL = "/functional/case/batch/move"; @@ -272,7 +275,35 @@ public class FunctionalCaseControllerTests extends BaseTest { put("type", "List"); }})); request.setCombine(map); - this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); + MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); + Pager> tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + + MvcResult moduleCountMvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_MODULE_COUNT, request); + Map moduleCount = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Map.class); + + //返回值的页码和当前页码相同 + Assertions.assertEquals(tableData.getCurrent(), request.getCurrent()); + //返回的数据量不超过规定要返回的数据量相同 + Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= request.getPageSize()); + + //如果没有数据,则返回的模块节点也不应该有数据 + boolean moduleHaveResource = false; + for (int countByModuleId : moduleCount.values()) { + if (countByModuleId > 0) { + moduleHaveResource = true; + break; + } + } + Assertions.assertEquals(request.getPageSize(), tableData.getPageSize()); + if (tableData.getTotal() > 0) { + Assertions.assertTrue(moduleHaveResource); + } + + Assertions.assertTrue(moduleCount.containsKey("all")); } diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseTrashControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseTrashControllerTests.java index 646f09d2e4..89fc11d926 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseTrashControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseTrashControllerTests.java @@ -2,11 +2,18 @@ package io.metersphere.functional.controller; import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCaseComment; +import io.metersphere.functional.domain.FunctionalCaseExample; +import io.metersphere.functional.dto.FunctionalCasePageDTO; import io.metersphere.functional.mapper.FunctionalCaseCommentMapper; import io.metersphere.functional.mapper.FunctionalCaseMapper; +import io.metersphere.functional.request.FunctionalCaseBatchRequest; +import io.metersphere.functional.request.FunctionalCasePageRequest; import io.metersphere.sdk.constants.SessionConstants; +import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.mapper.CustomFieldMapper; +import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -14,8 +21,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import java.nio.charset.StandardCharsets; +import java.util.*; + import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -23,9 +34,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @AutoConfigureMockMvc public class FunctionalCaseTrashControllerTests extends BaseTest { + private static final String URL_CASE_PAGE = "/functional/case/trash/page"; + private static final String URL_CASE_MODULE_COUNT = "/functional/case/trash/module/count"; private static final String URL_CASE_RECOVER = "/functional/case/trash/recover/"; + private static final String URL_CASE_BATCH_RECOVER = "/functional/case/trash/batch/recover"; private static final String URL_CASE_DELETE = "/functional/case/trash/delete/"; - + private static final String URL_CASE_BATCH_DELETE = "/functional/case/trash/batch/delete"; @Resource private FunctionalCaseMapper functionalCaseMapper; @@ -38,6 +52,62 @@ public class FunctionalCaseTrashControllerTests extends BaseTest { @Test @Order(1) @Sql(scripts = {"/dml/init_case_trash.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) + public void testGetPageList() throws Exception { + FunctionalCasePageRequest request = new FunctionalCasePageRequest(); + request.setProjectId("test_project_id"); + request.setCurrent(1); + request.setPageSize(10); + this.requestPost(URL_CASE_PAGE, request); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setSort(new HashMap<>() {{ + put("createTime", "desc"); + }}); + MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_CASE_PAGE, request); + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + + //自定义字段 测试 + Map map = new HashMap<>(); + map.put("customs", Arrays.asList(new LinkedHashMap() {{ + put("id", "TEST_FIELD_ID"); + put("operator", "in"); + put("value", "222"); + put("type", "List"); + }})); + request.setCombine(map); + MvcResult mvcResultPage = this.requestPostWithOkAndReturn(URL_CASE_PAGE, request); + Pager> tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + MvcResult moduleCountMvcResult = this.requestPostWithOkAndReturn(URL_CASE_MODULE_COUNT, request); + Map moduleCount = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Map.class); + + //返回值的页码和当前页码相同 + Assertions.assertEquals(tableData.getCurrent(), request.getCurrent()); + //返回的数据量不超过规定要返回的数据量相同 + Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= request.getPageSize()); + + //如果没有数据,则返回的模块节点也不应该有数据 + boolean moduleHaveResource = false; + for (int countByModuleId : moduleCount.values()) { + if (countByModuleId > 0) { + moduleHaveResource = true; + break; + } + } + Assertions.assertEquals(request.getPageSize(), tableData.getPageSize()); + if (tableData.getTotal() > 0) { + Assertions.assertTrue(moduleHaveResource); + } + + Assertions.assertTrue(moduleCount.containsKey("all")); + } + + @Test + @Order(2) public void recoverCaseSuccessWidthCustom() throws Exception { customFieldMapper.deleteByPrimaryKey("gyq_custom_id2"); this.requestGetWithOk(URL_CASE_RECOVER + "Trash_TEST_FUNCTIONAL_CASE_ID"); @@ -49,7 +119,7 @@ public class FunctionalCaseTrashControllerTests extends BaseTest { } @Test - @Order(2) + @Order(3) public void recoverCaseSuccessWidthNoCustom() throws Exception { this.requestGetWithOk(URL_CASE_RECOVER + "Trash_TEST_FUNCTIONAL_CASE_ID_1"); FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_1"); @@ -61,7 +131,7 @@ public class FunctionalCaseTrashControllerTests extends BaseTest { } @Test - @Order(3) + @Order(4) public void recoverCaseFalse() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get(URL_CASE_RECOVER + "Trash_TEST_FUNCTIONAL_CASE_ID_del").header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) @@ -70,13 +140,54 @@ public class FunctionalCaseTrashControllerTests extends BaseTest { } @Test - @Order(4) + @Order(5) + public void recoverBatchCaseSuccess() throws Exception { + FunctionalCaseBatchRequest request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-1"); + request.setSelectAll(false); + request.setSelectIds(Arrays.asList("Trash_TEST_FUNCTIONAL_CASE_ID_5", "Trash_TEST_FUNCTIONAL_CASE_ID_7")); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_RECOVER, request); + FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_6"); + Assertions.assertFalse(functionalCase.getDeleted()); + FunctionalCase functionalCase2 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_8"); + Assertions.assertFalse(functionalCase2.getDeleted()); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-1"); + request.setSelectAll(true); + request.setExcludeIds(List.of("Trash_TEST_FUNCTIONAL_CASE_ID_c")); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_RECOVER, request); + FunctionalCase functionalCase3 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_a"); + Assertions.assertFalse(functionalCase3.getDeleted()); + FunctionalCase functionalCase4 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_b"); + Assertions.assertTrue(functionalCase4.getDeleted()); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-X"); + request.setSelectAll(false); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_RECOVER, request); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-X"); + request.setSelectAll(true); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_RECOVER, request); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-1"); + request.setSelectAll(false); + request.setSelectIds(Arrays.asList("Trash_TEST_FUNCTIONAL_CASE_ID_x", "Trash_TEST_FUNCTIONAL_CASE_ID_y")); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_RECOVER, request); + } + + + @Test + @Order(6) public void deleteCaseWidthNoExist() throws Exception { this.requestGetWithOk(URL_CASE_DELETE + "Trash_TEST_FUNCTIONAL_CASE_ID_del"); } @Test - @Order(5) + @Order(7) public void deleteCaseWidthSuccess() throws Exception { this.requestGetWithOk(URL_CASE_DELETE + "Trash_TEST_FUNCTIONAL_CASE_ID"); FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID"); @@ -88,4 +199,77 @@ public class FunctionalCaseTrashControllerTests extends BaseTest { } + @Test + @Order(8) + public void batchDeleteCaseWidthSuccess() throws Exception { + FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andRefIdEqualTo("Trash_TEST_FUNCTIONAL_CASE_ID_1"); + List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); + functionalCases.forEach(t->{ + t.setDeleted(true); + functionalCaseMapper.updateByPrimaryKeySelective(t); + }); + FunctionalCaseBatchRequest request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test"); + request.setSelectAll(false); + request.setDeleteAll(true); + request.setSelectIds(List.of("Trash_TEST_FUNCTIONAL_CASE_ID_1")); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_DELETE, request); + FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_2"); + Assertions.assertNull(functionalCase); + + + functionalCaseExample= new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andProjectIdEqualTo("project-case-trash-test-1"); + List functionalCaseList = functionalCaseMapper.selectByExample(functionalCaseExample); + functionalCaseList.forEach(t->{ + t.setDeleted(true); + functionalCaseMapper.updateByPrimaryKeySelective(t); + }); + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-1"); + request.setSelectAll(false); + request.setDeleteAll(false); + request.setSelectIds(List.of("Trash_TEST_FUNCTIONAL_CASE_ID_5")); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_DELETE, request); + FunctionalCase functionalCase2 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_6"); + Assertions.assertNotNull(functionalCase2); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-1"); + request.setSelectAll(true); + request.setDeleteAll(false); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_DELETE, request); + FunctionalCase functionalCase3 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_a"); + Assertions.assertNull(functionalCase3); + FunctionalCase functionalCase4 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_9"); + Assertions.assertNotNull(functionalCase4); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-2"); + request.setSelectAll(true); + request.setDeleteAll(true); + request.setExcludeIds(List.of("Trash_TEST_FUNCTIONAL_CASE_ID_e")); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_DELETE, request); + FunctionalCase functionalCase5 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_f"); + Assertions.assertNull(functionalCase5); + FunctionalCase functionalCase6 = functionalCaseMapper.selectByPrimaryKey("Trash_TEST_FUNCTIONAL_CASE_ID_d"); + Assertions.assertNotNull(functionalCase6); + + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-x"); + request.setSelectAll(true); + request.setDeleteAll(true); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_DELETE, request); + + request = new FunctionalCaseBatchRequest(); + request.setProjectId("project-case-trash-test-1"); + request.setSelectAll(false); + request.setDeleteAll(true); + this.requestPostWithOkAndReturn(URL_CASE_BATCH_DELETE, request); + } + + + } diff --git a/backend/services/case-management/src/test/resources/dml/init_case_trash.sql b/backend/services/case-management/src/test/resources/dml/init_case_trash.sql index de561d4e60..37b9d6241b 100644 --- a/backend/services/case-management/src/test/resources/dml/init_case_trash.sql +++ b/backend/services/case-management/src/test/resources/dml/init_case_trash.sql @@ -26,10 +26,50 @@ INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, r VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_4', 4, 'Trash_TEST_MOUDLE_ID', 'project-case-trash-test', '100001', 'copy_测试多版本', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_5', 1, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本5', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_5', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_6', 2, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本6', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_5', 'UN_EXECUTED',true, b'0', b'1', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_7', 3, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本7', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_7', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_8', 4, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本8', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_7', 'UN_EXECUTED',true, b'0', b'1', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_9', 5, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本9', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_9', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_a', 6, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本a', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_9', 'UN_EXECUTED',true, b'0', b'1', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_b', 7, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本b', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_b', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_c', 8, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-1', '100001', 'copy_测试多版本c', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_b', 'UN_EXECUTED',true, b'0', b'1', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_d', 7, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-2', '100001', 'copy_测试多版本d', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_d', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_e', 8, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-2', '100001', 'copy_测试多版本e', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_d', 'UN_EXECUTED',true, b'0', b'1', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_f', 7, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-2', '100001', 'copy_测试多版本f', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_f', 'UN_EXECUTED',true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_g', 8, 'Trash_TEST_MOUDLE_ID_1', 'project-case-trash-test-2', '100001', 'copy_测试多版本g', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'Trash_TEST_FUNCTIONAL_CASE_ID_f', 'UN_EXECUTED',true, b'0', b'1', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL); + + + INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID', 'gyq_custom_id1', '22'); INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID', 'gyq_custom_id2', '33'); - +INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_5', 'gyq_custom_id1', '22'); +INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('Trash_TEST_FUNCTIONAL_CASE_ID_5', 'gyq_custom_id2', '33'); INSERT INTO custom_field(id, name, scene, `type`, remark, internal, scope_type, create_time, update_time, create_user, scope_id) @@ -41,3 +81,4 @@ VALUES('gyq_custom_id2', 'level', 'FUNCTIONAL', 'SELECT', '', 1, 'ORGANIZATION', INSERT INTO functional_case_comment(id, case_id, create_user, status, parent_id, resource_id, notifier, content, reply_user, create_time, update_time) VALUES ('trash_comment_id', 'Trash_TEST_FUNCTIONAL_CASE_ID', 'gyq', null, null, null, 'gyq','你好', null, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000); +INSERT INTO functional_case_module(id, project_id, name, parent_id, pos, create_time, update_time, create_user, update_user) VALUES ('Trash_TEST_MOUDLE_ID', '100001100001', '测试回收站所属模块', 'NONE', 0, 1669174143999, 1669174143999, 'admin', 'admin'); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java index 1b3009a983..e1b463546c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java @@ -77,14 +77,15 @@ public class TestResourcePoolService { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } - public void checkLoadConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) { + public boolean checkLoadConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) { if (testResourcePool.getLoadTest() == null || !testResourcePool.getLoadTest()) { - return; + return true; } boolean validate = checkNodeOrK8s(testResourceDTO, type, false); if (!validate) { testResourcePool.setEnable(false); } + return validate; } private static boolean checkNodeOrK8s(TestResourceDTO testResourceDTO, String type, Boolean usedApiType) { @@ -115,14 +116,15 @@ public class TestResourcePoolService { resourcePoolService.validate(testResourceDTO); } - public void checkApiConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) { + public boolean checkApiConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) { if (testResourcePool.getApiTest() == null || !testResourcePool.getApiTest()) { - return; + return true; } boolean validate = checkNodeOrK8s(testResourceDTO, type, true); if (!validate) { testResourcePool.setEnable(false); } + return validate; } public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) {