Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
point-project
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hqzhdj
point-project
Commits
53ea2934
Commit
53ea2934
authored
Nov 13, 2025
by
“Kongxiangkun”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加积分增加并发锁
parent
b152f992
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
cloud-point/src/main/java/com/yizhi/application/service/impl/PointServiceImpl.java
+19
-3
No files found.
cloud-point/src/main/java/com/yizhi/application/service/impl/PointServiceImpl.java
View file @
53ea2934
...
@@ -17,6 +17,7 @@ import com.yizhi.application.orm.id.IdGenerator;
...
@@ -17,6 +17,7 @@ import com.yizhi.application.orm.id.IdGenerator;
import
com.yizhi.application.service.PointDetailsService
;
import
com.yizhi.application.service.PointDetailsService
;
import
com.yizhi.application.service.PointService
;
import
com.yizhi.application.service.PointService
;
import
com.yizhi.application.service.PointUserService
;
import
com.yizhi.application.service.PointUserService
;
import
com.yizhi.core.application.cache.RedisCache
;
import
com.yizhi.core.application.context.ContextHolder
;
import
com.yizhi.core.application.context.ContextHolder
;
import
com.yizhi.point.application.vo.PointDetailListVO
;
import
com.yizhi.point.application.vo.PointDetailListVO
;
import
com.yizhi.point.application.vo.PointUserExchangeVO
;
import
com.yizhi.point.application.vo.PointUserExchangeVO
;
...
@@ -57,6 +58,8 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
...
@@ -57,6 +58,8 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
private
PointProductMapper
pointProductMapper
;
private
PointProductMapper
pointProductMapper
;
@Autowired
@Autowired
private
PointDetailsMapper
pointDetailsMapper
;
private
PointDetailsMapper
pointDetailsMapper
;
@Autowired
private
RedisCache
redisCache
;
@Override
@Override
public
Point
pointList
(
Long
companyId
,
Long
siteId
)
{
public
Point
pointList
(
Long
companyId
,
Long
siteId
)
{
...
@@ -97,8 +100,12 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
...
@@ -97,8 +100,12 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
addPoint
(
Long
accountId
,
String
type
,
String
sourceId
){
public
void
addPoint
(
Long
accountId
,
String
type
,
String
sourceId
){
if
(
accountId
==
null
||
StringUtils
.
isBlank
(
type
)){
String
redisKey
=
"add_point_locked_user:"
+
accountId
;
try
{
if
(
redisCache
.
setIfAbsent
(
redisKey
,
"1"
))
{
if
(
accountId
==
null
||
StringUtils
.
isBlank
(
type
))
{
log
.
error
(
"增加积分入参异常 accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
log
.
error
(
"增加积分入参异常 accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
redisCache
.
delete
(
redisKey
);
return
;
return
;
}
}
log
.
info
(
"增加积分入参: accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
log
.
info
(
"增加积分入参: accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
...
@@ -109,7 +116,7 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
...
@@ -109,7 +116,7 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
//执行积分奖励策略进行相应的业务校验
//执行积分奖励策略进行相应的业务校验
PointTypeStrategy
strategy
=
getPointByType
(
type
,
accountId
,
sourceId
);
PointTypeStrategy
strategy
=
getPointByType
(
type
,
accountId
,
sourceId
);
log
.
info
(
"获取赠送积分策略:{}"
,
JSONUtil
.
toJsonStr
(
strategy
));
log
.
info
(
"获取赠送积分策略:{}"
,
JSONUtil
.
toJsonStr
(
strategy
));
if
(
strategy
!=
null
)
{
if
(
strategy
!=
null
)
{
PointUser
pu
=
new
PointUser
();
PointUser
pu
=
new
PointUser
();
pu
.
setUserId
(
accountId
);
pu
.
setUserId
(
accountId
);
EntityWrapper
<
PointUser
>
wrapper
=
new
EntityWrapper
<
PointUser
>(
pu
);
EntityWrapper
<
PointUser
>
wrapper
=
new
EntityWrapper
<
PointUser
>(
pu
);
...
@@ -134,7 +141,7 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
...
@@ -134,7 +141,7 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
pu
.
setSiteId
(
siteId
);
pu
.
setSiteId
(
siteId
);
pu
.
setCompanyId
(
companyId
);
pu
.
setCompanyId
(
companyId
);
boolean
b
=
pointUserService
.
insertOrUpdate
(
pu
);
boolean
b
=
pointUserService
.
insertOrUpdate
(
pu
);
if
(
b
)
{
if
(
b
)
{
PointDetails
pd
=
new
PointDetails
();
PointDetails
pd
=
new
PointDetails
();
pd
.
setId
(
idGenerator
.
generate
());
pd
.
setId
(
idGenerator
.
generate
());
pd
.
setTime
(
new
Date
());
pd
.
setTime
(
new
Date
());
...
@@ -156,6 +163,15 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
...
@@ -156,6 +163,15 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
pointDetailsService
.
insert
(
pd
);
pointDetailsService
.
insert
(
pd
);
}
}
}
}
redisCache
.
delete
(
redisKey
);
}
else
{
log
.
info
(
"同一用户并发触发增加积分, 用户:{}"
+
accountId
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"增加积分发生异常:{}, 用户:{}, type:{}"
,
e
.
getMessage
(),
accountId
,
type
);
}
finally
{
redisCache
.
delete
(
redisKey
);
}
}
}
public
PointTypeStrategy
getPointByType
(
String
type
,
Long
accountId
,
String
sourceId
){
public
PointTypeStrategy
getPointByType
(
String
type
,
Long
accountId
,
String
sourceId
){
...
...
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