Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tagManager
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanmw
tagManager
Commits
47823d22
Commit
47823d22
authored
Feb 28, 2020
by
zhangkb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
标签关系维护添加判断关系是否已经存在逻辑
parent
677f0d6a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
TagRelCtrl.java
src/main/java/com/keymobile/tagmanager/api/TagRelCtrl.java
+4
-0
TagRelRepository.java
...om/keymobile/tagmanager/persistence/TagRelRepository.java
+3
-0
TagRelService.java
.../java/com/keymobile/tagmanager/service/TagRelService.java
+10
-0
No files found.
src/main/java/com/keymobile/tagmanager/api/TagRelCtrl.java
View file @
47823d22
...
...
@@ -36,6 +36,10 @@ public class TagRelCtrl {
if
(
sourceId
.
equals
(
targetId
))
{
throw
new
Exception
(
"can not make source and target as the same one."
);
}
//判断关系是否存在
if
(
tagRelService
.
tagRelExist
(
sourceId
,
targetId
))
{
throw
new
Exception
(
"the tag relation is exist"
);
}
return
tagRelService
.
addTagRel
(
sourceId
,
targetId
,
userId
,
org
);
}
...
...
src/main/java/com/keymobile/tagmanager/persistence/TagRelRepository.java
View file @
47823d22
package
com
.
keymobile
.
tagmanager
.
persistence
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
...
...
@@ -11,4 +12,6 @@ public interface TagRelRepository extends MongoRepository<TagRelation, String>{
List
<
TagRelation
>
findBySourceId
(
String
sourceId
);
List
<
TagRelation
>
findByTargetId
(
String
targetId
);
Optional
<
TagRelation
>
findBySourceIdAndTargetId
(
String
sourceId
,
String
targetId
);
}
src/main/java/com/keymobile/tagmanager/service/TagRelService.java
View file @
47823d22
package
com
.
keymobile
.
tagmanager
.
service
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -14,6 +15,15 @@ public class TagRelService {
@Autowired
private
TagRelRepository
tagRelRepo
;
//判断关系是否存在
public
boolean
tagRelExist
(
String
sourceId
,
String
targetId
)
{
Optional
<
TagRelation
>
tagRel
=
tagRelRepo
.
findBySourceIdAndTargetId
(
sourceId
,
targetId
);
if
(
tagRel
.
isPresent
())
{
return
true
;
}
return
false
;
}
public
TagRelation
addTagRel
(
String
sourceId
,
String
targetId
,
String
userName
,
String
org
)
{
TagRelation
tagRel
=
new
TagRelation
(
sourceId
,
targetId
,
userName
,
org
);
return
tagRelRepo
.
save
(
tagRel
);
...
...
Write
Preview
Markdown
is supported
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