refactor(功能用例): 回收站获取模块树删除模块加操作日志
This commit is contained in:
parent
b53cbda642
commit
86c35b3c6b
|
@ -58,4 +58,11 @@ public class FunctionalCaseModuleController {
|
|||
public void deleteNode(@PathVariable String moduleId) {
|
||||
functionalCaseModuleService.deleteModule(moduleId);
|
||||
}
|
||||
|
||||
@GetMapping("/trash/tree/{projectId}")
|
||||
@Operation(summary = "用例管理-功能用例-回收站-模块-获取模块树")
|
||||
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
|
||||
public List<BaseTreeNode> getTrashTree(@PathVariable String projectId) {
|
||||
return functionalCaseModuleService.getTrashTree(projectId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
|
||||
<select id="checkCaseByModuleIds" resultType="io.metersphere.functional.domain.FunctionalCase">
|
||||
SELECT
|
||||
id, module_id
|
||||
id, name, module_id, create_user
|
||||
FROM
|
||||
functional_case
|
||||
WHERE
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.util.List;
|
|||
public interface ExtFunctionalCaseModuleMapper {
|
||||
List<BaseTreeNode> selectBaseByProjectId(@Param("projectId")String projectId);
|
||||
|
||||
List<BaseTreeNode> selectBaseByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<String> selectChildrenIdsByParentIds(@Param("ids") List<String> deleteIds);
|
||||
|
||||
List<String> selectChildrenIdsSortByPos(String parentId);
|
||||
|
|
|
@ -7,6 +7,15 @@
|
|||
WHERE project_id = #{projectId}
|
||||
ORDER BY pos
|
||||
</select>
|
||||
<select id="selectBaseByIds" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
|
||||
SELECT id, name, parent_id AS parentId, 'module' AS type
|
||||
FROM functional_case_module
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
ORDER BY pos
|
||||
</select>
|
||||
<select id="selectModuleByParentIdAndPosOperator"
|
||||
parameterType="io.metersphere.project.dto.NodeSortQueryParam"
|
||||
resultType="io.metersphere.system.dto.sdk.BaseModule">
|
||||
|
|
|
@ -10,11 +10,13 @@ import io.metersphere.sdk.util.JSON;
|
|||
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 org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +29,9 @@ public class FunctionalCaseLogService {
|
|||
@Resource
|
||||
private FunctionalCaseMapper functionalCaseMapper;
|
||||
|
||||
@Resource
|
||||
private OperationLogService operationLogService;
|
||||
|
||||
|
||||
//TODO 日志(需要修改)
|
||||
|
||||
|
@ -104,4 +109,24 @@ public class FunctionalCaseLogService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void batchDelLog(List<FunctionalCase> functionalCases, String projectId) {
|
||||
List<LogDTO> dtoList = new ArrayList<>();
|
||||
functionalCases.forEach(item -> {
|
||||
LogDTO dto = new LogDTO(
|
||||
projectId,
|
||||
"",
|
||||
item.getId(),
|
||||
item.getCreateUser(),
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.FUNCTIONAL_CASE,
|
||||
item.getName());
|
||||
|
||||
dto.setPath("/functional/case/module/delete/");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
dtoList.add(dto);
|
||||
});
|
||||
operationLogService.batchAdd(dtoList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
package io.metersphere.functional.service;
|
||||
|
||||
|
||||
import io.metersphere.functional.domain.FunctionalCase;
|
||||
import io.metersphere.functional.domain.FunctionalCaseExample;
|
||||
import io.metersphere.functional.domain.FunctionalCaseModule;
|
||||
import io.metersphere.functional.domain.FunctionalCaseModuleExample;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseMapper;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseModuleMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseModuleMapper;
|
||||
import io.metersphere.functional.request.FunctionalCaseModuleCreateRequest;
|
||||
import io.metersphere.functional.request.FunctionalCaseModuleUpdateRequest;
|
||||
|
@ -32,6 +35,7 @@ import org.mybatis.spring.SqlSessionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -47,6 +51,10 @@ public class FunctionalCaseModuleService extends ModuleTreeService {
|
|||
private ExtFunctionalCaseModuleMapper extFunctionalCaseModuleMapper;
|
||||
@Resource
|
||||
private ExtFunctionalCaseMapper extFunctionalCaseMapper;
|
||||
@Resource
|
||||
private FunctionalCaseMapper functionalCaseMapper;
|
||||
@Resource
|
||||
private FunctionalCaseLogService functionalCaseLogService;
|
||||
|
||||
public List<BaseTreeNode> getTree(String projectId) {
|
||||
List<BaseTreeNode> fileModuleList = extFunctionalCaseModuleMapper.selectBaseByProjectId(projectId);
|
||||
|
@ -104,22 +112,28 @@ public class FunctionalCaseModuleService extends ModuleTreeService {
|
|||
public void deleteModule(String moduleId) {
|
||||
FunctionalCaseModule deleteModule = functionalCaseModuleMapper.selectByPrimaryKey(moduleId);
|
||||
if (deleteModule != null) {
|
||||
this.deleteModuleByIds(Collections.singletonList(moduleId));
|
||||
List<FunctionalCase> functionalCases = this.deleteModuleByIds(Collections.singletonList(moduleId), new ArrayList<>());
|
||||
functionalCaseLogService.batchDelLog(functionalCases, deleteModule.getProjectId());
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteModuleByIds(List<String>deleteIds){
|
||||
public List<FunctionalCase> deleteModuleByIds(List<String>deleteIds, List<FunctionalCase>functionalCases){
|
||||
if (CollectionUtils.isEmpty(deleteIds)) {
|
||||
return;
|
||||
return functionalCases;
|
||||
}
|
||||
FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample();
|
||||
functionalCaseModuleExample.createCriteria().andIdIn(deleteIds);
|
||||
functionalCaseModuleMapper.deleteByExample(functionalCaseModuleExample);
|
||||
List<FunctionalCase> functionalCaseList = extFunctionalCaseMapper.checkCaseByModuleIds(deleteIds);
|
||||
if (CollectionUtils.isNotEmpty(functionalCaseList)) {
|
||||
functionalCases.addAll(functionalCaseList);
|
||||
}
|
||||
extFunctionalCaseMapper.removeToTrashByModuleIds(deleteIds);
|
||||
List<String> childrenIds = extFunctionalCaseModuleMapper.selectChildrenIdsByParentIds(deleteIds);
|
||||
if (CollectionUtils.isNotEmpty(childrenIds)) {
|
||||
deleteModuleByIds(childrenIds);
|
||||
deleteModuleByIds(childrenIds, functionalCases);
|
||||
}
|
||||
return functionalCases;
|
||||
}
|
||||
|
||||
private Long countPos(String parentId) {
|
||||
|
@ -184,6 +198,15 @@ public class FunctionalCaseModuleService extends ModuleTreeService {
|
|||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<BaseTreeNode> getTrashTree(String projectId) {
|
||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
||||
functionalCaseExample.createCriteria().andDeletedEqualTo(true).andProjectIdEqualTo(projectId);
|
||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
||||
if (CollectionUtils.isEmpty(functionalCases)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> moduleIds = functionalCases.stream().map(FunctionalCase::getModuleId).distinct().toList();
|
||||
List<BaseTreeNode> baseTreeNodes = extFunctionalCaseModuleMapper.selectBaseByIds(moduleIds);
|
||||
return super.buildTreeAndCountResource(baseTreeNodes, false, Translator.get("default.module"));
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import io.metersphere.system.base.BaseTest;
|
|||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
@ -43,14 +44,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
public class FunctionalCaseModuleControllerTests extends BaseTest {
|
||||
|
||||
private static Project project;
|
||||
|
||||
private static List<BaseTreeNode> preliminaryTreeNodes = new ArrayList<>();
|
||||
|
||||
private static final String URL_MODULE_TREE = "/functional/case/module/tree/";
|
||||
private static final String URL_MODULE_TREE_ADD = "/functional/case/module/add";
|
||||
private static final String URL_MODULE_TREE_UPDATE = "/functional/case/module/update";
|
||||
|
||||
private static List<BaseTreeNode> preliminaryTreeNodes = new ArrayList<>();
|
||||
|
||||
private static final String URL_MODULE_TREE_MOVE = "/functional/case/module/move";
|
||||
private static final String URL_MODULE_TREE_DELETE = "/functional/case/module/delete/";
|
||||
private static final String URL_MODULE_TREE_TRASH = "/functional/case/module/trash/tree/";
|
||||
|
||||
|
||||
@Resource
|
||||
|
@ -662,12 +664,12 @@ public class FunctionalCaseModuleControllerTests extends BaseTest {
|
|||
// 删除有用例的节点 a1-a1 检查是否级联删除根节点
|
||||
//创建数据
|
||||
BaseTreeNode a1a1Node = getNodeByName(this.getFunctionalCaseModuleTreeNode(), "a1-a1");
|
||||
createCase(a1a1Node);
|
||||
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey("gyqTestCaseId");
|
||||
FunctionalCase name = createCase(a1a1Node, false, "name");
|
||||
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey(name.getId());
|
||||
Assertions.assertNotNull(functionalCase);
|
||||
this.requestGetWithOk(URL_MODULE_TREE_DELETE+a1a1Node.getId());
|
||||
this.checkModuleIsEmpty(a1a1Node.getId());
|
||||
FunctionalCase functionalCaseDel = functionalCaseMapper.selectByPrimaryKey("gyqTestCaseId");
|
||||
FunctionalCase functionalCaseDel = functionalCaseMapper.selectByPrimaryKey(name.getId());
|
||||
Assertions.assertTrue(functionalCaseDel.getDeleted());
|
||||
Assertions.assertTrue(StringUtils.equals(functionalCaseDel.getModuleId(), "root"));
|
||||
|
||||
|
@ -677,24 +679,61 @@ public class FunctionalCaseModuleControllerTests extends BaseTest {
|
|||
this.requestGetWithOk(URL_MODULE_TREE_DELETE+ModuleConstants.DEFAULT_NODE_ID);
|
||||
|
||||
//service层判断:测试删除空集合
|
||||
functionalCaseModuleService.deleteModuleByIds(new ArrayList<>());
|
||||
functionalCaseModuleService.deleteModuleByIds(new ArrayList<>(),new ArrayList<>());
|
||||
|
||||
checkLog(functionalCase.getId(), OperationLogType.DELETE, URL_MODULE_TREE_DELETE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void createCase(BaseTreeNode a1a1Node) {
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
public void getTrashTreeSuccess() throws Exception {
|
||||
//回收站为空
|
||||
MvcResult mvcResult = this.requestGetAndReturn(URL_MODULE_TREE_TRASH + project.getId());
|
||||
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||
List<BaseTreeNode> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
|
||||
Assertions.assertTrue(CollectionUtils.isEmpty(baseTreeNodes));
|
||||
//回收站有数据
|
||||
FunctionalCaseModuleCreateRequest request = new FunctionalCaseModuleCreateRequest();
|
||||
request.setProjectId(project.getId());
|
||||
request.setName("gyq");
|
||||
MvcResult mvcResultAdd = this.requestPostWithOkAndReturn(URL_MODULE_TREE_ADD, request);
|
||||
String returnId = mvcResultAdd.getResponse().getContentAsString();
|
||||
Assertions.assertNotNull(returnId);
|
||||
List<BaseTreeNode> treeNodes = this.getFunctionalCaseModuleTreeNode();
|
||||
BaseTreeNode a1Node = null;
|
||||
for (BaseTreeNode baseTreeNode : treeNodes) {
|
||||
if (StringUtils.equals(baseTreeNode.getName(), request.getName())) {
|
||||
a1Node = baseTreeNode;
|
||||
}
|
||||
Assertions.assertNotNull(baseTreeNode.getParentId());
|
||||
}
|
||||
Assertions.assertNotNull(a1Node);
|
||||
createCase(a1Node, true ,"name1");
|
||||
MvcResult mvcResultTrash = this.requestGetAndReturn(URL_MODULE_TREE_TRASH + project.getId());
|
||||
String contentTrash = mvcResultTrash.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolderTrash = JSON.parseObject(contentTrash, ResultHolder.class);
|
||||
List<BaseTreeNode> baseTreeNodeTrashList = JSON.parseArray(JSON.toJSONString(resultHolderTrash.getData()), BaseTreeNode.class);
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(baseTreeNodeTrashList));
|
||||
}
|
||||
|
||||
private FunctionalCase createCase(BaseTreeNode a1a1Node, Boolean deleted, String name) {
|
||||
FunctionalCase functionalCase = new FunctionalCase();
|
||||
functionalCase.setName("gyqTest");
|
||||
functionalCase.setName(name);
|
||||
functionalCase.setNum(100001);
|
||||
functionalCase.setModuleId(a1a1Node.getId());
|
||||
functionalCase.setProjectId(project.getId());
|
||||
functionalCase.setDeleted(false);
|
||||
functionalCase.setDeleted(deleted);
|
||||
functionalCase.setTemplateId("default_template");
|
||||
functionalCase.setId("gyqTestCaseId");
|
||||
functionalCase.setId(IDGenerator.nextStr());
|
||||
functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name());
|
||||
functionalCase.setCaseEditType("Text");
|
||||
functionalCase.setPos(500L);
|
||||
functionalCase.setVersionId("12335");
|
||||
functionalCase.setRefId("gyqTestCaseId");
|
||||
functionalCase.setRefId(functionalCase.getId());
|
||||
functionalCase.setLastExecuteResult(FunctionalCaseExecuteResult.UN_EXECUTED.name());
|
||||
functionalCase.setPublicCase(false);
|
||||
functionalCase.setLatest(true);
|
||||
|
@ -703,6 +742,7 @@ public class FunctionalCaseModuleControllerTests extends BaseTest {
|
|||
functionalCase.setUpdateUser("gyq");
|
||||
functionalCase.setUpdateTime(System.currentTimeMillis());
|
||||
functionalCaseMapper.insertSelective(functionalCase);
|
||||
return functionalCase;
|
||||
}
|
||||
|
||||
private void checkModuleIsEmpty(String id) {
|
||||
|
|
Loading…
Reference in New Issue