From e913074e2beb85a7f7fd6b593c7b4d27760c2536 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 22 Oct 2024 18:01:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C=E4=BB=BB=E5=8A=A1=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=9B=BD=E9=99=85=E5=8C=96=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047824 --user=陈建星 【项目任务中心】用例执行任务/用例执行任务详情列表-任务名称国际化错误 https://www.tapd.cn/55049933/s/1595865 --- .../definition/ApiTestCaseController.java | 3 +++ .../ApiScenarioBatchOperationController.java | 3 +++ .../api/service/ApiBatchRunBaseService.java | 17 +++++++++-------- .../definition/ApiTestCaseBatchRunService.java | 2 +- .../scenario/ApiScenarioBatchRunService.java | 2 +- .../controller/TestPlanApiCaseController.java | 3 +++ .../TestPlanApiScenarioController.java | 3 +++ .../service/TestPlanApiCaseBatchRunService.java | 2 +- .../TestPlanApiScenarioBatchRunService.java | 2 +- 9 files changed, 25 insertions(+), 12 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java index 8794ac558d..e6827f9977 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java @@ -9,6 +9,7 @@ import io.metersphere.api.dto.ReferenceDTO; import io.metersphere.api.dto.ReferenceRequest; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.request.ApiTransferRequest; +import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.ApiFileResourceService; import io.metersphere.api.service.definition.*; import io.metersphere.plugin.api.spi.AbstractMsTestElement; @@ -36,6 +37,7 @@ import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -300,6 +302,7 @@ public class ApiTestCaseController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE) @CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case") public void batchRun(@Validated @RequestBody ApiTestCaseBatchRunRequest request) { + ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale()); apiTestCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioBatchOperationController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioBatchOperationController.java index 0ba1034e31..a5242b5a95 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioBatchOperationController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioBatchOperationController.java @@ -6,6 +6,7 @@ import io.metersphere.api.dto.scenario.ApiScenarioBatchCopyMoveRequest; import io.metersphere.api.dto.scenario.ApiScenarioBatchEditRequest; import io.metersphere.api.dto.scenario.ApiScenarioBatchRequest; import io.metersphere.api.dto.scenario.ApiScenarioBatchRunRequest; +import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.ApiValidateService; import io.metersphere.api.service.scenario.ApiScenarioBatchRunService; import io.metersphere.api.service.scenario.ApiScenarioNoticeService; @@ -21,6 +22,7 @@ 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.context.i18n.LocaleContextHolder; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -99,6 +101,7 @@ public class ApiScenarioBatchOperationController { @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE) public void batchRun(@Validated @RequestBody ApiScenarioBatchRunRequest request) { apiValidateService.validateApiMenuInProject(request.getProjectId(), ApiResource.PROJECT.name()); + ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale()); apiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java index a6e0af72bd..f1aa3fed1a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java @@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; @@ -38,14 +39,14 @@ public class ApiBatchRunBaseService { @Resource private ExecTaskMapper execTaskMapper; - /** - * 初始化执行队列 - * - * @param resourceIds - * @return - */ - public ExecutionQueue initExecutionqueue(List resourceIds, String resourceType, String userId) { - return initExecutionqueue(resourceIds, null, resourceType, null, userId); + private final static ThreadLocal localeThreadLocal = new ThreadLocal<>(); + + public static void setLocale(Locale locale) { + localeThreadLocal.set(locale); + } + + public static Locale getLocale() { + return localeThreadLocal.get(); } /** diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java index 0f176b0ace..55a73edde1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java @@ -159,7 +159,7 @@ public class ApiTestCaseBatchRunService { if (runModeConfig.isIntegratedReport()) { execTask.setTaskName(runModeConfig.getCollectionReport().getReportName()); } else { - execTask.setTaskName(Translator.get("api_batch_task_name")); + execTask.setTaskName(Translator.get("api_batch_task_name", ApiBatchRunBaseService.getLocale())); } execTask.setOrganizationId(project.getOrganizationId()); execTask.setTriggerMode(TaskTriggerMode.BATCH.name()); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java index 0fcfbdfcb6..1fa746d04c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java @@ -243,7 +243,7 @@ public class ApiScenarioBatchRunService { if (runModeConfig.isIntegratedReport()) { execTask.setTaskName(runModeConfig.getCollectionReport().getReportName()); } else { - execTask.setTaskName(Translator.get("api_scenario_batch_task_name")); + execTask.setTaskName(Translator.get("api_scenario_batch_task_name", ApiBatchRunBaseService.getLocale())); } execTask.setOrganizationId(project.getOrganizationId()); execTask.setTriggerMode(TaskTriggerMode.BATCH.name()); 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 4e05cbdb07..63a09ca501 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 @@ -4,6 +4,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.definition.ApiReportDTO; import io.metersphere.api.dto.definition.ApiReportDetailDTO; +import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.definition.ApiReportService; import io.metersphere.bug.domain.Bug; import io.metersphere.bug.dto.request.BugEditRequest; @@ -39,6 +40,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -148,6 +150,7 @@ public class TestPlanApiCaseController { @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE) @CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "test_plan", relationType = "test_plan_api_case") public void batchRun(@Validated @RequestBody TestPlanApiCaseBatchRunRequest request) { + ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale()); testPlanApiCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); } 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 6f0708a6be..cad7a943d2 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 @@ -4,6 +4,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.scenario.ApiScenarioReportDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO; +import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.scenario.ApiScenarioReportService; import io.metersphere.bug.domain.Bug; import io.metersphere.bug.dto.request.BugEditRequest; @@ -36,6 +37,7 @@ import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -98,6 +100,7 @@ public class TestPlanApiScenarioController { @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE) @CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "test_plan", relationType = "test_plan_api_scenario") public void batchRun(@Validated @RequestBody TestPlanApiScenarioBatchRunRequest request) { + ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale()); testPlanApiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java index e7decc416d..77a90a7d3d 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java @@ -308,7 +308,7 @@ public class TestPlanApiCaseBatchRunService { private ExecTask initExecTask(int caseSize, Project project, String userId) { ExecTask execTask = apiCommonService.newExecTask(project.getId(), userId); execTask.setCaseCount(Long.valueOf(caseSize)); - execTask.setTaskName(Translator.get("api_batch_task_name")); + execTask.setTaskName(Translator.get("api_batch_task_name", ApiBatchRunBaseService.getLocale())); execTask.setOrganizationId(project.getOrganizationId()); execTask.setTriggerMode(TaskTriggerMode.BATCH.name()); execTask.setTaskType(ExecTaskType.TEST_PLAN_API_CASE_BATCH.name()); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java index 4301b40407..4398debf15 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java @@ -308,7 +308,7 @@ public class TestPlanApiScenarioBatchRunService { private ExecTask initExecTask(int caseSize, Project project, String userId) { ExecTask execTask = apiCommonService.newExecTask(project.getId(), userId); execTask.setCaseCount(Long.valueOf(caseSize)); - execTask.setTaskName(Translator.get("api_scenario_batch_task_name")); + execTask.setTaskName(Translator.get("api_scenario_batch_task_name", ApiBatchRunBaseService.getLocale())); execTask.setOrganizationId(project.getOrganizationId()); execTask.setTriggerMode(TaskTriggerMode.BATCH.name()); execTask.setTaskType(ExecTaskType.TEST_PLAN_API_SCENARIO_BATCH.name());