fix(任务中心): 修复批量执行任务名称国际化问题

--bug=1047888 --user=王旭 【任务中心】-场景批量执行的任务名称建议汉化 https://www.tapd.cn/55049933/s/1596693
This commit is contained in:
WangXu10 2024-10-23 17:10:55 +08:00 committed by Craftsman
parent b5a8bd541f
commit c747b28efa
8 changed files with 49 additions and 22 deletions

View File

@ -302,7 +302,6 @@ public class ApiTestCaseController {
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE)
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case") @CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
public void batchRun(@Validated @RequestBody ApiTestCaseBatchRunRequest request) { public void batchRun(@Validated @RequestBody ApiTestCaseBatchRunRequest request) {
ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale());
apiTestCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); apiTestCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId());
} }

View File

@ -101,7 +101,6 @@ public class ApiScenarioBatchOperationController {
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE) @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE)
public void batchRun(@Validated @RequestBody ApiScenarioBatchRunRequest request) { public void batchRun(@Validated @RequestBody ApiScenarioBatchRunRequest request) {
apiValidateService.validateApiMenuInProject(request.getProjectId(), ApiResource.PROJECT.name()); apiValidateService.validateApiMenuInProject(request.getProjectId(), ApiResource.PROJECT.name());
ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale());
apiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); apiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId());
} }
} }

View File

@ -21,10 +21,14 @@ import io.metersphere.system.service.BaseTaskHubService;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.concurrent.atomic.AtomicLong;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -70,7 +74,11 @@ public class ApiTestCaseBatchRunService {
* @param userId * @param userId
*/ */
public void asyncBatchRun(ApiTestCaseBatchRunRequest request, String 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 * @param ids
* @return * @return
*/ */

View File

@ -26,11 +26,13 @@ import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function; import java.util.function.Function;
@ -75,7 +77,11 @@ public class ApiScenarioBatchRunService {
* @param userId * @param userId
*/ */
public void asyncBatchRun(ApiScenarioBatchRunRequest request, String 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 * @param ids
* @return * @return
*/ */

View File

@ -150,7 +150,6 @@ public class TestPlanApiCaseController {
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE)
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "test_plan", relationType = "test_plan_api_case") @CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "test_plan", relationType = "test_plan_api_case")
public void batchRun(@Validated @RequestBody TestPlanApiCaseBatchRunRequest request) { public void batchRun(@Validated @RequestBody TestPlanApiCaseBatchRunRequest request) {
ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale());
testPlanApiCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); testPlanApiCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId());
} }

View File

@ -100,7 +100,6 @@ public class TestPlanApiScenarioController {
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE)
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "test_plan", relationType = "test_plan_api_scenario") @CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "test_plan", relationType = "test_plan_api_scenario")
public void batchRun(@Validated @RequestBody TestPlanApiScenarioBatchRunRequest request) { public void batchRun(@Validated @RequestBody TestPlanApiScenarioBatchRunRequest request) {
ApiBatchRunBaseService.setLocale(LocaleContextHolder.getLocale());
testPlanApiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId()); testPlanApiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId());
} }

View File

@ -11,12 +11,18 @@ import io.metersphere.api.service.definition.ApiTestCaseBatchRunService;
import io.metersphere.api.service.definition.ApiTestCaseService; import io.metersphere.api.service.definition.ApiTestCaseService;
import io.metersphere.api.service.queue.ApiExecutionQueueService; import io.metersphere.api.service.queue.ApiExecutionQueueService;
import io.metersphere.api.service.queue.ApiExecutionSetService; 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.TestPlanApiCaseBatchRunDTO;
import io.metersphere.plan.dto.request.ApiExecutionMapService; import io.metersphere.plan.dto.request.ApiExecutionMapService;
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest;
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRunRequest; 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.domain.Project;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.*; import io.metersphere.sdk.constants.*;
@ -32,6 +38,7 @@ import jakarta.annotation.Resource;
import jodd.util.StringUtil; import jodd.util.StringUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -90,7 +97,11 @@ public class TestPlanApiCaseBatchRunService {
public void asyncBatchRun(TestPlanApiCaseBatchRunRequest request, String userId) { public void asyncBatchRun(TestPlanApiCaseBatchRunRequest request, String userId) {
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
testPlanService.setActualStartTime(request.getTestPlanId()); 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); parallelExecute(execTask.getId(), collectionCases, runModeConfig, null, execTask.getId(), project, userId);
} else { } else {
// 串行执行测试集中的用例 // 串行执行测试集中的用例
serialExecute(execTask.getId(),collectionCases, runModeConfig, null, execTask.getId(), userId); serialExecute(execTask.getId(), collectionCases, runModeConfig, null, execTask.getId(), userId);
} }
} }
} else { } else {
@ -215,7 +226,6 @@ public class TestPlanApiCaseBatchRunService {
/** /**
* 串行批量执行 * 串行批量执行
*
*/ */
public void serialExecute(String taskId, public void serialExecute(String taskId,
List<TestPlanApiCaseBatchRunDTO> testPlanApiCases, List<TestPlanApiCaseBatchRunDTO> testPlanApiCases,
@ -229,7 +239,7 @@ public class TestPlanApiCaseBatchRunService {
List<ExecTaskItem> execTaskItems = new ArrayList<>(); List<ExecTaskItem> execTaskItems = new ArrayList<>();
SubListUtils.dealForSubList(testPlanApiCases, 100, SubListUtils.dealForSubList(testPlanApiCases, 100,
subTestPlanReportApiCases-> { subTestPlanReportApiCases -> {
List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiCaseBatchRunDTO::getId).toList(); List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiCaseBatchRunDTO::getId).toList();
execTaskItems.addAll(extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds)); execTaskItems.addAll(extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds));
}); });
@ -245,7 +255,6 @@ public class TestPlanApiCaseBatchRunService {
/** /**
* 并行批量执行 * 并行批量执行
*
*/ */
public void parallelExecute(String taskId, public void parallelExecute(String taskId,
List<TestPlanApiCaseBatchRunDTO> testPlanApiCases, List<TestPlanApiCaseBatchRunDTO> testPlanApiCases,
@ -296,7 +305,7 @@ public class TestPlanApiCaseBatchRunService {
private Map<String, String> getResourceTaskItemMap(String taskId, List<TestPlanApiCaseBatchRunDTO> testPlanApiCases) { private Map<String, String> getResourceTaskItemMap(String taskId, List<TestPlanApiCaseBatchRunDTO> testPlanApiCases) {
Map<String, String> resourceTaskItemMap = new HashMap<>(); Map<String, String> resourceTaskItemMap = new HashMap<>();
SubListUtils.dealForSubList(testPlanApiCases, 100, SubListUtils.dealForSubList(testPlanApiCases, 100,
subTestPlanReportApiCases-> { subTestPlanReportApiCases -> {
List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiCaseBatchRunDTO::getId).toList(); List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiCaseBatchRunDTO::getId).toList();
extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds) extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds)
.forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId())); .forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId()));
@ -443,7 +452,7 @@ public class TestPlanApiCaseBatchRunService {
* @return * @return
*/ */
public Map<String, String> initApiReport(Map<String, String> resourceExecTaskItemMap, ApiRunModeConfigDTO runModeConfig, List<TestPlanApiCaseBatchRunDTO> testPlanApiCases, public Map<String, String> initApiReport(Map<String, String> resourceExecTaskItemMap, ApiRunModeConfigDTO runModeConfig, List<TestPlanApiCaseBatchRunDTO> testPlanApiCases,
String projectId, String userId) { String projectId, String userId) {
List<ApiReport> apiReports = new ArrayList<>(); List<ApiReport> apiReports = new ArrayList<>();
List<ApiTestCaseRecord> apiTestCaseRecords = new ArrayList<>(); List<ApiTestCaseRecord> apiTestCaseRecords = new ArrayList<>();
List<ApiReportRelateTask> apiReportRelateTasks = new ArrayList<>(); List<ApiReportRelateTask> apiReportRelateTasks = new ArrayList<>();

View File

@ -21,7 +21,10 @@ import io.metersphere.plan.domain.TestPlanCollectionExample;
import io.metersphere.plan.dto.TestPlanApiScenarioBatchRunDTO; import io.metersphere.plan.dto.TestPlanApiScenarioBatchRunDTO;
import io.metersphere.plan.dto.request.ApiExecutionMapService; import io.metersphere.plan.dto.request.ApiExecutionMapService;
import io.metersphere.plan.dto.request.TestPlanApiScenarioBatchRunRequest; 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.domain.Project;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.*; import io.metersphere.sdk.constants.*;
@ -37,6 +40,7 @@ import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -96,7 +100,11 @@ public class TestPlanApiScenarioBatchRunService {
public void asyncBatchRun(TestPlanApiScenarioBatchRunRequest request, String userId) { public void asyncBatchRun(TestPlanApiScenarioBatchRunRequest request, String userId) {
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
testPlanService.setActualStartTime(request.getTestPlanId()); 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, public void serialExecute(String taskId,
List<TestPlanApiScenarioBatchRunDTO> testPlanApiScenarios, List<TestPlanApiScenarioBatchRunDTO> testPlanApiScenarios,
@ -241,7 +248,7 @@ public class TestPlanApiScenarioBatchRunService {
List<ExecTaskItem> execTaskItems = new ArrayList<>(); List<ExecTaskItem> execTaskItems = new ArrayList<>();
SubListUtils.dealForSubList(testPlanApiScenarios, 100, SubListUtils.dealForSubList(testPlanApiScenarios, 100,
subTestPlanReportApiCases-> { subTestPlanReportApiCases -> {
List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiScenarioBatchRunDTO::getId).toList(); List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiScenarioBatchRunDTO::getId).toList();
execTaskItems.addAll(extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds)); execTaskItems.addAll(extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds));
}); });
@ -255,7 +262,6 @@ public class TestPlanApiScenarioBatchRunService {
/** /**
* 并行批量执行 * 并行批量执行
*
*/ */
public void parallelExecute(String taskId, public void parallelExecute(String taskId,
List<TestPlanApiScenarioBatchRunDTO> testPlanApiScenarios, List<TestPlanApiScenarioBatchRunDTO> testPlanApiScenarios,
@ -296,7 +302,7 @@ public class TestPlanApiScenarioBatchRunService {
private Map<String, String> getResourceTaskItemMap(String taskId, List<TestPlanApiScenarioBatchRunDTO> testPlanApiCases) { private Map<String, String> getResourceTaskItemMap(String taskId, List<TestPlanApiScenarioBatchRunDTO> testPlanApiCases) {
Map<String, String> resourceTaskItemMap = new HashMap<>(); Map<String, String> resourceTaskItemMap = new HashMap<>();
SubListUtils.dealForSubList(testPlanApiCases, 100, SubListUtils.dealForSubList(testPlanApiCases, 100,
subTestPlanReportApiCases-> { subTestPlanReportApiCases -> {
List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiScenarioBatchRunDTO::getId).toList(); List<String> subIds = subTestPlanReportApiCases.stream().map(TestPlanApiScenarioBatchRunDTO::getId).toList();
extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds) extExecTaskItemMapper.selectExecInfoByTaskIdAndResourceIds(taskId, subIds)
.forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId())); .forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId()));