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

@ -137,3 +137,5 @@ test_plan.status.success=成功
test_plan.status.error=失败
test_plan.status.prepared=未开始
test_plan.status.underway=进行中
test_plan.update.executor=修改执行人

View File

@ -141,3 +141,5 @@ test_plan.status.success=Success
test_plan.status.error=Error
test_plan.status.prepared=Prepared
test_plan.status.underway=Underway
test_plan.update.executor=Modify the executor

View File

@ -141,3 +141,5 @@ test_plan.status.success=成功
test_plan.status.error=失败
test_plan.status.prepared=未开始
test_plan.status.underway=进行中
test_plan.update.executor=修改执行人

View File

@ -140,3 +140,5 @@ test_plan.status.success=成功
test_plan.status.error=失敗
test_plan.status.prepared=未開始
test_plan.status.underway=進行中
test_plan.update.executor=修改執行人

View File

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

View File

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

View File

@ -55,6 +55,8 @@ public class TestPlanFunctionalCaseController {
@Resource
private TestPlanFunctionalCaseService testPlanFunctionalCaseService;
@Resource
private TestPlanCaseLogService testPlanCaseLogService;
@Resource
private BugService bugService;
@Resource
private BugLogService bugLogService;
@ -74,7 +76,6 @@ public class TestPlanFunctionalCaseController {
public Pager<List<TestPlanCasePageResponse>> page(@Validated @RequestBody TestPlanCaseRequest request) {
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");
return PageUtils.setPageInfo(page, testPlanFunctionalCaseService.getFunctionalCasePage(request, false, SessionUtils.getCurrentProjectId()));
}
@ -173,9 +174,9 @@ public class TestPlanFunctionalCaseController {
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@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) {
testPlanFunctionalCaseService.batchUpdateExecutor(request);
testPlanCaseLogService.batchUpdateExecutor(request);
}
@GetMapping("/detail/{id}")
@ -207,9 +208,9 @@ public class TestPlanFunctionalCaseController {
@Operation(summary = "测试计划-计划详情-功能用例-批量移动")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@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) {
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.ApiTestCaseExample;
import io.metersphere.api.mapper.ApiTestCaseMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanApiCase;
import io.metersphere.plan.domain.TestPlanApiCaseExample;
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchMoveRequest;
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
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.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
@ -34,10 +40,19 @@ public class TestPlanApiCaseLogService {
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private ApiTestCaseMapper apiTestCaseMapper;
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ProjectMapper projectMapper;
@Resource
private OperationLogService operationLogService;
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
try {
List<String> ids = testPlanApiCaseService.doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria().andIdIn(ids);
List<TestPlanApiCase> planCaseList = testPlanApiCaseMapper.selectByExample(example);
@ -51,25 +66,32 @@ public class TestPlanApiCaseLogService {
List<LogDTO> dtoList = new ArrayList<>();
idsMap.forEach((k, v) -> {
LogDTO dto = new LogDTO(
null,
null,
project.getId(),
project.getOrganizationId(),
k,
null,
request.getUserId(),
OperationLogType.UPDATE.name(),
OperationLogModule.TEST_PLAN,
caseMap.get(v));
Translator.get("test_plan.update.executor") + ":" + caseMap.get(v));
dto.setPath("/test-plan/api/case/batch/update/executor");
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) {
try {
List<String> ids = testPlanApiCaseService.doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria().andIdIn(ids);
List<TestPlanApiCase> caseList = testPlanApiCaseMapper.selectByExample(example);
@ -81,10 +103,10 @@ public class TestPlanApiCaseLogService {
List<LogDTO> dtoList = new ArrayList<>();
caseList.forEach(item -> {
LogDTO dto = new LogDTO(
null,
null,
project.getId(),
project.getOrganizationId(),
item.getApiCaseId(),
null,
userId,
OperationLogType.UPDATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("move") + ":" + caseMap.get(item.getApiCaseId()));
@ -97,6 +119,10 @@ public class TestPlanApiCaseLogService {
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.ApiScenarioExample;
import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanApiScenario;
import io.metersphere.plan.domain.TestPlanApiScenarioExample;
import io.metersphere.plan.dto.request.BaseBatchMoveRequest;
import io.metersphere.plan.dto.request.TestPlanApiScenarioUpdateRequest;
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.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
@ -34,10 +40,20 @@ public class TestPlanApiScenarioLogService {
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ProjectMapper projectMapper;
@Resource
private OperationLogService operationLogService;
public void batchUpdateExecutor(TestPlanApiScenarioUpdateRequest request) {
try {
List<String> ids = testPlanApiScenarioService.doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria().andIdIn(ids);
List<TestPlanApiScenario> planApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
@ -51,13 +67,13 @@ public class TestPlanApiScenarioLogService {
List<LogDTO> dtoList = new ArrayList<>();
idsMap.forEach((k, v) -> {
LogDTO dto = new LogDTO(
null,
null,
project.getId(),
project.getOrganizationId(),
k,
null,
request.getUserId(),
OperationLogType.UPDATE.name(),
OperationLogModule.TEST_PLAN,
caseMap.get(v));
Translator.get("test_plan.update.executor") + ":" + caseMap.get(v));
dto.setPath("/test-plan/api/scenario/batch/update/executor");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k)));
@ -65,11 +81,17 @@ public class TestPlanApiScenarioLogService {
dtoList.add(dto);
});
}
} catch (Exception e) {
LogUtils.error(e);
}
}
public void batchMove(BaseBatchMoveRequest request) {
public void batchMove(BaseBatchMoveRequest request, String userId) {
try {
List<String> ids = testPlanApiScenarioService.doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria().andIdIn(ids);
List<TestPlanApiScenario> caseList = testPlanApiScenarioMapper.selectByExample(example);
@ -81,10 +103,10 @@ public class TestPlanApiScenarioLogService {
List<LogDTO> dtoList = new ArrayList<>();
caseList.forEach(item -> {
LogDTO dto = new LogDTO(
null,
null,
project.getId(),
project.getOrganizationId(),
item.getApiScenarioId(),
null,
userId,
OperationLogType.UPDATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("move") + ":" + caseMap.get(item.getApiScenarioId()));
@ -97,7 +119,10 @@ public class TestPlanApiScenarioLogService {
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.FunctionalCaseExample;
import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanFunctionalCase;
import io.metersphere.plan.domain.TestPlanFunctionalCaseExample;
import io.metersphere.plan.dto.request.BaseBatchMoveRequest;
import io.metersphere.plan.dto.request.TestPlanCaseUpdateRequest;
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.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
@ -34,10 +40,19 @@ public class TestPlanCaseLogService {
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
@Resource
private FunctionalCaseMapper functionalCaseMapper;
@Resource
private OperationLogService operationLogService;
@Resource
private ProjectMapper projectMapper;
@Resource
private TestPlanMapper testPlanMapper;
public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) {
try {
List<String> ids = testPlanFunctionalCaseService.doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample();
example.createCriteria().andIdIn(ids);
List<TestPlanFunctionalCase> planCaseList = testPlanFunctionalCaseMapper.selectByExample(example);
@ -51,26 +66,33 @@ public class TestPlanCaseLogService {
List<LogDTO> dtoList = new ArrayList<>();
idsMap.forEach((k, v) -> {
LogDTO dto = new LogDTO(
null,
null,
project.getId(),
project.getOrganizationId(),
k,
null,
request.getUserId(),
OperationLogType.UPDATE.name(),
OperationLogModule.TEST_PLAN,
caseMap.get(v));
Translator.get("test_plan.update.executor") + ":" + caseMap.get(v));
dto.setPath("/test-plan/functional/case/batch/update/executor");
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) {
try {
List<String> ids = testPlanFunctionalCaseService.doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample();
example.createCriteria().andIdIn(ids);
List<TestPlanFunctionalCase> caseList = testPlanFunctionalCaseMapper.selectByExample(example);
@ -82,10 +104,10 @@ public class TestPlanCaseLogService {
List<LogDTO> dtoList = new ArrayList<>();
caseList.forEach(item -> {
LogDTO dto = new LogDTO(
null,
null,
project.getId(),
project.getOrganizationId(),
item.getFunctionalCaseId(),
null,
userId,
OperationLogType.UPDATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("move") + ":" + caseMap.get(item.getFunctionalCaseId()));
@ -98,6 +120,10 @@ public class TestPlanCaseLogService {
dto.setModifiedValue(JSON.toJSONBytes(testPlanFunctionalCase));
dtoList.add(dto);
});
operationLogService.batchAdd(dtoList);
}
} catch (Exception e) {
LogUtils.error(e);
}
}