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());