联动删除
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.test.common.annotation.Excel;
|
||||
|
||||
/**
|
||||
* 接口对象 test_api
|
||||
*
|
||||
* @author xiaoe
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.test.common.annotation.Excel;
|
||||
|
||||
/**
|
||||
* 节点(文件夹)对象 test_group
|
||||
*
|
||||
* @author xiaoe
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<TestApi> 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<Long> groupIds);
|
||||
}
|
||||
|
||||
@@ -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<TestGroup> selectTestGroupList(String type);
|
||||
|
||||
/**
|
||||
* 查询节点(文件夹)列表
|
||||
*
|
||||
* @param type 节点类型
|
||||
* @return 节点(文件夹)集合
|
||||
*/
|
||||
public List<TestGroup> selectTestGroupList(String type);
|
||||
List<TestGroup> selectTestGroupListByParentIds(List<Long> 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<Long> ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<TestApi> 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<Long> groupIds);
|
||||
|
||||
/**
|
||||
* 删除接口信息
|
||||
*
|
||||
* @param id 接口主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteTestApiById(Long id);
|
||||
}
|
||||
|
||||
@@ -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<TestGroup> selectTestGroupList(String type);
|
||||
List<TestGroup> 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;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ public class TestApiServiceImpl implements ITestApiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteTestApiByGroupId(Long groupId) {
|
||||
return testApiMapper.deleteTestApiByGroupId(groupId);
|
||||
public int deleteTestApiByGroups(List<Long> groupIds) {
|
||||
return testApiMapper.deleteTestApiByGroups(groupIds);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<TestGroup> 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<Long> 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<Long> getAllChildrenId(List<Long> parentIds) {
|
||||
List<Long> idList = testGroupMapper.selectTestGroupListByParentIds(parentIds).stream().map(TestGroup::getId).collect(Collectors.toList());
|
||||
if (!idList.isEmpty()) {
|
||||
List<Long> childrenIds = getAllChildrenId(idList);
|
||||
if (!childrenIds.isEmpty()) {
|
||||
idList.addAll(childrenIds);
|
||||
}
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,10 @@
|
||||
delete from test_api where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTestApiByGroupId" parameterType="Long">
|
||||
delete from test_api where groupId = #{groupId}
|
||||
<delete id="deleteTestApiByGroups" parameterType="String">
|
||||
delete from test_api where group_id in
|
||||
<foreach item="groupId" collection="list" open="(" separator="," close=")">
|
||||
#{groupId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -27,9 +27,14 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectTestGroupById" parameterType="Long" resultMap="TestGroupResult">
|
||||
<select id="selectTestGroupListByParentIds" parameterType="String" resultMap="TestGroupResult">
|
||||
<include refid="selectTestGroupVo"/>
|
||||
where id = #{id}
|
||||
<where>
|
||||
parent_id in
|
||||
<foreach item="parentId" collection="list" open="(" separator="," close=")">
|
||||
#{parentId}
|
||||
</foreach>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertTestGroup" parameterType="TestGroup" useGeneratedKeys="true" keyProperty="id">
|
||||
@@ -71,13 +76,9 @@
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteTestGroupById" parameterType="Long">
|
||||
delete from test_group where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTestGroupByIds" parameterType="String">
|
||||
delete from test_group where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
<foreach item="id" collection="list" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
@@ -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}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
},
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user