Commit 8f8d6430 authored by zhangfeng's avatar zhangfeng

积分规则触发

parent 55dcf89a
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
......
......@@ -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 OrderVStrategy extends AbstractScoreRuleStrategy {
@Resource
private OrderApi orderApi;
@Resource
private MemberUserScoreApi memberUserScoreApi;
@Resource
private MemberUserScoreLogService memberUserScoreLogService;
@Resource
private CustomerContactsService customerContactsService;
public OderVStrategy(ScoreRuleService scoreRuleService,MemberUserScoreLogService memberUserScoreLogService) {
super(scoreRuleService, memberUserScoreLogService);
public OrderVStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService) {
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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment