Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
cf7b1990
提交
cf7b1990
authored
8月 09, 2022
作者:
mry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(web): 接口文档同步
上级
42400e44
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
80 行增加
和
182 行删除
+80
-182
InterfaceDocServiceImpl.java
...java/org/matrix/service/impl/InterfaceDocServiceImpl.java
+57
-145
MouldDocServiceImpl.java
...ain/java/org/matrix/service/impl/MouldDocServiceImpl.java
+23
-37
没有找到文件。
kt-database/src/main/java/org/matrix/service/impl/InterfaceDocServiceImpl.java
浏览文件 @
cf7b1990
...
@@ -78,12 +78,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -78,12 +78,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
StatusCode
statusCode
=
new
StatusCode
();
StatusCode
statusCode
=
new
StatusCode
();
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
//当前项目中所有的接口文档
List
<
InterfaceDoc
>
interfaceDocList
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//导入的接口 将当前导入的对象按照tag分组
//导入的接口 将当前导入的对象按照tag分组
Map
<
String
,
List
<
InterfaceVo
>>
tagMap
=
interfaceVos
.
stream
()
Map
<
String
,
List
<
InterfaceVo
>>
tagMap
=
getTagsMap
(
interfaceVos
);
.
filter
(
interfaceVo
->
interfaceVo
!=
null
&&
interfaceVo
.
getTags
()
!=
null
&&
!
""
.
equals
(
interfaceVo
.
getTags
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceVo:
:
getTags
));
//当前项目中所有的pathUrl(唯一的),同名的取第一个
List
<
InterfaceDoc
>
interfaceDocList
=
getDocByPathUrl
(
projectId
);
if
(!
CollectionUtils
.
isEmpty
(
tagMap
))
{
if
(!
CollectionUtils
.
isEmpty
(
tagMap
))
{
Set
<
String
>
tags
=
tagMap
.
keySet
();
Set
<
String
>
tags
=
tagMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
...
@@ -114,7 +113,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -114,7 +113,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
//获取到这条数据的主键id,为了后面可以将id放到新的数据中
//获取到这条数据的主键id,为了后面可以将id放到新的数据中
Long
id
=
interfaceDocs
.
get
(
0
).
getId
();
Long
id
=
interfaceDocs
.
get
(
0
).
getId
();
interfaceDocList
.
remove
(
interfaceDoc
);
interfaceDocList
.
remove
(
interfaceDoc
s
.
get
(
0
)
);
interfaceDoc
.
setId
(
id
);
interfaceDoc
.
setId
(
id
);
interfaceDoc
.
setStatus
(
SyncStatus
.
UPDATE
);
interfaceDoc
.
setStatus
(
SyncStatus
.
UPDATE
);
//覆盖数据也就是更新
//覆盖数据也就是更新
...
@@ -160,12 +159,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -160,12 +159,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
StatusCode
statusCode
=
new
StatusCode
();
StatusCode
statusCode
=
new
StatusCode
();
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
//当前项目中存在的数据,同名同组的取第一个
//当前项目中所有的接口文档
List
<
InterfaceDoc
>
docByPathUrlAndGrouping
=
getDocByPathUrlAndGrouping
(
projectId
);
List
<
InterfaceDoc
>
interfaceDocList
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//导入的数据根据tag分组
//导入的数据根据tag分组
Map
<
String
,
List
<
InterfaceVo
>>
tagsMap
=
interfaceVos
.
stream
()
Map
<
String
,
List
<
InterfaceVo
>>
tagsMap
=
getTagsMap
(
interfaceVos
);
.
filter
(
interfaceVo
->
interfaceVo
!=
null
&&
interfaceVo
.
getTags
()
!=
null
&&
!
""
.
equals
(
interfaceVo
.
getTags
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceVo:
:
getTags
));
if
(!
CollectionUtils
.
isEmpty
(
tagsMap
))
{
if
(!
CollectionUtils
.
isEmpty
(
tagsMap
))
{
Set
<
String
>
tags
=
tagsMap
.
keySet
();
Set
<
String
>
tags
=
tagsMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
...
@@ -190,19 +188,22 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -190,19 +188,22 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
List
<
InterfaceDoc
>
interfaceDocs
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
List
<
InterfaceDoc
>
interfaceDocs
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceDoc:
:
getPathUrl
,
interfaceDoc
.
getPathUrl
())
.
eq
(
InterfaceDoc:
:
getPathUrl
,
interfaceDoc
.
getPathUrl
())
.
eq
(
InterfaceDoc:
:
getHttpMethod
,
interfaceDoc
.
getHttpMethod
())
.
eq
(
InterfaceDoc:
:
getInterfaceGroupId
,
interfaceDoc
.
getInterfaceGroupId
()))).
orElse
(
new
ArrayList
<>());
.
eq
(
InterfaceDoc:
:
getInterfaceGroupId
,
interfaceDoc
.
getInterfaceGroupId
()))).
orElse
(
new
ArrayList
<>());
//不为null说明存在这条pathUrl
//不为null说明存在这条pathUrl
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
//获取到这条数据的主键id,为了后面可以将id放到新的数据中
//获取到这条数据的主键id,为了后面可以将id放到新的数据中
Long
id
=
interfaceDocs
.
get
(
0
).
getId
();
Long
id
=
interfaceDocs
.
get
(
0
).
getId
();
interfaceDocList
.
remove
(
interfaceDocs
.
get
(
0
));
interfaceDoc
.
setStatus
(
SyncStatus
.
UPDATE
);
interfaceDoc
.
setId
(
id
);
interfaceDoc
.
setId
(
id
);
//覆盖数据也就是更新
//覆盖数据也就是更新
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
updateById
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"修改失败"
));
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
updateById
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"修改失败"
));
updateNum
=
updateNum
+
integer
;
updateNum
=
updateNum
+
integer
;
//然后将查询到已经存在的数据删除掉,剩下的就是本次导入不存在,但是原始数据中存在的
//然后将查询到已经存在的数据删除掉,剩下的就是本次导入不存在,但是原始数据中存在的
docByPathUrlAndGrouping
.
remove
(
interfaceDoc
);
}
else
{
}
else
{
//不存在的话直接新增
//不存在的话直接新增
interfaceDoc
.
setStatus
(
SyncStatus
.
INSERT
);
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
insert
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
insert
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
saveNum
=
saveNum
+
integer
;
saveNum
=
saveNum
+
integer
;
}
}
...
@@ -211,8 +212,8 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -211,8 +212,8 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
}
}
}
}
}
}
if
(!
CollectionUtils
.
isEmpty
(
docByPathUrlAndGrouping
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocList
))
{
for
(
InterfaceDoc
interfaceDoc
:
docByPathUrlAndGrouping
)
{
for
(
InterfaceDoc
interfaceDoc
:
interfaceDocList
)
{
interfaceDoc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDoc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDocMapper
.
updateById
(
interfaceDoc
);
interfaceDocMapper
.
updateById
(
interfaceDoc
);
}
}
...
@@ -239,12 +240,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -239,12 +240,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
StatusCode
statusCode
=
new
StatusCode
();
StatusCode
statusCode
=
new
StatusCode
();
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
//当前项目中所有的pathUrl(唯一的)
//当前项目中所有的接口文档
List
<
InterfaceDoc
>
interfaceDocList
=
getDocByPathUrl
(
projectId
);
List
<
InterfaceDoc
>
interfaceDocList
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//导入的接口 将当前导入的对象按照tag分组
//导入的接口 将当前导入的对象按照tag分组
Map
<
String
,
List
<
InterfaceVo
>>
tagMap
=
interfaceVos
.
stream
()
Map
<
String
,
List
<
InterfaceVo
>>
tagMap
=
getTagsMap
(
interfaceVos
);
.
filter
(
interfaceVo
->
interfaceVo
!=
null
&&
interfaceVo
.
getTags
()
!=
null
&&
!
""
.
equals
(
interfaceVo
.
getTags
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceVo:
:
getTags
));
if
(!
CollectionUtils
.
isEmpty
(
tagMap
))
{
if
(!
CollectionUtils
.
isEmpty
(
tagMap
))
{
Set
<
String
>
tags
=
tagMap
.
keySet
();
Set
<
String
>
tags
=
tagMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
...
@@ -263,15 +263,9 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -263,15 +263,9 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceDoc:
:
getPathUrl
,
interfaceDoc
.
getPathUrl
())
.
eq
(
InterfaceDoc:
:
getPathUrl
,
interfaceDoc
.
getPathUrl
())
.
eq
(
InterfaceDoc:
:
getHttpMethod
,
interfaceDoc
.
getHttpMethod
()))).
orElse
(
new
ArrayList
<>());
.
eq
(
InterfaceDoc:
:
getHttpMethod
,
interfaceDoc
.
getHttpMethod
()))).
orElse
(
new
ArrayList
<>());
//
不为null说明存在这条pathUrl
//
只有不存在时才进行添加操作
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
InterfaceDoc
doc
=
interfaceDocs
.
get
(
0
);
ignoreNum
=
ignoreNum
+
1
;
doc
.
setStatus
(
SyncStatus
.
NO
);
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
updateById
(
doc
)).
orElseThrow
(()
->
new
GlobalException
(
"修改失败"
));
//不做任何操作,忽略数量+1
ignoreNum
=
ignoreNum
+
integer
;
//然后将查询到已经存在的数据删除掉,剩下的就是本次导入不存在,但是原始数据中存在的
interfaceDocList
.
remove
(
interfaceDoc
);
}
else
{
}
else
{
interfaceDoc
.
setEnvId
(
envId
);
interfaceDoc
.
setEnvId
(
envId
);
interfaceDoc
.
setInterfaceGroupId
(
groupingId
);
interfaceDoc
.
setInterfaceGroupId
(
groupingId
);
...
@@ -318,12 +312,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -318,12 +312,11 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
StatusCode
statusCode
=
new
StatusCode
();
StatusCode
statusCode
=
new
StatusCode
();
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceVos
))
{
//当前项目中所有的接口文档
List
<
InterfaceDoc
>
interfaceDocList
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//导入的数据根据tag分组
//导入的数据根据tag分组
Map
<
String
,
List
<
InterfaceVo
>>
tagsMap
=
interfaceVos
.
stream
()
Map
<
String
,
List
<
InterfaceVo
>>
tagsMap
=
getTagsMap
(
interfaceVos
);
.
filter
(
interfaceVo
->
interfaceVo
!=
null
&&
interfaceVo
.
getTags
()
!=
null
&&
!
""
.
equals
(
interfaceVo
.
getTags
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceVo:
:
getTags
));
//当前项目中存在的数据,同名同组的取第一个
List
<
InterfaceDoc
>
docByPathUrlAndGrouping
=
getDocByPathUrlAndGrouping
(
projectId
);
if
(!
CollectionUtils
.
isEmpty
(
tagsMap
))
{
if
(!
CollectionUtils
.
isEmpty
(
tagsMap
))
{
Set
<
String
>
tags
=
tagsMap
.
keySet
();
Set
<
String
>
tags
=
tagsMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
...
@@ -351,22 +344,19 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -351,22 +344,19 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
.
eq
(
InterfaceDoc:
:
getInterfaceGroupId
,
interfaceDoc
.
getInterfaceGroupId
()))).
orElse
(
new
ArrayList
<>());
.
eq
(
InterfaceDoc:
:
getInterfaceGroupId
,
interfaceDoc
.
getInterfaceGroupId
()))).
orElse
(
new
ArrayList
<>());
//不为null说明存在这条pathUrl
//不为null说明存在这条pathUrl
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
//不做任何操作,忽略数量+1
ignoreNum
=
ignoreNum
+
1
;
ignoreNum
=
ignoreNum
+
1
;
//然后将查询到已经存在的数据删除掉,剩下的就是本次导入不存在,但是原始数据中存在的
docByPathUrlAndGrouping
.
remove
(
interfaceDoc
);
}
else
{
}
else
{
interfaceDoc
.
setStatus
(
SyncStatus
.
INSERT
);
//不存在的话直接新增
//不存在的话直接新增
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
insert
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
insert
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
saveNum
=
saveNum
+
integer
;
saveNum
=
saveNum
+
integer
;
}
}
}
}
}
}
}
}
}
}
if
(!
CollectionUtils
.
isEmpty
(
docByPathUrlAndGrouping
))
{
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocList
))
{
for
(
InterfaceDoc
interfaceDoc
:
docByPathUrlAndGrouping
)
{
for
(
InterfaceDoc
interfaceDoc
:
interfaceDocList
)
{
interfaceDoc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDoc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDocMapper
.
updateById
(
interfaceDoc
);
interfaceDocMapper
.
updateById
(
interfaceDoc
);
}
}
...
@@ -378,6 +368,18 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -378,6 +368,18 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
return
statusCode
;
return
statusCode
;
}
}
/**
* 将前端返回的参数根据分组分类
*
* @param interfaceVos 接口前端的接口信息
* @return key: 分组 values: 分组下的接口集合
*/
private
Map
<
String
,
List
<
InterfaceVo
>>
getTagsMap
(
List
<
InterfaceVo
>
interfaceVos
)
{
return
interfaceVos
.
stream
()
.
filter
(
interfaceVo
->
interfaceVo
!=
null
&&
interfaceVo
.
getTags
()
!=
null
&&
!
""
.
equals
(
interfaceVo
.
getTags
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceVo:
:
getTags
));
}
/**
/**
* 5. 同时存在
* 5. 同时存在
*
*
...
@@ -392,29 +394,12 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -392,29 +394,12 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
int
ignoreNum
=
0
;
int
ignoreNum
=
0
;
StatusCode
statusCode
=
new
StatusCode
();
StatusCode
statusCode
=
new
StatusCode
();
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
INTERFACE_DOC
);
if
(
interfaceVos
.
size
()
!=
0
)
{
if
(
!
CollectionUtils
.
isEmpty
(
interfaceVos
)
)
{
//当前项目中所有的接口文档
//当前项目中所有的接口文档
List
<
InterfaceDoc
>
interfaceDocList
=
Optional
.
of
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
List
<
InterfaceDoc
>
interfaceDocList
=
Optional
.
of
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//取出key : url value : 接口文档对象
Map
<
String
,
List
<
InterfaceDoc
>>
urlsMap
=
interfaceDocList
.
stream
()
.
filter
(
interfaceDoc
->
interfaceDoc
!=
null
&&
interfaceDoc
.
getPathUrl
()
!=
null
&&
!
""
.
equals
(
interfaceDoc
.
getPathUrl
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceDoc:
:
getPathUrl
));
//存在的不同Url的接口
List
<
InterfaceDoc
>
list
=
new
ArrayList
<>();
if
(!
CollectionUtils
.
isEmpty
(
urlsMap
))
{
Set
<
String
>
pathUrls
=
urlsMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
pathUrls
))
{
for
(
String
pathUrl
:
pathUrls
)
{
InterfaceDoc
interfaceDoc
=
urlsMap
.
get
(
pathUrl
).
get
(
0
);
list
.
add
(
interfaceDoc
);
}
}
}
//导入的数据
//导入的数据
Map
<
String
,
List
<
InterfaceVo
>>
tagsMap
=
interfaceVos
.
stream
()
Map
<
String
,
List
<
InterfaceVo
>>
tagsMap
=
getTagsMap
(
interfaceVos
);
.
filter
(
interfaceVo
->
interfaceVo
!=
null
&&
interfaceVo
.
getTags
()
!=
null
&&
!
""
.
equals
(
interfaceVo
.
getTags
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceVo:
:
getTags
));
if
(!
CollectionUtils
.
isEmpty
(
tagsMap
))
{
if
(!
CollectionUtils
.
isEmpty
(
tagsMap
))
{
Set
<
String
>
tags
=
tagsMap
.
keySet
();
Set
<
String
>
tags
=
tagsMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
if
(!
CollectionUtils
.
isEmpty
(
tags
))
{
...
@@ -434,31 +419,32 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -434,31 +419,32 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
if
(
interfaceVo
.
getResponses
()
!=
null
)
{
if
(
interfaceVo
.
getResponses
()
!=
null
)
{
interfaceDoc
.
setResponses
(
interfaceVo
.
getResponses
().
toJSONString
());
interfaceDoc
.
setResponses
(
interfaceVo
.
getResponses
().
toJSONString
());
}
}
List
<
InterfaceDoc
>
interfaceDocs
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceDoc:
:
getHttpMethod
,
interfaceDoc
.
getHttpMethod
())
.
eq
(
InterfaceDoc:
:
getPathUrl
,
interfaceDoc
.
getPathUrl
()))).
orElse
(
new
ArrayList
<>());
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
for
(
InterfaceDoc
doc
:
interfaceDocs
)
{
if
(
doc
.
toString
().
equals
(
interfaceDoc
.
toString
()))
{
interfaceDocList
.
remove
(
doc
);
doc
.
setStatus
(
SyncStatus
.
UPDATE
);
}
}
}
//todo 负责人,以及开发状态未添加
//todo 负责人,以及开发状态未添加
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
insert
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
Integer
integer
=
Optional
.
of
(
interfaceDocMapper
.
insert
(
interfaceDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
saveNum
=
saveNum
+
integer
;
saveNum
=
saveNum
+
integer
;
//操作数据库中存在的接口
for
(
InterfaceDoc
doc
:
list
)
{
//如果url相同就设置成未同步
if
(
doc
.
getPathUrl
().
equals
(
interfaceDoc
.
getPathUrl
()))
{
list
.
remove
(
doc
);
doc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDocMapper
.
updateById
(
doc
);
break
;
}
}
}
}
}
}
//剩下的就是当前存在,但是导入的数据中不存在的
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocList
))
{
if
(
list
.
size
()
!=
0
)
{
for
(
InterfaceDoc
interfaceDoc
:
interfaceDocList
)
{
for
(
InterfaceDoc
interfaceDoc
:
list
)
{
interfaceDoc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDoc
.
setStatus
(
SyncStatus
.
NO
);
interfaceDocMapper
.
updateById
(
interfaceDoc
);
interfaceDocMapper
.
updateById
(
interfaceDoc
);
}
}
}
}
}
}
}
}
}
}
statusCode
.
setSaveNum
(
saveNum
);
statusCode
.
setSaveNum
(
saveNum
);
statusCode
.
setUpdateNum
(
updateNum
);
statusCode
.
setUpdateNum
(
updateNum
);
statusCode
.
setIgnoreNum
(
ignoreNum
);
statusCode
.
setIgnoreNum
(
ignoreNum
);
...
@@ -480,7 +466,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -480,7 +466,7 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
.
eq
(
InterfaceGrouping:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceGrouping:
:
getProjectId
,
projectId
)
.
eq
(
InterfaceGrouping:
:
getInterfaceGroupingId
,
interfaceGroupingId
)
.
eq
(
InterfaceGrouping:
:
getInterfaceGroupingId
,
interfaceGroupingId
)
.
eq
(
InterfaceGrouping:
:
getTag
,
tag
))).
orElse
(
new
ArrayList
<>());
.
eq
(
InterfaceGrouping:
:
getTag
,
tag
))).
orElse
(
new
ArrayList
<>());
if
(
interfaceGroupings
.
size
()
!=
0
)
{
if
(
!
CollectionUtils
.
isEmpty
(
interfaceGroupings
)
)
{
InterfaceGrouping
interfaceGrouping
=
interfaceGroupings
.
get
(
0
);
InterfaceGrouping
interfaceGrouping
=
interfaceGroupings
.
get
(
0
);
interfaceGrouping
.
setEnvId
(
envId
);
interfaceGrouping
.
setEnvId
(
envId
);
interfaceGroupingMapper
.
updateById
(
interfaceGrouping
);
interfaceGroupingMapper
.
updateById
(
interfaceGrouping
);
...
@@ -501,77 +487,4 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
...
@@ -501,77 +487,4 @@ public class InterfaceDocServiceImpl extends ServiceImpl<InterfaceDocMapper, Int
return
id
;
return
id
;
}
}
/**
* 当前项目中的根据pathUrl去重,取第一个
*
* @param projectId 项目id
* @return 唯一pathUrl的接口集合
*/
public
List
<
InterfaceDoc
>
getDocByPathUrl
(
Long
projectId
)
{
List
<
InterfaceDoc
>
list
=
new
ArrayList
<>();
//当前项目中的所有接口
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
()
.
filter
(
interfaceDoc
->
interfaceDoc
!=
null
&&
interfaceDoc
.
getPathUrl
()
!=
null
&&
!
""
.
equals
(
interfaceDoc
.
getPathUrl
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceDoc:
:
getPathUrl
));
if
(!
CollectionUtils
.
isEmpty
(
pathUrlMap
))
{
Set
<
String
>
pathUrls
=
pathUrlMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
pathUrls
))
{
for
(
String
pathUrl
:
pathUrls
)
{
InterfaceDoc
interfaceDoc
=
pathUrlMap
.
get
(
pathUrl
).
get
(
0
);
list
.
add
(
interfaceDoc
);
}
}
}
}
return
list
;
}
/**
* 当前项目中同url同分组的数据
*
* @param projectId 项目id
* @return 唯一pathUrl的接口集合
*/
public
List
<
InterfaceDoc
>
getDocByPathUrlAndGrouping
(
Long
projectId
)
{
List
<
InterfaceDoc
>
list
=
new
ArrayList
<>();
//项目中存在的数据
List
<
InterfaceDoc
>
interfaceDocs
=
Optional
.
ofNullable
(
interfaceDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
InterfaceDoc
.
class
)
.
eq
(
InterfaceDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//找到分组以及pathUrl都相同的数据
if
(!
CollectionUtils
.
isEmpty
(
interfaceDocs
))
{
Map
<
String
,
List
<
InterfaceDoc
>>
pathUrlMap
=
interfaceDocs
.
stream
()
.
filter
(
interfaceDoc
->
interfaceDoc
!=
null
&&
interfaceDoc
.
getPathUrl
()
!=
null
&&
!
""
.
equals
(
interfaceDoc
.
getPathUrl
()))
.
collect
(
Collectors
.
groupingBy
(
InterfaceDoc:
:
getPathUrl
));
if
(!
CollectionUtils
.
isEmpty
(
pathUrlMap
))
{
Set
<
String
>
pathUrls
=
pathUrlMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
pathUrls
))
{
for
(
String
pathUrl
:
pathUrls
)
{
List
<
InterfaceDoc
>
interfaceDocList
=
pathUrlMap
.
get
(
pathUrl
);
//url 与 分组 都相同的
Map
<
Long
,
List
<
InterfaceDoc
>>
groupingMap
=
interfaceDocList
.
stream
()
.
filter
(
interfaceDoc
->
interfaceDoc
!=
null
&&
interfaceDoc
.
getInterfaceGroupId
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
InterfaceDoc:
:
getInterfaceGroupId
));
if
(!
CollectionUtils
.
isEmpty
(
groupingMap
))
{
Set
<
Long
>
longs
=
groupingMap
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
longs
))
{
for
(
Long
aLong
:
longs
)
{
List
<
InterfaceDoc
>
urlGroupings
=
groupingMap
.
get
(
aLong
);
//只取第一条
if
(!
CollectionUtils
.
isEmpty
(
urlGroupings
))
{
list
.
add
(
urlGroupings
.
get
(
0
));
}
}
}
}
}
}
}
}
return
list
;
}
}
}
\ No newline at end of file
kt-database/src/main/java/org/matrix/service/impl/MouldDocServiceImpl.java
浏览文件 @
cf7b1990
...
@@ -18,8 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -18,8 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.stream.Collectors
;
import
java.util.List
;
import
java.util.Optional
;
/**
/**
* @author mruny
* @author mruny
...
@@ -331,51 +332,36 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
...
@@ -331,51 +332,36 @@ public class MouldDocServiceImpl extends ServiceImpl<MouldDocMapper, MouldDoc> i
int
ignoreNum
=
0
;
int
ignoreNum
=
0
;
StatusCode
statusCode
=
new
StatusCode
();
StatusCode
statusCode
=
new
StatusCode
();
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
MOULD_DOC
);
statusCode
.
setSwaggerDataType
(
SwaggerDataType
.
MOULD_DOC
);
if
(
mouldVos
.
size
()
!=
0
)
{
if
(
!
CollectionUtils
.
isEmpty
(
mouldVos
)
)
{
List
<
MouldDoc
>
mouldDocs
=
getMouldDoc
(
mouldVos
);
List
<
MouldDoc
>
mouldDocs
=
getMouldDoc
(
mouldVos
);
//
当前项目中的所有
数据模型
//
数据库中存在的当前项目中所有的
数据模型
List
<
MouldDoc
>
mouldDocList
=
Optional
.
ofNullable
(
mouldDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
MouldDoc
.
class
)
List
<
MouldDoc
>
pastMouldDocs
=
Optional
.
ofNullable
(
mouldDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
MouldDoc
.
class
)
.
eq
(
MouldDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
.
eq
(
MouldDoc:
:
getProjectId
,
projectId
))).
orElse
(
new
ArrayList
<>());
//按照名称分组
//如果存在当前分组就直接使用,如果不存在就创建在使用
Map
<
String
,
List
<
MouldDoc
>>
collect
=
mouldDocList
.
stream
()
.
filter
(
mouldDoc
->
mouldDoc
!=
null
&&
mouldDoc
.
getObjName
()
!=
null
&&
!
""
.
equals
(
mouldDoc
.
getObjName
()))
.
collect
(
Collectors
.
groupingBy
(
MouldDoc:
:
getObjName
));
//存在的不同名称的数据模型(如果同名取第一个)
List
<
MouldDoc
>
list
=
new
ArrayList
<>();
//每组取第一个
if
(!
CollectionUtils
.
isEmpty
(
collect
))
{
Set
<
String
>
objNames
=
collect
.
keySet
();
if
(!
CollectionUtils
.
isEmpty
(
objNames
))
{
for
(
String
objName
:
objNames
)
{
MouldDoc
mouldDoc
=
collect
.
get
(
objName
).
get
(
0
);
list
.
add
(
mouldDoc
);
}
}
}
Long
groupingId
=
getGroupingId
(
mouldId
,
projectId
);
Long
groupingId
=
getGroupingId
(
mouldId
,
projectId
);
//存数据,并且将数据库中同名的数据模型修改未未同步
for
(
MouldDoc
mouldDoc
:
mouldDocs
)
{
for
(
MouldDoc
mouldDoc
:
mouldDocs
)
{
//将新的分组存入到数据中
mouldDoc
.
setMouldGroupingId
(
groupingId
);
mouldDoc
.
setMouldGroupingId
(
groupingId
);
mouldDoc
.
setProjectId
(
projectId
);
mouldDoc
.
setProjectId
(
projectId
);
mouldDoc
.
setStatus
(
SyncStatus
.
INSERT
);
mouldDoc
.
setStatus
(
SyncStatus
.
INSERT
);
Integer
integer
=
Optional
.
of
(
mouldDocMapper
.
insert
(
mouldDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加数据模型失败"
));
List
<
MouldDoc
>
mouldDocList
=
Optional
.
ofNullable
(
mouldDocMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
MouldDoc
.
class
)
saveNum
=
saveNum
+
integer
;
.
eq
(
MouldDoc:
:
getProjectId
,
projectId
)
//操作数据库中存在的数据模型
.
eq
(
MouldDoc:
:
getObjName
,
mouldDoc
.
getObjName
()))).
orElse
(
new
ArrayList
<>());
for
(
MouldDoc
doc
:
list
)
{
if
(!
CollectionUtils
.
isEmpty
(
mouldDocList
))
{
//如果同名,就将库存中的同名数据模型修改为未同步
for
(
MouldDoc
doc
:
mouldDocList
)
{
if
(
mouldDoc
.
getObjName
().
equals
(
doc
.
getObjName
()))
{
if
(
doc
.
toString
().
equals
(
mouldDoc
.
toString
()))
{
list
.
remove
(
doc
);
pastMouldDocs
.
remove
(
doc
);
doc
.
setStatus
(
SyncStatus
.
NO
);
doc
.
setStatus
(
SyncStatus
.
UPDATE
);
mouldDocMapper
.
updateById
(
doc
);
break
;
}
}
}
}
}
}
//剩下的就是当前存在,但是导入的数据中不存在的
Integer
integer
=
Optional
.
of
(
mouldDocMapper
.
insert
(
mouldDoc
)).
orElseThrow
(()
->
new
GlobalException
(
"添加失败"
));
if
(
list
.
size
()
!=
0
)
{
saveNum
=
saveNum
+
integer
;
for
(
MouldDoc
mouldDoc
:
list
)
{
}
mouldDoc
.
setStatus
(
SyncStatus
.
NO
);
if
(!
CollectionUtils
.
isEmpty
(
pastMouldDocs
))
{
mouldDocMapper
.
updateById
(
mouldDoc
);
for
(
MouldDoc
pastMouldDoc
:
pastMouldDocs
)
{
pastMouldDoc
.
setStatus
(
SyncStatus
.
NO
);
mouldDocMapper
.
updateById
(
pastMouldDoc
);
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论