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
2b680f95
Commit
2b680f95
authored
Aug 26, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兑换礼品修改
parent
605cfe64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
25 deletions
+78
-25
RedeemRewardApi.java
...coder/yudao/module/reward/api/reward/RedeemRewardApi.java
+41
-0
RedeemRewardApiImpl.java
...r/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
+35
-25
YudaoServerApplication.java
.../java/cn/iocoder/yudao/server/YudaoServerApplication.java
+2
-0
No files found.
yudao-module-reward/yudao-module-reward-api/src/main/java/cn/iocoder/yudao/module/reward/api/reward/RedeemRewardApi.java
View file @
2b680f95
...
...
@@ -11,9 +11,50 @@ import java.util.List;
*/
public
interface
RedeemRewardApi
{
/**
* 兑换礼品
*
* @param redeemRewardReqVO
* @return
*/
Boolean
redeemReward
(
RedeemRewardReqVO
redeemRewardReqVO
);
/**
* 执行兑换事务
*
* @param redeemRewardReqVO
* @param pointsRequire
* @param rewardId
*/
void
executeRedeem
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
,
Long
rewardId
);
/**
* 批量兑换礼品
*
* @param redeemRewardReqVOList
* @return
*/
List
<
RedeemRewardRespDTO
>
redeemRewards
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
);
/**
* 批量执行兑换事务
*
* @param redeemRewardReqVOList
* @param pointsRequire
* @param rewardId
*/
void
batchExecuteRedeem
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
,
Integer
pointsRequire
,
Long
rewardId
);
/**
* 客户端获取礼品详情
* @param redeemId
* @return
*/
RedeemDetailForUserDTO
getRedeemDetailForUser
(
Long
redeemId
);
/**
* 兑换礼品发送验证码
* @param memberId
*/
void
sendSmsCode
(
Long
memberId
);
}
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
View file @
2b680f95
...
...
@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.lang3.StringUtils
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.aop.framework.AopContext
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -70,7 +71,6 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
private
SmsCodeApi
smsCodeApi
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
redeemReward
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
UserRespDTO
memberUser
=
memberUserApi
.
getUser
(
redeemRewardReqVO
.
getMemberId
());
if
(
memberUser
==
null
)
{
...
...
@@ -98,12 +98,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
if
(!
lock
.
tryLock
(
2
,
10
,
TimeUnit
.
SECONDS
))
{
throw
exception
(
GET_LOCK_FAILED
);
}
// 添加兑换记录
Long
redeemId
=
addRedeemRecord
(
redeemRewardReqVO
,
rewardDO
);
// 更新会员积分
updateMemberScore
(
redeemRewardReqVO
,
rewardDO
,
redeemId
);
// 更新礼品
redeemReward
(
rewardDO
,
redeemRewardReqVO
.
getRewardCount
());
RedeemRewardApi
currentProxy
=
(
RedeemRewardApi
)
AopContext
.
currentProxy
();
currentProxy
.
executeRedeem
(
redeemRewardReqVO
,
rewardDO
.
getPointsRequire
(),
rewardDO
.
getId
());
}
catch
(
InterruptedException
e
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
finally
{
...
...
@@ -112,6 +108,17 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return
true
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
executeRedeem
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
,
Long
rewardId
)
{
// 添加兑换记录
Long
redeemId
=
addRedeemRecord
(
redeemRewardReqVO
,
pointsRequire
);
// 更新会员积分
updateMemberScore
(
redeemRewardReqVO
,
pointsRequire
,
redeemId
);
// 更新礼品
redeemReward
(
rewardId
,
redeemRewardReqVO
.
getRewardCount
());
}
private
RewardDO
getAndVerifyRewardDO
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
// 查询礼品
RewardDO
rewardDO
=
rewardMapper
.
selectById
(
redeemRewardReqVO
.
getRewardId
());
...
...
@@ -150,41 +157,42 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
}
}
private
void
redeemReward
(
RewardDO
rewar
d
,
Integer
rewardCount
)
{
private
void
redeemReward
(
Long
rewardI
d
,
Integer
rewardCount
)
{
// 更新时校验礼品数量是否足够
RewardDO
rewardDO
=
rewardMapper
.
selectById
(
reward
.
getId
()
);
RewardDO
rewardDO
=
rewardMapper
.
selectById
(
reward
Id
);
if
(
rewardDO
.
getQuantityRemain
()
<
rewardCount
)
{
throw
exception
(
REWARD_COUNT_NOT_ENOUGH
);
}
reward
.
setExchangeCount
(
rewardDO
.
getExchangeCount
()
+
1
);
reward
.
setQuantityRemain
(
rewardDO
.
getQuantityRemain
()
-
rewardCount
);
rewardMapper
.
updateById
(
reward
);
RewardDO
upReward
=
new
RewardDO
();
upReward
.
setId
(
rewardId
);
upReward
.
setExchangeCount
(
rewardDO
.
getExchangeCount
()
+
1
);
upReward
.
setQuantityRemain
(
rewardDO
.
getQuantityRemain
()
-
rewardCount
);
rewardMapper
.
updateById
(
upReward
);
}
private
void
updateMemberScore
(
RedeemRewardReqVO
redeemRewardReqVO
,
RewardDO
rewardDO
,
Long
redeemId
)
{
private
void
updateMemberScore
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
,
Long
redeemId
)
{
Map
<
String
,
Object
>
extParam
=
new
HashMap
<>();
extParam
.
put
(
"redeemId"
,
redeemId
);
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
redeemRewardReqVO
.
getMemberId
())
.
sourceType
(
ScoreSourceTypeEnum
.
EXCHANGE_REWARD
)
.
scoreCount
(
redeemRewardReqVO
.
getRewardCount
()
*
rewardDO
.
getPointsRequire
()
)
.
scoreCount
(
redeemRewardReqVO
.
getRewardCount
()
*
pointsRequire
)
.
releationId
(
String
.
valueOf
(
redeemId
))
.
uniqueId
(
String
.
valueOf
(
redeemId
))
.
extParam
(
extParam
)
.
build
());
}
private
Long
addRedeemRecord
(
RedeemRewardReqVO
redeemRewardReqVO
,
RewardDO
rewardDO
)
{
private
Long
addRedeemRecord
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
)
{
RewardRedeemDO
rewardRedeemDO
=
BeanUtil
.
copyProperties
(
redeemRewardReqVO
,
RewardRedeemDO
.
class
);
rewardRedeemDO
.
setId
(
snowflakeGenerator
.
next
());
rewardRedeemDO
.
setStatus
(
RewardRedeemStatusEnum
.
REDEEMING
.
getValue
());
rewardRedeemDO
.
setScoreCount
(
redeemRewardReqVO
.
getRewardCount
()
*
rewardDO
.
getPointsRequire
()
);
rewardRedeemDO
.
setScoreCount
(
redeemRewardReqVO
.
getRewardCount
()
*
pointsRequire
);
rewardRedeemMapper
.
insert
(
rewardRedeemDO
);
return
rewardRedeemDO
.
getId
();
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
List
<
RedeemRewardRespDTO
>
redeemRewards
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
)
{
// 批量兑换每次最多十条
if
(
redeemRewardReqVOList
.
size
()
>
10
)
{
...
...
@@ -230,14 +238,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
if
(!
lock
.
tryLock
(
2
,
10
,
TimeUnit
.
SECONDS
))
{
throw
exception
(
GET_LOCK_FAILED
);
}
for
(
RedeemRewardReqVO
redeemRewardReqVO
:
redeemRewardReqVOList
)
{
// 添加兑换记录
Long
redeemId
=
addRedeemRecord
(
redeemRewardReqVO
,
rewardDO
);
// 更新会员积分
updateMemberScore
(
redeemRewardReqVO
,
rewardDO
,
redeemId
);
// 更新礼品
redeemReward
(
rewardDO
,
redeemRewardReqVO
.
getRewardCount
());
}
RedeemRewardApi
currentProxy
=
(
RedeemRewardApi
)
AopContext
.
currentProxy
();
currentProxy
.
batchExecuteRedeem
(
redeemRewardReqVOList
,
rewardDO
.
getPointsRequire
(),
rewardDO
.
getId
());
}
catch
(
ServiceException
e
)
{
log
.
error
(
"batch redeem rewards exception:{}"
,
e
.
getMessage
());
throw
e
;
...
...
@@ -249,6 +251,14 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return
null
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
batchExecuteRedeem
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
,
Integer
pointsRequire
,
Long
rewardId
)
{
for
(
RedeemRewardReqVO
redeemRewardReqVO
:
redeemRewardReqVOList
)
{
executeRedeem
(
redeemRewardReqVO
,
pointsRequire
,
rewardId
);
}
}
@Override
public
RedeemDetailForUserDTO
getRedeemDetailForUser
(
Long
redeemId
)
{
RewardRedeemDO
rewardRedeemDO
=
rewardRedeemMapper
.
selectById
(
redeemId
);
...
...
yudao-server/src/main/java/cn/iocoder/yudao/server/YudaoServerApplication.java
View file @
2b680f95
...
...
@@ -3,10 +3,12 @@ package cn.iocoder.yudao.server;
import
cn.jasonone.ueditor.EnableUeditor
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
@SuppressWarnings
(
"SpringComponentScan"
)
// 忽略 IDEA 无法识别 ${yudao.info.base-package}
//@EnableUeditor
@SpringBootApplication
(
scanBasePackages
=
{
"${yudao.info.base-package}.server"
,
"${yudao.info.base-package}.module"
})
@EnableAspectJAutoProxy
(
exposeProxy
=
true
)
public
class
YudaoServerApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
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