fix(测试计划): 测试计划用例批量操作没有日志

--bug=1048219 --user=陈建星 【测试计划】测试计划-功能用例详情页批量修改执行人,没有日志记录 https://www.tapd.cn/55049933/s/1599739
This commit is contained in:
AgAngle 2024-10-29 10:55:54 +08:00 committed by Craftsman
parent a137e5f581
commit b96a33622b
10 changed files with 276 additions and 186 deletions

View File

@ -136,4 +136,6 @@ test_plan.status.completed=已完成
test_plan.status.success=成功 test_plan.status.success=成功
test_plan.status.error=失败 test_plan.status.error=失败
test_plan.status.prepared=未开始 test_plan.status.prepared=未开始
test_plan.status.underway=进行中 test_plan.status.underway=进行中
test_plan.update.executor=修改执行人

View File

@ -140,4 +140,6 @@ test_plan.status.completed=Completed
test_plan.status.success=Success test_plan.status.success=Success
test_plan.status.error=Error test_plan.status.error=Error
test_plan.status.prepared=Prepared test_plan.status.prepared=Prepared
test_plan.status.underway=Underway test_plan.status.underway=Underway
test_plan.update.executor=Modify the executor

View File

@ -140,4 +140,6 @@ test_plan.status.completed=已完成
test_plan.status.success=成功 test_plan.status.success=成功
test_plan.status.error=失败 test_plan.status.error=失败
test_plan.status.prepared=未开始 test_plan.status.prepared=未开始
test_plan.status.underway=进行中 test_plan.status.underway=进行中
test_plan.update.executor=修改执行人

View File

@ -139,4 +139,6 @@ test_plan.status.completed=已完成
test_plan.status.success=成功 test_plan.status.success=成功
test_plan.status.error=失敗 test_plan.status.error=失敗
test_plan.status.prepared=未開始 test_plan.status.prepared=未開始
test_plan.status.underway=進行中 test_plan.status.underway=進行中
test_plan.update.executor=修改執行人

View File

@ -63,6 +63,8 @@ public class TestPlanApiCaseController {
private BugService bugService; private BugService bugService;
@Resource @Resource
private BugLogService bugLogService; private BugLogService bugLogService;
@Resource
private TestPlanApiCaseLogService testPlanApiCaseLogService;
@PostMapping(value = "/sort") @PostMapping(value = "/sort")
@Operation(summary = "测试计划功能用例-功能用例拖拽排序") @Operation(summary = "测试计划功能用例-功能用例拖拽排序")
@ -129,9 +131,9 @@ public class TestPlanApiCaseController {
@Operation(summary = "测试计划-计划详情-接口用例列表-批量更新执行人") @Operation(summary = "测试计划-计划详情-接口用例列表-批量更新执行人")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @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) { public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiCaseUpdateRequest request) {
testPlanApiCaseService.batchUpdateExecutor(request); testPlanApiCaseService.batchUpdateExecutor(request);
testPlanApiCaseLogService.batchUpdateExecutor(request);
} }
@GetMapping("/run/{id}") @GetMapping("/run/{id}")
@ -179,9 +181,9 @@ public class TestPlanApiCaseController {
@Operation(summary = "测试计划-计划详情-接口用例-批量移动") @Operation(summary = "测试计划-计划详情-接口用例-批量移动")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @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) { public void batchMove(@Validated @RequestBody TestPlanApiCaseBatchMoveRequest request) {
testPlanApiCaseService.batchMove(request); testPlanApiCaseService.batchMove(request);
testPlanApiCaseLogService.batchMove(request, SessionUtils.getUserId());
} }
@PostMapping("/associate/bug/page") @PostMapping("/associate/bug/page")

View File

@ -60,6 +60,8 @@ public class TestPlanApiScenarioController {
private BugService bugService; private BugService bugService;
@Resource @Resource
private BugLogService bugLogService; private BugLogService bugLogService;
@Resource
private TestPlanApiScenarioLogService testPlanApiScenarioLogService;
@PostMapping("/page") @PostMapping("/page")
@Operation(summary = "测试计划-已关联场景用例列表分页查询") @Operation(summary = "测试计划-已关联场景用例列表分页查询")
@ -129,9 +131,9 @@ public class TestPlanApiScenarioController {
@Operation(summary = "测试计划-计划详情-场景用例列表-批量更新执行人") @Operation(summary = "测试计划-计划详情-场景用例列表-批量更新执行人")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @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) { public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiScenarioUpdateRequest request) {
testPlanApiScenarioService.batchUpdateExecutor(request); testPlanApiScenarioService.batchUpdateExecutor(request);
testPlanApiScenarioLogService.batchUpdateExecutor(request);
} }
@GetMapping("/report/get/{id}") @GetMapping("/report/get/{id}")
@ -164,9 +166,9 @@ public class TestPlanApiScenarioController {
@Operation(summary = "测试计划-计划详情-场景用例-批量移动") @Operation(summary = "测试计划-计划详情-场景用例-批量移动")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @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) { public void batchMove(@Validated @RequestBody BaseBatchMoveRequest request) {
testPlanApiScenarioService.batchMove(request); testPlanApiScenarioService.batchMove(request);
testPlanApiScenarioLogService.batchMove(request, SessionUtils.getUserId());
} }
@PostMapping("/associate/bug/page") @PostMapping("/associate/bug/page")

View File

@ -55,6 +55,8 @@ public class TestPlanFunctionalCaseController {
@Resource @Resource
private TestPlanFunctionalCaseService testPlanFunctionalCaseService; private TestPlanFunctionalCaseService testPlanFunctionalCaseService;
@Resource @Resource
private TestPlanCaseLogService testPlanCaseLogService;
@Resource
private BugService bugService; private BugService bugService;
@Resource @Resource
private BugLogService bugLogService; private BugLogService bugLogService;
@ -74,7 +76,6 @@ public class TestPlanFunctionalCaseController {
public Pager<List<TestPlanCasePageResponse>> page(@Validated @RequestBody TestPlanCaseRequest request) { public Pager<List<TestPlanCasePageResponse>> page(@Validated @RequestBody TestPlanCaseRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> 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"); 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())); return PageUtils.setPageInfo(page, testPlanFunctionalCaseService.getFunctionalCasePage(request, false, SessionUtils.getCurrentProjectId()));
} }
@ -173,9 +174,9 @@ public class TestPlanFunctionalCaseController {
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人") @Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @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) { public void batchUpdateExecutor(@Validated @RequestBody TestPlanCaseUpdateRequest request) {
testPlanFunctionalCaseService.batchUpdateExecutor(request); testPlanFunctionalCaseService.batchUpdateExecutor(request);
testPlanCaseLogService.batchUpdateExecutor(request);
} }
@GetMapping("/detail/{id}") @GetMapping("/detail/{id}")
@ -207,9 +208,9 @@ public class TestPlanFunctionalCaseController {
@Operation(summary = "测试计划-计划详情-功能用例-批量移动") @Operation(summary = "测试计划-计划详情-功能用例-批量移动")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @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) { public void batchMove(@Validated @RequestBody BaseBatchMoveRequest request) {
testPlanFunctionalCaseService.batchMove(request); testPlanFunctionalCaseService.batchMove(request);
testPlanCaseLogService.batchMove(request, SessionUtils.getUserId());
} }

View File

@ -3,17 +3,23 @@ package io.metersphere.plan.service;
import io.metersphere.api.domain.ApiTestCase; import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.api.domain.ApiTestCaseExample; import io.metersphere.api.domain.ApiTestCaseExample;
import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.mapper.ApiTestCaseMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanApiCase; import io.metersphere.plan.domain.TestPlanApiCase;
import io.metersphere.plan.domain.TestPlanApiCaseExample; import io.metersphere.plan.domain.TestPlanApiCaseExample;
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchMoveRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseBatchMoveRequest;
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
import io.metersphere.plan.mapper.TestPlanApiCaseMapper; 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.constants.HttpMethodConstants;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,69 +40,89 @@ public class TestPlanApiCaseLogService {
private TestPlanApiCaseMapper testPlanApiCaseMapper; private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource @Resource
private ApiTestCaseMapper apiTestCaseMapper; private ApiTestCaseMapper apiTestCaseMapper;
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ProjectMapper projectMapper;
@Resource
private OperationLogService operationLogService;
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) { public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
List<String> ids = testPlanApiCaseService.doSelectIds(request); try {
if (CollectionUtils.isNotEmpty(ids)) { List<String> ids = testPlanApiCaseService.doSelectIds(request);
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
List<TestPlanApiCase> planCaseList = testPlanApiCaseMapper.selectByExample(example); Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
Map<String, String> userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getExecuteUser)); TestPlanApiCaseExample example = new TestPlanApiCaseExample();
Map<String, String> idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getApiCaseId)); example.createCriteria().andIdIn(ids);
List<String> caseIds = planCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); List<TestPlanApiCase> planCaseList = testPlanApiCaseMapper.selectByExample(example);
ApiTestCaseExample caseExample = new ApiTestCaseExample(); Map<String, String> userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getExecuteUser));
caseExample.createCriteria().andIdIn(caseIds); Map<String, String> idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getApiCaseId));
List<ApiTestCase> functionalCases = apiTestCaseMapper.selectByExample(caseExample); List<String> caseIds = planCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName)); ApiTestCaseExample caseExample = new ApiTestCaseExample();
List<LogDTO> dtoList = new ArrayList<>(); caseExample.createCriteria().andIdIn(caseIds);
idsMap.forEach((k, v) -> { List<ApiTestCase> functionalCases = apiTestCaseMapper.selectByExample(caseExample);
LogDTO dto = new LogDTO( Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName));
null, List<LogDTO> dtoList = new ArrayList<>();
null, idsMap.forEach((k, v) -> {
k, LogDTO dto = new LogDTO(
null, project.getId(),
OperationLogType.UPDATE.name(), project.getOrganizationId(),
OperationLogModule.TEST_PLAN, k,
caseMap.get(v)); request.getUserId(),
dto.setPath("/test-plan/api/case/batch/update/executor"); OperationLogType.UPDATE.name(),
dto.setMethod(HttpMethodConstants.POST.name()); OperationLogModule.TEST_PLAN,
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); Translator.get("test_plan.update.executor") + ":" + caseMap.get(v));
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); dto.setPath("/test-plan/api/case/batch/update/executor");
dtoList.add(dto); 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) { public void batchMove(TestPlanApiCaseBatchMoveRequest request, String userId) {
List<String> ids = testPlanApiCaseService.doSelectIds(request); try {
if (CollectionUtils.isNotEmpty(ids)) { List<String> ids = testPlanApiCaseService.doSelectIds(request);
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
List<TestPlanApiCase> caseList = testPlanApiCaseMapper.selectByExample(example); Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
List<String> apiCaseIds = caseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); TestPlanApiCaseExample example = new TestPlanApiCaseExample();
ApiTestCaseExample caseExample = new ApiTestCaseExample(); example.createCriteria().andIdIn(ids);
caseExample.createCriteria().andIdIn(apiCaseIds); List<TestPlanApiCase> caseList = testPlanApiCaseMapper.selectByExample(example);
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(caseExample); List<String> apiCaseIds = caseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
Map<String, String> caseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName)); ApiTestCaseExample caseExample = new ApiTestCaseExample();
List<LogDTO> dtoList = new ArrayList<>(); caseExample.createCriteria().andIdIn(apiCaseIds);
caseList.forEach(item -> { List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(caseExample);
LogDTO dto = new LogDTO( Map<String, String> caseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName));
null, List<LogDTO> dtoList = new ArrayList<>();
null, caseList.forEach(item -> {
item.getApiCaseId(), LogDTO dto = new LogDTO(
null, project.getId(),
OperationLogType.UPDATE.name(), project.getOrganizationId(),
OperationLogModule.TEST_PLAN, item.getApiCaseId(),
Translator.get("move") + ":" + caseMap.get(item.getApiCaseId())); userId,
dto.setPath("/test-plan/api/case/batch/move"); OperationLogType.UPDATE.name(),
dto.setMethod(HttpMethodConstants.POST.name()); OperationLogModule.TEST_PLAN,
dto.setOriginalValue(JSON.toJSONBytes(item)); Translator.get("move") + ":" + caseMap.get(item.getApiCaseId()));
TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); dto.setPath("/test-plan/api/case/batch/move");
testPlanApiCase.setId(item.getId()); dto.setMethod(HttpMethodConstants.POST.name());
testPlanApiCase.setTestPlanCollectionId(request.getTargetCollectionId()); dto.setOriginalValue(JSON.toJSONBytes(item));
dto.setModifiedValue(JSON.toJSONBytes(testPlanApiCase)); TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
dtoList.add(dto); 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);
} }
} }
} }

View File

@ -3,17 +3,23 @@ package io.metersphere.plan.service;
import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.domain.ApiScenarioExample; import io.metersphere.api.domain.ApiScenarioExample;
import io.metersphere.api.mapper.ApiScenarioMapper; import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanApiScenario; import io.metersphere.plan.domain.TestPlanApiScenario;
import io.metersphere.plan.domain.TestPlanApiScenarioExample; import io.metersphere.plan.domain.TestPlanApiScenarioExample;
import io.metersphere.plan.dto.request.BaseBatchMoveRequest; import io.metersphere.plan.dto.request.BaseBatchMoveRequest;
import io.metersphere.plan.dto.request.TestPlanApiScenarioUpdateRequest; import io.metersphere.plan.dto.request.TestPlanApiScenarioUpdateRequest;
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper; 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.constants.HttpMethodConstants;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,70 +40,89 @@ public class TestPlanApiScenarioLogService {
private TestPlanApiScenarioMapper testPlanApiScenarioMapper; private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource @Resource
private ApiScenarioMapper apiScenarioMapper; private ApiScenarioMapper apiScenarioMapper;
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ProjectMapper projectMapper;
@Resource
private OperationLogService operationLogService;
public void batchUpdateExecutor(TestPlanApiScenarioUpdateRequest request) { public void batchUpdateExecutor(TestPlanApiScenarioUpdateRequest request) {
List<String> ids = testPlanApiScenarioService.doSelectIds(request); try {
if (CollectionUtils.isNotEmpty(ids)) { List<String> ids = testPlanApiScenarioService.doSelectIds(request);
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
List<TestPlanApiScenario> planApiScenarioList = testPlanApiScenarioMapper.selectByExample(example); Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
Map<String, String> userMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getExecuteUser)); TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
Map<String, String> idsMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getApiScenarioId)); example.createCriteria().andIdIn(ids);
List<String> scenarioIds = planApiScenarioList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); List<TestPlanApiScenario> planApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
ApiScenarioExample scenarioExample = new ApiScenarioExample(); Map<String, String> userMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getExecuteUser));
scenarioExample.createCriteria().andIdIn(scenarioIds); Map<String, String> idsMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getApiScenarioId));
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(scenarioExample); List<String> scenarioIds = planApiScenarioList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList());
Map<String, String> caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName)); ApiScenarioExample scenarioExample = new ApiScenarioExample();
List<LogDTO> dtoList = new ArrayList<>(); scenarioExample.createCriteria().andIdIn(scenarioIds);
idsMap.forEach((k, v) -> { List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(scenarioExample);
LogDTO dto = new LogDTO( Map<String, String> caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName));
null, List<LogDTO> dtoList = new ArrayList<>();
null, idsMap.forEach((k, v) -> {
k, LogDTO dto = new LogDTO(
null, project.getId(),
OperationLogType.UPDATE.name(), project.getOrganizationId(),
OperationLogModule.TEST_PLAN, k,
caseMap.get(v)); request.getUserId(),
dto.setPath("/test-plan/api/scenario/batch/update/executor"); OperationLogType.UPDATE.name(),
dto.setMethod(HttpMethodConstants.POST.name()); OperationLogModule.TEST_PLAN,
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); Translator.get("test_plan.update.executor") + ":" + caseMap.get(v));
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); dto.setPath("/test-plan/api/scenario/batch/update/executor");
dtoList.add(dto); 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) { public void batchMove(BaseBatchMoveRequest request, String userId) {
List<String> ids = testPlanApiScenarioService.doSelectIds(request); try {
if (CollectionUtils.isNotEmpty(ids)) { List<String> ids = testPlanApiScenarioService.doSelectIds(request);
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
List<TestPlanApiScenario> caseList = testPlanApiScenarioMapper.selectByExample(example); Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
List<String> apiScenarioIds = caseList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
ApiScenarioExample scenarioExample = new ApiScenarioExample(); example.createCriteria().andIdIn(ids);
scenarioExample.createCriteria().andIdIn(apiScenarioIds); List<TestPlanApiScenario> caseList = testPlanApiScenarioMapper.selectByExample(example);
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(scenarioExample); List<String> apiScenarioIds = caseList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList());
Map<String, String> caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName)); ApiScenarioExample scenarioExample = new ApiScenarioExample();
List<LogDTO> dtoList = new ArrayList<>(); scenarioExample.createCriteria().andIdIn(apiScenarioIds);
caseList.forEach(item -> { List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(scenarioExample);
LogDTO dto = new LogDTO( Map<String, String> caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::getName));
null, List<LogDTO> dtoList = new ArrayList<>();
null, caseList.forEach(item -> {
item.getApiScenarioId(), LogDTO dto = new LogDTO(
null, project.getId(),
OperationLogType.UPDATE.name(), project.getOrganizationId(),
OperationLogModule.TEST_PLAN, item.getApiScenarioId(),
Translator.get("move") + ":" + caseMap.get(item.getApiScenarioId())); userId,
dto.setPath("/test-plan/api/scenario/batch/move"); OperationLogType.UPDATE.name(),
dto.setMethod(HttpMethodConstants.POST.name()); OperationLogModule.TEST_PLAN,
dto.setOriginalValue(JSON.toJSONBytes(item)); Translator.get("move") + ":" + caseMap.get(item.getApiScenarioId()));
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); dto.setPath("/test-plan/api/scenario/batch/move");
testPlanApiScenario.setId(item.getId()); dto.setMethod(HttpMethodConstants.POST.name());
testPlanApiScenario.setTestPlanCollectionId(request.getTargetCollectionId()); dto.setOriginalValue(JSON.toJSONBytes(item));
dto.setModifiedValue(JSON.toJSONBytes(testPlanApiScenario)); TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
dtoList.add(dto); 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);
} }
} }

View File

@ -3,17 +3,23 @@ package io.metersphere.plan.service;
import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseExample; import io.metersphere.functional.domain.FunctionalCaseExample;
import io.metersphere.functional.mapper.FunctionalCaseMapper; import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanFunctionalCase; import io.metersphere.plan.domain.TestPlanFunctionalCase;
import io.metersphere.plan.domain.TestPlanFunctionalCaseExample; import io.metersphere.plan.domain.TestPlanFunctionalCaseExample;
import io.metersphere.plan.dto.request.BaseBatchMoveRequest; import io.metersphere.plan.dto.request.BaseBatchMoveRequest;
import io.metersphere.plan.dto.request.TestPlanCaseUpdateRequest; import io.metersphere.plan.dto.request.TestPlanCaseUpdateRequest;
import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper; 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.constants.HttpMethodConstants;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,70 +40,90 @@ public class TestPlanCaseLogService {
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper; private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
@Resource @Resource
private FunctionalCaseMapper functionalCaseMapper; private FunctionalCaseMapper functionalCaseMapper;
@Resource
private OperationLogService operationLogService;
@Resource
private ProjectMapper projectMapper;
@Resource
private TestPlanMapper testPlanMapper;
public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) { public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) {
List<String> ids = testPlanFunctionalCaseService.doSelectIds(request); try {
if (CollectionUtils.isNotEmpty(ids)) { List<String> ids = testPlanFunctionalCaseService.doSelectIds(request);
TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
List<TestPlanFunctionalCase> planCaseList = testPlanFunctionalCaseMapper.selectByExample(example); Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
Map<String, String> userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getExecuteUser)); TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample();
Map<String, String> idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getFunctionalCaseId)); example.createCriteria().andIdIn(ids);
List<String> caseIds = planCaseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); List<TestPlanFunctionalCase> planCaseList = testPlanFunctionalCaseMapper.selectByExample(example);
FunctionalCaseExample caseExample = new FunctionalCaseExample(); Map<String, String> userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getExecuteUser));
caseExample.createCriteria().andIdIn(caseIds); Map<String, String> idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getFunctionalCaseId));
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(caseExample); List<String> caseIds = planCaseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList());
Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); FunctionalCaseExample caseExample = new FunctionalCaseExample();
List<LogDTO> dtoList = new ArrayList<>(); caseExample.createCriteria().andIdIn(caseIds);
idsMap.forEach((k, v) -> { List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(caseExample);
LogDTO dto = new LogDTO( Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName));
null, List<LogDTO> dtoList = new ArrayList<>();
null, idsMap.forEach((k, v) -> {
k, LogDTO dto = new LogDTO(
null, project.getId(),
OperationLogType.UPDATE.name(), project.getOrganizationId(),
OperationLogModule.TEST_PLAN, k,
caseMap.get(v)); request.getUserId(),
dto.setPath("/test-plan/functional/case/batch/update/executor"); OperationLogType.UPDATE.name(),
dto.setMethod(HttpMethodConstants.POST.name()); OperationLogModule.TEST_PLAN,
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); Translator.get("test_plan.update.executor") + ":" + caseMap.get(v));
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); dto.setPath("/test-plan/functional/case/batch/update/executor");
dtoList.add(dto); 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) { public void batchMove(BaseBatchMoveRequest request, String userId) {
List<String> ids = testPlanFunctionalCaseService.doSelectIds(request); try {
if (CollectionUtils.isNotEmpty(ids)) { List<String> ids = testPlanFunctionalCaseService.doSelectIds(request);
TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
List<TestPlanFunctionalCase> caseList = testPlanFunctionalCaseMapper.selectByExample(example); Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
List<String> functionalCaseIds = caseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample();
FunctionalCaseExample caseExample = new FunctionalCaseExample(); example.createCriteria().andIdIn(ids);
caseExample.createCriteria().andIdIn(functionalCaseIds); List<TestPlanFunctionalCase> caseList = testPlanFunctionalCaseMapper.selectByExample(example);
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(caseExample); List<String> functionalCaseIds = caseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList());
Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); FunctionalCaseExample caseExample = new FunctionalCaseExample();
List<LogDTO> dtoList = new ArrayList<>(); caseExample.createCriteria().andIdIn(functionalCaseIds);
caseList.forEach(item -> { List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(caseExample);
LogDTO dto = new LogDTO( Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName));
null, List<LogDTO> dtoList = new ArrayList<>();
null, caseList.forEach(item -> {
item.getFunctionalCaseId(), LogDTO dto = new LogDTO(
null, project.getId(),
OperationLogType.UPDATE.name(), project.getOrganizationId(),
OperationLogModule.TEST_PLAN, item.getFunctionalCaseId(),
Translator.get("move") + ":" + caseMap.get(item.getFunctionalCaseId())); userId,
dto.setPath("/test-plan/functional/case/batch/move"); OperationLogType.UPDATE.name(),
dto.setMethod(HttpMethodConstants.POST.name()); OperationLogModule.TEST_PLAN,
dto.setOriginalValue(JSON.toJSONBytes(item)); Translator.get("move") + ":" + caseMap.get(item.getFunctionalCaseId()));
TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase(); dto.setPath("/test-plan/functional/case/batch/move");
testPlanFunctionalCase.setId(item.getId()); dto.setMethod(HttpMethodConstants.POST.name());
testPlanFunctionalCase.setTestPlanCollectionId(request.getTargetCollectionId()); dto.setOriginalValue(JSON.toJSONBytes(item));
dto.setModifiedValue(JSON.toJSONBytes(testPlanFunctionalCase)); TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase();
dtoList.add(dto); 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);
} }
} }