Commit e05f532f authored by zhangfeng's avatar zhangfeng

bugfix(member): 推荐规则触发更新分享记录

parent 6f7e9cb1
......@@ -2,18 +2,22 @@ package cn.iocoder.yudao.module.member.mq.consumer.score.core;
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.ScoreRuleShareRecord.ScoreRuleShareRecordDO;
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.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.ScoreRuleShareRecord.ScoreRuleShareRecordService;
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.util.ScoreRuleGenCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
/**
......@@ -24,6 +28,10 @@ import java.util.HashMap;
public class RecommendStrategy extends AbstractScoreRuleStrategy {
@Resource
private MemberUserService memberUserService;
@Resource
private ScoreRuleShareRecordService scoreRuleShareRecordService;
@Resource
private ScoreRuleGenCodeUtils scoreRuleGenCodeUtils;
public RecommendStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService, MemberUserScoreApi memberUserScoreApi) {
super(scoreRuleService, memberUserScoreLogService, memberUserService, memberUserScoreApi);
......@@ -39,6 +47,7 @@ public class RecommendStrategy extends AbstractScoreRuleStrategy {
return;
}
Long userId = memberUserDO.getId();
// 获取推荐规则
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnableScoreRuleByType(ScoreRuleTypeEnum.RECOMMEND);
if (scoreRuleDO == null) {
log.info("Recommend rule is not exist,userID:{}", userId);
......@@ -50,6 +59,19 @@ public class RecommendStrategy extends AbstractScoreRuleStrategy {
log.info("Recommend listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId());
return;
}
// 根据分享人和规则id获取分享记录
ScoreRuleShareRecordDO scoreRuleShareRecordDO = scoreRuleShareRecordService.selectOne("member_id", userId, "rule_id", scoreRuleDO.getId());
if (scoreRuleShareRecordDO == null) {
// 没有分享记录说明是手动输入推荐码,创建分享记录
scoreRuleShareRecordDO = new ScoreRuleShareRecordDO();
scoreRuleShareRecordDO.setMemberId(userId);
scoreRuleShareRecordDO.setRuleId(scoreRuleDO.getId());
scoreRuleShareRecordDO.setCode(scoreRuleGenCodeUtils.generateShareRecordCode());
scoreRuleShareRecordDO.setTotalScore(0);
}
scoreRuleShareRecordDO.setLastTriggerTime(new Date());
scoreRuleShareRecordDO.setTotalScore(scoreRuleShareRecordDO.getTotalScore() + scoreRuleDO.getGetScoreOnce());
scoreRuleShareRecordService.saveOrUpdate(scoreRuleShareRecordDO);
try {
HashMap<String, Object> map = new HashMap<>();
map.put("userId", userId);
......
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