提交 974d9ee4 authored 作者: mry's avatar mry

fix(web): 递归删除分组以及分组下的接口,用例,或者数据模型

上级 cf7b1990
......@@ -11,7 +11,6 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.matrix.enums.SyncStatus;
import org.matrix.vo.InterfaceDocVo;
import org.matrix.vo.InterfaceSortVo;
import org.springframework.beans.BeanUtils;
/**
......@@ -120,10 +119,4 @@ public class InterfaceDoc extends BaseEntity {
return interfaceDocVo;
}
public InterfaceSortVo toInterfaceSortVo() {
InterfaceSortVo interfaceSortVo = new InterfaceSortVo();
BeanUtils.copyProperties(this, interfaceSortVo);
interfaceSortVo.setUrl(this.getHttpMethod() + this.getPathUrl());
return interfaceSortVo;
}
}
......@@ -2,13 +2,16 @@ package org.matrix.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.entity.Case;
import org.matrix.entity.InterfaceDoc;
import org.matrix.entity.InterfaceGrouping;
import org.matrix.mapper.CaseMapper;
import org.matrix.mapper.InterfaceDocMapper;
import org.matrix.mapper.InterfaceGroupingMapper;
import org.matrix.service.IInterfaceGroupingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -27,48 +30,54 @@ public class InterfaceGroupingServiceImpl extends ServiceImpl<InterfaceGroupingM
@Autowired
private InterfaceDocMapper interfaceDocMapper;
@Autowired
private CaseMapper caseMapper;
@Override
public void removeInterfaceGrouping(Long id) {
//删除当前分组下的接口文档
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getInterfaceGroupId, id))).orElse(new ArrayList<>());
if (interfaceDocs.size() != 0) {
interfaceDocMapper.deleteBatchIds(interfaceDocs);
List<Long> list = getGroupIds(id);
//所有的分组id
for (Long groupId : list) {
//分组下的接口
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getInterfaceGroupId, groupId))).orElse(new ArrayList<>());
if (!CollectionUtils.isEmpty(interfaceDocs)) {
//删除接口下的测试用例
for (InterfaceDoc interfaceDoc : interfaceDocs) {
List<Case> cases = Optional.ofNullable(caseMapper.selectList(Wrappers.lambdaQuery(Case.class)
.eq(Case::getDocId, interfaceDoc.getId()))).orElse(new ArrayList<>());
if (!CollectionUtils.isEmpty(cases)) {
caseMapper.deleteBatchIds(cases);
}
}
//测试用例删除完成,删除接口
interfaceDocMapper.deleteBatchIds(interfaceDocs);
}
//最后删除分组
interfaceGroupingMapper.deleteBatchIds(list);
interfaceGroupingMapper.deleteById(id);
}
recursionInterface(id);
//最后删除当前分组
interfaceGroupingMapper.deleteById(id);
}
/**
* 递归处理当前分组下的分组
* 获取所有分组的主键id
*
* @param id 当前分组id
* @param id 当前要删除的分组id
* @return 该分组下所有分组的主键id, 也包括当前分组本身
*/
public void recursionInterface(Long id) {
//找到当前分组下的子分组
private List<Long> getGroupIds(Long id) {
List<Long> list = new ArrayList<>();
//根据分组id找到分组下的分组
List<InterfaceGrouping> interfaceGroupings = Optional.ofNullable(interfaceGroupingMapper.selectList(Wrappers.lambdaQuery(InterfaceGrouping.class)
.eq(InterfaceGrouping::getInterfaceGroupingId, id))).orElse(new ArrayList<>());
//是否存在子分组,如果不存在就不做任何操作,如果存在进入下一层
if (interfaceGroupings.size() != 0) {
//找到当前分组下的每个子类分组
//存在分组
if (!CollectionUtils.isEmpty(interfaceGroupings)) {
for (InterfaceGrouping interfaceGrouping : interfaceGroupings) {
//删除子类分组中的数据模型
Long groupingId = interfaceGrouping.getId();
List<InterfaceGrouping> recursionsInterfaces = Optional.ofNullable(interfaceGroupingMapper.selectList(Wrappers.lambdaQuery(InterfaceGrouping.class)
.eq(InterfaceGrouping::getInterfaceGroupingId, groupingId))).orElse(new ArrayList<>());
if (recursionsInterfaces.size() != 0) {
interfaceDocMapper.deleteBatchIds(recursionsInterfaces);
}
recursionInterface(groupingId);
//删除当前分组下的接口
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getInterfaceGroupId, groupingId))).orElse(new ArrayList<>());
if (interfaceDocs.size() != 0) {
interfaceDocMapper.deleteBatchIds(interfaceDocs);
}
list.add(interfaceGrouping.getId());
getGroupIds(interfaceGrouping.getId());
}
}
return list;
}
}
......@@ -9,6 +9,7 @@ import org.matrix.mapper.MouldGroupingMapper;
import org.matrix.service.IMouldGroupingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -29,46 +30,32 @@ public class MouldGroupingServiceImpl extends ServiceImpl<MouldGroupingMapper, M
@Override
public void removeMould(Long id) {
//删除当前分组下的数据模型
List<MouldDoc> mouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getMouldGroupingId, id))).orElse(new ArrayList<>());
if (mouldDocs.size() != 0) {
mouldDocMapper.deleteBatchIds(mouldDocs);
List<Long> list = getGroupIds(id);
for (Long groupId : list) {
//分组下的数据模型
List<MouldDoc> mouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getMouldGroupingId, groupId))).orElse(new ArrayList<>());
if (!CollectionUtils.isEmpty(mouldDocs)) {
mouldDocMapper.deleteBatchIds(mouldDocs);
}
}
recursionMould(id);
//最后删除当前分组
mouldGroupingMapper.deleteBatchIds(list);
mouldGroupingMapper.deleteById(id);
}
/**
* 递归处理当前分组下的分组
*
* @param id 当前分组id
*/
public void recursionMould(Long id) {
//找到当前分组下的子分组
private List<Long> getGroupIds(Long id) {
List<Long> list = new ArrayList<>();
//根据分组id找到分组下的分组
List<MouldGrouping> mouldGroupings = Optional.ofNullable(mouldGroupingMapper.selectList(Wrappers.lambdaQuery(MouldGrouping.class)
.eq(MouldGrouping::getMouldId, id))).orElse(new ArrayList<>());
//是否存在子分组,如果不存在就不做任何操作,如果存在进入下一层
if (mouldGroupings.size() != 0) {
//找到当前分组下的每个子类分组
//存在分组
if (!CollectionUtils.isEmpty(mouldGroupings)) {
for (MouldGrouping mouldGrouping : mouldGroupings) {
//删除子类分组中的数据模型
Long groupingId = mouldGrouping.getId();
List<MouldGrouping> recursionsMoulds = Optional.ofNullable(mouldGroupingMapper.selectList(Wrappers.lambdaQuery(MouldGrouping.class)
.eq(MouldGrouping::getMouldId, groupingId))).orElse(new ArrayList<>());
if (recursionsMoulds.size() != 0) {
mouldDocMapper.deleteBatchIds(recursionsMoulds);
}
recursionMould(groupingId);
//删除当前分组下的接口
List<MouldDoc> mouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getMouldGroupingId, groupingId))).orElse(new ArrayList<>());
if (mouldDocs.size() != 0) {
mouldDocMapper.deleteBatchIds(mouldDocs);
}
list.add(mouldGrouping.getId());
getGroupIds(mouldGrouping.getId());
}
}
return list;
}
}
package org.matrix.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.matrix.entity.InterfaceDoc;
import org.matrix.enums.SyncStatus;
import org.springframework.beans.BeanUtils;
/**
* @author mruny
* @create 2022/8/5 16:03:14
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InterfaceSortVo {
/**
* id
*/
private Long id;
/**
* 名称
*/
@ApiModelProperty("名称")
private String summary;
/**
* 说明
*/
@ApiModelProperty("说明")
private String des;
/**
* 请求方式
*/
@ApiModelProperty("请求方式")
private String httpMethod;
/**
* 接口相对路径
*/
@ApiModelProperty("接口相对路径")
private String pathUrl;
/**
* 参数详情(整段json)
*/
@ApiModelProperty("参数详情(整段json)")
private String parameters;
/**
* 返回值信息(整段json)
*/
@ApiModelProperty("返回值信息(整段json)")
private String responses;
/**
* 项目id
*/
@ApiModelProperty("项目id")
private Long projectId;
/**
* 环境id
*/
@ApiModelProperty("环境id")
private Long envId;
/**
* 分组id
*/
@ApiModelProperty("分组id")
private Long interfaceGroupId;
/**
* 同步状态
*/
@ApiModelProperty("同步状态")
private SyncStatus status;
/**
* 开发状态
*/
@ApiModelProperty("开发状态")
private String devStatus;
/**
* 负责人
*/
@ApiModelProperty("负责人")
private String dutyPeople;
@ApiModelProperty("请求以及url相对路径")
private String url;
public InterfaceDoc toInterfaceDoc() {
InterfaceDoc interfaceDoc = new InterfaceDoc();
BeanUtils.copyProperties(this, interfaceDoc);
return interfaceDoc;
}
}
package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.matrix.entity.Case;
......@@ -12,8 +11,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
......@@ -45,10 +42,10 @@ public class CaseController {
@ApiOperation("添加测试用例")
@PostMapping
public ResponseEntity<Case> insertCase(@RequestBody Case aCase) {
return Optional.of(caseService.save(aCase)).orElseThrow(() -> new GlobalException("添加失败"))
? ResponseEntity.ok(aCase)
: ResponseEntity.status(HttpStatus.BAD_REQUEST).body(aCase);
public ResponseEntity<Case> insertCase(@RequestBody Case testCase) {
return Optional.of(caseService.save(testCase)).orElseThrow(() -> new GlobalException("添加失败"))
? ResponseEntity.ok(testCase)
: ResponseEntity.status(HttpStatus.BAD_REQUEST).body(testCase);
}
@ApiOperation("修改测试用例")
......@@ -59,15 +56,6 @@ public class CaseController {
: ResponseEntity.status(HttpStatus.BAD_REQUEST).body(aCase);
}
@ApiOperation("查询快捷请求")
@GetMapping
public ResponseEntity<List<Case>> findCase(@RequestParam Long projectId) {
List<Case> cases = Optional.ofNullable(caseService.list(Wrappers.lambdaQuery(Case.class)
.eq(Case::getProjectId, projectId)
.eq(Case::getDocId, -1L))).orElse(new ArrayList<>());
return ResponseEntity.ok(cases);
}
@ApiOperation("查询当前项目下所有分组,以及分组下的接口,测试用例等")
@GetMapping("/all")
public ResponseEntity<InterfaceGroupVo> findAll(@RequestParam Long projectId) {
......
......@@ -52,7 +52,7 @@ public class InterfaceGroupingController {
return ResponseEntity.ok(interfaceGrouping);
}
@ApiOperation("根据接口分组主键id删除分组以及分组下所有分组和接口文档")
@ApiOperation("根据接口分组主键id删除分组以及分组下所有分组,接口文档,测试用例")
@DeleteMapping("/{id}")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> removeInterfaceGrouping(@PathVariable Long id) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论