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

fix(web): 数据模型同步

上级 01551216
......@@ -11,6 +11,7 @@ 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;
/**
......@@ -118,4 +119,11 @@ public class InterfaceDoc extends BaseEntity {
BeanUtils.copyProperties(this, 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;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
......@@ -18,32 +17,18 @@ public enum SyncStatus {
/**
* 覆盖
*/
UPDATE(0, "更新"),
UPDATE(0, "已同步"),
/**
* 新增
*/
INSERT(1, "新增"),
/**
* 复制
*/
COPY(2, "同时存在"),
/**
* 未同步
*/
NO(3, "未同步"),
/**
* 上次忽略的
*/
IGNORE(4,"上次忽略的"),
NO(2, "未同步");
/**
* 上次导入不存在
*/
OTHER(4, "上次导入不存在");
@EnumValue
private final int code;
......
......@@ -50,28 +50,40 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
Map<Long, List<InterfaceGroupVo>> interfaceGroupingVosMap,
Map<Long, List<TestCaseVo>> testCaseVosMap,
List<InterfaceGroupVo> interfaceGroupVos) {
if (interfaceGroupVos.size() != 0) {
if (!CollectionUtils.isEmpty(interfaceGroupVos)) {
//根据父分组,查出所有的子分组
for (InterfaceGroupVo interfaceGroupVo : interfaceGroupVos) {
if (interfaceGroupVo.getId() != null) {
interfaceGroupVo.setSort("group");
//父分组id
Long groupId = interfaceGroupVo.getId();
//分组下的分组
List<InterfaceGroupVo> interfaceGroupVoList = interfaceGroupingVosMap.get(groupId);
if (!CollectionUtils.isEmpty(interfaceGroupVoList)) {
for (InterfaceGroupVo groupVo : interfaceGroupVoList) {
groupVo.setSort("group");
}
}
//分组下的接口
List<InterfaceDocVo> interfaceDocVoList = interfaceDocVosMap.get(groupId);
//找接口下的测试用例
if (interfaceDocVoList != null) {
if (!CollectionUtils.isEmpty(interfaceDocVoList)) {
for (InterfaceDocVo interfaceDocVo : interfaceDocVoList) {
if (interfaceDocVo.getId() != null) {
interfaceDocVo.setSort("doc");
Long docId = interfaceDocVo.getId();
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.setInterfaceDocVos(interfaceDocVoList);
interfaceGroupVo.setChildren(interfaceDocVoList);
if (!CollectionUtils.isEmpty(interfaceGroupVoList)) {
getRecursiveGrouping(interfaceDocVosMap, interfaceGroupingVosMap, testCaseVosMap, interfaceGroupVoList);
}
......@@ -91,6 +103,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
.eq(InterfaceGrouping::getProjectId, projectId))).orElse(new ArrayList<>());
for (InterfaceGrouping interfaceGrouping : interfaceGroupings) {
InterfaceGroupVo interfaceGroupVo = interfaceGrouping.toInterfaceGroupVo();
interfaceGroupVo.setLabel(interfaceGrouping.getTag());
interfaceGroupVo.setSort("group");
interfaceGroupVos.add(interfaceGroupVo);
}
//key: 父分组id value : 接口分组集合
......@@ -111,6 +125,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
.eq(InterfaceDoc::getProjectId, projectId))).orElse(new ArrayList<>());
for (InterfaceDoc interfaceDoc : interfaceDocs) {
InterfaceDocVo interfaceDocVo = interfaceDoc.toInterfaceDocVo();
interfaceDocVo.setSort("doc");
interfaceDocVo.setLabel(interfaceDoc.getSummary());
interfaceDocVos.add(interfaceDocVo);
}
//key : 接口分组主键id value : 接口文档集合
......@@ -121,7 +137,7 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
List<InterfaceDocVo> firstInterfaceDocVos = new ArrayList<>();
if (interfaceDocVosMap.get(-1L) != null) {
firstInterfaceDocVos = interfaceDocVosMap.get(-1L);
groupVo.setInterfaceDocVos(firstInterfaceDocVos);
groupVo.setChildren(firstInterfaceDocVos);
}
//所有测试用例
......@@ -130,6 +146,8 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
.eq(Case::getProjectId, projectId))).orElse(new ArrayList<>());
for (Case aCase : cases) {
TestCaseVo testCaseVo = aCase.toTestCaseVo();
testCaseVo.setSort("testCase");
testCaseVo.setLabel(aCase.getName());
testCaseVos.add(testCaseVo);
}
//key : 接口文档id value : 测试用例集合
......@@ -144,12 +162,11 @@ public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements IC
Long id = firstInterfaceDocVo.getId();
//接口中所有的测试用例
List<TestCaseVo> testCaseVoList = testCaseVosMap.get(id);
firstInterfaceDocVo.setTestCaseVos(testCaseVoList);
firstInterfaceDocVo.setChildren(testCaseVoList);
}
}
getRecursiveGrouping(interfaceDocVosMap, interfaceGroupingVosMap, testCaseVosMap, firstInterfaceVoGroupings);
return groupVo;
}
}
......@@ -11,6 +11,7 @@ import org.matrix.service.IEnvironmentService;
import org.matrix.vo.StatusCode;
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;
......@@ -46,16 +47,18 @@ public class EnvironmentServiceImpl extends ServiceImpl<EnvironmentMapper, Envir
StatusCode statusCode = new StatusCode();
statusCode.setSwaggerDataType(SwaggerDataType.ENV);
if (environment != null && environment.getIp() != null) {
//根据新导入的环境ip判断项目中是否存在相同的ip
List<Environment> environments = Optional.ofNullable(environmentMapper.selectList(Wrappers.lambdaQuery(Environment.class)
.eq(Environment::getProjectId, environment.getProjectId()))).orElse(new ArrayList<>());
for (Environment env : environments) {
if (environment.getIp().equals(env.getIp())) {
.eq(Environment::getProjectId, environment.getProjectId())
.eq(Environment::getIp, environment.getIp()))).orElse(new ArrayList<>());
//存在则修改,不存在则直接添加
if (!CollectionUtils.isEmpty(environments)) {
//找到当前数据主键id
Long id = environments.get(0).getId();
environment.setId(id);
Integer integer = Optional.of(environmentMapper.updateById(environment)).orElseThrow(() -> new GlobalException("修改失败"));
updateNum = updateNum + integer;
}
break;
}
if (updateNum == 0) {
} else {
Integer integer = Optional.of(environmentMapper.insert(environment)).orElseThrow(() -> new GlobalException("添加失败"));
saveNum = saveNum + integer;
}
......
......@@ -65,8 +65,6 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
/**
* 1. 同url覆盖
* <p>
* // * @param interfaceVos 接口文档Vo类
*
* @param projectId 项目id
* @param envId 环境id
......@@ -98,32 +96,35 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
for (InterfaceVo interfaceVo : interfaceVoList) {
//当前分组下的接口
InterfaceDoc interfaceDoc = interfaceVo.toInterfaceDoc();
// if (interfaceVo.getParameters().toJSONString() != null) {
// interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
// }
// if (interfaceVo.getResponses().toJSONString() != null) {
// interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
// }
if (interfaceVo.getParameters() != null) {
interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
}
if (interfaceVo.getResponses() != null) {
interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
}
interfaceDoc.setEnvId(envId);
interfaceDoc.setInterfaceGroupId(groupingId);
interfaceDoc.setProjectId(projectId);
//判断这条数据是否存在(当前项目,url)
//判断这条数据是否存在(当前项目,url,httpMethod)
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getProjectId, projectId)
.eq(InterfaceDoc::getPathUrl, interfaceDoc.getPathUrl()))).orElse(new ArrayList<>());
.eq(InterfaceDoc::getPathUrl, interfaceDoc.getPathUrl())
.eq(InterfaceDoc::getHttpMethod, interfaceDoc.getHttpMethod()))).orElse(new ArrayList<>());
//不为null说明存在这条pathUrl
if (!CollectionUtils.isEmpty(interfaceDocs)) {
//获取到这条数据的主键id,为了后面可以将id放到新的数据中
Long id = interfaceDocs.get(0).getId();
interfaceDocList.remove(interfaceDoc);
interfaceDoc.setId(id);
interfaceDoc.setStatus(SyncStatus.UPDATE);
//覆盖数据也就是更新
Integer integer = Optional.of(interfaceDocMapper.updateById(interfaceDoc)).orElseThrow(() -> new GlobalException("修改失败"));
//如果导入需要导入测试用例
updateNum = updateNum + integer;
//然后将查询到已经存在的数据删除掉,剩下的就是本次导入不存在,但是原始数据中存在的
interfaceDocList.remove(interfaceDoc);
} else {
//不存在的话直接新增
interfaceDoc.setStatus(SyncStatus.INSERT);
Integer integer = Optional.of(interfaceDocMapper.insert(interfaceDoc)).orElseThrow(() -> new GlobalException("添加失败"));
saveNum = saveNum + integer;
}
......@@ -133,7 +134,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
}
if (!CollectionUtils.isEmpty(interfaceDocList)) {
for (InterfaceDoc interfaceDoc : interfaceDocList) {
interfaceDoc.setStatus(SyncStatus.OTHER);
interfaceDoc.setStatus(SyncStatus.NO);
interfaceDocMapper.updateById(interfaceDoc);
}
}
......@@ -176,12 +177,12 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
for (InterfaceVo interfaceVo : interfaceVoList) {
//当前分组下的接口
InterfaceDoc interfaceDoc = interfaceVo.toInterfaceDoc();
// if (interfaceVo.getParameters().toJSONString() != null) {
// interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
// }
// if (interfaceVo.getResponses().toJSONString() != null) {
// interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
// }
if (interfaceVo.getParameters() != null) {
interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
}
if (interfaceVo.getResponses() != null) {
interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
}
interfaceDoc.setProjectId(projectId);
interfaceDoc.setEnvId(envId);
interfaceDoc.setInterfaceGroupId(groupingId);
......@@ -212,7 +213,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
}
if (!CollectionUtils.isEmpty(docByPathUrlAndGrouping)) {
for (InterfaceDoc interfaceDoc : docByPathUrlAndGrouping) {
interfaceDoc.setStatus(SyncStatus.OTHER);
interfaceDoc.setStatus(SyncStatus.NO);
interfaceDocMapper.updateById(interfaceDoc);
}
}
......@@ -260,22 +261,27 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
//判断这条数据是否存在(当前项目,url)
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getProjectId, projectId)
.eq(InterfaceDoc::getPathUrl, interfaceDoc.getPathUrl()))).orElse(new ArrayList<>());
.eq(InterfaceDoc::getPathUrl, interfaceDoc.getPathUrl())
.eq(InterfaceDoc::getHttpMethod, interfaceDoc.getHttpMethod()))).orElse(new ArrayList<>());
//不为null说明存在这条pathUrl
if (!CollectionUtils.isEmpty(interfaceDocs)) {
InterfaceDoc doc = interfaceDocs.get(0);
doc.setStatus(SyncStatus.NO);
Integer integer = Optional.of(interfaceDocMapper.updateById(doc)).orElseThrow(() -> new GlobalException("修改失败"));
//不做任何操作,忽略数量+1
ignoreNum = ignoreNum + 1;
ignoreNum = ignoreNum + integer;
//然后将查询到已经存在的数据删除掉,剩下的就是本次导入不存在,但是原始数据中存在的
interfaceDocList.remove(interfaceDoc);
} else {
interfaceDoc.setEnvId(envId);
interfaceDoc.setInterfaceGroupId(groupingId);
// if (interfaceVo.getParameters().toJSONString() != null) {
// interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
// }
// if (interfaceVo.getResponses().toJSONString() != null) {
// interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
// }
if (interfaceVo.getParameters() != null) {
interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
}
if (interfaceVo.getResponses() != null) {
interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
}
interfaceDoc.setStatus(SyncStatus.INSERT);
//不存在的话直接新增
Integer integer = Optional.of(interfaceDocMapper.insert(interfaceDoc)).orElseThrow(() -> new GlobalException("添加失败"));
saveNum = saveNum + integer;
......@@ -286,7 +292,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
}
if (!CollectionUtils.isEmpty(interfaceDocList)) {
for (InterfaceDoc interfaceDoc : interfaceDocList) {
interfaceDoc.setStatus(SyncStatus.OTHER);
interfaceDoc.setStatus(SyncStatus.NO);
interfaceDocMapper.updateById(interfaceDoc);
}
}
......@@ -332,12 +338,12 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
interfaceDoc.setEnvId(envId);
interfaceDoc.setInterfaceGroupId(groupingId);
interfaceDoc.setProjectId(projectId);
// if (interfaceVo.getParameters().toJSONString() != null) {
// interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
// }
// if (interfaceVo.getResponses().toJSONString() != null) {
// interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
// }
if (interfaceVo.getParameters() != null) {
interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
}
if (interfaceVo.getResponses() != null) {
interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
}
//判断这条数据是否存在(当前项目,分组,url)
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getProjectId, projectId)
......@@ -361,7 +367,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
}
if (!CollectionUtils.isEmpty(docByPathUrlAndGrouping)) {
for (InterfaceDoc interfaceDoc : docByPathUrlAndGrouping) {
interfaceDoc.setStatus(SyncStatus.OTHER);
interfaceDoc.setStatus(SyncStatus.NO);
interfaceDocMapper.updateById(interfaceDoc);
}
}
......@@ -420,14 +426,14 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
InterfaceDoc interfaceDoc = interfaceVo.toInterfaceDoc();
interfaceDoc.setInterfaceGroupId(groupingId);
interfaceDoc.setProjectId(projectId);
interfaceDoc.setStatus(SyncStatus.COPY);
// if (interfaceVo.getParameters().toJSONString() != null) {
// interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
// }
// interfaceDoc.setEnvId(envId);
// if (interfaceVo.getResponses().toJSONString() != null) {
// interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
// }
interfaceDoc.setStatus(SyncStatus.INSERT);
if (interfaceVo.getParameters() != null) {
interfaceDoc.setParameters(interfaceVo.getParameters().toJSONString());
}
interfaceDoc.setEnvId(envId);
if (interfaceVo.getResponses() != null) {
interfaceDoc.setResponses(interfaceVo.getResponses().toJSONString());
}
//todo 负责人,以及开发状态未添加
Integer integer = Optional.of(interfaceDocMapper.insert(interfaceDoc)).orElseThrow(() -> new GlobalException("添加失败"));
saveNum = saveNum + integer;
......@@ -445,7 +451,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
//剩下的就是当前存在,但是导入的数据中不存在的
if (list.size() != 0) {
for (InterfaceDoc interfaceDoc : list) {
interfaceDoc.setStatus(SyncStatus.OTHER);
interfaceDoc.setStatus(SyncStatus.NO);
interfaceDocMapper.updateById(interfaceDoc);
}
}
......@@ -506,6 +512,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
//当前项目中的所有接口
List<InterfaceDoc> interfaceDocs = Optional.ofNullable(interfaceDocMapper.selectList(Wrappers.lambdaQuery(InterfaceDoc.class)
.eq(InterfaceDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//根据pathUrl取出独一份pathUrl的接口
if (!CollectionUtils.isEmpty(interfaceDocs)) {
Map<String, List<InterfaceDoc>> pathUrlMap = interfaceDocs.stream()
......
package org.matrix.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.entity.MouldDoc;
......@@ -63,13 +64,19 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
return statusCode;
}
/**
* 将导入的数据转换成entity
*
* @param mouldVos 导入的数据
* @return 导入数据的entity集合
*/
public List<MouldDoc> getMouldDoc(List<MouldVo> mouldVos) {
List<MouldDoc> mouldDocs = new ArrayList<>();
if (!CollectionUtils.isEmpty(mouldVos)) {
for (MouldVo mouldVo : mouldVos) {
MouldDoc mouldDoc = new MouldDoc();
mouldDoc.setObjName(mouldVo.getObjName());
// mouldDoc.setAttributeOutVo(mouldVo.getAttributeOutVo());
mouldDoc.setAttributeOutVo(JSON.toJSONString(mouldVo.getAttributeOutVo()));
mouldDocs.add(mouldDoc);
}
}
......@@ -90,9 +97,12 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
int ignoreNum = 0;
StatusCode statusCode = new StatusCode();
statusCode.setSwaggerDataType(SwaggerDataType.MOULD_DOC);
if (mouldVos.size() != 0) {
if (!CollectionUtils.isEmpty(mouldVos)) {
List<MouldDoc> mouldDocs = getMouldDoc(mouldVos);
List<Long> longList = getIdList(projectId);
//数据库中存在的当前项目中所有的数据模型
List<MouldDoc> pastMouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//如果存在当前分组就直接使用,如果不存在就创建在使用
Long groupingId = getGroupingId(mouldId, projectId);
for (MouldDoc mouldDoc : mouldDocs) {
//将分组加到对象中
......@@ -102,15 +112,15 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
List<MouldDoc> mouldDocList = Optional.of(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getObjName, mouldDoc.getObjName())
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//覆盖第一个
if (mouldDocList.size() != 0) {
//覆盖第一个,其余变成未同步
if (!CollectionUtils.isEmpty(mouldDocList)) {
//如果存在就覆盖第一个
Long mouldDocId = mouldDocList.get(0).getId();
mouldDoc.setId(mouldDocId);
pastMouldDocs.remove(mouldDocList.get(0));
mouldDoc.setStatus(SyncStatus.UPDATE);
mouldDoc.setId(mouldDocId);
Integer integer = Optional.of(mouldDocMapper.updateById(mouldDoc)).orElseThrow(() -> new GlobalException("修改数据模型失败"));
updateNum = updateNum + integer;
longList.remove(mouldDoc.getId());
} else {
mouldDoc.setStatus(SyncStatus.INSERT);
//如果不存在就直接添加
......@@ -118,7 +128,13 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
saveNum = saveNum + integer;
}
}
updateStatusNo(longList);
//其余的都变成未同步
if (!CollectionUtils.isEmpty(pastMouldDocs)) {
for (MouldDoc pastMouldDoc : pastMouldDocs) {
pastMouldDoc.setStatus(SyncStatus.NO);
mouldDocMapper.updateById(pastMouldDoc);
}
}
}
statusCode.setSaveNum(saveNum);
statusCode.setUpdateNum(updateNum);
......@@ -142,7 +158,10 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
statusCode.setSwaggerDataType(SwaggerDataType.MOULD_DOC);
if (mouldVos.size() != 0) {
List<MouldDoc> mouldDocs = getMouldDoc(mouldVos);
List<Long> longList = getIdList(projectId);
//数据库中存在的当前项目中所有的数据模型
List<MouldDoc> pastMouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//如果存在当前分组就直接使用,如果不存在就创建在使用
Long groupingId = getGroupingId(mouldId, projectId);
for (MouldDoc mouldDoc : mouldDocs) {
//将新的分组存入到数据中
......@@ -154,9 +173,10 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
.eq(MouldDoc::getProjectId, projectId)
.eq(MouldDoc::getMouldGroupingId, mouldDoc.getMouldGroupingId()))).orElse(new ArrayList<>());
//覆盖第一个
if (mouldDocList.size() != 0) {
if (!CollectionUtils.isEmpty(mouldDocList)) {
//如果存在就覆盖第一个
Long mouldDocId = mouldDocList.get(0).getId();
pastMouldDocs.remove(mouldDocList.get(0));
mouldDoc.setId(mouldDocId);
mouldDoc.setStatus(SyncStatus.UPDATE);
Integer integer = Optional.of(mouldDocMapper.updateById(mouldDoc)).orElseThrow(() -> new GlobalException("修改数据模型失败"));
......@@ -168,7 +188,13 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
saveNum = saveNum + integer;
}
}
updateStatusNo(longList);
//其余的都变成未同步
if (!CollectionUtils.isEmpty(pastMouldDocs)) {
for (MouldDoc pastMouldDoc : pastMouldDocs) {
pastMouldDoc.setStatus(SyncStatus.NO);
mouldDocMapper.updateById(pastMouldDoc);
}
}
}
statusCode.setSaveNum(saveNum);
statusCode.setUpdateNum(updateNum);
......@@ -190,28 +216,42 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
int ignoreNum = 0;
StatusCode statusCode = new StatusCode();
statusCode.setSwaggerDataType(SwaggerDataType.MOULD_DOC);
if (mouldVos.size() != 0) {
if (!CollectionUtils.isEmpty(mouldVos)) {
List<MouldDoc> mouldDocs = getMouldDoc(mouldVos);
List<Long> longList = getIdList(projectId);
//数据库中存在的当前项目中所有的数据模型
List<MouldDoc> pastMouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//如果存在当前分组就直接使用,如果不存在就创建在使用
Long groupingId = getGroupingId(mouldId, projectId);
for (MouldDoc mouldDoc : mouldDocs) {
//将新的分组存入到数据中
mouldDoc.setMouldGroupingId(groupingId);
mouldDoc.setProjectId(projectId);
//找到可以不做任何操作的
//当前项目中是否存在这个名称的数据模型
List<MouldDoc> mouldDocList = Optional.of(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getObjName, mouldDoc.getObjName())
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//忽略数+1
if (mouldDocList.size() != 0) {
ignoreNum = ignoreNum + 1;
if (!CollectionUtils.isEmpty(mouldDocList)) {
MouldDoc doc = mouldDocList.get(0);
//当前项目中存在的数据模型
pastMouldDocs.remove(mouldDocList.get(0));
doc.setStatus(SyncStatus.NO);
Integer integer = Optional.of(mouldDocMapper.updateById(doc)).orElseThrow(() -> new GlobalException("修改失败"));
ignoreNum = ignoreNum + integer;
} else {
mouldDoc.setStatus(SyncStatus.INSERT);
//如果不存在就直接添加
Integer integer = Optional.of(mouldDocMapper.insert(mouldDoc)).orElseThrow(() -> new GlobalException("添加数据模型失败"));
saveNum = saveNum + integer;
}
}
updateStatusNo(longList);
if (!CollectionUtils.isEmpty(pastMouldDocs)) {
for (MouldDoc pastMouldDoc : pastMouldDocs) {
pastMouldDoc.setStatus(SyncStatus.NO);
mouldDocMapper.updateById(pastMouldDoc);
}
}
}
statusCode.setSaveNum(saveNum);
statusCode.setUpdateNum(updateNum);
......@@ -235,7 +275,10 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
statusCode.setSwaggerDataType(SwaggerDataType.MOULD_DOC);
if (mouldVos.size() != 0) {
List<MouldDoc> mouldDocs = getMouldDoc(mouldVos);
List<Long> longList = getIdList(projectId);
//数据库中存在的当前项目中所有的数据模型
List<MouldDoc> pastMouldDocs = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//如果存在当前分组就直接使用,如果不存在就创建在使用
Long groupingId = getGroupingId(mouldId, projectId);
for (MouldDoc mouldDoc : mouldDocs) {
//将新的分组存入到数据中
......@@ -248,20 +291,25 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
.eq(MouldDoc::getMouldGroupingId, mouldDoc.getMouldGroupingId()))).orElse(new ArrayList<>());
//忽略数+1
if (mouldDocList.size() != 0) {
ignoreNum = ignoreNum + 1;
//上次忽略的
for (MouldDoc doc : mouldDocList) {
doc.setStatus(SyncStatus.IGNORE);
MouldDoc doc = mouldDocList.get(0);
pastMouldDocs.remove(mouldDocList.get(0));
doc.setStatus(SyncStatus.NO);
Integer integer = Optional.of(mouldDocMapper.updateById(doc)).orElseThrow(() -> new GlobalException("修改失败"));
ignoreNum = ignoreNum + integer;
}
//当前项目中存在的数据模型
} else {
mouldDoc.setStatus(SyncStatus.INSERT);
//如果不存在就直接添加
Integer integer = Optional.of(mouldDocMapper.insert(mouldDoc)).orElseThrow(() -> new GlobalException("添加数据模型失败"));
saveNum = saveNum + integer;
}
}
updateStatusNo(longList);
if (!CollectionUtils.isEmpty(pastMouldDocs)) {
for (MouldDoc pastMouldDoc : pastMouldDocs) {
pastMouldDoc.setStatus(SyncStatus.NO);
mouldDocMapper.updateById(pastMouldDoc);
}
}
}
statusCode.setSaveNum(saveNum);
statusCode.setUpdateNum(updateNum);
......@@ -309,7 +357,7 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
for (MouldDoc mouldDoc : mouldDocs) {
mouldDoc.setMouldGroupingId(groupingId);
mouldDoc.setProjectId(projectId);
mouldDoc.setStatus(SyncStatus.COPY);
mouldDoc.setStatus(SyncStatus.INSERT);
Integer integer = Optional.of(mouldDocMapper.insert(mouldDoc)).orElseThrow(() -> new GlobalException("添加数据模型失败"));
saveNum = saveNum + integer;
//操作数据库中存在的数据模型
......@@ -326,7 +374,7 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
//剩下的就是当前存在,但是导入的数据中不存在的
if (list.size() != 0) {
for (MouldDoc mouldDoc : list) {
mouldDoc.setStatus(SyncStatus.OTHER);
mouldDoc.setStatus(SyncStatus.NO);
mouldDocMapper.updateById(mouldDoc);
}
}
......@@ -371,41 +419,4 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
return id;
}
/**
* 将未涉及到的数据模型都变成: 上次导入不存在
*
* @param longList 未涉及到的数据模型的主键id集合
*/
public void updateStatusNo(List<Long> longList) {
//未涉及到的数据模型都变成未同步
if (longList.size() != 0) {
for (Long id : longList) {
MouldDoc mouldDoc = mouldDocMapper.selectById(id);
mouldDoc.setStatus(SyncStatus.OTHER);
mouldDocMapper.updateById(mouldDoc);
}
}
}
/**
* 获取当前项目中所有的数据模型的主键id集合
*
* @param projectId 项目id
* @return 当前项目中所有的数据模型的主键id集合
*/
private List<Long> getIdList(Long projectId) {
//当前项目中的所有数据模型
List<MouldDoc> list = Optional.ofNullable(mouldDocMapper.selectList(Wrappers.lambdaQuery(MouldDoc.class)
.eq(MouldDoc::getProjectId, projectId))).orElse(new ArrayList<>());
//将主键id整理到集合中
List<Long> longList = new ArrayList<>();
if (list.size() != 0) {
for (MouldDoc mouldDoc : list) {
Long id = mouldDoc.getId();
longList.add(id);
}
}
return longList;
}
}
......@@ -22,7 +22,7 @@ import java.util.List;
public class InterfaceDocVo {
@ApiModelProperty("接口文档下可以存在多个测试用例")
private List<TestCaseVo> testCaseVos;
private List<TestCaseVo> children;
/**
* id
......@@ -35,7 +35,7 @@ public class InterfaceDocVo {
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("名称")
private String summary;
private String label;
/**
* 说明
......@@ -113,4 +113,9 @@ public class InterfaceDocVo {
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("负责人")
private String dutyPeople;
/**
* 用来区分分组,接口,用例
*/
public String sort;
}
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.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -30,7 +28,7 @@ public class InterfaceGroupVo {
* 分组下可以存在多个接口
*/
@ApiModelProperty("分组下可以存在多个接口")
private List<InterfaceDocVo> interfaceDocVos;
private List<InterfaceDocVo> children;
/**
* id
......@@ -41,49 +39,47 @@ public class InterfaceGroupVo {
/**
* 名称(标签/分组(存在根目录))
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("名称(标签/分组(存在根目录))")
private String tag;
private String label;
/**
* 说明
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("说明")
private String des;
/**
* 环境id
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("环境id")
private Long envId;
/**
* 项目id
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("项目id")
private Long projectId;
/**
* 前置操作id
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("前置操作id")
private Long moveBefore;
/**
* 后置操作id
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("后置操作id")
private Long moveAfter;
/**
* 父类id(根目录默认为0)
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("父类id(根目录默认为0)")
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 {
*/
@TableField(fill = FieldFill.UPDATE)
@ApiModelProperty("名称")
private String name;
private String label;
/**
* 接口文档id
......@@ -73,4 +73,9 @@ public class TestCaseVo {
@ApiModelProperty("项目id")
private Long projectId;
/**
* 用来区分分组,接口,用例
*/
public String sort;
}
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.InterfaceGrouping;
......@@ -11,6 +12,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
......@@ -57,4 +60,12 @@ public class InterfaceGroupingController {
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论