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
8f8d6430
Commit
8f8d6430
authored
Aug 05, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
积分规则触发
parent
55dcf89a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
77 deletions
+93
-77
AbstractScoreRuleStrategy.java
...ber/mq/consumer/score/core/AbstractScoreRuleStrategy.java
+4
-63
OrderVStrategy.java
.../module/member/mq/consumer/score/core/OrderVStrategy.java
+5
-6
RecommendStrategy.java
...dule/member/mq/consumer/score/core/RecommendStrategy.java
+4
-5
RegisterStrategy.java
...odule/member/mq/consumer/score/core/RegisterStrategy.java
+3
-3
ScoreRuleService.java
...dao/module/member/service/scoreRule/ScoreRuleService.java
+25
-0
ScoreRuleServiceImpl.java
...module/member/service/scoreRule/ScoreRuleServiceImpl.java
+52
-0
No files found.
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/AbstractScoreRuleStrategy.java
View file @
8f8d6430
package
cn
.
iocoder
.
yudao
.
module
.
member
.
mq
.
consumer
.
score
.
core
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
import
cn.iocoder.yudao.module.member.dal.redis.scoreRule.ScoreRuleRedisDao
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.TransportTypeEnum
;
import
cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService
;
import
cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService
;
import
cn.iocoder.yudao.module.member.service.user.MemberUserService
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
/**
...
...
@@ -24,66 +17,14 @@ public abstract class AbstractScoreRuleStrategy implements ScoreRuleStrategy {
protected
ScoreRuleService
scoreRuleService
;
protected
MemberUserScoreLogService
memberUserScoreLogService
;
protected
MemberUserService
memberUserService
;
@Autowired
public
AbstractScoreRuleStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
)
{
public
AbstractScoreRuleStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
,
MemberUserService
memberUserService
)
{
this
.
scoreRuleService
=
scoreRuleService
;
this
.
memberUserScoreLogService
=
memberUserScoreLogService
;
this
.
memberUserService
=
memberUserService
;
}
@Resource
ScoreRuleRedisDao
scoreRuleRedisDao
;
protected
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
)
{
ScoreRuleDO
enableScoreRule
;
enableScoreRule
=
scoreRuleRedisDao
.
getEnableScoreRule
(
scoreRuleType
);
if
(
enableScoreRule
==
null
)
{
enableScoreRule
=
scoreRuleService
.
selectOne
(
new
LambdaQuery
<
ScoreRuleDO
>()
.
eq
(
ScoreRuleDO:
:
getType
,
scoreRuleType
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()));
if
(
enableScoreRule
==
null
)
{
return
null
;
}
// 校验一下活动开始结束时间
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
scoreRuleRedisDao
.
setEnableScoreRule
(
enableScoreRule
);
}
else
{
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
}
return
enableScoreRule
;
}
protected
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
,
TransportTypeEnum
transportType
)
{
ScoreRuleDO
enableScoreRule
;
switch
(
scoreRuleType
)
{
case
ORDER_V:
enableScoreRule
=
scoreRuleRedisDao
.
getEnableScoreRule
(
scoreRuleType
,
transportType
);
if
(
enableScoreRule
==
null
)
{
enableScoreRule
=
scoreRuleService
.
getEnabledOrderVScoreRuleByTransportType
(
transportType
.
getValue
());
if
(
enableScoreRule
==
null
)
{
return
null
;
}
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
scoreRuleRedisDao
.
setEnableScoreRule
(
enableScoreRule
);
}
else
{
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
}
return
enableScoreRule
;
case
RECOMMEND:
case
REGISTER:
return
getEnableScoreRuleByType
(
scoreRuleType
);
}
return
null
;
}
/**
* 计算用户在某一活动获得积分总数
* @param scoreRuleId
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/OderVStrategy.java
→
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/O
r
derVStrategy.java
View file @
8f8d6430
...
...
@@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.member.enums.*;
import
cn.iocoder.yudao.module.member.mq.message.ScoreMessage
;
import
cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService
;
import
cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService
;
import
cn.iocoder.yudao.module.member.service.user.MemberUserService
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -33,18 +34,16 @@ import java.util.Objects;
*/
@Service
@Slf4j
public
class
OderVStrategy
extends
AbstractScoreRuleStrategy
{
public
class
O
r
derVStrategy
extends
AbstractScoreRuleStrategy
{
@Resource
private
OrderApi
orderApi
;
@Resource
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
MemberUserScoreLogService
memberUserScoreLogService
;
@Resource
private
CustomerContactsService
customerContactsService
;
public
O
derVStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLog
Service
)
{
super
(
scoreRuleService
,
memberUserScoreLogService
);
public
O
rderVStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
,
MemberUserService
memberUser
Service
)
{
super
(
scoreRuleService
,
memberUserScoreLogService
,
memberUserService
);
}
@Override
...
...
@@ -68,7 +67,7 @@ public class OderVStrategy extends AbstractScoreRuleStrategy {
}
// 判断海运空运
Integer
transportId
=
order
.
getTransportId
();
ScoreRuleDO
scoreRuleDO
=
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
.
ORDER_V
,
TransportTypeEnum
.
parseByValue
(
transportId
));
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
.
ORDER_V
,
TransportTypeEnum
.
parseByValue
(
transportId
));
if
(
Objects
.
isNull
(
scoreRuleDO
))
{
log
.
info
(
"Order in shipping listener: No score rule match,orderID:{}"
,
orderId
);
return
;
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/RecommendStrategy.java
View file @
8f8d6430
...
...
@@ -27,10 +27,9 @@ public class RecommendStrategy extends AbstractScoreRuleStrategy {
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
MemberUserService
memberUserService
;
@Resource
private
MemberUserScoreLogService
memberUserScoreLogService
;
public
RecommendStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
)
{
super
(
scoreRuleService
,
memberUserScoreLogService
);
public
RecommendStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
,
MemberUserService
memberUserService
)
{
super
(
scoreRuleService
,
memberUserScoreLogService
,
memberUserService
);
}
@Override
...
...
@@ -38,7 +37,7 @@ public class RecommendStrategy extends AbstractScoreRuleStrategy {
// 根据推荐码获取推荐用户id
Long
userId
=
ReferralCodeUtils
.
getUserId
(
message
.
getReferralCode
());
log
.
info
(
"Received Recommend message,userID:{}"
,
userId
);
ScoreRuleDO
scoreRuleDO
=
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
.
RECOMMEND
);
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
.
RECOMMEND
);
if
(
scoreRuleDO
==
null
)
{
log
.
info
(
"Recommend rule is not exist,userID:{}"
,
userId
);
return
;
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/RegisterStrategy.java
View file @
8f8d6430
...
...
@@ -29,15 +29,15 @@ public class RegisterStrategy extends AbstractScoreRuleStrategy {
@Resource
private
MemberUserService
memberUserService
;
public
RegisterStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
)
{
super
(
scoreRuleService
,
memberUserScoreLogService
);
public
RegisterStrategy
(
ScoreRuleService
scoreRuleService
,
MemberUserScoreLogService
memberUserScoreLogService
,
MemberUserService
memberUserService
)
{
super
(
scoreRuleService
,
memberUserScoreLogService
,
memberUserService
);
}
@Override
public
void
addScore
(
ScoreMessage
message
)
{
Long
userId
=
message
.
getUserId
();
log
.
info
(
"Received register message,userID:{}"
,
userId
);
ScoreRuleDO
scoreRuleDO
=
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
.
REGISTER
);
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
.
REGISTER
);
if
(
scoreRuleDO
==
null
)
{
log
.
info
(
"Register rule is not exist,userID:{}"
,
userId
);
return
;
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/scoreRule/ScoreRuleService.java
View file @
8f8d6430
...
...
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import
cn.iocoder.yudao.framework.mybatis.core.service.IService
;
import
cn.iocoder.yudao.framework.mybatis.core.vo.PageVO
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.TransportTypeEnum
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.*
;
/**
...
...
@@ -18,6 +20,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 创建积分规则
*
* @param createReqVO 创建信息
* @return 编号
*/
...
...
@@ -25,12 +28,14 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 更新积分规则
*
* @param updateReqVO 更新信息
*/
void
updateScoreRule
(
@Valid
ScoreRuleUpdateReqVO
updateReqVO
);
/**
* 删除积分规则
*
* @param id 编号
*/
void
deleteScoreRule
(
Long
id
);
...
...
@@ -62,6 +67,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 获得积分规则列表, 用于 Excel 导出
*
* @param query 查询
* @return 积分规则列表
*/
...
...
@@ -69,6 +75,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 积分规则启用关闭
*
* @param scoreRuleStatusReqVO 积分规则状态
* @return
*/
...
...
@@ -76,6 +83,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 积分规则复制
*
* @param id
* @return
*/
...
...
@@ -83,6 +91,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 积分规则延期
*
* @param scoreDelayReqVO 积分规则延期
* @return
*/
...
...
@@ -90,8 +99,24 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/**
* 根据运输方式获取已启用订单V值规则
*
* @param transportType
* @return
*/
ScoreRuleDO
getEnabledOrderVScoreRuleByTransportType
(
Integer
transportType
);
/**
* 根据类型获取已启用积分规则
* @param scoreRuleType
* @return
*/
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
);
/**
* 根据类型获取已启用积分规则(带运输类型)
* @param scoreRuleType
* @param transportType
* @return
*/
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
,
TransportTypeEnum
transportType
);
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/scoreRule/ScoreRuleServiceImpl.java
View file @
8f8d6430
...
...
@@ -350,4 +350,56 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
}
return
null
;
}
@Override
public
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
)
{
ScoreRuleDO
enableScoreRule
;
enableScoreRule
=
scoreRuleRedisDao
.
getEnableScoreRule
(
scoreRuleType
);
if
(
enableScoreRule
==
null
)
{
enableScoreRule
=
selectOne
(
new
LambdaQuery
<
ScoreRuleDO
>()
.
eq
(
ScoreRuleDO:
:
getType
,
scoreRuleType
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()));
if
(
enableScoreRule
==
null
)
{
return
null
;
}
// 校验一下活动开始结束时间
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
scoreRuleRedisDao
.
setEnableScoreRule
(
enableScoreRule
);
}
else
{
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
}
return
enableScoreRule
;
}
@Override
public
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
,
TransportTypeEnum
transportType
)
{
ScoreRuleDO
enableScoreRule
;
switch
(
scoreRuleType
)
{
case
ORDER_V:
enableScoreRule
=
scoreRuleRedisDao
.
getEnableScoreRule
(
scoreRuleType
,
transportType
);
if
(
enableScoreRule
==
null
)
{
enableScoreRule
=
getEnabledOrderVScoreRuleByTransportType
(
transportType
.
getValue
());
if
(
enableScoreRule
==
null
)
{
return
null
;
}
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
scoreRuleRedisDao
.
setEnableScoreRule
(
enableScoreRule
);
}
else
{
if
(!
enableScoreRule
.
getEndTime
().
after
(
new
Date
())
||
!
enableScoreRule
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
}
return
enableScoreRule
;
case
RECOMMEND:
case
REGISTER:
return
getEnableScoreRuleByType
(
scoreRuleType
);
}
return
null
;
}
}
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