Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
5dd42263
Commit
5dd42263
authored
Feb 04, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复重复关注的问题
parent
db2d6b8e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
19 deletions
+39
-19
src/main/java/cn/meteor/beyondclouds/modules/question/mapper/xml/QuestionMapper.xml
+2
-2
src/main/java/cn/meteor/beyondclouds/modules/user/api/UserApi.java
+5
-1
src/main/java/cn/meteor/beyondclouds/modules/user/enums/UserErrorCode.java
+2
-1
src/main/java/cn/meteor/beyondclouds/modules/user/service/IUserFollowService.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserFollowServiceImpl.java
+29
-14
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/mapper/xml/QuestionMapper.xml
View file @
5dd42263
...
@@ -31,8 +31,8 @@
...
@@ -31,8 +31,8 @@
on q.question_id = qt.question_id
on q.question_id = qt.question_id
left join tag t
left join tag t
on t.tag_id = qt.tag_id
on t.tag_id = qt.tag_id
<if
test=
"ew != null and ew.
s
qlSegment != null"
>
<if
test=
"ew != null and ew.
customS
qlSegment != null"
>
where ${ew.s
qlSegment}
${ew.customS
qlSegment}
</if>
</if>
</select>
</select>
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/api/UserApi.java
View file @
5dd42263
...
@@ -161,9 +161,13 @@ public class UserApi {
...
@@ -161,9 +161,13 @@ public class UserApi {
@DeleteMapping
(
"/user/{userId}/follower"
)
@DeleteMapping
(
"/user/{userId}/follower"
)
public
Response
delFollower
(
@PathVariable
(
name
=
"userId"
)
String
userId
,
@CurrentSubject
Subject
subject
){
public
Response
delFollower
(
@PathVariable
(
name
=
"userId"
)
String
userId
,
@CurrentSubject
Subject
subject
){
try
{
userFollowService
.
delFollow
(
userId
,
String
.
valueOf
(
subject
.
getId
()));
userFollowService
.
delFollow
(
userId
,
String
.
valueOf
(
subject
.
getId
()));
return
Response
.
success
();
return
Response
.
success
();
}
catch
(
UserServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
}
@ApiOperation
((
"获取我的粉丝"
))
@ApiOperation
((
"获取我的粉丝"
))
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/enums/UserErrorCode.java
View file @
5dd42263
...
@@ -16,7 +16,8 @@ public enum UserErrorCode implements IErrorCode {
...
@@ -16,7 +16,8 @@ public enum UserErrorCode implements IErrorCode {
CAN_NOT_FOLLOW_SELF
(
1003
,
"不能关注自己"
),
CAN_NOT_FOLLOW_SELF
(
1003
,
"不能关注自己"
),
FOLLOWED_USER_NOT_EXISTS
(
1004
,
"被关注用户不存在"
),
FOLLOWED_USER_NOT_EXISTS
(
1004
,
"被关注用户不存在"
),
FOLLOWER_USER_NOT_EXISTS
(
1005
,
"关注者不存在"
),
FOLLOWER_USER_NOT_EXISTS
(
1005
,
"关注者不存在"
),
ALREADY_FOLLOWED
(
1006
,
"已关注过该用户"
);
ALREADY_FOLLOWED
(
1006
,
"已关注过该用户"
),
NON_FOLLOWED
(
1007
,
"没有关注过该用户"
);
UserErrorCode
(
long
code
,
String
msg
)
{
UserErrorCode
(
long
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
code
=
code
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/service/IUserFollowService.java
View file @
5dd42263
...
@@ -26,7 +26,7 @@ public interface IUserFollowService extends IService<UserFollow> {
...
@@ -26,7 +26,7 @@ public interface IUserFollowService extends IService<UserFollow> {
* @param followedId
* @param followedId
* @param followerId
* @param followerId
*/
*/
void
delFollow
(
String
followedId
,
String
followerId
);
void
delFollow
(
String
followedId
,
String
followerId
)
throws
UserServiceException
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserFollowServiceImpl.java
View file @
5dd42263
...
@@ -8,7 +8,6 @@ import cn.meteor.beyondclouds.modules.user.mapper.IUserFollowMapper;
...
@@ -8,7 +8,6 @@ import cn.meteor.beyondclouds.modules.user.mapper.IUserFollowMapper;
import
cn.meteor.beyondclouds.modules.user.service.IUserFollowService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserFollowService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
@@ -43,16 +42,25 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
...
@@ -43,16 +42,25 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
throw
new
UserServiceException
(
UserErrorCode
.
CAN_NOT_FOLLOW_SELF
);
throw
new
UserServiceException
(
UserErrorCode
.
CAN_NOT_FOLLOW_SELF
);
}
}
UserFollow
userFollow
=
new
UserFollow
();
userFollow
.
setFollowedId
(
followedId
);
userFollow
.
setFollowerId
(
followerId
);
QueryWrapper
<
UserFollow
>
userFollowQueryWrapper
=
new
QueryWrapper
<>(
userFollow
);
QueryWrapper
<
UserFollow
>
userFollowQueryWrapper
=
new
QueryWrapper
<>();
if
(
null
!=
getOne
(
userFollowQueryWrapper
))
{
userFollowQueryWrapper
.
eq
(
"followed_id"
,
followedId
);
userFollowQueryWrapper
.
eq
(
"follower_id"
,
followerId
);
UserFollow
userFollow
=
getOne
(
userFollowQueryWrapper
);
if
(
null
!=
userFollow
&&
userFollow
.
getFollowStatus
()
==
0
)
{
throw
new
UserServiceException
(
UserErrorCode
.
ALREADY_FOLLOWED
);
throw
new
UserServiceException
(
UserErrorCode
.
ALREADY_FOLLOWED
);
}
}
boolean
update
=
true
;
if
(
null
==
userFollow
)
{
update
=
false
;
userFollow
=
new
UserFollow
();
userFollow
.
setFollowerId
(
followerId
);
userFollow
.
setFollowedId
(
followedId
);
}
userFollow
.
setFollowStatus
(
0
);
//1.查询被关注用户的基本信息
//1.查询被关注用户的基本信息
User
followedUser
=
userService
.
getById
(
followedId
);
User
followedUser
=
userService
.
getById
(
followedId
);
if
(
null
==
followedUser
)
{
if
(
null
==
followedUser
)
{
...
@@ -69,8 +77,11 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
...
@@ -69,8 +77,11 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
userFollow
.
setFollowerNick
(
followerUser
.
getNickName
());
userFollow
.
setFollowerNick
(
followerUser
.
getNickName
());
userFollow
.
setFollowerAvatar
(
followerUser
.
getUserAvatar
());
userFollow
.
setFollowerAvatar
(
followerUser
.
getUserAvatar
());
userFollow
.
setFollowStatus
(
0
);
if
(
update
)
{
update
(
userFollow
,
userFollowQueryWrapper
);
}
else
{
save
(
userFollow
);
save
(
userFollow
);
}
}
}
...
@@ -80,16 +91,20 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
...
@@ -80,16 +91,20 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
* @param followerId 关注者户的userId
* @param followerId 关注者户的userId
*/
*/
@Override
@Override
public
void
delFollow
(
String
followedId
,
String
followerId
)
{
public
void
delFollow
(
String
followedId
,
String
followerId
)
throws
UserServiceException
{
QueryWrapper
<
UserFollow
>
userFollowQueryWrapper
=
new
QueryWrapper
<>();
userFollowQueryWrapper
.
eq
(
"followed_id"
,
followedId
);
userFollowQueryWrapper
.
eq
(
"follower_id"
,
followerId
);
userFollowQueryWrapper
.
eq
(
"follow_status"
,
0
);
UserFollow
userFollow
=
getOne
(
userFollowQueryWrapper
);
if
(
null
==
userFollow
)
{
throw
new
UserServiceException
(
UserErrorCode
.
NON_FOLLOWED
);
}
userFollow
.
setFollowStatus
(-
1
);
//1.查找符合条件的关注信息
//1.查找符合条件的关注信息
UpdateWrapper
updateWrapper
=
new
UpdateWrapper
();
updateWrapper
.
eq
(
"followed_id"
,
followedId
);
updateWrapper
.
eq
(
"follower_id"
,
followerId
);
//2.将关注状态设置为-1并保存
//2.将关注状态设置为-1并保存
updateWrapper
.
set
(
"follow_status"
,
-
1
);
update
(
userFollow
,
userFollowQueryWrapper
);
update
(
updateWrapper
);
}
}
/**
/**
...
...
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