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
285a39fa
Commit
285a39fa
authored
Sep 03, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix-172: 兑换记录ID命名规则修改
parent
5dc74d01
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
121 additions
and
8 deletions
+121
-8
RedeemRewardApiImpl.java
...r/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
+11
-6
RedemptionNumberFlushTask.java
...eward/controller/admin/job/RedemptionNumberFlushTask.java
+26
-0
AppRewardRedeemDetailRespVO.java
...controller/app/redeem/vo/AppRewardRedeemDetailRespVO.java
+2
-0
AppRewardRedeemListRespVO.java
...d/controller/app/redeem/vo/AppRewardRedeemListRespVO.java
+2
-0
RewardRedeemDO.java
...o/module/reward/dal/dataobject/redeem/RewardRedeemDO.java
+4
-0
RewardRedeemMapper.java
...ao/module/reward/dal/mysql/redeem/RewardRedeemMapper.java
+2
-0
RewardRedeemServiceImpl.java
...module/reward/service/redeem/RewardRedeemServiceImpl.java
+2
-0
RewardGenCodeUtils.java
.../iocoder/yudao/module/reward/util/RewardGenCodeUtils.java
+63
-2
RewardRedeemBaseVO.java
...der/yudao/module/reward/vo/reward/RewardRedeemBaseVO.java
+5
-0
RewardRedeemMapper.xml
...ard-impl/src/main/resources/mapper/RewardRedeemMapper.xml
+4
-0
No files found.
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
View file @
285a39fa
...
...
@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.reward.enums.RewardPickMethedEnum;
import
cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum
;
import
cn.iocoder.yudao.module.reward.enums.RewardStatusEnum
;
import
cn.iocoder.yudao.module.reward.service.reward.RewardService
;
import
cn.iocoder.yudao.module.reward.util.RewardGenCodeUtils
;
import
cn.iocoder.yudao.module.system.api.sms.SmsCodeApi
;
import
cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO
;
import
cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO
;
...
...
@@ -69,6 +70,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
private
SnowflakeGenerator
snowflakeGenerator
;
@Resource
private
SmsCodeApi
smsCodeApi
;
@Resource
private
RewardGenCodeUtils
rewardGenCodeUtils
;
@Override
public
Boolean
redeemReward
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
...
...
@@ -112,9 +115,9 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
executeRedeem
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
,
Long
rewardId
)
{
// 添加兑换记录
Long
redeemI
d
=
addRedeemRecord
(
redeemRewardReqVO
,
pointsRequire
);
RewardRedeemDO
redeemRecor
d
=
addRedeemRecord
(
redeemRewardReqVO
,
pointsRequire
);
// 更新会员积分
updateMemberScore
(
redeemRewardReqVO
,
pointsRequire
,
redeem
Id
);
updateMemberScore
(
redeemRewardReqVO
,
pointsRequire
,
redeem
Record
.
getId
(),
redeemRecord
.
getRedemptionNumber
()
);
// 更新礼品
redeemReward
(
rewardId
,
redeemRewardReqVO
.
getRewardCount
());
}
...
...
@@ -150,7 +153,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
if
(
StringUtils
.
isBlank
(
redeemRewardReqVO
.
getRecipientPhoneNum
()))
{
redeemRewardReqVO
.
setRecipientPhoneNum
(
memberUser
.
getMobile
());
}
}
else
if
(
redeemRewardReqVO
.
getEntrance
()
!=
PlatformTypeEnum
.
BACKEND
.
getValue
()){
}
else
if
(
redeemRewardReqVO
.
getEntrance
()
!=
PlatformTypeEnum
.
BACKEND
.
getValue
())
{
if
(
StringUtils
.
isAnyBlank
(
redeemRewardReqVO
.
getRecipientName
(),
redeemRewardReqVO
.
getRecipientPhoneNum
(),
redeemRewardReqVO
.
getRecipientAddress
()))
{
throw
exception
(
REWARD_REDEEM_RECIPIENT_ERROR
);
}
...
...
@@ -170,9 +173,10 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
rewardMapper
.
updateById
(
upReward
);
}
private
void
updateMemberScore
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
,
Long
redeemId
)
{
private
void
updateMemberScore
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
,
Long
redeemId
,
String
redemptionNumber
)
{
Map
<
String
,
Object
>
extParam
=
new
HashMap
<>();
extParam
.
put
(
"redeemId"
,
redeemId
);
extParam
.
put
(
"redemptionNumber"
,
redemptionNumber
);
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
redeemRewardReqVO
.
getMemberId
())
.
sourceType
(
ScoreSourceTypeEnum
.
EXCHANGE_REWARD
)
...
...
@@ -183,13 +187,14 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
.
build
());
}
private
Long
addRedeemRecord
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
)
{
private
RewardRedeemDO
addRedeemRecord
(
RedeemRewardReqVO
redeemRewardReqVO
,
Integer
pointsRequire
)
{
RewardRedeemDO
rewardRedeemDO
=
BeanUtil
.
copyProperties
(
redeemRewardReqVO
,
RewardRedeemDO
.
class
);
rewardRedeemDO
.
setId
(
snowflakeGenerator
.
next
());
rewardRedeemDO
.
setRedemptionNumber
(
rewardGenCodeUtils
.
generateRedemptionNumber
());
rewardRedeemDO
.
setStatus
(
RewardRedeemStatusEnum
.
REDEEMING
.
getValue
());
rewardRedeemDO
.
setScoreCount
(
redeemRewardReqVO
.
getRewardCount
()
*
pointsRequire
);
rewardRedeemMapper
.
insert
(
rewardRedeemDO
);
return
rewardRedeemDO
.
getId
()
;
return
rewardRedeemDO
;
}
@Override
...
...
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/controller/admin/job/RedemptionNumberFlushTask.java
0 → 100644
View file @
285a39fa
package
cn
.
iocoder
.
yudao
.
module
.
reward
.
controller
.
admin
.
job
;
import
cn.iocoder.yudao.framework.quartz.core.handler.JobHandler
;
import
cn.iocoder.yudao.module.reward.util.RewardGenCodeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
/**
* 兑换记录编号刷新任务
* @author zhaobiyan
*/
@Component
@Slf4j
public
class
RedemptionNumberFlushTask
implements
JobHandler
{
@Resource
private
RewardGenCodeUtils
rewardGenCodeUtils
;
@Override
public
String
execute
(
String
param
)
throws
Exception
{
rewardGenCodeUtils
.
redemptionNumberFlush
();
return
"success"
;
}
}
\ No newline at end of file
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/controller/app/redeem/vo/AppRewardRedeemDetailRespVO.java
View file @
285a39fa
...
...
@@ -14,6 +14,8 @@ public class AppRewardRedeemDetailRespVO {
@ApiModelProperty
(
value
=
"id"
)
@JsonSerialize
(
using
=
ToStringSerializer
.
class
)
private
Long
id
;
@ApiModelProperty
(
value
=
"兑换记录编号"
)
private
String
redemptionNumber
;
@ApiModelProperty
(
value
=
"会员id"
)
private
Long
memberId
;
@ApiModelProperty
(
value
=
"礼品id"
)
...
...
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/controller/app/redeem/vo/AppRewardRedeemListRespVO.java
View file @
285a39fa
...
...
@@ -23,6 +23,8 @@ public class AppRewardRedeemListRespVO {
@ApiModelProperty
(
value
=
"id"
)
@JsonSerialize
(
using
=
ToStringSerializer
.
class
)
private
Long
id
;
@ApiModelProperty
(
value
=
"兑换记录编号"
)
private
String
redemptionNumber
;
@ApiModelProperty
(
value
=
"礼品ID"
)
private
Long
rewardCode
;
@ApiModelProperty
(
value
=
"礼品名称(中文)"
)
...
...
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/dal/dataobject/redeem/RewardRedeemDO.java
View file @
285a39fa
...
...
@@ -21,6 +21,10 @@ public class RewardRedeemDO extends BaseDO {
*/
@TableId
private
Long
id
;
/**
* 兑换记录编号
*/
private
String
redemptionNumber
;
/**
* 会员id
*/
...
...
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/dal/mysql/redeem/RewardRedeemMapper.java
View file @
285a39fa
...
...
@@ -23,4 +23,6 @@ public interface RewardRedeemMapper extends AbstractMapper<RewardRedeemDO> {
RewardRedeemPageRespVO
detail
(
@Param
(
"id"
)
Long
id
);
List
<
RewardRedeemPageRespVO
>
exportList
(
@Param
(
"req"
)
RewardRedeemPageReqVO
request
);
String
getCurrentMaxRedemptionNumber
();
}
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/service/redeem/RewardRedeemServiceImpl.java
View file @
285a39fa
...
...
@@ -288,6 +288,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
}
Map
<
String
,
Object
>
extParam
=
new
HashMap
<>();
extParam
.
put
(
"redeemId"
,
req
.
getId
());
extParam
.
put
(
"redemptionNumber"
,
rewardRedeemDO
.
getRedemptionNumber
());
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
rewardRedeemDO
.
getMemberId
())
.
sourceType
(
ScoreSourceTypeEnum
.
EXCHANGE_REWARD_CANCEL
)
...
...
@@ -323,6 +324,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
RewardDO
rewardDO
=
rewardService
.
getById
(
rewardRedeemDO
.
getRewardId
());
return
AppRewardRedeemListRespVO
.
builder
()
.
id
(
rewardRedeemDO
.
getId
())
.
redemptionNumber
(
rewardRedeemDO
.
getRedemptionNumber
())
.
createTime
(
rewardRedeemDO
.
getCreateTime
())
.
rewardCode
(
rewardRedeemDO
.
getRewardId
())
.
rewardTitleEn
(
rewardDO
.
getTitleEn
())
...
...
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/util/RewardGenCodeUtils.java
View file @
285a39fa
package
cn
.
iocoder
.
yudao
.
module
.
reward
.
util
;
import
cn.iocoder.yudao.framework.redis.helper.RedisHelper
;
import
cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO
;
import
cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO
;
import
cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper
;
import
cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper
;
import
com.alibaba.excel.util.DateUtils
;
import
org.redisson.api.RLock
;
...
...
@@ -27,6 +29,8 @@ public class RewardGenCodeUtils {
private
RedisHelper
redisHelper
;
@Resource
private
RedissonClient
redissonClient
;
@Resource
private
RewardRedeemMapper
rewardRedeemMapper
;
/**
* 生成礼品ID
...
...
@@ -48,8 +52,50 @@ public class RewardGenCodeUtils {
throw
exception
(
GET_LOCK_FAILED
);
}
String
currentMaxRewardCode
=
rewardMapper
.
getCurrentMaxRewardCode
();
if
(
currentMaxRewardCode
==
null
){
codeNum
=
1L
;
}
else
{
codeNum
=
Long
.
parseLong
(
currentMaxRewardCode
.
substring
(
3
))
+
1
;
redisHelper
.
set
(
key
,
String
.
valueOf
(
codeNum
),
10
,
TimeUnit
.
MINUTES
);
}
redisHelper
.
set
(
key
,
String
.
valueOf
(
codeNum
),
10
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
finally
{
lock
.
unlock
();
}
}
// 获得5位序列号,不足位前面补0
code
.
append
(
String
.
format
(
"%05d"
,
codeNum
));
return
code
.
toString
();
}
/**
* 生成兑换记录编号
*/
public
String
generateRedemptionNumber
()
{
String
key
=
"redemptionNumber:max:number"
;
// EC+年月+5位序列号,例如EC240900005
StringBuilder
code
=
new
StringBuilder
();
code
.
append
(
"EC"
);
String
currentYearMonth
=
DateUtils
.
format
(
new
Date
(),
"yyMM"
);
code
.
append
(
currentYearMonth
);
Long
codeNum
;
if
(
redisHelper
.
hasKey
(
key
))
{
codeNum
=
redisHelper
.
incrBy
(
key
,
1
);
}
else
{
RLock
lock
=
redissonClient
.
getLock
(
"next:redemptionNumber:code:lock"
);
try
{
boolean
lockSuccess
=
lock
.
tryLock
(
2
,
2
,
TimeUnit
.
SECONDS
);
if
(!
lockSuccess
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
String
currentMaxRedemptionNumber
=
rewardRedeemMapper
.
getCurrentMaxRedemptionNumber
();
if
(
currentMaxRedemptionNumber
==
null
){
codeNum
=
1L
;
}
else
{
codeNum
=
Long
.
parseLong
(
currentMaxRedemptionNumber
.
substring
(
6
))
+
1
;
}
redisHelper
.
set
(
key
,
String
.
valueOf
(
codeNum
),
10
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
finally
{
...
...
@@ -74,4 +120,19 @@ public class RewardGenCodeUtils {
start
+=
1
;
}
}
public
void
redemptionNumberFlush
()
{
long
start
=
1L
;
redisHelper
.
delete
(
"redemptionNumber:max:number"
);
List
<
RewardRedeemDO
>
rewardRedeemDOList
=
rewardRedeemMapper
.
selectList
();
for
(
RewardRedeemDO
rewardRedeemDO
:
rewardRedeemDOList
)
{
StringBuilder
code
=
new
StringBuilder
();
code
.
append
(
"EC"
);
String
currentYearMonth
=
DateUtils
.
format
(
new
Date
(),
"yyMM"
);
code
.
append
(
currentYearMonth
);
code
.
append
(
String
.
format
(
"%05d"
,
start
));
rewardRedeemDO
.
setRedemptionNumber
(
code
.
toString
());
rewardRedeemMapper
.
updateById
(
rewardRedeemDO
);
start
+=
1
;
}
}
}
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/vo/reward/RewardRedeemBaseVO.java
View file @
285a39fa
...
...
@@ -12,6 +12,11 @@ public class RewardRedeemBaseVO {
@ApiModelProperty
(
value
=
"id"
)
@JsonSerialize
(
using
=
ToStringSerializer
.
class
)
private
Long
id
;
/**
* 兑换记录编号
*/
@ApiModelProperty
(
value
=
"兑换记录编号"
)
private
String
redemptionNumber
;
/**
* 会员id
*/
...
...
yudao-module-reward/yudao-module-reward-impl/src/main/resources/mapper/RewardRedeemMapper.xml
View file @
285a39fa
...
...
@@ -73,9 +73,13 @@
<include
refid=
"pageCondition"
/>
order by er.create_time desc
</select>
<select
id=
"getCurrentMaxRedemptionNumber"
resultType=
"java.lang.String"
>
select redemption_number from ecw_reward_redeem order by redemption_number desc limit 1
</select>
<sql
id=
"columns"
>
err.id ,
err.redemption_number as redemptionNumber,
err.member_id as memberId,
err.reward_id as rewardId,
err.status,
...
...
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