From b96a33622b236f605eb76f8d8d2fe36b61e3d1aa Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 29 Oct 2024 10:55:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E7=94=A8=E4=BE=8B=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=93=8D=E4=BD=9C=E6=B2=A1=E6=9C=89=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048219 --user=陈建星 【测试计划】测试计划-功能用例详情页批量修改执行人,没有日志记录 https://www.tapd.cn/55049933/s/1599739 --- .../src/main/resources/i18n/plan.properties | 4 +- .../main/resources/i18n/plan_en_US.properties | 4 +- .../main/resources/i18n/plan_zh_CN.properties | 4 +- .../main/resources/i18n/plan_zh_TW.properties | 4 +- .../controller/TestPlanApiCaseController.java | 6 +- .../TestPlanApiScenarioController.java | 6 +- .../TestPlanFunctionalCaseController.java | 7 +- .../service/TestPlanApiCaseLogService.java | 142 ++++++++++------- .../TestPlanApiScenarioLogService.java | 143 ++++++++++-------- .../plan/service/TestPlanCaseLogService.java | 142 ++++++++++------- 10 files changed, 276 insertions(+), 186 deletions(-) diff --git a/backend/framework/sdk/src/main/resources/i18n/plan.properties b/backend/framework/sdk/src/main/resources/i18n/plan.properties index 7d89aef490..e247b1f64c 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan.properties @@ -136,4 +136,6 @@ test_plan.status.completed=已完成 test_plan.status.success=成功 test_plan.status.error=失败 test_plan.status.prepared=未开始 -test_plan.status.underway=进行中 \ No newline at end of file +test_plan.status.underway=进行中 + +test_plan.update.executor=修改执行人 diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties index 937f72049b..37f110e561 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties @@ -140,4 +140,6 @@ test_plan.status.completed=Completed test_plan.status.success=Success test_plan.status.error=Error test_plan.status.prepared=Prepared -test_plan.status.underway=Underway \ No newline at end of file +test_plan.status.underway=Underway + +test_plan.update.executor=Modify the executor diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties index 36f53131ab..78c51ea1ad 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties @@ -140,4 +140,6 @@ test_plan.status.completed=已完成 test_plan.status.success=成功 test_plan.status.error=失败 test_plan.status.prepared=未开始 -test_plan.status.underway=进行中 \ No newline at end of file +test_plan.status.underway=进行中 + +test_plan.update.executor=修改执行人 diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties index 063ba6ae3c..76f319a5e7 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties @@ -139,4 +139,6 @@ test_plan.status.completed=已完成 test_plan.status.success=成功 test_plan.status.error=失敗 test_plan.status.prepared=未開始 -test_plan.status.underway=進行中 \ No newline at end of file +test_plan.status.underway=進行中 + +test_plan.update.executor=修改執行人 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java index ae8072234a..2c00f0acd1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java @@ -63,6 +63,8 @@ public class TestPlanApiCaseController { private BugService bugService; @Resource private BugLogService bugLogService; + @Resource + private TestPlanApiCaseLogService testPlanApiCaseLogService; @PostMapping(value = "/sort") @Operation(summary = "测试计划功能用例-功能用例拖拽排序") @@ -129,9 +131,9 @@ public class TestPlanApiCaseController { @Operation(summary = "测试计划-计划详情-接口用例列表-批量更新执行人") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiCaseLogService.class) public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiCaseUpdateRequest request) { testPlanApiCaseService.batchUpdateExecutor(request); + testPlanApiCaseLogService.batchUpdateExecutor(request); } @GetMapping("/run/{id}") @@ -179,9 +181,9 @@ public class TestPlanApiCaseController { @Operation(summary = "测试计划-计划详情-接口用例-批量移动") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchMove(#request)", msClass = TestPlanApiCaseLogService.class) public void batchMove(@Validated @RequestBody TestPlanApiCaseBatchMoveRequest request) { testPlanApiCaseService.batchMove(request); + testPlanApiCaseLogService.batchMove(request, SessionUtils.getUserId()); } @PostMapping("/associate/bug/page") diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java index 613b6c998b..43c99bf587 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java @@ -60,6 +60,8 @@ public class TestPlanApiScenarioController { private BugService bugService; @Resource private BugLogService bugLogService; + @Resource + private TestPlanApiScenarioLogService testPlanApiScenarioLogService; @PostMapping("/page") @Operation(summary = "测试计划-已关联场景用例列表分页查询") @@ -129,9 +131,9 @@ public class TestPlanApiScenarioController { @Operation(summary = "测试计划-计划详情-场景用例列表-批量更新执行人") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiScenarioLogService.class) public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiScenarioUpdateRequest request) { testPlanApiScenarioService.batchUpdateExecutor(request); + testPlanApiScenarioLogService.batchUpdateExecutor(request); } @GetMapping("/report/get/{id}") @@ -164,9 +166,9 @@ public class TestPlanApiScenarioController { @Operation(summary = "测试计划-计划详情-场景用例-批量移动") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchMove(#request)", msClass = TestPlanApiScenarioLogService.class) public void batchMove(@Validated @RequestBody BaseBatchMoveRequest request) { testPlanApiScenarioService.batchMove(request); + testPlanApiScenarioLogService.batchMove(request, SessionUtils.getUserId()); } @PostMapping("/associate/bug/page") diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java index 62866feee5..a69bd35f1b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java @@ -55,6 +55,8 @@ public class TestPlanFunctionalCaseController { @Resource private TestPlanFunctionalCaseService testPlanFunctionalCaseService; @Resource + private TestPlanCaseLogService testPlanCaseLogService; + @Resource private BugService bugService; @Resource private BugLogService bugLogService; @@ -74,7 +76,6 @@ public class TestPlanFunctionalCaseController { public Pager> page(@Validated @RequestBody TestPlanCaseRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString("id", "functional_case")) ? request.getSortString("id", "functional_case") : "test_plan_functional_case.pos desc"); - return PageUtils.setPageInfo(page, testPlanFunctionalCaseService.getFunctionalCasePage(request, false, SessionUtils.getCurrentProjectId())); } @@ -173,9 +174,9 @@ public class TestPlanFunctionalCaseController { @Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanCaseLogService.class) public void batchUpdateExecutor(@Validated @RequestBody TestPlanCaseUpdateRequest request) { testPlanFunctionalCaseService.batchUpdateExecutor(request); + testPlanCaseLogService.batchUpdateExecutor(request); } @GetMapping("/detail/{id}") @@ -207,9 +208,9 @@ public class TestPlanFunctionalCaseController { @Operation(summary = "测试计划-计划详情-功能用例-批量移动") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchMove(#request)", msClass = TestPlanCaseLogService.class) public void batchMove(@Validated @RequestBody BaseBatchMoveRequest request) { testPlanFunctionalCaseService.batchMove(request); + testPlanCaseLogService.batchMove(request, SessionUtils.getUserId()); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java index 4c4823365f..6442a2b94e 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java @@ -3,17 +3,23 @@ package io.metersphere.plan.service; import io.metersphere.api.domain.ApiTestCase; import io.metersphere.api.domain.ApiTestCaseExample; import io.metersphere.api.mapper.ApiTestCaseMapper; +import io.metersphere.plan.domain.TestPlan; import io.metersphere.plan.domain.TestPlanApiCase; import io.metersphere.plan.domain.TestPlanApiCaseExample; import io.metersphere.plan.dto.request.TestPlanApiCaseBatchMoveRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest; import io.metersphere.plan.mapper.TestPlanApiCaseMapper; +import io.metersphere.plan.mapper.TestPlanMapper; +import io.metersphere.project.domain.Project; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; 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 jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -34,69 +40,89 @@ public class TestPlanApiCaseLogService { private TestPlanApiCaseMapper testPlanApiCaseMapper; @Resource private ApiTestCaseMapper apiTestCaseMapper; + @Resource + private TestPlanMapper testPlanMapper; + @Resource + private ProjectMapper projectMapper; + @Resource + private OperationLogService operationLogService; public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) { - List ids = testPlanApiCaseService.doSelectIds(request); - if (CollectionUtils.isNotEmpty(ids)) { - TestPlanApiCaseExample example = new TestPlanApiCaseExample(); - example.createCriteria().andIdIn(ids); - List planCaseList = testPlanApiCaseMapper.selectByExample(example); - Map userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getExecuteUser)); - Map idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getApiCaseId)); - List caseIds = planCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); - ApiTestCaseExample caseExample = new ApiTestCaseExample(); - caseExample.createCriteria().andIdIn(caseIds); - List functionalCases = apiTestCaseMapper.selectByExample(caseExample); - Map caseMap = functionalCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName)); - List dtoList = new ArrayList<>(); - idsMap.forEach((k, v) -> { - LogDTO dto = new LogDTO( - null, - null, - k, - null, - OperationLogType.UPDATE.name(), - OperationLogModule.TEST_PLAN, - caseMap.get(v)); - dto.setPath("/test-plan/api/case/batch/update/executor"); - dto.setMethod(HttpMethodConstants.POST.name()); - dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); - dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); - dtoList.add(dto); - }); + try { + List ids = testPlanApiCaseService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); + Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId()); + TestPlanApiCaseExample example = new TestPlanApiCaseExample(); + example.createCriteria().andIdIn(ids); + List planCaseList = testPlanApiCaseMapper.selectByExample(example); + Map userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getExecuteUser)); + Map idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getApiCaseId)); + List caseIds = planCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); + ApiTestCaseExample caseExample = new ApiTestCaseExample(); + caseExample.createCriteria().andIdIn(caseIds); + List functionalCases = apiTestCaseMapper.selectByExample(caseExample); + Map caseMap = functionalCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName)); + List dtoList = new ArrayList<>(); + idsMap.forEach((k, v) -> { + LogDTO dto = new LogDTO( + project.getId(), + project.getOrganizationId(), + k, + request.getUserId(), + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + Translator.get("test_plan.update.executor") + ":" + caseMap.get(v)); + dto.setPath("/test-plan/api/case/batch/update/executor"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); + dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } + } catch (Exception e) { + LogUtils.error(e); } } - public void batchMove(TestPlanApiCaseBatchMoveRequest request) { - List ids = testPlanApiCaseService.doSelectIds(request); - if (CollectionUtils.isNotEmpty(ids)) { - TestPlanApiCaseExample example = new TestPlanApiCaseExample(); - example.createCriteria().andIdIn(ids); - List caseList = testPlanApiCaseMapper.selectByExample(example); - List apiCaseIds = caseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); - ApiTestCaseExample caseExample = new ApiTestCaseExample(); - caseExample.createCriteria().andIdIn(apiCaseIds); - List apiTestCases = apiTestCaseMapper.selectByExample(caseExample); - Map caseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName)); - List dtoList = new ArrayList<>(); - caseList.forEach(item -> { - LogDTO dto = new LogDTO( - null, - null, - item.getApiCaseId(), - null, - OperationLogType.UPDATE.name(), - OperationLogModule.TEST_PLAN, - Translator.get("move") + ":" + caseMap.get(item.getApiCaseId())); - dto.setPath("/test-plan/api/case/batch/move"); - dto.setMethod(HttpMethodConstants.POST.name()); - dto.setOriginalValue(JSON.toJSONBytes(item)); - TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); - testPlanApiCase.setId(item.getId()); - testPlanApiCase.setTestPlanCollectionId(request.getTargetCollectionId()); - dto.setModifiedValue(JSON.toJSONBytes(testPlanApiCase)); - dtoList.add(dto); - }); + public void batchMove(TestPlanApiCaseBatchMoveRequest request, String userId) { + try { + List ids = testPlanApiCaseService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); + Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId()); + TestPlanApiCaseExample example = new TestPlanApiCaseExample(); + example.createCriteria().andIdIn(ids); + List caseList = testPlanApiCaseMapper.selectByExample(example); + List apiCaseIds = caseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); + ApiTestCaseExample caseExample = new ApiTestCaseExample(); + caseExample.createCriteria().andIdIn(apiCaseIds); + List apiTestCases = apiTestCaseMapper.selectByExample(caseExample); + Map caseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName)); + List dtoList = new ArrayList<>(); + caseList.forEach(item -> { + LogDTO dto = new LogDTO( + project.getId(), + project.getOrganizationId(), + item.getApiCaseId(), + userId, + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + Translator.get("move") + ":" + caseMap.get(item.getApiCaseId())); + dto.setPath("/test-plan/api/case/batch/move"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(item)); + TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); + testPlanApiCase.setId(item.getId()); + testPlanApiCase.setTestPlanCollectionId(request.getTargetCollectionId()); + dto.setModifiedValue(JSON.toJSONBytes(testPlanApiCase)); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } + } catch (Exception e) { + LogUtils.error(e); } } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioLogService.java index 59bce6bc46..d5e6f1042c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioLogService.java @@ -3,17 +3,23 @@ package io.metersphere.plan.service; import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenarioExample; import io.metersphere.api.mapper.ApiScenarioMapper; +import io.metersphere.plan.domain.TestPlan; import io.metersphere.plan.domain.TestPlanApiScenario; import io.metersphere.plan.domain.TestPlanApiScenarioExample; import io.metersphere.plan.dto.request.BaseBatchMoveRequest; import io.metersphere.plan.dto.request.TestPlanApiScenarioUpdateRequest; import io.metersphere.plan.mapper.TestPlanApiScenarioMapper; +import io.metersphere.plan.mapper.TestPlanMapper; +import io.metersphere.project.domain.Project; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; 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 jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -34,70 +40,89 @@ public class TestPlanApiScenarioLogService { private TestPlanApiScenarioMapper testPlanApiScenarioMapper; @Resource private ApiScenarioMapper apiScenarioMapper; + @Resource + private TestPlanMapper testPlanMapper; + @Resource + private ProjectMapper projectMapper; + @Resource + private OperationLogService operationLogService; + public void batchUpdateExecutor(TestPlanApiScenarioUpdateRequest request) { - List ids = testPlanApiScenarioService.doSelectIds(request); - if (CollectionUtils.isNotEmpty(ids)) { - TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); - example.createCriteria().andIdIn(ids); - List planApiScenarioList = testPlanApiScenarioMapper.selectByExample(example); - Map userMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getExecuteUser)); - Map idsMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getApiScenarioId)); - List scenarioIds = planApiScenarioList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); - ApiScenarioExample scenarioExample = new ApiScenarioExample(); - scenarioExample.createCriteria().andIdIn(scenarioIds); - List apiScenarios = apiScenarioMapper.selectByExample(scenarioExample); - Map caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName)); - List dtoList = new ArrayList<>(); - idsMap.forEach((k, v) -> { - LogDTO dto = new LogDTO( - null, - null, - k, - null, - OperationLogType.UPDATE.name(), - OperationLogModule.TEST_PLAN, - caseMap.get(v)); - dto.setPath("/test-plan/api/scenario/batch/update/executor"); - dto.setMethod(HttpMethodConstants.POST.name()); - dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); - dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); - dtoList.add(dto); - }); + try { + List ids = testPlanApiScenarioService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); + Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId()); + TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); + example.createCriteria().andIdIn(ids); + List planApiScenarioList = testPlanApiScenarioMapper.selectByExample(example); + Map userMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getExecuteUser)); + Map idsMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getApiScenarioId)); + List scenarioIds = planApiScenarioList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); + ApiScenarioExample scenarioExample = new ApiScenarioExample(); + scenarioExample.createCriteria().andIdIn(scenarioIds); + List apiScenarios = apiScenarioMapper.selectByExample(scenarioExample); + Map caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName)); + List dtoList = new ArrayList<>(); + idsMap.forEach((k, v) -> { + LogDTO dto = new LogDTO( + project.getId(), + project.getOrganizationId(), + k, + request.getUserId(), + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + Translator.get("test_plan.update.executor") + ":" + caseMap.get(v)); + dto.setPath("/test-plan/api/scenario/batch/update/executor"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); + dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); + dtoList.add(dto); + }); + } + } catch (Exception e) { + LogUtils.error(e); } } - public void batchMove(BaseBatchMoveRequest request) { - List ids = testPlanApiScenarioService.doSelectIds(request); - if (CollectionUtils.isNotEmpty(ids)) { - TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); - example.createCriteria().andIdIn(ids); - List caseList = testPlanApiScenarioMapper.selectByExample(example); - List apiScenarioIds = caseList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); - ApiScenarioExample scenarioExample = new ApiScenarioExample(); - scenarioExample.createCriteria().andIdIn(apiScenarioIds); - List apiScenarios = apiScenarioMapper.selectByExample(scenarioExample); - Map caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName)); - List dtoList = new ArrayList<>(); - caseList.forEach(item -> { - LogDTO dto = new LogDTO( - null, - null, - item.getApiScenarioId(), - null, - OperationLogType.UPDATE.name(), - OperationLogModule.TEST_PLAN, - Translator.get("move") + ":" + caseMap.get(item.getApiScenarioId())); - dto.setPath("/test-plan/api/scenario/batch/move"); - dto.setMethod(HttpMethodConstants.POST.name()); - dto.setOriginalValue(JSON.toJSONBytes(item)); - TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); - testPlanApiScenario.setId(item.getId()); - testPlanApiScenario.setTestPlanCollectionId(request.getTargetCollectionId()); - dto.setModifiedValue(JSON.toJSONBytes(testPlanApiScenario)); - dtoList.add(dto); - }); - + public void batchMove(BaseBatchMoveRequest request, String userId) { + try { + List ids = testPlanApiScenarioService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); + Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId()); + TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); + example.createCriteria().andIdIn(ids); + List caseList = testPlanApiScenarioMapper.selectByExample(example); + List apiScenarioIds = caseList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); + ApiScenarioExample scenarioExample = new ApiScenarioExample(); + scenarioExample.createCriteria().andIdIn(apiScenarioIds); + List apiScenarios = apiScenarioMapper.selectByExample(scenarioExample); + Map caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName)); + List dtoList = new ArrayList<>(); + caseList.forEach(item -> { + LogDTO dto = new LogDTO( + project.getId(), + project.getOrganizationId(), + item.getApiScenarioId(), + userId, + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + Translator.get("move") + ":" + caseMap.get(item.getApiScenarioId())); + dto.setPath("/test-plan/api/scenario/batch/move"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(item)); + TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); + testPlanApiScenario.setId(item.getId()); + testPlanApiScenario.setTestPlanCollectionId(request.getTargetCollectionId()); + dto.setModifiedValue(JSON.toJSONBytes(testPlanApiScenario)); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } + } catch (Exception e) { + LogUtils.error(e); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java index 5209f84d22..38a4eb781c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java @@ -3,17 +3,23 @@ package io.metersphere.plan.service; import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCaseExample; import io.metersphere.functional.mapper.FunctionalCaseMapper; +import io.metersphere.plan.domain.TestPlan; import io.metersphere.plan.domain.TestPlanFunctionalCase; import io.metersphere.plan.domain.TestPlanFunctionalCaseExample; import io.metersphere.plan.dto.request.BaseBatchMoveRequest; import io.metersphere.plan.dto.request.TestPlanCaseUpdateRequest; import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper; +import io.metersphere.plan.mapper.TestPlanMapper; +import io.metersphere.project.domain.Project; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; 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 jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -34,70 +40,90 @@ public class TestPlanCaseLogService { private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper; @Resource private FunctionalCaseMapper functionalCaseMapper; + @Resource + private OperationLogService operationLogService; + @Resource + private ProjectMapper projectMapper; + @Resource + private TestPlanMapper testPlanMapper; public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) { - List ids = testPlanFunctionalCaseService.doSelectIds(request); - if (CollectionUtils.isNotEmpty(ids)) { - TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); - example.createCriteria().andIdIn(ids); - List planCaseList = testPlanFunctionalCaseMapper.selectByExample(example); - Map userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getExecuteUser)); - Map idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getFunctionalCaseId)); - List caseIds = planCaseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); - FunctionalCaseExample caseExample = new FunctionalCaseExample(); - caseExample.createCriteria().andIdIn(caseIds); - List functionalCases = functionalCaseMapper.selectByExample(caseExample); - Map caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); - List dtoList = new ArrayList<>(); - idsMap.forEach((k, v) -> { - LogDTO dto = new LogDTO( - null, - null, - k, - null, - OperationLogType.UPDATE.name(), - OperationLogModule.TEST_PLAN, - caseMap.get(v)); - dto.setPath("/test-plan/functional/case/batch/update/executor"); - dto.setMethod(HttpMethodConstants.POST.name()); - dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); - dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); - dtoList.add(dto); - }); + try { + List ids = testPlanFunctionalCaseService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); + Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId()); + TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); + example.createCriteria().andIdIn(ids); + List planCaseList = testPlanFunctionalCaseMapper.selectByExample(example); + Map userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getExecuteUser)); + Map idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getFunctionalCaseId)); + List caseIds = planCaseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); + FunctionalCaseExample caseExample = new FunctionalCaseExample(); + caseExample.createCriteria().andIdIn(caseIds); + List functionalCases = functionalCaseMapper.selectByExample(caseExample); + Map caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); + List dtoList = new ArrayList<>(); + idsMap.forEach((k, v) -> { + LogDTO dto = new LogDTO( + project.getId(), + project.getOrganizationId(), + k, + request.getUserId(), + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + Translator.get("test_plan.update.executor") + ":" + caseMap.get(v)); + dto.setPath("/test-plan/functional/case/batch/update/executor"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); + dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } + } catch (Exception e) { + LogUtils.error(e); } } - public void batchMove(BaseBatchMoveRequest request) { - List ids = testPlanFunctionalCaseService.doSelectIds(request); - if (CollectionUtils.isNotEmpty(ids)) { - TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); - example.createCriteria().andIdIn(ids); - List caseList = testPlanFunctionalCaseMapper.selectByExample(example); - List functionalCaseIds = caseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); - FunctionalCaseExample caseExample = new FunctionalCaseExample(); - caseExample.createCriteria().andIdIn(functionalCaseIds); - List functionalCases = functionalCaseMapper.selectByExample(caseExample); - Map caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); - List dtoList = new ArrayList<>(); - caseList.forEach(item -> { - LogDTO dto = new LogDTO( - null, - null, - item.getFunctionalCaseId(), - null, - OperationLogType.UPDATE.name(), - OperationLogModule.TEST_PLAN, - Translator.get("move") + ":" + caseMap.get(item.getFunctionalCaseId())); - dto.setPath("/test-plan/functional/case/batch/move"); - dto.setMethod(HttpMethodConstants.POST.name()); - dto.setOriginalValue(JSON.toJSONBytes(item)); - TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase(); - testPlanFunctionalCase.setId(item.getId()); - testPlanFunctionalCase.setTestPlanCollectionId(request.getTargetCollectionId()); - dto.setModifiedValue(JSON.toJSONBytes(testPlanFunctionalCase)); - dtoList.add(dto); - }); + public void batchMove(BaseBatchMoveRequest request, String userId) { + try { + List ids = testPlanFunctionalCaseService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); + Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId()); + TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); + example.createCriteria().andIdIn(ids); + List caseList = testPlanFunctionalCaseMapper.selectByExample(example); + List functionalCaseIds = caseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); + FunctionalCaseExample caseExample = new FunctionalCaseExample(); + caseExample.createCriteria().andIdIn(functionalCaseIds); + List functionalCases = functionalCaseMapper.selectByExample(caseExample); + Map caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); + List dtoList = new ArrayList<>(); + caseList.forEach(item -> { + LogDTO dto = new LogDTO( + project.getId(), + project.getOrganizationId(), + item.getFunctionalCaseId(), + userId, + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + Translator.get("move") + ":" + caseMap.get(item.getFunctionalCaseId())); + dto.setPath("/test-plan/functional/case/batch/move"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(item)); + TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase(); + testPlanFunctionalCase.setId(item.getId()); + testPlanFunctionalCase.setTestPlanCollectionId(request.getTargetCollectionId()); + dto.setModifiedValue(JSON.toJSONBytes(testPlanFunctionalCase)); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } + } catch (Exception e) { + LogUtils.error(e); } }