feat(测试用例): 用例评审新增模块操作日志
This commit is contained in:
parent
b7bf3a01ec
commit
31d9ae57ab
|
@ -38,7 +38,7 @@ public class CaseReviewModuleController {
|
|||
@RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_ADD)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
public String add(@RequestBody @Validated CaseReviewModuleCreateRequest request) {
|
||||
return caseReviewModuleService.add(request, SessionUtils.getUserId());
|
||||
return caseReviewModuleService.add(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
|
@ -62,7 +62,7 @@ public class CaseReviewModuleController {
|
|||
@RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_DELETE)
|
||||
@CheckOwner(resourceId = "#moduleId", resourceType = "case_review_module")
|
||||
public void deleteNode(@PathVariable String moduleId) {
|
||||
caseReviewModuleService.deleteModule(moduleId);
|
||||
caseReviewModuleService.deleteModule(moduleId, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package io.metersphere.functional.service;
|
||||
|
||||
import io.metersphere.functional.domain.CaseReview;
|
||||
import io.metersphere.functional.domain.CaseReviewModule;
|
||||
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.system.dto.builder.LogDTOBuilder;
|
||||
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.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class CaseReviewModuleLogService {
|
||||
private static final String CASE_REVIEW_MODULE = "/case/review/module";
|
||||
private static final String ADD = CASE_REVIEW_MODULE + "/add";
|
||||
private static final String UPDATE = CASE_REVIEW_MODULE + "/update";
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
@Resource
|
||||
private OperationLogService operationLogService;
|
||||
|
||||
/**
|
||||
* 评审新增模块日志
|
||||
*
|
||||
* @param caseReviewModule
|
||||
* @param userId
|
||||
*/
|
||||
public void addModuleLog(CaseReviewModule caseReviewModule, String userId) {
|
||||
Project project = projectMapper.selectByPrimaryKey(caseReviewModule.getProjectId());
|
||||
LogDTO dto = LogDTOBuilder.builder()
|
||||
.projectId(caseReviewModule.getProjectId())
|
||||
.organizationId(project.getOrganizationId())
|
||||
.type(OperationLogType.ADD.name())
|
||||
.module(OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW_MODULE)
|
||||
.method(HttpMethodConstants.POST.name())
|
||||
.path(ADD)
|
||||
.sourceId(caseReviewModule.getId())
|
||||
.content(caseReviewModule.getName())
|
||||
.originalValue(JSON.toJSONBytes(caseReviewModule))
|
||||
.createUser(userId)
|
||||
.build().getLogDTO();
|
||||
operationLogService.add(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评审更新模块日志
|
||||
*
|
||||
* @param updateModule
|
||||
* @param operator
|
||||
*/
|
||||
public void updateModuleLog(CaseReviewModule updateModule, String operator) {
|
||||
Project project = projectMapper.selectByPrimaryKey(updateModule.getProjectId());
|
||||
LogDTO dto = LogDTOBuilder.builder()
|
||||
.projectId(project.getId())
|
||||
.organizationId(project.getOrganizationId())
|
||||
.type(OperationLogType.UPDATE.name())
|
||||
.module(OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW_MODULE)
|
||||
.method(HttpMethodConstants.POST.name())
|
||||
.path(UPDATE)
|
||||
.sourceId(updateModule.getId())
|
||||
.content(updateModule.getName())
|
||||
.originalValue(JSON.toJSONBytes(updateModule))
|
||||
.createUser(operator)
|
||||
.build().getLogDTO();
|
||||
operationLogService.add(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 评审删除模块日志
|
||||
*
|
||||
* @param caseReviews
|
||||
* @param projectId
|
||||
* @param userId
|
||||
* @param path
|
||||
*/
|
||||
public void batchDelLog(List<CaseReview> caseReviews, String projectId, String userId, String path) {
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
List<LogDTO> dtoList = new ArrayList<>();
|
||||
caseReviews.forEach(item -> {
|
||||
LogDTO dto = new LogDTO(
|
||||
projectId,
|
||||
project.getOrganizationId(),
|
||||
item.getId(),
|
||||
userId,
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW_MODULE,
|
||||
item.getName());
|
||||
dto.setPath(path);
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
dtoList.add(dto);
|
||||
});
|
||||
operationLogService.batchAdd(dtoList);
|
||||
}
|
||||
}
|
|
@ -18,17 +18,11 @@ import io.metersphere.functional.request.CaseReviewModuleUpdateRequest;
|
|||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.dto.NodeSortDTO;
|
||||
import io.metersphere.project.service.ModuleTreeService;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
|
||||
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 io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
@ -59,10 +53,8 @@ public class CaseReviewModuleService extends ModuleTreeService {
|
|||
private ExtCaseReviewMapper extCaseReviewMapper;
|
||||
@Resource
|
||||
private DeleteCaseReviewService deleteCaseReviewService;
|
||||
|
||||
|
||||
@Resource
|
||||
private OperationLogService operationLogService;
|
||||
private CaseReviewModuleLogService caseReviewModuleLogService;
|
||||
|
||||
public List<BaseTreeNode> getTree(String projectId) {
|
||||
List<BaseTreeNode> fileModuleList = extCaseReviewModuleMapper.selectBaseByProjectId(projectId);
|
||||
|
@ -82,6 +74,7 @@ public class CaseReviewModuleService extends ModuleTreeService {
|
|||
caseReviewModule.setCreateUser(userId);
|
||||
caseReviewModule.setUpdateUser(userId);
|
||||
caseReviewModuleMapper.insert(caseReviewModule);
|
||||
caseReviewModuleLogService.addModuleLog(caseReviewModule, userId);
|
||||
return caseReviewModule.getId();
|
||||
}
|
||||
|
||||
|
@ -97,6 +90,7 @@ public class CaseReviewModuleService extends ModuleTreeService {
|
|||
updateModule.setCreateUser(null);
|
||||
updateModule.setCreateTime(null);
|
||||
caseReviewModuleMapper.updateByPrimaryKeySelective(updateModule);
|
||||
caseReviewModuleLogService.updateModuleLog(updateModule, userId);
|
||||
}
|
||||
|
||||
public void moveNode(NodeMoveRequest request, String userId) {
|
||||
|
@ -122,34 +116,14 @@ public class CaseReviewModuleService extends ModuleTreeService {
|
|||
super.sort(nodeSortDTO);
|
||||
}
|
||||
|
||||
public void deleteModule(String moduleId) {
|
||||
public void deleteModule(String moduleId, String userId) {
|
||||
CaseReviewModule deleteModule = caseReviewModuleMapper.selectByPrimaryKey(moduleId);
|
||||
if (deleteModule != null) {
|
||||
List<CaseReview> caseReviews = this.deleteModuleByIds(Collections.singletonList(moduleId), new ArrayList<>(), deleteModule.getProjectId());
|
||||
batchDelLog(caseReviews, deleteModule.getProjectId());
|
||||
caseReviewModuleLogService.batchDelLog(caseReviews, deleteModule.getProjectId(), userId, "/case/review/module/delete/" + moduleId);
|
||||
}
|
||||
}
|
||||
|
||||
public void batchDelLog(List<CaseReview> caseReviews, String projectId) {
|
||||
List<LogDTO> dtoList = new ArrayList<>();
|
||||
caseReviews.forEach(item -> {
|
||||
LogDTO dto = new LogDTO(
|
||||
projectId,
|
||||
"",
|
||||
item.getId(),
|
||||
item.getCreateUser(),
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW,
|
||||
item.getName());
|
||||
|
||||
dto.setPath("/case/review/module/delete/");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
dtoList.add(dto);
|
||||
});
|
||||
operationLogService.batchAdd(dtoList);
|
||||
}
|
||||
|
||||
public List<CaseReview> deleteModuleByIds(List<String> deleteIds, List<CaseReview> caseReviews, String projectId) {
|
||||
if (CollectionUtils.isEmpty(deleteIds)) {
|
||||
return caseReviews;
|
||||
|
|
|
@ -701,7 +701,6 @@ public class CaseReviewModuleControllerTests extends BaseTest {
|
|||
//service层判断:测试删除空集合
|
||||
caseReviewModuleService.deleteModuleByIds(new ArrayList<>(),new ArrayList<>(), project.getId());
|
||||
|
||||
checkLog(caseReview.getId(), OperationLogType.DELETE, URL_MODULE_TREE_DELETE);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -151,6 +151,8 @@ public class OperationLogModule {
|
|||
public static final String CASE_MANAGEMENT_REVIEW_REVIEW = "CASE_MANAGEMENT_REVIEW_REVIEW";
|
||||
//评审详情
|
||||
public static final String CASE_REVIEW_DETAIL = "CASE_MANAGEMENT_REVIEW_DETAIL";
|
||||
//模块
|
||||
public static final String CASE_MANAGEMENT_REVIEW_REVIEW_MODULE = "CASE_MANAGEMENT_REVIEW_REVIEW_MODULE";
|
||||
|
||||
//接口调试
|
||||
public static final String API_TEST_DEBUG_MANAGEMENT_DEBUG = "API_TEST_DEBUG_MANAGEMENT_DEBUG";
|
||||
|
|
Loading…
Reference in New Issue