Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
lanbaoming
jiedao-api-boot-master
Commits
89c2443c
Commit
89c2443c
authored
Jul 31, 2024
by
zhaobiyan
Browse files
Options
Browse Files
Download
Plain Diff
会员id生成锁修改
parents
33a5ce84
fffe49e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
12 deletions
+13
-12
YudaoRedisAutoConfiguration.java
...o/framework/redis/config/YudaoRedisAutoConfiguration.java
+0
-1
MemberUserScoreApiImpl.java
...yudao/module/member/api/score/MemberUserScoreApiImpl.java
+1
-1
MemberUserServiceImpl.java
...dao/module/member/service/user/MemberUserServiceImpl.java
+12
-10
No files found.
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoRedisAutoConfiguration.java
View file @
89c2443c
...
...
@@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.redis.helper.RedisDistributedLock;
import
cn.iocoder.yudao.framework.redis.helper.RedisHelper
;
import
cn.iocoder.yudao.framework.redis.helper.RedisLockTemplate
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.EnableCaching
;
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/api/score/MemberUserScoreApiImpl.java
View file @
89c2443c
...
...
@@ -67,7 +67,7 @@ public class MemberUserScoreApiImpl implements MemberUserScoreApi{
String
lockKey
=
"member:operate:score:"
+
req
.
getMemberId
();
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
try
{
boolean
lockSuccess
=
lock
.
tryLock
(
2
,
2
,
TimeUnit
.
MINUTE
S
);
boolean
lockSuccess
=
lock
.
tryLock
(
2
,
2
,
TimeUnit
.
SECOND
S
);
if
(!
lockSuccess
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
View file @
89c2443c
...
...
@@ -4,15 +4,14 @@ import cn.hutool.core.date.DateUtil;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.iocoder.yudao.framework.apollo.core.event.MemberRegEvent
;
import
cn.iocoder.yudao.framework.common.util.spring.enums.CommonStatusEnum
;
import
cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.common.util.date.DateUtils
;
import
cn.iocoder.yudao.framework.common.util.spring.enums.CommonStatusEnum
;
import
cn.iocoder.yudao.framework.i18n.core.I18nMessage
;
import
cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX
;
import
cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils
;
import
cn.iocoder.yudao.framework.mybatis.core.vo.PageVO
;
import
cn.iocoder.yudao.framework.redis.helper.RedisDistributedLock
;
import
cn.iocoder.yudao.framework.redis.helper.RedisHelper
;
import
cn.iocoder.yudao.module.ecw.api.customer.CustomerApi
;
import
cn.iocoder.yudao.module.ecw.api.internalMessage.ClientInternalMessageApi
;
...
...
@@ -49,6 +48,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import
com.google.common.annotations.VisibleForTesting
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.data.redis.core.script.DefaultRedisScript
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
...
...
@@ -114,8 +115,7 @@ public class MemberUserServiceImpl implements MemberUserService {
private
RedisHelper
redisHelper
;
@Resource
private
RedisDistributedLock
redisDistributedLock
;
private
RedissonClient
redissonClient
;
@Override
public
MemberUserDO
getUserByMobile
(
String
mobile
)
{
...
...
@@ -581,15 +581,15 @@ public class MemberUserServiceImpl implements MemberUserService {
redisScript
.
setScriptText
(
incrIfExistScript
);
redisScript
.
setResultType
(
Long
.
class
);
Long
nextMemberCodeNumber
=
redisHelper
.
execute4Long
(
redisScript
,
Collections
.
singletonList
(
key
));
if
(
nextMemberCodeNumber
!=
null
)
{
return
MemberUserCodeUtils
.
generateMemberCode
(
nextMemberCodeNumber
);
}
boolean
lock
=
redisDistributedLock
.
lock
(
"next:member:code:lock"
,
2000
,
3
,
500
);
if
(!
lock
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
RLock
lock
=
redissonClient
.
getLock
(
"next:member:code:lock"
);
try
{
boolean
lockSuccess
=
lock
.
tryLock
(
2
,
2
,
TimeUnit
.
SECONDS
);
if
(!
lockSuccess
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
nextMemberCodeNumber
=
redisHelper
.
execute4Long
(
redisScript
,
Collections
.
singletonList
(
key
));
if
(
nextMemberCodeNumber
!=
null
)
{
return
MemberUserCodeUtils
.
generateMemberCode
(
nextMemberCodeNumber
);
...
...
@@ -598,8 +598,10 @@ public class MemberUserServiceImpl implements MemberUserService {
Long
memberCodeMaxNumber
=
MemberUserCodeUtils
.
getMemberCodeNumber
(
currentMaxMemberCode
);
redisHelper
.
set
(
key
,
String
.
valueOf
(
memberCodeMaxNumber
),
5
,
TimeUnit
.
MINUTES
);
return
MemberUserCodeUtils
.
generateMemberCode
(
redisHelper
.
incrBy
(
key
,
1
));
}
catch
(
InterruptedException
e
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
finally
{
redisDistributedLock
.
releaseLock
(
"next:member:code:lock"
);
lock
.
unlock
(
);
}
}
...
...
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