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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
56 deletions
+72
-56
cloud-point/src/main/java/com/yizhi/application/service/impl/PointServiceImpl.java
+72
-56
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;
import
com.yizhi.application.service.PointDetailsService
;
import
com.yizhi.application.service.PointService
;
import
com.yizhi.application.service.PointUserService
;
import
com.yizhi.core.application.cache.RedisCache
;
import
com.yizhi.core.application.context.ContextHolder
;
import
com.yizhi.point.application.vo.PointDetailListVO
;
import
com.yizhi.point.application.vo.PointUserExchangeVO
;
...
...
@@ -57,6 +58,8 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
private
PointProductMapper
pointProductMapper
;
@Autowired
private
PointDetailsMapper
pointDetailsMapper
;
@Autowired
private
RedisCache
redisCache
;
@Override
public
Point
pointList
(
Long
companyId
,
Long
siteId
)
{
...
...
@@ -97,64 +100,77 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
addPoint
(
Long
accountId
,
String
type
,
String
sourceId
){
if
(
accountId
==
null
||
StringUtils
.
isBlank
(
type
)){
log
.
error
(
"增加积分入参异常 accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
return
;
}
log
.
info
(
"增加积分入参: accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
Long
companyId
=
ContextHolder
.
get
().
getCompanyId
();
Long
orgId
=
ContextHolder
.
get
().
getOrgId
();
Long
siteId
=
ContextHolder
.
get
().
getSiteId
();
String
accountName
=
ContextHolder
.
get
().
getAccountName
();
//执行积分奖励策略进行相应的业务校验
PointTypeStrategy
strategy
=
getPointByType
(
type
,
accountId
,
sourceId
);
log
.
info
(
"获取赠送积分策略:{}"
,
JSONUtil
.
toJsonStr
(
strategy
));
if
(
strategy
!=
null
)
{
PointUser
pu
=
new
PointUser
();
pu
.
setUserId
(
accountId
);
EntityWrapper
<
PointUser
>
wrapper
=
new
EntityWrapper
<
PointUser
>(
pu
);
pu
=
pointUserService
.
selectOne
(
wrapper
);
Long
id
=
idGenerator
.
generate
();
if
(
pu
==
null
)
{
pu
=
new
PointUser
();
pu
.
setId
(
id
);
pu
.
setUserId
(
accountId
);
pu
.
setTotalPoint
(
strategy
.
getPoint
());
pu
.
setState
(
1
);
pu
.
setCreateById
(
accountId
);
pu
.
setCreateByName
(
accountName
);
pu
.
setCreateTime
(
new
Date
());
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
);
redisCache
.
delete
(
redisKey
);
return
;
}
log
.
info
(
"增加积分入参: accountId:{}, type:{}, sourceId:{}"
,
accountId
,
type
,
sourceId
);
Long
companyId
=
ContextHolder
.
get
().
getCompanyId
();
Long
orgId
=
ContextHolder
.
get
().
getOrgId
();
Long
siteId
=
ContextHolder
.
get
().
getSiteId
();
String
accountName
=
ContextHolder
.
get
().
getAccountName
();
//执行积分奖励策略进行相应的业务校验
PointTypeStrategy
strategy
=
getPointByType
(
type
,
accountId
,
sourceId
);
log
.
info
(
"获取赠送积分策略:{}"
,
JSONUtil
.
toJsonStr
(
strategy
));
if
(
strategy
!=
null
)
{
PointUser
pu
=
new
PointUser
();
pu
.
setUserId
(
accountId
);
EntityWrapper
<
PointUser
>
wrapper
=
new
EntityWrapper
<
PointUser
>(
pu
);
pu
=
pointUserService
.
selectOne
(
wrapper
);
Long
id
=
idGenerator
.
generate
();
if
(
pu
==
null
)
{
pu
=
new
PointUser
();
pu
.
setId
(
id
);
pu
.
setUserId
(
accountId
);
pu
.
setTotalPoint
(
strategy
.
getPoint
());
pu
.
setState
(
1
);
pu
.
setCreateById
(
accountId
);
pu
.
setCreateByName
(
accountName
);
pu
.
setCreateTime
(
new
Date
());
}
else
{
pu
.
setTotalPoint
(
pu
.
getTotalPoint
()
+
strategy
.
getPoint
());
pu
.
setUpdateById
(
accountId
);
pu
.
setUpdateByName
(
accountName
);
pu
.
setUpdateTime
(
new
Date
());
}
pu
.
setOrgId
(
orgId
);
pu
.
setSiteId
(
siteId
);
pu
.
setCompanyId
(
companyId
);
boolean
b
=
pointUserService
.
insertOrUpdate
(
pu
);
if
(
b
)
{
PointDetails
pd
=
new
PointDetails
();
pd
.
setId
(
idGenerator
.
generate
());
pd
.
setTime
(
new
Date
());
pd
.
setChangeBefore
(
pu
.
getTotalPoint
());
pd
.
setPoint
(
strategy
.
getPoint
());
pd
.
setChangeAfter
(
pu
.
getTotalPoint
()
+
strategy
.
getPoint
());
pd
.
setMultiple
(
1
);
pd
.
setAccountId
(
accountId
);
pd
.
setLearnName
(
strategy
.
getPointTypeEnum
().
getDesc
());
pd
.
setLearnSource
(
strategy
.
getLearnSource
());
pd
.
setLearnType
(
strategy
.
getPointTypeEnum
().
getKey
());
pd
.
setState
(
1
);
pd
.
setCreateById
(
accountId
);
pd
.
setCreateByName
(
accountName
);
pd
.
setCreateTime
(
new
Date
());
pd
.
setOrgId
(
orgId
);
pd
.
setCompanyId
(
companyId
);
pd
.
setSiteId
(
siteId
);
pointDetailsService
.
insert
(
pd
);
}
}
redisCache
.
delete
(
redisKey
);
}
else
{
pu
.
setTotalPoint
(
pu
.
getTotalPoint
()
+
strategy
.
getPoint
());
pu
.
setUpdateById
(
accountId
);
pu
.
setUpdateByName
(
accountName
);
pu
.
setUpdateTime
(
new
Date
());
}
pu
.
setOrgId
(
orgId
);
pu
.
setSiteId
(
siteId
);
pu
.
setCompanyId
(
companyId
);
boolean
b
=
pointUserService
.
insertOrUpdate
(
pu
);
if
(
b
)
{
PointDetails
pd
=
new
PointDetails
();
pd
.
setId
(
idGenerator
.
generate
());
pd
.
setTime
(
new
Date
());
pd
.
setChangeBefore
(
pu
.
getTotalPoint
());
pd
.
setPoint
(
strategy
.
getPoint
());
pd
.
setChangeAfter
(
pu
.
getTotalPoint
()
+
strategy
.
getPoint
());
pd
.
setMultiple
(
1
);
pd
.
setAccountId
(
accountId
);
pd
.
setLearnName
(
strategy
.
getPointTypeEnum
().
getDesc
());
pd
.
setLearnSource
(
strategy
.
getLearnSource
());
pd
.
setLearnType
(
strategy
.
getPointTypeEnum
().
getKey
());
pd
.
setState
(
1
);
pd
.
setCreateById
(
accountId
);
pd
.
setCreateByName
(
accountName
);
pd
.
setCreateTime
(
new
Date
());
pd
.
setOrgId
(
orgId
);
pd
.
setCompanyId
(
companyId
);
pd
.
setSiteId
(
siteId
);
pointDetailsService
.
insert
(
pd
);
log
.
info
(
"同一用户并发触发增加积分, 用户:{}"
+
accountId
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"增加积分发生异常:{}, 用户:{}, type:{}"
,
e
.
getMessage
(),
accountId
,
type
);
}
finally
{
redisCache
.
delete
(
redisKey
);
}
}
...
...
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