提交 42400e44 authored 作者: mry's avatar mry

fix(web): 数据模型同步

上级 01551216
...@@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode; ...@@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.matrix.enums.SyncStatus; import org.matrix.enums.SyncStatus;
import org.matrix.vo.InterfaceDocVo; import org.matrix.vo.InterfaceDocVo;
import org.matrix.vo.InterfaceSortVo;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
/** /**
...@@ -118,4 +119,11 @@ public class InterfaceDoc extends BaseEntity { ...@@ -118,4 +119,11 @@ public class InterfaceDoc extends BaseEntity {
BeanUtils.copyProperties(this, interfaceDocVo); BeanUtils.copyProperties(this, interfaceDocVo);
return interfaceDocVo; return interfaceDocVo;
} }
public InterfaceSortVo toInterfaceSortVo() {
InterfaceSortVo interfaceSortVo = new InterfaceSortVo();
BeanUtils.copyProperties(this, interfaceSortVo);
interfaceSortVo.setUrl(this.getHttpMethod() + this.getPathUrl());
return interfaceSortVo;
}
} }
package org.matrix.enums; package org.matrix.enums;
import com.baomidou.mybatisplus.annotation.EnumValue; import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
...@@ -18,32 +17,18 @@ public enum SyncStatus { ...@@ -18,32 +17,18 @@ public enum SyncStatus {
/** /**
* 覆盖 * 覆盖
*/ */
UPDATE(0, "更新"), UPDATE(0, "已同步"),
/** /**
* 新增 * 新增
*/ */
INSERT(1, "新增"), INSERT(1, "新增"),
/**
* 复制
*/
COPY(2, "同时存在"),
/** /**
* 未同步 * 未同步
*/ */
NO(3, "未同步"), NO(2, "未同步");
/**
* 上次忽略的
*/
IGNORE(4,"上次忽略的"),
/**
* 上次导入不存在
*/
OTHER(4, "上次导入不存在");
@EnumValue @EnumValue
private final int code; private final int code;
......
...@@ -50,28 +50,40 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC ...@@ -50,28 +50,40 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
Map<Long, List<InterfaceGroupVo>> interfaceGroupingVosMap, Map<Long, List<InterfaceGroupVo>> interfaceGroupingVosMap,
Map<Long, List<TestCaseVo>> testCaseVosMap, Map<Long, List<TestCaseVo>> testCaseVosMap,
List<InterfaceGroupVo> interfaceGroupVos) { List<InterfaceGroupVo> interfaceGroupVos) {
if (interfaceGroupVos.size() != 0) { if (!CollectionUtils.isEmpty(interfaceGroupVos)) {
//根据父分组,查出所有的子分组 //根据父分组,查出所有的子分组
for (InterfaceGroupVo interfaceGroupVo : interfaceGroupVos) { for (InterfaceGroupVo interfaceGroupVo : interfaceGroupVos) {
if (interfaceGroupVo.getId() != null) { if (interfaceGroupVo.getId() != null) {
interfaceGroupVo.setSort("group");
//父分组id //父分组id
Long groupId = interfaceGroupVo.getId(); Long groupId = interfaceGroupVo.getId();
//分组下的分组 //分组下的分组
List<InterfaceGroupVo> interfaceGroupVoList = interfaceGroupingVosMap.get(groupId); List<InterfaceGroupVo> interfaceGroupVoList = interfaceGroupingVosMap.get(groupId);
if (!CollectionUtils.isEmpty(interfaceGroupVoList)) {
for (InterfaceGroupVo groupVo : interfaceGroupVoList) {
groupVo.setSort("group");
}
}
//分组下的接口 //分组下的接口
List<InterfaceDocVo> interfaceDocVoList = interfaceDocVosMap.get(groupId); List<InterfaceDocVo> interfaceDocVoList = interfaceDocVosMap.get(groupId);
//找接口下的测试用例 //找接口下的测试用例
if (interfaceDocVoList != null) { if (!CollectionUtils.isEmpty(interfaceDocVoList)) {
for (InterfaceDocVo interfaceDocVo : interfaceDocVoList) { for (InterfaceDocVo interfaceDocVo : interfaceDocVoList) {
if (interfaceDocVo.getId() != null) { if (interfaceDocVo.getId() != null) {
interfaceDocVo.setSort("doc");
Long docId = interfaceDocVo.getId(); Long docId = interfaceDocVo.getId();
List<TestCaseVo> testCaseVos = testCaseVosMap.get(docId); List<TestCaseVo> testCaseVos = testCaseVosMap.get(docId);
interfaceDocVo.setTestCaseVos(testCaseVos); if (!CollectionUtils.isEmpty(testCaseVos)) {
for (TestCaseVo testCaseVo : testCaseVos) {
testCaseVo.setSort("testCase");
}
}
interfaceDocVo.setChildren(testCaseVos);
} }
} }
} }
interfaceGroupVo.setInterfaceGroupVos(interfaceGroupVoList); interfaceGroupVo.setInterfaceGroupVos(interfaceGroupVoList);
interfaceGroupVo.setInterfaceDocVos(interfaceDocVoList); interfaceGroupVo.setChildren(interfaceDocVoList);
if (!CollectionUtils.isEmpty(interfaceGroupVoList)) { if (!CollectionUtils.isEmpty(interfaceGroupVoList)) {
getRecursiveGrouping(interfaceDocVosMap, interfaceGroupingVosMap, testCaseVosMap, interfaceGroupVoList); getRecursiveGrouping(interfaceDocVosMap, interfaceGroupingVosMap, testCaseVosMap, interfaceGroupVoList);
} }
...@@ -91,6 +103,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC ...@@ -91,6 +103,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
.eq(InterfaceGrouping::getProjectId, projectId))).orElse(new ArrayList<>()); .eq(InterfaceGrouping::getProjectId, projectId))).orElse(new ArrayList<>());
for (InterfaceGrouping interfaceGrouping : interfaceGroupings) { for (InterfaceGrouping interfaceGrouping : interfaceGroupings) {
InterfaceGroupVo interfaceGroupVo = interfaceGrouping.toInterfaceGroupVo(); InterfaceGroupVo interfaceGroupVo = interfaceGrouping.toInterfaceGroupVo();
interfaceGroupVo.setLabel(interfaceGrouping.getTag());
interfaceGroupVo.setSort("group");
interfaceGroupVos.add(interfaceGroupVo); interfaceGroupVos.add(interfaceGroupVo);
} }
//key: 父分组id value : 接口分组集合 //key: 父分组id value : 接口分组集合
...@@ -111,6 +125,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC ...@@ -111,6 +125,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
.eq(InterfaceDoc::getProjectId, projectId))).orElse(new ArrayList<>()); .eq(InterfaceDoc::getProjectId, projectId))).orElse(new ArrayList<>());
for (InterfaceDoc interfaceDoc : interfaceDocs) { for (InterfaceDoc interfaceDoc : interfaceDocs) {
InterfaceDocVo interfaceDocVo = interfaceDoc.toInterfaceDocVo(); InterfaceDocVo interfaceDocVo = interfaceDoc.toInterfaceDocVo();
interfaceDocVo.setSort("doc");
interfaceDocVo.setLabel(interfaceDoc.getSummary());
interfaceDocVos.add(interfaceDocVo); interfaceDocVos.add(interfaceDocVo);
} }
//key : 接口分组主键id value : 接口文档集合 //key : 接口分组主键id value : 接口文档集合
...@@ -121,7 +137,7 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC ...@@ -121,7 +137,7 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
List<InterfaceDocVo> firstInterfaceDocVos = new ArrayList<>(); List<InterfaceDocVo> firstInterfaceDocVos = new ArrayList<>();
if (interfaceDocVosMap.get(-1L) != null) { if (interfaceDocVosMap.get(-1L) != null) {
firstInterfaceDocVos = interfaceDocVosMap.get(-1L); firstInterfaceDocVos = interfaceDocVosMap.get(-1L);
groupVo.setInterfaceDocVos(firstInterfaceDocVos); groupVo.setChildren(firstInterfaceDocVos);
} }
//所有测试用例 //所有测试用例
...@@ -130,6 +146,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC ...@@ -130,6 +146,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
.eq(Case::getProjectId, projectId))).orElse(new ArrayList<>()); .eq(Case::getProjectId, projectId))).orElse(new ArrayList<>());
for (Case aCase : cases) { for (Case aCase : cases) {
TestCaseVo testCaseVo = aCase.toTestCaseVo(); TestCaseVo testCaseVo = aCase.toTestCaseVo();
testCaseVo.setSort("testCase");
testCaseVo.setLabel(aCase.getName());
testCaseVos.add(testCaseVo); testCaseVos.add(testCaseVo);
} }
//key : 接口文档id value : 测试用例集合 //key : 接口文档id value : 测试用例集合
...@@ -144,12 +162,11 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC ...@@ -144,12 +162,11 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
Long id = firstInterfaceDocVo.getId(); Long id = firstInterfaceDocVo.getId();
//接口中所有的测试用例 //接口中所有的测试用例
List<TestCaseVo> testCaseVoList = testCaseVosMap.get(id); List<TestCaseVo> testCaseVoList = testCaseVosMap.get(id);
firstInterfaceDocVo.setTestCaseVos(testCaseVoList); firstInterfaceDocVo.setChildren(testCaseVoList);
} }
} }
getRecursiveGrouping(interfaceDocVosMap, interfaceGroupingVosMap, testCaseVosMap, firstInterfaceVoGroupings); getRecursiveGrouping(interfaceDocVosMap, interfaceGroupingVosMap, testCaseVosMap, firstInterfaceVoGroupings);
return groupVo; return groupVo;
} }
} }
...@@ -11,6 +11,7 @@ import org.matrix.service.IEnvironmentService; ...@@ -11,6 +11,7 @@ import org.matrix.service.IEnvironmentService;
import org.matrix.vo.StatusCode; import org.matrix.vo.StatusCode;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -46,16 +47,18 @@ public class EnvironmentServiceImpl extends ServiceImpl<EnvironmentMapper, Envir ...@@ -46,16 +47,18 @@ public class EnvironmentServiceImpl extends ServiceImpl<EnvironmentMapper, Envir
StatusCode statusCode = new StatusCode(); StatusCode statusCode = new StatusCode();
statusCode.setSwaggerDataType(SwaggerDataType.ENV); statusCode.setSwaggerDataType(SwaggerDataType.ENV);
if (environment != null && environment.getIp() != null) { if (environment != null && environment.getIp() != null) {
//根据新导入的环境ip判断项目中是否存在相同的ip
List<Environment> environments = Optional.ofNullable(environmentMapper.selectList(Wrappers.lambdaQuery(Environment.class) List<Environment> environments = Optional.ofNullable(environmentMapper.selectList(Wrappers.lambdaQuery(Environment.class)
.eq(Environment::getProjectId, environment.getProjectId()))).orElse(new ArrayList<>()); .eq(Environment::getProjectId, environment.getProjectId())
for (Environment env : environments) { .eq(Environment::getIp, environment.getIp()))).orElse(new ArrayList<>());
if (environment.getIp().equals(env.getIp())) { //存在则修改,不存在则直接添加
Integer integer = Optional.of(environmentMapper.updateById(environment)).orElseThrow(() -> new GlobalException("修改失败")); if (!CollectionUtils.isEmpty(environments)) {
updateNum = updateNum + integer; //找到当前数据主键id
} Long id = environments.get(0).getId();
break; environment.setId(id);
} Integer integer = Optional.of(environmentMapper.updateById(environment)).orElseThrow(() -> new GlobalException("修改失败"));
if (updateNum == 0) { updateNum = updateNum + integer;
} else {
Integer integer = Optional.of(environmentMapper.insert(environment)).orElseThrow(() -> new GlobalException("添加失败")); Integer integer = Optional.of(environmentMapper.insert(environment)).orElseThrow(() -> new GlobalException("添加失败"));
saveNum = saveNum + integer; saveNum = saveNum + integer;
} }
......
...@@ -22,7 +22,7 @@ import java.util.List; ...@@ -22,7 +22,7 @@ import java.util.List;
public class InterfaceDocVo { public class InterfaceDocVo {
@ApiModelProperty("接口文档下可以存在多个测试用例") @ApiModelProperty("接口文档下可以存在多个测试用例")
private List<TestCaseVo> testCaseVos; private List<TestCaseVo> children;
/** /**
* id * id
...@@ -35,7 +35,7 @@ public class InterfaceDocVo { ...@@ -35,7 +35,7 @@ public class InterfaceDocVo {
*/ */
@TableField(fill = FieldFill.UPDATE) @TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("名称") @ApiModelProperty("名称")
private String summary; private String label;
/** /**
* 说明 * 说明
...@@ -113,4 +113,9 @@ public class InterfaceDocVo { ...@@ -113,4 +113,9 @@ public class InterfaceDocVo {
@TableField(fill = FieldFill.UPDATE) @TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("负责人") @ApiModelProperty("负责人")
private String dutyPeople; private String dutyPeople;
/**
* 用来区分分组,接口,用例
*/
public String sort;
} }
package org.matrix.vo; package org.matrix.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
...@@ -30,7 +28,7 @@ public class InterfaceGroupVo { ...@@ -30,7 +28,7 @@ public class InterfaceGroupVo {
* 分组下可以存在多个接口 * 分组下可以存在多个接口
*/ */
@ApiModelProperty("分组下可以存在多个接口") @ApiModelProperty("分组下可以存在多个接口")
private List<InterfaceDocVo> interfaceDocVos; private List<InterfaceDocVo> children;
/** /**
* id * id
...@@ -41,49 +39,47 @@ public class InterfaceGroupVo { ...@@ -41,49 +39,47 @@ public class InterfaceGroupVo {
/** /**
* 名称(标签/分组(存在根目录)) * 名称(标签/分组(存在根目录))
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("名称(标签/分组(存在根目录))") @ApiModelProperty("名称(标签/分组(存在根目录))")
private String tag; private String label;
/** /**
* 说明 * 说明
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("说明") @ApiModelProperty("说明")
private String des; private String des;
/** /**
* 环境id * 环境id
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("环境id") @ApiModelProperty("环境id")
private Long envId; private Long envId;
/** /**
* 项目id * 项目id
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("项目id") @ApiModelProperty("项目id")
private Long projectId; private Long projectId;
/** /**
* 前置操作id * 前置操作id
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("前置操作id") @ApiModelProperty("前置操作id")
private Long moveBefore; private Long moveBefore;
/** /**
* 后置操作id * 后置操作id
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("后置操作id") @ApiModelProperty("后置操作id")
private Long moveAfter; private Long moveAfter;
/** /**
* 父类id(根目录默认为0) * 父类id(根目录默认为0)
*/ */
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("父类id(根目录默认为0)") @ApiModelProperty("父类id(根目录默认为0)")
private Long interfaceGroupingId; private Long interfaceGroupingId;
/**
* 用来区分分组,接口,用例
*/
public String sort;
} }
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;
}
}
...@@ -29,7 +29,7 @@ public class TestCaseVo { ...@@ -29,7 +29,7 @@ public class TestCaseVo {
*/ */
@TableField(fill = FieldFill.UPDATE) @TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("名称") @ApiModelProperty("名称")
private String name; private String label;
/** /**
* 接口文档id * 接口文档id
...@@ -73,4 +73,9 @@ public class TestCaseVo { ...@@ -73,4 +73,9 @@ public class TestCaseVo {
@ApiModelProperty("项目id") @ApiModelProperty("项目id")
private Long projectId; private Long projectId;
/**
* 用来区分分组,接口,用例
*/
public String sort;
} }
package org.matrix.autotest.controller; package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.matrix.entity.InterfaceGrouping; import org.matrix.entity.InterfaceGrouping;
...@@ -11,6 +12,8 @@ import org.springframework.http.ResponseEntity; ...@@ -11,6 +12,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional; import java.util.Optional;
/** /**
...@@ -57,4 +60,12 @@ public class InterfaceGroupingController { ...@@ -57,4 +60,12 @@ public class InterfaceGroupingController {
return ResponseEntity.ok(String.format("删除成功,删除的接口分组id为: %d", id)); return ResponseEntity.ok(String.format("删除成功,删除的接口分组id为: %d", id));
} }
@ApiOperation("查询当前项目下所有接口分组")
@GetMapping
public ResponseEntity<List<InterfaceGrouping>> findInterfaceGrouping(@RequestParam Long projectId) {
List<InterfaceGrouping> interfaceGroupings = Optional.ofNullable(interfaceGroupingService.list(Wrappers.lambdaQuery(InterfaceGrouping.class)
.eq(InterfaceGrouping::getProjectId, projectId))).orElse(new ArrayList<>());
return ResponseEntity.ok(interfaceGroupings);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论