From 890429bb6e2f43914174e9e5b1270b1e58e484c0 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 2 Apr 2024 20:46:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E7=9B=B8=E5=85=B3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scenario/ApiScenarioController.java | 2 +- .../scenario/ApiScenarioReportController.java | 5 +- .../definition/ApiDefinitionService.java | 12 ++- .../definition/ApiTestCaseService.java | 12 ++- .../scenario/ApiScenarioReportService.java | 2 - .../service/scenario/ApiScenarioService.java | 17 +++- .../api-test/report/component/reportList.vue | 2 +- .../views/api-test/scenario/locale/en-US.ts | 2 + .../views/api-test/scenario/locale/zh-CN.ts | 2 + .../scenario/recycle/recycleTable.vue | 92 +++++++++++++++++-- 10 files changed, 131 insertions(+), 17 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index ef71bb1df7..79add25f70 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -124,7 +124,7 @@ public class ApiScenarioController { @CheckOwner(resourceId = "#id", resourceType = "api_scenario") @SendNotice(taskType = NoticeConstants.TaskType.API_SCENARIO_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getScenarioDTO(#id)", targetClass = ApiScenarioNoticeService.class) public void deleteToGc(@PathVariable String id) { - apiScenarioService.deleteToGc(id); + apiScenarioService.deleteToGc(id, SessionUtils.getUserId()); } @GetMapping("/get/{scenarioId}") diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java index 85b1fec5d9..de616cd357 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java @@ -1,6 +1,5 @@ package io.metersphere.api.controller.scenario; -import com.fasterxml.jackson.databind.node.TextNode; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.definition.ApiReportBatchRequest; @@ -54,8 +53,8 @@ public class ApiScenarioReportController { @CheckOwner(resourceId = "#id", resourceType = "api_scenario_report") @RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = ApiScenarioReportLogService.class) - public void rename(@PathVariable String id, @RequestBody TextNode name) { - apiScenarioReportService.rename(id, name.asText(), SessionUtils.getUserId()); + public void rename(@PathVariable String id, @RequestBody Object name) { + apiScenarioReportService.rename(id, name.toString(), SessionUtils.getUserId()); } @GetMapping("/delete/{id}") diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index 544a037a85..0ba438f39b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -178,7 +178,7 @@ public class ApiDefinitionService extends MoveNodeService { public ApiDefinitionDTO get(String id, String userId) { // 1. 避免重复查询数据库,将查询结果传递给get方法 - ApiDefinition apiDefinition = checkApiDefinition(id); + ApiDefinition apiDefinition = checkApiDefinitionDeleted(id); return getApiDefinitionInfo(id, userId, apiDefinition); } @@ -508,6 +508,16 @@ public class ApiDefinitionService extends MoveNodeService { return apiDefinition; } + public ApiDefinition checkApiDefinitionDeleted(String apiId) { + ApiDefinitionExample example = new ApiDefinitionExample(); + example.createCriteria().andIdEqualTo(apiId).andDeletedEqualTo(false); + List apiDefinitions = apiDefinitionMapper.selectByExample(example); + if (CollectionUtils.isEmpty(apiDefinitions)) { + throw new MSException(ApiResultCode.API_DEFINITION_NOT_EXIST); + } + return apiDefinitions.getFirst(); + } + private void checkAddExist(ApiDefinition apiDefinition) { if (!StringUtils.equals(apiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) { return; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index 0a11c30eda..e9ad4764f1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -204,9 +204,19 @@ public class ApiTestCaseService extends MoveNodeService { return testCase; } + private ApiTestCase checkResourceNoDeleted(String id) { + ApiTestCaseExample example = new ApiTestCaseExample(); + example.createCriteria().andIdEqualTo(id).andDeletedEqualTo(false); + List testCase = apiTestCaseMapper.selectByExample(example); + if (CollectionUtils.isEmpty(testCase)) { + throw new MSException(Translator.get("api_test_case_not_exist")); + } + return testCase.getFirst(); + } + public ApiTestCaseDTO get(String id, String userId) { ApiTestCaseDTO apiTestCaseDTO = new ApiTestCaseDTO(); - ApiTestCase testCase = checkResourceExist(id); + ApiTestCase testCase = checkResourceNoDeleted(id); ApiTestCaseBlob testCaseBlob = apiTestCaseBlobMapper.selectByPrimaryKey(id); BeanUtils.copyBean(apiTestCaseDTO, testCase); if (CollectionUtils.isNotEmpty(testCase.getTags())) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java index 0fb8ae073e..ffc3eb0526 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java @@ -306,8 +306,6 @@ public class ApiScenarioReportService { step.setStatus(ApiReportStatus.FAKE_ERROR.name()); } else if (successStatus.size() == children.size() - noControllerIds.size()) { step.setStatus(ApiReportStatus.SUCCESS.name()); - } else { - step.setStatus(ApiReportStatus.PENDING.name()); } } else if (stepTypes.contains(step.getStepType())) { step.setStatus(ApiReportStatus.PENDING.name()); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 43b39c1ef3..3bf9859256 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -84,6 +84,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.kafka.common.errors.ResourceNotFoundException; import org.mybatis.spring.SqlSessionUtils; import org.quartz.CronExpression; import org.quartz.CronScheduleBuilder; @@ -1195,11 +1196,13 @@ public class ApiScenarioService extends MoveNodeService { apiScenarioMapper.updateByPrimaryKeySelective(apiScenario); } - public void deleteToGc(String id) { + public void deleteToGc(String id, String operator) { checkResourceExist(id); ApiScenario apiScenario = new ApiScenario(); apiScenario.setId(id); apiScenario.setDeleted(true); + apiScenario.setDeleteUser(operator); + apiScenario.setDeleteTime(System.currentTimeMillis()); apiScenarioMapper.updateByPrimaryKeySelective(apiScenario); //删除定时任务 @@ -1926,8 +1929,18 @@ public class ApiScenarioService extends MoveNodeService { return apiScenarioDetailDTO; } + private ApiScenario checkResourceIsNoDeleted(String id) { + ApiScenarioExample example = new ApiScenarioExample(); + example.createCriteria().andIdEqualTo(id).andDeletedEqualTo(false); + List apiScenarios = apiScenarioMapper.selectByExample(example); + if (CollectionUtils.isEmpty(apiScenarios)) { + throw new MSException(Translator.get("api_scenario_is_not_exist")); + } + return apiScenarios.getFirst(); + } + public ApiScenarioDetail get(String scenarioId) { - ApiScenario apiScenario = checkResourceExist(scenarioId); + ApiScenario apiScenario = checkResourceIsNoDeleted(scenarioId); ApiScenarioDetail apiScenarioDetail = BeanUtils.copyBean(new ApiScenarioDetail(), apiScenario); ApiScenarioBlob apiScenarioBlob = apiScenarioBlobMapper.selectByPrimaryKey(scenarioId); if (apiScenarioBlob != null) { diff --git a/frontend/src/views/api-test/report/component/reportList.vue b/frontend/src/views/api-test/report/component/reportList.vue index cbeb0c2a25..5be1c7b778 100644 --- a/frontend/src/views/api-test/report/component/reportList.vue +++ b/frontend/src/views/api-test/report/component/reportList.vue @@ -307,7 +307,7 @@ x: '100%', }, showSetting: true, - selectable: hasAnyPermission(['PROJECT_API_REPORT:READ+DELETE', 'PROJECT_API_REPORT:READ']), + selectable: hasAnyPermission(['PROJECT_API_REPORT:READ+DELETE']), heightUsed: 330, showSelectorAll: true, }, diff --git a/frontend/src/views/api-test/scenario/locale/en-US.ts b/frontend/src/views/api-test/scenario/locale/en-US.ts index 1ece7e6886..18aae36b7c 100644 --- a/frontend/src/views/api-test/scenario/locale/en-US.ts +++ b/frontend/src/views/api-test/scenario/locale/en-US.ts @@ -45,6 +45,8 @@ export default { 'apiScenario.table.columns.createTime': 'Create time', 'apiScenario.table.columns.updateUser': 'Update user', 'apiScenario.table.columns.updateTime': 'Update time', + 'apiScenario.table.columns.operation': 'Operation', + 'apiScenario.table.columns.deleteTime': 'Delete time', 'api_scenario.table.tableNoDataAndPlease': 'No data yet, please', 'api_scenario.table.or': 'or', 'apiScenario.execute': 'Execute', diff --git a/frontend/src/views/api-test/scenario/locale/zh-CN.ts b/frontend/src/views/api-test/scenario/locale/zh-CN.ts index 72f7e6aaaa..953e3bdfe5 100644 --- a/frontend/src/views/api-test/scenario/locale/zh-CN.ts +++ b/frontend/src/views/api-test/scenario/locale/zh-CN.ts @@ -44,6 +44,8 @@ export default { 'apiScenario.table.columns.createTime': '创建时间', 'apiScenario.table.columns.updateUser': '更新人', 'apiScenario.table.columns.updateTime': '更新时间', + 'apiScenario.table.columns.operation': '操作人', + 'apiScenario.table.columns.deleteTime': '删除时间', 'api_scenario.table.searchPlaceholder': '通过 ID/名称/标签搜索', 'api_scenario.table.batchModalSubTitle': '(已选 {count} 个场景)', 'api_scenario.table.chooseAttr': '选择属性', diff --git a/frontend/src/views/api-test/scenario/recycle/recycleTable.vue b/frontend/src/views/api-test/scenario/recycle/recycleTable.vue index 30a5ab0d87..9991df7f8a 100644 --- a/frontend/src/views/api-test/scenario/recycle/recycleTable.vue +++ b/frontend/src/views/api-test/scenario/recycle/recycleTable.vue @@ -1,7 +1,8 @@ + + +