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
b5756901
Commit
b5756901
authored
Jul 25, 2024
by
zhaobiyan
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
035f70f1
104b9bbe
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
131 additions
and
6 deletions
+131
-6
RedeemRewardReqVO.java
...yudao/module/reward/api/reward/dto/RedeemRewardReqVO.java
+2
-5
ErrorCodeConstants.java
...iocoder/yudao/module/reward/enums/ErrorCodeConstants.java
+4
-0
pom.xml
yudao-module-reward/yudao-module-reward-impl/pom.xml
+10
-1
RedeemRewardApiImpl.java
...r/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
+114
-0
RewardServiceImpl.java
...yudao/module/reward/service/reward/RewardServiceImpl.java
+1
-0
No files found.
yudao-module-reward/yudao-module-reward-api/src/main/java/cn/iocoder/yudao/module/reward/api/reward/dto/RedeemRewardReqVO.java
View file @
b5756901
...
@@ -12,11 +12,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
...
@@ -12,11 +12,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@Data
@ApiModel
(
"管理后台 - 礼品兑换 Request VO"
)
@ApiModel
(
"管理后台 - 礼品兑换 Request VO"
)
public
class
RedeemRewardReqVO
{
public
class
RedeemRewardReqVO
{
@ApiModelProperty
(
value
=
"会员名称"
)
@ApiModelProperty
(
value
=
"会员id"
)
private
String
memberName
;
private
Long
memberId
;
@ApiModelProperty
(
value
=
"当前积分"
)
private
Integer
score
;
@ApiModelProperty
(
value
=
"礼品id"
)
@ApiModelProperty
(
value
=
"礼品id"
)
private
Long
rewardId
;
private
Long
rewardId
;
...
...
yudao-module-reward/yudao-module-reward-api/src/main/java/cn/iocoder/yudao/module/reward/enums/ErrorCodeConstants.java
View file @
b5756901
...
@@ -17,5 +17,9 @@ public interface ErrorCodeConstants {
...
@@ -17,5 +17,9 @@ public interface ErrorCodeConstants {
ErrorCode
REWARD_PICK_METHOD_NOT_ALLOW_CREATE
=
new
ErrorCode
(
1001011009
,
"领取方式不合法"
);
ErrorCode
REWARD_PICK_METHOD_NOT_ALLOW_CREATE
=
new
ErrorCode
(
1001011009
,
"领取方式不合法"
);
ErrorCode
REWARD_STATUS_NOT_ALLOW_UPDATE
=
new
ErrorCode
(
1001011010
,
"礼物状态不允许编辑"
);
ErrorCode
REWARD_STATUS_NOT_ALLOW_UPDATE
=
new
ErrorCode
(
1001011010
,
"礼物状态不允许编辑"
);
ErrorCode
REWARD_STATUS_NOT_ALLOW_ENABLE
=
new
ErrorCode
(
1001011011
,
"礼物不能启用"
);
ErrorCode
REWARD_STATUS_NOT_ALLOW_ENABLE
=
new
ErrorCode
(
1001011011
,
"礼物不能启用"
);
ErrorCode
REWARD_NOT_ENABLE
=
new
ErrorCode
(
1001011012
,
"礼物未启用"
);
ErrorCode
REWARD_SCORE_NOT_ENOUGH
=
new
ErrorCode
(
1001011013
,
"会员积分不够"
);
ErrorCode
REWARD_COUNT_NOT_ENOUGH
=
new
ErrorCode
(
1001011014
,
"礼品数量不够"
);
ErrorCode
REWARD_REDEEM_FAIL
=
new
ErrorCode
(
1001011015
,
"批量兑换失败"
);
}
}
yudao-module-reward/yudao-module-reward-impl/pom.xml
View file @
b5756901
...
@@ -26,7 +26,16 @@
...
@@ -26,7 +26,16 @@
<artifactId>
yudao-module-reward-api
</artifactId>
<artifactId>
yudao-module-reward-api
</artifactId>
<version>
${revision}
</version>
<version>
${revision}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
cn.iocoder.boot
</groupId>
<artifactId>
yudao-module-infra-api
</artifactId>
<version>
${revision}
</version>
</dependency>
<dependency>
<groupId>
cn.iocoder.boot
</groupId>
<artifactId>
yudao-module-member-api
</artifactId>
<version>
${revision}
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
View file @
b5756901
package
cn
.
iocoder
.
yudao
.
module
.
reward
.
api
.
reward
;
package
cn
.
iocoder
.
yudao
.
module
.
reward
.
api
.
reward
;
import
cn.iocoder.yudao.framework.redis.helper.RedisDistributedLock
;
import
cn.iocoder.yudao.module.member.api.user.MemberUserApi
;
import
cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO
;
import
cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO
;
import
cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO
;
import
cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO
;
import
cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO
;
import
cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO
;
import
cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
exception
.
util
.
ServiceExceptionUtil
.
exception
;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
GET_LOCK_FAILED
;
import
static
cn
.
iocoder
.
yudao
.
module
.
member
.
enums
.
ErrorCodeConstants
.
USER_NOT_EXISTS
;
import
static
cn
.
iocoder
.
yudao
.
module
.
reward
.
enums
.
ErrorCodeConstants
.*;
@Service
@Service
@Validated
@Validated
public
class
RedeemRewardApiImpl
implements
RedeemRewardApi
{
public
class
RedeemRewardApiImpl
implements
RedeemRewardApi
{
@Resource
private
RewardMapper
rewardMapper
;
@Resource
private
MemberUserApi
memberUserApi
;
@Resource
private
RedisDistributedLock
redisDistributedLock
;
@Override
@Override
public
RedeemRewardRespDTO
redeemReward
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
public
RedeemRewardRespDTO
redeemReward
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
boolean
lock
=
false
;
try
{
lock
=
redisDistributedLock
.
lock
(
"reward:redeem:lock:"
+
redeemRewardReqVO
.
getRewardId
());
if
(!
lock
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
// 查询会员积分
UserRespDTO
memberUser
=
memberUserApi
.
getUser
(
redeemRewardReqVO
.
getRewardId
());
if
(
memberUser
==
null
)
{
throw
exception
(
USER_NOT_EXISTS
);
}
Integer
holdScore
=
memberUser
.
getHoldScore
();
// 查询礼品
RewardDO
rewardDO
=
rewardMapper
.
selectById
(
redeemRewardReqVO
.
getRewardId
());
if
(
rewardDO
==
null
)
{
throw
exception
(
REWARD_NOT_EXISTS
);
}
// 礼品未开启
if
(
rewardDO
.
getStatus
()
!=
1
)
{
throw
exception
(
REWARD_NOT_ENABLE
);
}
// 会员积分不够
if
(
holdScore
<
rewardDO
.
getPointsRequire
()
*
redeemRewardReqVO
.
getCount
())
{
throw
exception
(
REWARD_SCORE_NOT_ENOUGH
);
}
// 礼品数量不够
if
(
rewardDO
.
getQuantityRemain
()
<
redeemRewardReqVO
.
getCount
())
{
throw
exception
(
REWARD_COUNT_NOT_ENOUGH
);
}
// 兑换方式不匹配
if
(!
Objects
.
equals
(
rewardDO
.
getPickMethod
(),
redeemRewardReqVO
.
getRedeemType
()))
{
throw
exception
(
REWARD_PICK_METHOD_NOT_ALLOW_CREATE
);
}
//TODO:校验兑换次数(查兑换记录)
// 更新礼品
rewardMapper
.
updateById
(
rewardDO
);
// 添加兑换记录
// 更新会员积分
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
redisDistributedLock
.
releaseLock
(
"reward:redeem:lock:"
+
redeemRewardReqVO
.
getRewardId
());
}
return
null
;
return
null
;
}
}
@Override
@Override
public
List
<
RedeemRewardRespDTO
>
redeemRewards
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
)
{
public
List
<
RedeemRewardRespDTO
>
redeemRewards
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
)
{
Long
rewardId
=
redeemRewardReqVOList
.
get
(
0
).
getRewardId
();
// 查询礼品
RewardDO
rewardDO
=
rewardMapper
.
selectById
(
rewardId
);
// 礼品未开启
if
(
rewardDO
.
getStatus
()
!=
1
)
{
throw
exception
(
REWARD_NOT_ENABLE
);
}
boolean
lock
=
false
;
try
{
lock
=
redisDistributedLock
.
lock
(
"reward:redeem:lock:"
+
rewardId
);
if
(!
lock
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
// 校验礼品数量
//
ArrayList
<
Long
>
memberIds
=
new
ArrayList
<>();
int
totalCount
=
0
;
ArrayList
<
UserRespDTO
>
members
=
new
ArrayList
<>();
for
(
RedeemRewardReqVO
redeemRewardReqVO
:
redeemRewardReqVOList
)
{
// 每个兑换VO校验一遍
// 兑换方式不匹配
if
(!
Objects
.
equals
(
rewardDO
.
getPickMethod
(),
redeemRewardReqVO
.
getRedeemType
()))
{
throw
exception
(
REWARD_PICK_METHOD_NOT_ALLOW_CREATE
);
}
// 查询会员id列表,暂时挨个查
memberIds
.
add
(
redeemRewardReqVO
.
getMemberId
());
members
.
add
(
memberUserApi
.
getUser
(
redeemRewardReqVO
.
getMemberId
()));
// 记录兑换总数
totalCount
+=
redeemRewardReqVO
.
getCount
();
}
// 查询会员列表,获取积分列表
// 判断兑换总数是否大于礼物数量
if
(
totalCount
>
rewardDO
.
getQuantityRemain
()){
throw
exception
(
REWARD_COUNT_NOT_ENOUGH
);
}
// 判断会员积分是否够(初步校验,实际兑换时会再加锁校验)
}
catch
(
Exception
e
)
{
throw
exception
(
REWARD_REDEEM_FAIL
);
}
finally
{
redisDistributedLock
.
releaseLock
(
"reward:redeem:lock:"
+
rewardId
);
}
return
null
;
return
null
;
}
}
}
}
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/service/reward/RewardServiceImpl.java
View file @
b5756901
...
@@ -271,6 +271,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
...
@@ -271,6 +271,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
}
//校验礼品是否过期并修改礼品状态
//校验礼品是否过期并修改礼品状态
//TODO:异步更新礼品状态
private
void
validateExpire
(
RewardDO
rewardDO
)
{
private
void
validateExpire
(
RewardDO
rewardDO
)
{
if
(
rewardDO
.
getStatus
()
==
1
&&
rewardDO
.
getEndTime
().
toInstant
().
isBefore
(
Instant
.
now
()))
{
if
(
rewardDO
.
getStatus
()
==
1
&&
rewardDO
.
getEndTime
().
toInstant
().
isBefore
(
Instant
.
now
()))
{
RewardDO
expireReward
=
new
RewardDO
();
RewardDO
expireReward
=
new
RewardDO
();
...
...
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