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
d7e8488e
Commit
d7e8488e
authored
Aug 02, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
注册,推荐触发逻辑
parent
d6827fec
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
281 additions
and
12 deletions
+281
-12
AbstractScoreRuleStrategy.java
...ber/mq/consumer/score/core/AbstractScoreRuleStrategy.java
+89
-0
OderVStrategy.java
...o/module/member/mq/consumer/score/core/OderVStrategy.java
+8
-4
RecommendStrategy.java
...dule/member/mq/consumer/score/core/RecommendStrategy.java
+86
-3
RegisterStrategy.java
...odule/member/mq/consumer/score/core/RegisterStrategy.java
+64
-3
ScoreRuleStrategy.java
...dule/member/mq/consumer/score/core/ScoreRuleStrategy.java
+2
-1
ScoreRuleStrategyFactory.java
...mber/mq/consumer/score/core/ScoreRuleStrategyFactory.java
+1
-1
ScoreMessage.java
.../iocoder/yudao/module/member/mq/message/ScoreMessage.java
+31
-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
0 → 100644
View file @
d7e8488e
package
cn
.
iocoder
.
yudao
.
module
.
member
.
mq
.
consumer
.
score
.
core
;
import
cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
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.scoreRule.ScoreRuleService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Date
;
/**
* 半成品
* @author zhangfeng
*/
public
abstract
class
AbstractScoreRuleStrategy
implements
ScoreRuleStrategy
{
private
static
ScoreRuleDO
orderVShipScoreRule
=
null
;
private
static
ScoreRuleDO
orderVFlyScoreRule
=
null
;
private
static
ScoreRuleDO
registerScoreRule
=
null
;
private
static
ScoreRuleDO
recommendScoreRule
=
null
;
protected
ScoreRuleService
scoreRuleService
;
@Autowired
public
AbstractScoreRuleStrategy
(
ScoreRuleService
scoreRuleService
)
{
this
.
scoreRuleService
=
scoreRuleService
;
}
public
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
)
{
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
selectOne
(
new
LambdaQuery
<
ScoreRuleDO
>()
.
eq
(
ScoreRuleDO:
:
getType
,
scoreRuleType
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()));
if
(
scoreRuleDO
!=
null
)
{
// 校验一下活动开始结束时间
if
(!
scoreRuleDO
.
getEndTime
().
after
(
new
Date
())
||
!
scoreRuleDO
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
else
{
recommendScoreRule
=
scoreRuleDO
;
return
recommendScoreRule
;
}
}
return
null
;
}
public
ScoreRuleDO
getEnableScoreRuleByType
(
ScoreRuleTypeEnum
scoreRuleType
,
TransportTypeEnum
transportType
)
{
ScoreRuleDO
scoreRuleDO
=
null
;
switch
(
scoreRuleType
)
{
case
ORDER_V:
scoreRuleDO
=
scoreRuleService
.
getEnabledOrderVScoreRuleByTransportType
(
transportType
.
getValue
());
if
(
scoreRuleDO
!=
null
)
{
if
(!
scoreRuleDO
.
getEndTime
().
after
(
new
Date
())
||
!
scoreRuleDO
.
getStartTime
().
before
(
new
Date
()))
{
return
null
;
}
if
(
transportType
==
TransportTypeEnum
.
OCEAN_LCL
)
{
orderVShipScoreRule
=
scoreRuleDO
;
return
orderVShipScoreRule
;
}
if
(
transportType
==
TransportTypeEnum
.
SPECIAL_LINE_AIR_FREIGHT
)
{
orderVFlyScoreRule
=
scoreRuleDO
;
return
orderVFlyScoreRule
;
}
}
break
;
case
RECOMMEND:
case
REGISTER:
return
getEnableScoreRuleByType
(
scoreRuleType
);
}
return
null
;
}
@Override
public
void
refreshScoreRule
(
ScoreRuleTypeEnum
scoreRuleType
)
{
switch
(
scoreRuleType
)
{
case
ORDER_V:
orderVShipScoreRule
=
null
;
orderVFlyScoreRule
=
null
;
break
;
case
RECOMMEND:
recommendScoreRule
=
null
;
break
;
case
REGISTER:
registerScoreRule
=
null
;
break
;
}
}
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/OderVStrategy.java
View file @
d7e8488e
...
...
@@ -37,18 +37,20 @@ import java.util.Objects;
*/
@Service
@Slf4j
public
class
OderVStrategy
implements
ScoreRuleStrategy
{
public
class
OderVStrategy
extends
Abstract
ScoreRuleStrategy
{
@Resource
private
OrderApi
orderApi
;
@Resource
private
ScoreRuleService
scoreRuleService
;
@Resource
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
MemberUserScoreLogService
memberUserScoreLogService
;
@Resource
private
CustomerContactsService
customerContactsService
;
public
OderVStrategy
(
ScoreRuleService
scoreRuleService
)
{
super
(
scoreRuleService
);
}
@Override
public
void
addScore
(
ScoreMessage
message
)
{
log
.
info
(
"Received order V message,orderID:{}"
,
message
.
getOrderId
());
...
...
@@ -182,6 +184,8 @@ public class OderVStrategy implements ScoreRuleStrategy {
.
sourceType
(
ScoreSourceTypeEnum
.
ORDER_V
)
.
ruleId
(
scoreRuleDO
.
getId
())
.
expireDays
(
scoreRuleDO
.
getScorePeriod
())
.
releationId
(
String
.
valueOf
(
orderId
))
.
uniqueId
(
String
.
valueOf
(
orderId
))
.
extParam
(
map
)
.
build
()
);
...
...
@@ -192,7 +196,7 @@ public class OderVStrategy implements ScoreRuleStrategy {
}
@Override
public
ScoreRuleTypeEnum
getScoreRuleType
()
{
public
ScoreRuleTypeEnum
getS
trategyS
coreRuleType
()
{
return
ScoreRuleTypeEnum
.
ORDER_V
;
}
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/RecommendStrategy.java
View file @
d7e8488e
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.api.score.MemberUserScoreApi
;
import
cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO
;
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.dataobject.user.MemberUserDO
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum
;
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
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
/**
* @author zhangfeng
*/
@Service
@Slf4j
public
class
RecommendStrategy
implements
ScoreRuleStrategy
{
public
class
RecommendStrategy
extends
AbstractScoreRuleStrategy
{
@Resource
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
MemberUserService
memberUserService
;
@Resource
private
MemberUserScoreLogService
memberUserScoreLogService
;
public
RecommendStrategy
(
ScoreRuleService
scoreRuleService
)
{
super
(
scoreRuleService
);
}
@Override
public
void
addScore
(
ScoreMessage
message
)
{
log
.
info
(
"推荐增加积分"
);
Long
userId
=
message
.
getUserId
();
log
.
info
(
"Received Recommend message,userID:{}"
,
userId
);
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
selectOne
(
new
LambdaQuery
<
ScoreRuleDO
>()
.
eq
(
ScoreRuleDO:
:
getType
,
ScoreRuleTypeEnum
.
RECOMMEND
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()));
if
(
scoreRuleDO
==
null
)
{
log
.
info
(
"Recommend rule is not exist,userID:{}"
,
userId
);
return
;
}
// 是否过期,或者活动还没开始
if
(!
scoreRuleDO
.
getEndTime
().
after
(
new
Date
())
||
!
scoreRuleDO
.
getStartTime
().
before
(
new
Date
()))
{
log
.
info
(
"Recommend listener: The score rule has expired,scoreRuleID:{}"
,
scoreRuleDO
.
getId
());
return
;
}
MemberUserDO
memberUserDO
=
memberUserService
.
getUser
(
userId
);
if
(
memberUserDO
==
null
)
{
log
.
info
(
"Recommend listener: The user does not exist,userID:{}"
,
userId
);
return
;
}
// 校验累计最高分
Integer
userScoreTotalCount
=
0
;
LambdaQueryWrapper
<
MemberUserScoreLogDO
>
scoreLogQueryWrapper
=
new
LambdaQueryWrapper
<>();
scoreLogQueryWrapper
.
eq
(
MemberUserScoreLogDO:
:
getMemberId
,
userId
)
.
eq
(
MemberUserScoreLogDO:
:
getRuleId
,
scoreRuleDO
.
getId
());
List
<
MemberUserScoreLogDO
>
memberUserScoreLogs
=
memberUserScoreLogService
.
selectList
(
scoreLogQueryWrapper
);
if
(
CollUtil
.
isNotEmpty
(
memberUserScoreLogs
))
{
for
(
MemberUserScoreLogDO
memberUserScoreLog
:
memberUserScoreLogs
)
{
userScoreTotalCount
+=
memberUserScoreLog
.
getScoreCount
();
}
}
if
(
userScoreTotalCount
>=
scoreRuleDO
.
getMaxScoreTotal
())
{
log
.
info
(
"Recommend listener: The user has reached the maximum score,userId:{},scoreRuleId:{}"
,
userId
,
scoreRuleDO
.
getId
());
return
;
}
try
{
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"userId"
,
userId
);
map
.
put
(
"userNameZh"
,
message
.
getUserNameZh
());
map
.
put
(
"userNameEn"
,
message
.
getUserNameEn
());
String
desensitizedPhoneNumber
=
message
.
getPhone
().
replaceAll
(
"(\\d{3})\\d{4}(\\d{4})"
,
"$1****$2"
);
map
.
put
(
"phone"
,
desensitizedPhoneNumber
);
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
userId
)
.
scoreCount
(
scoreRuleDO
.
getGetScoreOnce
())
.
sourceType
(
ScoreSourceTypeEnum
.
RECOMMEND
)
.
ruleId
(
scoreRuleDO
.
getId
())
.
uniqueId
(
userId
+
"_"
+
message
.
getRecommendUserId
())
.
expireDays
(
scoreRuleDO
.
getScorePeriod
())
.
build
());
}
catch
(
Exception
e
)
{
log
.
error
(
"Recommend listener: operateScore error"
,
e
);
}
log
.
info
(
"Recommend rule add score success,ruleID:{},userID:{}"
,
scoreRuleDO
.
getId
(),
userId
);
}
@Override
public
ScoreRuleTypeEnum
getScoreRuleType
()
{
public
ScoreRuleTypeEnum
getS
trategyS
coreRuleType
()
{
return
ScoreRuleTypeEnum
.
RECOMMEND
;
}
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/RegisterStrategy.java
View file @
d7e8488e
package
cn
.
iocoder
.
yudao
.
module
.
member
.
mq
.
consumer
.
score
.
core
;
import
cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery
;
import
cn.iocoder.yudao.module.member.api.score.MemberUserScoreApi
;
import
cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
import
cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum
;
import
cn.iocoder.yudao.module.member.mq.message.ScoreMessage
;
import
cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService
;
import
cn.iocoder.yudao.module.member.service.user.MemberUserService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.HashMap
;
/**
* @author zhangfeng
*/
@Service
@Slf4j
public
class
RegisterStrategy
implements
ScoreRuleStrategy
{
public
class
RegisterStrategy
extends
AbstractScoreRuleStrategy
{
@Resource
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
MemberUserService
memberUserService
;
public
RegisterStrategy
(
ScoreRuleService
scoreRuleService
)
{
super
(
scoreRuleService
);
}
@Override
public
void
addScore
(
ScoreMessage
message
)
{
log
.
info
(
"注册增加积分"
);
Long
userId
=
message
.
getUserId
();
log
.
info
(
"Received register message,userID:{}"
,
userId
);
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
selectOne
(
new
LambdaQuery
<
ScoreRuleDO
>()
.
eq
(
ScoreRuleDO:
:
getType
,
ScoreRuleTypeEnum
.
REGISTER
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()));
if
(
scoreRuleDO
==
null
)
{
log
.
info
(
"Register rule is not exist,userID:{}"
,
userId
);
return
;
}
// 是否过期,或者活动还没开始
if
(!
scoreRuleDO
.
getEndTime
().
after
(
new
Date
())
||
!
scoreRuleDO
.
getStartTime
().
before
(
new
Date
()))
{
log
.
info
(
"Register listener: The score rule has expired,scoreRuleID:{}"
,
scoreRuleDO
.
getId
());
return
;
}
MemberUserDO
memberUserDO
=
memberUserService
.
getUser
(
userId
);
if
(
memberUserDO
==
null
)
{
log
.
info
(
"Register listener: The user does not exist,userID:{}"
,
userId
);
return
;
}
//TODO:校验注册入口,目前表没加
try
{
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"userId"
,
userId
);
map
.
put
(
"userNameZh"
,
message
.
getUserNameZh
());
map
.
put
(
"userNameEn"
,
message
.
getUserNameEn
());
String
desensitizedPhoneNumber
=
message
.
getPhone
().
replaceAll
(
"(\\d{3})\\d{4}(\\d{4})"
,
"$1****$2"
);
map
.
put
(
"phone"
,
desensitizedPhoneNumber
);
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
userId
)
.
scoreCount
(
scoreRuleDO
.
getGetScoreOnce
())
.
sourceType
(
ScoreSourceTypeEnum
.
REGISTER
)
.
ruleId
(
scoreRuleDO
.
getId
())
.
uniqueId
(
String
.
valueOf
(
userId
))
.
expireDays
(
scoreRuleDO
.
getScorePeriod
())
.
build
());
}
catch
(
Exception
e
)
{
log
.
error
(
"Register listener: operateScore error"
,
e
);
}
log
.
info
(
"Register rule add score success,ruleID:{},userID:{}"
,
scoreRuleDO
.
getId
(),
userId
);
}
@Override
public
ScoreRuleTypeEnum
getScoreRuleType
()
{
public
ScoreRuleTypeEnum
getS
trategyS
coreRuleType
()
{
return
ScoreRuleTypeEnum
.
REGISTER
;
}
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/ScoreRuleStrategy.java
View file @
d7e8488e
...
...
@@ -7,5 +7,6 @@ import cn.iocoder.yudao.module.member.mq.message.ScoreMessage;
*/
public
interface
ScoreRuleStrategy
{
void
addScore
(
ScoreMessage
message
);
ScoreRuleTypeEnum
getScoreRuleType
();
ScoreRuleTypeEnum
getStrategyScoreRuleType
();
void
refreshScoreRule
(
ScoreRuleTypeEnum
scoreRuleType
);
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/consumer/score/core/ScoreRuleStrategyFactory.java
View file @
d7e8488e
...
...
@@ -17,7 +17,7 @@ public class ScoreRuleStrategyFactory {
@Autowired
public
void
setStrategyFactory
(
List
<
ScoreRuleStrategy
>
strategyList
)
{
for
(
ScoreRuleStrategy
strategy
:
strategyList
)
{
strategies
.
put
(
strategy
.
getScoreRuleType
(),
strategy
);
strategies
.
put
(
strategy
.
getS
trategyS
coreRuleType
(),
strategy
);
}
}
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/mq/message/ScoreMessage.java
View file @
d7e8488e
...
...
@@ -12,8 +12,39 @@ import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
public
class
ScoreMessage
extends
AbstractStreamMessage
{
/**
* 积分规则类型所有消息必填
*/
private
ScoreRuleTypeEnum
scoreRuleType
;
/**
* 订单ID:订单V值消息必填
*/
private
Long
orderId
;
/**
* userID:注册,推荐必填(加分的人)
*/
private
Long
userId
;
/**
* 被推荐的会员ID:推荐必填
*/
private
Long
recommendUserId
;
/**
* 中文名:注册,推荐必填,推荐时填推荐人的信息
*/
private
String
userNameZh
;
/**
* 英文名:注册,推荐必填,推荐时填推荐人的信息
*/
private
String
userNameEn
;
/**
* userID:注册,推荐必填,推荐时填推荐人的信息
*/
private
String
phone
;
/**
* 推荐码:推荐必填
*/
private
String
recommendCode
;
@Override
public
String
getStreamKey
()
{
return
"member.score.add"
;
...
...
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