Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
xiaofang li
MeterSphere
Commits
16fffc9c
Commit
16fffc9c
authored
3 years ago
by
song-tianyang
Browse files
Options
Download
Email Patches
Plain Diff
fix(接口导入): 修复接口导入选择覆盖时未覆盖mock期望的bug
修复接口导入选择覆盖时未覆盖mock期望的bug
parent
bfb01376
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java
+4
-0
...java/io/metersphere/api/service/ApiDefinitionService.java
backend/src/main/java/io/metersphere/api/service/MockConfigService.java
+78
-24
...in/java/io/metersphere/api/service/MockConfigService.java
with
82 additions
and
24 deletions
+82
-24
backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java
+
4
-
0
View file @
16fffc9c
...
@@ -630,6 +630,9 @@ public class ApiDefinitionService {
...
@@ -630,6 +630,9 @@ public class ApiDefinitionService {
reSetImportMocksApiId
(
mocks
,
originId
,
apiDefinition
.
getId
(),
apiDefinition
.
getNum
());
reSetImportMocksApiId
(
mocks
,
originId
,
apiDefinition
.
getId
(),
apiDefinition
.
getNum
());
apiDefinition
.
setRequest
(
requestStr
);
apiDefinition
.
setRequest
(
requestStr
);
importApiCase
(
apiDefinition
,
apiTestImportRequest
);
importApiCase
(
apiDefinition
,
apiTestImportRequest
);
}
else
{
//不覆盖的接口,如果没有sameRequest则不导入。此时清空mock信息
mocks
.
clear
();
}
}
}
else
{
}
else
{
_importCreate
(
sameRequest
,
batchMapper
,
apiDefinition
,
apiTestCaseMapper
,
apiTestImportRequest
,
cases
,
mocks
);
_importCreate
(
sameRequest
,
batchMapper
,
apiDefinition
,
apiTestCaseMapper
,
apiTestImportRequest
,
cases
,
mocks
);
...
@@ -696,6 +699,7 @@ public class ApiDefinitionService {
...
@@ -696,6 +699,7 @@ public class ApiDefinitionService {
apiDefinitionMapper
.
updateByPrimaryKeyWithBLOBs
(
apiDefinition
);
apiDefinitionMapper
.
updateByPrimaryKeyWithBLOBs
(
apiDefinition
);
apiDefinition
.
setRequest
(
request
);
apiDefinition
.
setRequest
(
request
);
reSetImportCasesApiId
(
cases
,
originId
,
apiDefinition
.
getId
());
reSetImportCasesApiId
(
cases
,
originId
,
apiDefinition
.
getId
());
reSetImportMocksApiId
(
mocks
,
originId
,
apiDefinition
.
getId
(),
apiDefinition
.
getNum
());
importApiCase
(
apiDefinition
,
apiTestImportRequest
);
importApiCase
(
apiDefinition
,
apiTestImportRequest
);
}
else
{
}
else
{
apiDefinition
.
setId
(
sameRequest
.
get
(
0
).
getId
());
apiDefinition
.
setId
(
sameRequest
.
get
(
0
).
getId
());
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/api/service/MockConfigService.java
+
78
-
24
View file @
16fffc9c
...
@@ -1381,7 +1381,7 @@ public class MockConfigService {
...
@@ -1381,7 +1381,7 @@ public class MockConfigService {
if
(
CollectionUtils
.
isNotEmpty
(
apiImport
.
getMocks
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
apiImport
.
getMocks
()))
{
Map
<
String
,
List
<
MockExpectConfigWithBLOBs
>>
saveMap
=
new
HashMap
<>();
Map
<
String
,
List
<
MockExpectConfigWithBLOBs
>>
saveMap
=
new
HashMap
<>();
for
(
MockConfigImportDTO
dto
:
apiImport
.
getMocks
())
{
for
(
MockConfigImportDTO
dto
:
apiImport
.
getMocks
())
{
String
apiId
=
dto
.
getApiId
();
//de33108c-26e2-4d4f-826a-a5f8e017d2f4
String
apiId
=
dto
.
getApiId
();
if
(
saveMap
.
containsKey
(
apiId
))
{
if
(
saveMap
.
containsKey
(
apiId
))
{
saveMap
.
get
(
apiId
).
add
(
dto
);
saveMap
.
get
(
apiId
).
add
(
dto
);
}
else
{
}
else
{
...
@@ -1393,37 +1393,91 @@ public class MockConfigService {
...
@@ -1393,37 +1393,91 @@ public class MockConfigService {
for
(
Map
.
Entry
<
String
,
List
<
MockExpectConfigWithBLOBs
>>
entry
:
saveMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
MockExpectConfigWithBLOBs
>>
entry
:
saveMap
.
entrySet
())
{
String
apiId
=
entry
.
getKey
();
String
apiId
=
entry
.
getKey
();
this
.
deleteMockConfigByApiId
(
apiId
);
List
<
MockExpectConfigWithBLOBs
>
list
=
entry
.
getValue
();
List
<
MockExpectConfigWithBLOBs
>
list
=
entry
.
getValue
();
String
mockId
=
UUID
.
randomUUID
().
toString
();
MockConfig
mockConfig
=
this
.
selectMockConfigByApiId
(
apiId
);
MockConfig
config
=
new
MockConfig
();
if
(
mockConfig
==
null
)
{
config
.
setProjectId
(
request
.
getProjectId
());
this
.
insertMockExpectConfigs
(
apiId
,
request
.
getProjectId
(),
list
,
sqlSession
);
config
.
setId
(
mockId
);
}
else
{
config
.
setCreateUserId
(
SessionUtils
.
getUserId
());
this
.
updateMockExpectConfigs
(
mockConfig
,
list
,
sqlSession
);
config
.
setCreateTime
(
System
.
currentTimeMillis
());
config
.
setUpdateTime
(
System
.
currentTimeMillis
());
config
.
setApiId
(
apiId
);
mockConfigMapper
.
insert
(
config
);
int
batchCount
=
0
;
for
(
MockExpectConfigWithBLOBs
mockExpect
:
list
)
{
mockExpect
.
setId
(
UUID
.
randomUUID
().
toString
());
mockExpect
.
setMockConfigId
(
mockId
);
mockExpect
.
setCreateTime
(
System
.
currentTimeMillis
());
mockExpect
.
setUpdateTime
(
System
.
currentTimeMillis
());
mockExpect
.
setCreateUserId
(
SessionUtils
.
getUserId
());
mockExpectConfigMapper
.
insert
(
mockExpect
);
}
if
(
batchCount
%
300
==
0
)
{
sqlSession
.
flushStatements
();
}
}
}
}
}
}
}
}
private
void
updateMockExpectConfigs
(
MockConfig
mockConfig
,
List
<
MockExpectConfigWithBLOBs
>
list
,
SqlSession
sqlSession
)
{
int
batchCount
=
0
;
for
(
MockExpectConfigWithBLOBs
mockExpect
:
list
)
{
MockExpectConfig
expectInDb
=
this
.
findMockExpectConfigByMockConfigIdAndExpectNum
(
mockConfig
.
getId
(),
mockExpect
.
getExpectNum
());
if
(
expectInDb
==
null
){
mockExpect
.
setId
(
UUID
.
randomUUID
().
toString
());
mockExpect
.
setMockConfigId
(
mockConfig
.
getId
());
mockExpect
.
setCreateTime
(
System
.
currentTimeMillis
());
mockExpect
.
setUpdateTime
(
System
.
currentTimeMillis
());
mockExpect
.
setCreateUserId
(
SessionUtils
.
getUserId
());
mockExpectConfigMapper
.
insert
(
mockExpect
);
}
else
{
mockExpect
.
setMockConfigId
(
mockConfig
.
getId
());
mockExpect
.
setId
(
expectInDb
.
getId
());
mockExpect
.
setUpdateTime
(
System
.
currentTimeMillis
());
mockExpectConfigMapper
.
updateByPrimaryKey
(
mockExpect
);
}
}
if
(
batchCount
%
300
==
0
)
{
sqlSession
.
flushStatements
();
}
}
private
MockExpectConfig
findMockExpectConfigByMockConfigIdAndExpectNum
(
String
mockConfigId
,
String
expectNum
)
{
MockExpectConfigExample
example
=
new
MockExpectConfigExample
();
example
.
createCriteria
().
andMockConfigIdEqualTo
(
mockConfigId
).
andExpectNumEqualTo
(
expectNum
);
List
<
MockExpectConfig
>
bloBs
=
this
.
mockExpectConfigMapper
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isNotEmpty
(
bloBs
)){
return
bloBs
.
get
(
0
);
}
else
{
return
null
;
}
}
private
void
insertMockExpectConfigs
(
String
apiId
,
String
projectId
,
List
<
MockExpectConfigWithBLOBs
>
list
,
SqlSession
sqlSession
)
{
String
mockId
=
UUID
.
randomUUID
().
toString
();
MockConfig
config
=
new
MockConfig
();
config
.
setProjectId
(
projectId
);
config
.
setId
(
mockId
);
config
.
setCreateUserId
(
SessionUtils
.
getUserId
());
config
.
setCreateTime
(
System
.
currentTimeMillis
());
config
.
setUpdateTime
(
System
.
currentTimeMillis
());
config
.
setApiId
(
apiId
);
mockConfigMapper
.
insert
(
config
);
int
batchCount
=
0
;
for
(
MockExpectConfigWithBLOBs
mockExpect
:
list
)
{
mockExpect
.
setId
(
UUID
.
randomUUID
().
toString
());
mockExpect
.
setMockConfigId
(
mockId
);
mockExpect
.
setCreateTime
(
System
.
currentTimeMillis
());
mockExpect
.
setUpdateTime
(
System
.
currentTimeMillis
());
mockExpect
.
setCreateUserId
(
SessionUtils
.
getUserId
());
mockExpectConfigMapper
.
insert
(
mockExpect
);
}
if
(
batchCount
%
300
==
0
)
{
sqlSession
.
flushStatements
();
}
}
private
MockConfig
selectMockConfigByApiId
(
String
apiId
)
{
MockConfigExample
example
=
new
MockConfigExample
();
example
.
createCriteria
().
andApiIdEqualTo
(
apiId
);
List
<
MockConfig
>
mockConfigList
=
this
.
mockConfigMapper
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isNotEmpty
(
mockConfigList
))
{
return
mockConfigList
.
get
(
0
);
}
else
{
return
null
;
}
}
public
void
updateMockReturnMsgByApi
(
ApiDefinitionWithBLOBs
apiDefinitionWithBLOBs
)
{
public
void
updateMockReturnMsgByApi
(
ApiDefinitionWithBLOBs
apiDefinitionWithBLOBs
)
{
if
(
apiDefinitionWithBLOBs
==
null
)
{
if
(
apiDefinitionWithBLOBs
==
null
)
{
return
;
return
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment