diff --git a/test-test/src/main/java/com/test/test/controller/TestGroupController.java b/test-test/src/main/java/com/test/test/controller/TestGroupController.java index 8880769..2ef9a9c 100644 --- a/test-test/src/main/java/com/test/test/controller/TestGroupController.java +++ b/test-test/src/main/java/com/test/test/controller/TestGroupController.java @@ -5,9 +5,10 @@ import com.test.common.core.controller.BaseController; import com.test.common.core.domain.AjaxResult; import com.test.common.enums.BusinessType; import com.test.test.domain.TestGroup; -import com.test.test.domain.qo.IDQO; +import com.test.test.domain.qo.GroupDelectQO; import com.test.test.service.ITestGroupService; import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -50,7 +51,7 @@ public class TestGroupController extends BaseController { */ @Log(title = "接口节点", businessType = BusinessType.DELETE) @PostMapping("/del") - public AjaxResult remove(@RequestBody IDQO qo) { - return toAjax(testGroupService.deleteTestGroupById(qo.getId())); + public AjaxResult remove(@RequestBody @Validated GroupDelectQO qo) throws Exception { + return toAjax(testGroupService.deleteTestGroupById(qo)); } } diff --git a/test-test/src/main/java/com/test/test/domain/TestApi.java b/test-test/src/main/java/com/test/test/domain/TestApi.java index 867115a..889f46e 100644 --- a/test-test/src/main/java/com/test/test/domain/TestApi.java +++ b/test-test/src/main/java/com/test/test/domain/TestApi.java @@ -8,8 +8,6 @@ import com.test.common.annotation.Excel; /** * 接口对象 test_api - * - * @author xiaoe */ @Setter @Getter diff --git a/test-test/src/main/java/com/test/test/domain/TestGroup.java b/test-test/src/main/java/com/test/test/domain/TestGroup.java index 33e721a..6e52845 100644 --- a/test-test/src/main/java/com/test/test/domain/TestGroup.java +++ b/test-test/src/main/java/com/test/test/domain/TestGroup.java @@ -8,8 +8,6 @@ import com.test.common.annotation.Excel; /** * 节点(文件夹)对象 test_group - * - * @author xiaoe */ @Setter @Getter diff --git a/test-test/src/main/java/com/test/test/domain/qo/GroupDelectQO.java b/test-test/src/main/java/com/test/test/domain/qo/GroupDelectQO.java new file mode 100644 index 0000000..d0269db --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/qo/GroupDelectQO.java @@ -0,0 +1,16 @@ +package com.test.test.domain.qo; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class GroupDelectQO { + + @NotNull(message = "节点id不能为空") + private Long id; + + @NotNull(message = "节点类型不能为空") + @NotBlank(message = "节点类型不能为空") + private String type; +} diff --git a/test-test/src/main/java/com/test/test/mapper/TestApiMapper.java b/test-test/src/main/java/com/test/test/mapper/TestApiMapper.java index c2564d0..84b7eb8 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestApiMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestApiMapper.java @@ -7,55 +7,35 @@ import com.test.test.domain.qo.TestApiListQO; /** * 接口Mapper接口 - * - * @author xiaoe */ public interface TestApiMapper { /** * 查询接口 - * - * @param id 接口主键 - * @return 接口 */ TestApi selectTestApiById(Long id); /** * 查询接口列表 - * - * @param qo 接口 - * @return 接口集合 */ List selectTestApiList(TestApiListQO qo); /** * 新增接口 - * - * @param testApi 接口 - * @return 结果 */ int insertTestApi(TestApi testApi); /** * 修改接口 - * - * @param testApi 接口 - * @return 结果 */ int updateTestApi(TestApi testApi); /** * 删除接口 - * - * @param id 接口主键 - * @return 结果 */ int deleteTestApiById(Long id); /** * 批量删除接口(通过节点id) - * - * @param groupId 需要删除的接口主键集合 - * @return 结果 */ - int deleteTestApiByGroupId(Long groupId); + int deleteTestApiByGroups(List groupIds); } diff --git a/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java b/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java index 969be5e..275fbf5 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java @@ -5,50 +5,32 @@ import com.test.test.domain.TestGroup; /** * 节点(文件夹)Mapper接口 - * - * @author xiaoe - * @date 2025-02-12 */ public interface TestGroupMapper { /** - * 查询节点(文件夹) - * - * @param id 节点(文件夹)主键 - * @return 节点(文件夹) + * 查询节点(文件夹)列表 */ - public TestGroup selectTestGroupById(Long id); + List selectTestGroupList(String type); /** * 查询节点(文件夹)列表 - * - * @param type 节点类型 - * @return 节点(文件夹)集合 */ - public List selectTestGroupList(String type); + List selectTestGroupListByParentIds(List parentIds); /** * 新增节点(文件夹) - * - * @param testGroup 节点(文件夹) - * @return 结果 */ - public int insertTestGroup(TestGroup testGroup); + int insertTestGroup(TestGroup testGroup); /** * 修改节点(文件夹) - * - * @param testGroup 节点(文件夹) - * @return 结果 */ - public int updateTestGroup(TestGroup testGroup); + int updateTestGroup(TestGroup testGroup); /** - * 删除节点(文件夹) - * - * @param id 节点(文件夹)主键 - * @return 结果 + * 批量删除节点(文件夹) */ - public int deleteTestGroupById(Long id); + int deleteTestGroupByIds(List ids); } diff --git a/test-test/src/main/java/com/test/test/service/ITestApiService.java b/test-test/src/main/java/com/test/test/service/ITestApiService.java index 2b15457..b5d688d 100644 --- a/test-test/src/main/java/com/test/test/service/ITestApiService.java +++ b/test-test/src/main/java/com/test/test/service/ITestApiService.java @@ -13,57 +13,36 @@ import com.test.test.domain.qo.TestApiListQO; public interface ITestApiService { /** * 查询接口 - * - * @param id 接口主键 - * @return 接口 */ TestApi selectTestApiById(Long id); /** * 查询接口列表 - * - * @param qo 接口 - * @return 接口集合 */ List selectTestApiList(TestApiListQO qo); /** * 新增接口 - * - * @param testApi 接口 - * @return 结果 */ int insertTestApi(TestApi testApi); /** * 导入Swagger接口 - * - * @param url Swagger文档链接 - * @return 结果 */ int importSwaggerApi(String url); /** * 修改接口 - * - * @param testApi 接口 - * @return 结果 */ int updateTestApi(TestApi testApi); /** * 批量删除接口(通过节点id) - * - * @param groupId 需要删除的接口主键集合 - * @return 结果 */ - int deleteTestApiByGroupId(Long groupId); + int deleteTestApiByGroups(List groupIds); /** * 删除接口信息 - * - * @param id 接口主键 - * @return 结果 */ int deleteTestApiById(Long id); } diff --git a/test-test/src/main/java/com/test/test/service/ITestGroupService.java b/test-test/src/main/java/com/test/test/service/ITestGroupService.java index c453995..5ab13c7 100644 --- a/test-test/src/main/java/com/test/test/service/ITestGroupService.java +++ b/test-test/src/main/java/com/test/test/service/ITestGroupService.java @@ -2,6 +2,7 @@ package com.test.test.service; import java.util.List; import com.test.test.domain.TestGroup; +import com.test.test.domain.qo.GroupDelectQO; /** * 节点(文件夹)Service接口 @@ -12,33 +13,21 @@ public interface ITestGroupService { /** * 查询节点(文件夹)列表 - * - * @param type 节点类型 - * @return 节点(文件夹)集合 */ - public List selectTestGroupList(String type); + List selectTestGroupList(String type); /** * 新增节点(文件夹) - * - * @param testGroup 节点(文件夹) - * @return 结果 */ - public TestGroup insertTestGroup(TestGroup testGroup); + TestGroup insertTestGroup(TestGroup testGroup); /** * 修改节点(文件夹) - * - * @param testGroup 节点(文件夹) - * @return 结果 */ - public int updateTestGroup(TestGroup testGroup); + int updateTestGroup(TestGroup testGroup); /** * 删除节点(文件夹)信息 - * - * @param id 节点(文件夹)主键 - * @return 结果 */ - public int deleteTestGroupById(Long id); + int deleteTestGroupById(GroupDelectQO qo) throws Exception; } diff --git a/test-test/src/main/java/com/test/test/service/impl/TestApiServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestApiServiceImpl.java index 48661be..7b4ad91 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestApiServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestApiServiceImpl.java @@ -75,8 +75,8 @@ public class TestApiServiceImpl implements ITestApiService { } @Override - public int deleteTestApiByGroupId(Long groupId) { - return testApiMapper.deleteTestApiByGroupId(groupId); + public int deleteTestApiByGroups(List groupIds) { + return testApiMapper.deleteTestApiByGroups(groupIds); } /** diff --git a/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java index a19e996..c6974f7 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java @@ -1,13 +1,18 @@ package com.test.test.service.impl; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import com.test.common.utils.DateUtils; +import com.test.common.utils.StringUtils; +import com.test.test.domain.qo.GroupDelectQO; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import com.test.test.mapper.TestGroupMapper; import com.test.test.domain.TestGroup; import com.test.test.service.ITestGroupService; +import org.springframework.transaction.annotation.Transactional; /** * 节点(文件夹)Service业务层处理 @@ -25,9 +30,6 @@ public class TestGroupServiceImpl implements ITestGroupService { /** * 查询节点(文件夹)列表 - * - * @param type 节点类型 - * @return 节点(文件夹) */ @Override public List selectTestGroupList(String type) { @@ -36,9 +38,6 @@ public class TestGroupServiceImpl implements ITestGroupService { /** * 新增节点(文件夹) - * - * @param testGroup 节点(文件夹) - * @return 结果 */ @Override public TestGroup insertTestGroup(TestGroup testGroup) { @@ -49,9 +48,6 @@ public class TestGroupServiceImpl implements ITestGroupService { /** * 修改节点(文件夹) - * - * @param testGroup 节点(文件夹) - * @return 结果 */ @Override public int updateTestGroup(TestGroup testGroup) { @@ -61,13 +57,38 @@ public class TestGroupServiceImpl implements ITestGroupService { /** * 删除节点(文件夹)信息 - * - * @param id 节点(文件夹)主键 - * @return 结果 */ @Override - public int deleteTestGroupById(Long id) { + @Transactional + public int deleteTestGroupById(GroupDelectQO qo) throws Exception { + // 获取所有叶子节点 + List idList = new ArrayList<>(List.of(qo.getId())); + idList.addAll(getAllChildrenId(idList)); + // 删除节点 + switch (qo.getType()) { + case "api": + testApiServiceImpl.deleteTestApiByGroups(idList); + break; + case "case": + System.out.println("case"); + break; + case "task": + System.out.println("task"); + break; + default: + throw new Exception(StringUtils.format("文件夹类型({})非法。 ", qo.getType())); + } + return testGroupMapper.deleteTestGroupByIds(idList); + } - return testGroupMapper.deleteTestGroupById(id); + private List getAllChildrenId(List parentIds) { + List idList = testGroupMapper.selectTestGroupListByParentIds(parentIds).stream().map(TestGroup::getId).collect(Collectors.toList()); + if (!idList.isEmpty()) { + List childrenIds = getAllChildrenId(idList); + if (!childrenIds.isEmpty()) { + idList.addAll(childrenIds); + } + } + return idList; } } diff --git a/test-test/src/main/resources/mapper/test/TestApiMapper.xml b/test-test/src/main/resources/mapper/test/TestApiMapper.xml index 1879a7d..ef4cde5 100644 --- a/test-test/src/main/resources/mapper/test/TestApiMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestApiMapper.xml @@ -94,7 +94,10 @@ delete from test_api where id = #{id} - - delete from test_api where groupId = #{groupId} + + delete from test_api where group_id in + + #{groupId} + \ No newline at end of file diff --git a/test-test/src/main/resources/mapper/test/TestGroupMapper.xml b/test-test/src/main/resources/mapper/test/TestGroupMapper.xml index 1d20097..29ef807 100644 --- a/test-test/src/main/resources/mapper/test/TestGroupMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestGroupMapper.xml @@ -27,9 +27,14 @@ - - where id = #{id} + + parent_id in + + #{parentId} + + @@ -71,13 +76,9 @@ where id = #{id} - - delete from test_group where id = #{id} - - delete from test_group where id in - + #{id} diff --git a/test-ui/src/api/test/group.js b/test-ui/src/api/test/group.js index b60116a..fc48ce4 100644 --- a/test-ui/src/api/test/group.js +++ b/test-ui/src/api/test/group.js @@ -28,10 +28,10 @@ export function updateGroup(data) { } // 删除节点 -export function delGroup(id) { +export function delGroup(id, type) { return request({ url: '/test/group/del', method: 'post', - data: {id} + data: {id, type} }) } diff --git a/test-ui/src/components/FolderPage/index.vue b/test-ui/src/components/FolderPage/index.vue index 10bf009..f0e6b65 100644 --- a/test-ui/src/components/FolderPage/index.vue +++ b/test-ui/src/components/FolderPage/index.vue @@ -159,14 +159,13 @@ export default { }, nodeDelete(node) { this.$refs.tree.setCurrentKey(this.groupId); - if (node.data.children && node.data.children.length > 0) { - this.$message.error("包含子节点,无法删除") - return - } - this.$modal.confirm('是否确认删除?').then(function () { - return delGroup(node.data.id); + this.$modal.confirm('是否确认删除?会连带删除文件夹下所有内容').then(() => { + return delGroup(node.data.id, this.type); }).then(() => { this.$modal.msgSuccess("删除成功"); + if (this.groupId === node.data.id) { + this.$emit("click", null); + } this.$refs.tree.remove(node) }) }, diff --git a/test-ui/src/views/test/api/index.vue b/test-ui/src/views/test/api/index.vue index 6d83f32..5aec5db 100644 --- a/test-ui/src/views/test/api/index.vue +++ b/test-ui/src/views/test/api/index.vue @@ -87,8 +87,12 @@ export default { }, methods: { folderHandleSelected(id) { - this.queryParams.groupId = id; - this.getList(); + if (id) { + this.queryParams.groupId = id; + this.getList(); + } else { + this.apiList = []; + } }, /** 查询接口列表 */ getList() {