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 e6827f9977..db5e045746 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 @@ -302,7 +302,6 @@ 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 a5242b5a95..eaca18a643 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 @@ -101,7 +101,6 @@ 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/definition/ApiTestCaseBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java index 55a73edde1..f059ae7bbd 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 @@ -21,10 +21,14 @@ import io.metersphere.system.service.BaseTaskHubService; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.stream.Collectors; @@ -70,7 +74,11 @@ public class ApiTestCaseBatchRunService { * @param userId */ public void asyncBatchRun(ApiTestCaseBatchRunRequest request, String userId) { - Thread.startVirtualThread(() -> batchRun(request, userId)); + Locale locale = LocaleContextHolder.getLocale(); + Thread.startVirtualThread(() -> { + ApiBatchRunBaseService.setLocale(locale); + batchRun(request, userId); + }); } /** @@ -226,6 +234,7 @@ public class ApiTestCaseBatchRunService { /** * 获取有序的用例 + * * @param ids * @return */ 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 1fa746d04c..87f0c517ce 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 @@ -26,11 +26,13 @@ import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; @@ -75,7 +77,11 @@ public class ApiScenarioBatchRunService { * @param userId */ public void asyncBatchRun(ApiScenarioBatchRunRequest request, String userId) { - Thread.startVirtualThread(() -> batchRun(request, userId)); + Locale locale = LocaleContextHolder.getLocale(); + Thread.startVirtualThread(() -> { + ApiBatchRunBaseService.setLocale(locale); + batchRun(request, userId); + }); } /** @@ -208,6 +214,7 @@ public class ApiScenarioBatchRunService { /** * 获取有序的用例 + * * @param ids * @return */ 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 63a09ca501..ae8072234a 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 @@ -150,7 +150,6 @@ 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 cad7a943d2..613b6c998b 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 @@ -100,7 +100,6 @@ 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 1082519195..fd4a28d0aa 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 @@ -11,12 +11,18 @@ import io.metersphere.api.service.definition.ApiTestCaseBatchRunService; import io.metersphere.api.service.definition.ApiTestCaseService; import io.metersphere.api.service.queue.ApiExecutionQueueService; import io.metersphere.api.service.queue.ApiExecutionSetService; -import io.metersphere.plan.domain.*; +import io.metersphere.plan.domain.TestPlan; +import io.metersphere.plan.domain.TestPlanApiCase; +import io.metersphere.plan.domain.TestPlanCollection; +import io.metersphere.plan.domain.TestPlanCollectionExample; import io.metersphere.plan.dto.TestPlanApiCaseBatchRunDTO; import io.metersphere.plan.dto.request.ApiExecutionMapService; import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRunRequest; -import io.metersphere.plan.mapper.*; +import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper; +import io.metersphere.plan.mapper.TestPlanApiCaseMapper; +import io.metersphere.plan.mapper.TestPlanCollectionMapper; +import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.*; @@ -32,6 +38,7 @@ import jakarta.annotation.Resource; import jodd.util.StringUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -90,7 +97,11 @@ public class TestPlanApiCaseBatchRunService { public void asyncBatchRun(TestPlanApiCaseBatchRunRequest request, String userId) { TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); testPlanService.setActualStartTime(request.getTestPlanId()); - Thread.startVirtualThread(() -> batchRun(request, userId)); + Locale locale = LocaleContextHolder.getLocale(); + Thread.startVirtualThread(() -> { + ApiBatchRunBaseService.setLocale(locale); + batchRun(request, userId); + }); } /** @@ -148,7 +159,7 @@ public class TestPlanApiCaseBatchRunService { parallelExecute(execTask.getId(), collectionCases, runModeConfig, null, execTask.getId(), project, userId); } else { // 串行执行测试集中的用例 - serialExecute(execTask.getId(),collectionCases, runModeConfig, null, execTask.getId(), userId); + serialExecute(execTask.getId(), collectionCases, runModeConfig, null, execTask.getId(), userId); } } } else { @@ -215,7 +226,6 @@ public class TestPlanApiCaseBatchRunService { /** * 串行批量执行 - * */ public void serialExecute(String taskId, List testPlanApiCases, @@ -229,7 +239,7 @@ public class TestPlanApiCaseBatchRunService { List execTaskItems = new ArrayList<>(); SubListUtils.dealForSubList(testPlanApiCases, 100, - subTestPlanReportApiCases-> { + subTestPlanReportApiCases -> { List subIds = subTestPlanReportApiCases.stream().map(TestPlanApiCaseBatchRunDTO::getId).toList(); execTaskItems.addAll(extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds)); }); @@ -245,7 +255,6 @@ public class TestPlanApiCaseBatchRunService { /** * 并行批量执行 - * */ public void parallelExecute(String taskId, List testPlanApiCases, @@ -296,7 +305,7 @@ public class TestPlanApiCaseBatchRunService { private Map getResourceTaskItemMap(String taskId, List testPlanApiCases) { Map resourceTaskItemMap = new HashMap<>(); SubListUtils.dealForSubList(testPlanApiCases, 100, - subTestPlanReportApiCases-> { + subTestPlanReportApiCases -> { List subIds = subTestPlanReportApiCases.stream().map(TestPlanApiCaseBatchRunDTO::getId).toList(); extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds) .forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId())); @@ -443,7 +452,7 @@ public class TestPlanApiCaseBatchRunService { * @return */ public Map initApiReport(Map resourceExecTaskItemMap, ApiRunModeConfigDTO runModeConfig, List testPlanApiCases, - String projectId, String userId) { + String projectId, String userId) { List apiReports = new ArrayList<>(); List apiTestCaseRecords = new ArrayList<>(); List apiReportRelateTasks = new ArrayList<>(); 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 b2adc89321..f35b660121 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 @@ -21,7 +21,10 @@ import io.metersphere.plan.domain.TestPlanCollectionExample; import io.metersphere.plan.dto.TestPlanApiScenarioBatchRunDTO; import io.metersphere.plan.dto.request.ApiExecutionMapService; import io.metersphere.plan.dto.request.TestPlanApiScenarioBatchRunRequest; -import io.metersphere.plan.mapper.*; +import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper; +import io.metersphere.plan.mapper.TestPlanApiScenarioMapper; +import io.metersphere.plan.mapper.TestPlanCollectionMapper; +import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.*; @@ -37,6 +40,7 @@ import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -96,7 +100,11 @@ public class TestPlanApiScenarioBatchRunService { public void asyncBatchRun(TestPlanApiScenarioBatchRunRequest request, String userId) { TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); testPlanService.setActualStartTime(request.getTestPlanId()); - Thread.startVirtualThread(() -> batchRun(request, userId)); + Locale locale = LocaleContextHolder.getLocale(); + Thread.startVirtualThread(() -> { + ApiBatchRunBaseService.setLocale(locale); + batchRun(request, userId); + }); } /** @@ -227,7 +235,6 @@ public class TestPlanApiScenarioBatchRunService { /** * 串行批量执行 - * */ public void serialExecute(String taskId, List testPlanApiScenarios, @@ -241,7 +248,7 @@ public class TestPlanApiScenarioBatchRunService { List execTaskItems = new ArrayList<>(); SubListUtils.dealForSubList(testPlanApiScenarios, 100, - subTestPlanReportApiCases-> { + subTestPlanReportApiCases -> { List subIds = subTestPlanReportApiCases.stream().map(TestPlanApiScenarioBatchRunDTO::getId).toList(); execTaskItems.addAll(extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds)); }); @@ -255,7 +262,6 @@ public class TestPlanApiScenarioBatchRunService { /** * 并行批量执行 - * */ public void parallelExecute(String taskId, List testPlanApiScenarios, @@ -296,7 +302,7 @@ public class TestPlanApiScenarioBatchRunService { private Map getResourceTaskItemMap(String taskId, List testPlanApiCases) { Map resourceTaskItemMap = new HashMap<>(); SubListUtils.dealForSubList(testPlanApiCases, 100, - subTestPlanReportApiCases-> { + subTestPlanReportApiCases -> { List subIds = subTestPlanReportApiCases.stream().map(TestPlanApiScenarioBatchRunDTO::getId).toList(); extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds) .forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId()));