Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
d93da892
Commit
d93da892
authored
Sep 06, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
关注操作加锁
parent
c14f1a83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
52 deletions
+52
-52
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FollowFansRecordServiceImpl.java
...java/com/wwdz/ch/wx/impl/FollowFansRecordServiceImpl.java
+52
-52
No files found.
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FollowFansRecordServiceImpl.java
View file @
d93da892
...
@@ -26,12 +26,15 @@ import com.wwdz.ch.wx.service.FollowFansRecordService;
...
@@ -26,12 +26,15 @@ import com.wwdz.ch.wx.service.FollowFansRecordService;
import
com.wwdz.ch.wx.service.MessageService
;
import
com.wwdz.ch.wx.service.MessageService
;
import
com.wwdz.ch.core.service.SendMsgService
;
import
com.wwdz.ch.core.service.SendMsgService
;
import
com.xxdxxs.utils.EntityMapper
;
import
com.xxdxxs.utils.EntityMapper
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -42,6 +45,8 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService {
...
@@ -42,6 +45,8 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService {
private
static
final
String
TEMPLET_URL
=
"/pages/followAndFansList/index"
;
private
static
final
String
TEMPLET_URL
=
"/pages/followAndFansList/index"
;
private
final
static
String
FOLLOW_AND_FANS_KEY
=
"FOLLOW_AND_FANS:"
;
@Autowired
@Autowired
FollowFansRecordDao
followFansRecordDao
;
FollowFansRecordDao
followFansRecordDao
;
...
@@ -69,67 +74,62 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService {
...
@@ -69,67 +74,62 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService {
@Autowired
@Autowired
WxAppletApi
wxAppletApi
;
WxAppletApi
wxAppletApi
;
@Autowired
RedissonClient
redissonClient
;
@Override
@Override
public
Result
follow
(
FollowFansRecordRequestDto
dto
)
{
public
Result
follow
(
FollowFansRecordRequestDto
dto
)
{
String
key
=
FOLLOW_AND_FANS_KEY
+
dto
.
getFollowerId
()
+
":"
+
dto
.
getFansId
();
RLock
lock
=
redissonClient
.
getLock
(
key
);
try
{
try
{
if
(
dto
.
getFollowerId
()
==
null
||
dto
.
getFansId
()
==
null
)
{
if
(
lock
.
tryLock
(
5
,
TimeUnit
.
SECONDS
))
{
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
if
(
dto
.
getFollowerId
()
==
null
||
dto
.
getFansId
()
==
null
)
{
}
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
//校验是否已有关注记录
}
if
(
isFollowed
(
dto
))
{
//校验是否已有关注记录
return
Result
.
failed
(
"已经关注,无需重复操作"
);
if
(
isFollowed
(
dto
))
{
}
return
Result
.
failed
(
"已经关注,无需重复操作"
);
}
Date
now
=
new
Date
();
Date
now
=
new
Date
();
FollowFansRecord
followFansRecord
=
new
FollowFansRecord
();
FollowFansRecord
followFansRecord
=
new
FollowFansRecord
();
EntityMapper
.
copyAttribute
(
dto
,
followFansRecord
);
EntityMapper
.
copyAttribute
(
dto
,
followFansRecord
);
followFansRecord
.
setCreateTime
(
now
);
followFansRecord
.
setCreateTime
(
now
);
followFansRecord
.
setUpdateTime
(
now
);
followFansRecord
.
setUpdateTime
(
now
);
followFansRecord
.
setState
(
1
);
followFansRecord
.
setState
(
1
);
int
id
=
followFansRecordDao
.
add
(
followFansRecord
);
int
id
=
followFansRecordDao
.
add
(
followFansRecord
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"recordId"
,
id
);
map
.
put
(
"recordId"
,
id
);
String
fansName
=
cacheUtil
.
appletUserInfoCache
.
get
(
dto
.
getFansId
()).
get
().
getNickname
();
String
fansName
=
cacheUtil
.
appletUserInfoCache
.
get
(
dto
.
getFansId
()).
get
().
getNickname
();
//发送消息通知对应的分销商有用户出价
//发送消息通知对应的分销商有用户出价
String
openId
=
sendMsgService
.
getOpenIdByUserId
(
dto
.
getFollowerId
());
String
openId
=
sendMsgService
.
getOpenIdByUserId
(
dto
.
getFollowerId
());
if
(
com
.
xxdxxs
.
utils
.
StringUtils
.
hasLength
(
openId
))
{
if
(
com
.
xxdxxs
.
utils
.
StringUtils
.
hasLength
(
openId
))
{
FollowFansMsg
followFansMsg
=
new
FollowFansMsg
();
FollowFansMsg
followFansMsg
=
new
FollowFansMsg
();
followFansMsg
.
setFansName
(
fansName
+
"关注了你"
);
followFansMsg
.
setFansName
(
fansName
+
"关注了你"
);
followFansMsg
.
setOpenId
(
openId
);
followFansMsg
.
setOpenId
(
openId
);
followFansMsg
.
setContent
(
"由"
+
cacheUtil
.
appletUserInfoCache
.
get
(
dto
.
getIntroducerId
()).
get
().
getNickname
()
+
"介绍"
);
followFansMsg
.
setContent
(
"由"
+
cacheUtil
.
appletUserInfoCache
.
get
(
dto
.
getIntroducerId
()).
get
().
getNickname
()
+
"介绍"
);
Result
result
=
sendMsgService
.
followNoticeMsg
(
followFansMsg
);
Result
result
=
sendMsgService
.
followNoticeMsg
(
followFansMsg
);
if
(!
result
.
getSuccess
())
{
if
(!
result
.
getSuccess
())
{
String
url
=
wxAppletApi
.
getUrlLink
(
TEMPLET_URL
,
"tabType=2"
);
String
url
=
wxAppletApi
.
getUrlLink
(
TEMPLET_URL
,
"tabType=2"
);
String
msg
=
"您新增了一个粉丝"
+
fansName
+
", 请前往"
+
url
+
"查看"
;
String
msg
=
"您新增了一个粉丝"
+
fansName
+
", 请前往"
+
url
+
"查看"
;
aliSmsSender
.
sendSms
(
dto
.
getFollowerId
(),
msg
);
}
}
else
{
String
url
=
wxAppletApi
.
getUrlLink
(
TEMPLET_URL
,
"tabType=2"
);
String
msg
=
"您新增了一个粉丝"
+
fansName
+
", 请前往"
+
url
+
"查看"
;
aliSmsSender
.
sendSms
(
dto
.
getFollowerId
(),
msg
);
aliSmsSender
.
sendSms
(
dto
.
getFollowerId
(),
msg
);
}
}
}
else
{
String
url
=
wxAppletApi
.
getUrlLink
(
TEMPLET_URL
,
"tabType=2"
);
String
msg
=
"您新增了一个粉丝"
+
fansName
+
", 请前往"
+
url
+
"查看"
;
aliSmsSender
.
sendSms
(
dto
.
getFollowerId
(),
msg
);
}
/* String messageKey = StringUtil.formatMessageKey(dto.getFansId(), MessageEnum.TypeEnum.FOLLOW.getCode(), dto.getFollowerId());
if (redisUtils.hasKey(messageKey)) {
return
Result
.
success
(
map
);
return
Result
.
success
(
map
);
}
else
{
return
Result
.
failed
(
"稍后再试"
);
}
}
//发送关注的消息
MessageRequestDto messageRequestDto = new MessageRequestDto();
messageRequestDto.setSenderId(dto.getFansId());
messageRequestDto.setReceiverId(dto.getFollowerId());
messageRequestDto.setType(MessageEnum.TypeEnum.FOLLOW.getCode());
MessageContentText messageContentText = new MessageContentText();
messageContentText.setId(dto.getFansId());
messageContentText.setIdType(MessageEnum.ContentIdTypeEnum.USERID.getCode());
messageContentText.setText("关注了您");
messageRequestDto.setContent(JsonUtils.from(messageContentText));
messageService.add(messageRequestDto);
//五分钟内再次关注不会发送消息
redisUtils.set(messageKey, LocalDateTime.now(), 60 * 5);*/
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"{} 关注 {} error {}"
,
dto
.
getFansId
(),
dto
.
getFollowerId
(),
e
);
logger
.
error
(
"{} 关注 {} error {}"
,
dto
.
getFansId
(),
dto
.
getFollowerId
(),
e
);
}
finally
{
if
(
lock
!=
null
&&
lock
.
isHeldByCurrentThread
())
{
lock
.
unlock
();
logger
.
info
(
"======================== 关注操作 释放锁成功 ========================"
,
Thread
.
currentThread
().
getId
());
}
}
}
return
Result
.
failed
();
return
Result
.
failed
();
}
}
...
...
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