init
This commit is contained in:
@@ -1,13 +1,40 @@
|
||||
package com.ruoyi.test;
|
||||
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import com.ruoyi.cai.rank.RankNode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 带参数单元测试案例
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class CaiUnitTest {
|
||||
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
|
||||
@Test
|
||||
public void rank(){
|
||||
List<RankNode> nodes = rankManager.getLoveRankDayToday(9);
|
||||
for (RankNode node : nodes) {
|
||||
log.info("userId={}, score={}", node.getUserId(),node.getScore());
|
||||
}
|
||||
nodes = rankManager.getLoveRankDayLastDay(9);
|
||||
for (RankNode node : nodes) {
|
||||
log.info("userId={}, score={}", node.getUserId(),node.getScore());
|
||||
}
|
||||
nodes = rankManager.getInviteRankDayToday(9);
|
||||
for (RankNode node : nodes) {
|
||||
log.info("userId={}, score={}", node.getUserId(),node.getScore());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,5 +12,7 @@ public class RedisConstant {
|
||||
public static final String BLACK_REDIS = REDIS_P + "black:%s";
|
||||
|
||||
public static final String FORBID_CACHE_REDIS = REDIS_P + "forbid:%s";
|
||||
public static final String LOVE_RANK_REDIS = REDIS_P + "loveRank:%s:%s";
|
||||
public static final String INVITE_RANK_REDIS = REDIS_P + "inviteRank:%s:%s";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import com.ruoyi.cai.domain.ConsumeLog;
|
||||
import com.ruoyi.cai.dto.ConsumeResp;
|
||||
import com.ruoyi.cai.dto.app.query.GiveGiftRes;
|
||||
import com.ruoyi.cai.dto.app.query.GiveGuardReq;
|
||||
import com.ruoyi.cai.dto.video.VideoSettleResp;
|
||||
import com.ruoyi.cai.mq.AmqpProducer;
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import com.ruoyi.cai.service.AccountService;
|
||||
import com.ruoyi.cai.service.GuardTotalService;
|
||||
import com.ruoyi.cai.service.RechargeOrderService;
|
||||
import com.ruoyi.cai.service.UserGiftService;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -22,6 +27,10 @@ public class ConsumerManager {
|
||||
private AmqpProducer amqpProducer;
|
||||
@Autowired
|
||||
private RechargeOrderService rechargeOrderService;
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
|
||||
public ConsumeResp sendGuard(GiveGuardReq query){
|
||||
ConsumeResp resp = guardTotalService.giveGuard(query);
|
||||
@@ -47,6 +56,18 @@ public class ConsumerManager {
|
||||
return resp;
|
||||
}
|
||||
|
||||
public VideoSettleResp videoSettle(Room room){
|
||||
VideoSettleResp resp = accountService.videoSettle(room);
|
||||
ConsumeLog consumeLog = resp.getConsumeLog();
|
||||
try {
|
||||
amqpProducer.sendCalculateSales(consumeLog.getId()+"");
|
||||
}catch (Exception e){
|
||||
log.error("RabbitMq 发送失败, 视频分销流程流转失败!",e);
|
||||
}
|
||||
rankManager.sendLoveRankMq(consumeLog.getSourceUserId(),consumeLog.getAnchorAmount(),consumeLog.getTraceId());
|
||||
return resp;
|
||||
}
|
||||
|
||||
public ConsumeResp rechargeOrderSuccess(String tradeNo){
|
||||
ConsumeResp resp = rechargeOrderService.orderSuccess(tradeNo);
|
||||
if(resp.isSuccess()){
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.ruoyi.cai.mq;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.cai.mq.consumer.CalculateSalesQueueConsumer;
|
||||
import com.ruoyi.cai.mq.consumer.CommonConsumer;
|
||||
import com.ruoyi.cai.mq.dto.CommonDTO;
|
||||
import com.ruoyi.cai.mq.dto.CommonDelayDto;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,6 +18,12 @@ public class AmqpProducer {
|
||||
rabbitTemplate.convertAndSend(CalculateSalesQueueConsumer.CALCULATE_SALES_EXCHANGE, CalculateSalesQueueConsumer.CALCULATE_SALES_KEY, message);
|
||||
}
|
||||
|
||||
|
||||
public <T extends CommonDTO> void sendCommonMq(T dto){
|
||||
rabbitTemplate.convertAndSend(CommonConsumer.COMMON_EXCHANGE,
|
||||
CommonConsumer.COMMON_KEY, JSON.toJSONString(dto));
|
||||
}
|
||||
|
||||
public void sendCheckTimeOut(String message,Integer timeout){
|
||||
rabbitTemplate.convertAndSend(CheckTimeOutMqConfig.EXCHANGE_NAME,
|
||||
CheckTimeOutMqConfig.ROUTING_KEY,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ruoyi.cai.mq.consumer;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.mq.handle.HandleConfig;
|
||||
import com.ruoyi.cai.mq.handle.IHandle;
|
||||
import com.ruoyi.cai.service.ConsumeLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CommonConsumer {
|
||||
public final static String COMMON_QUEUE = "caiCommonQueue";
|
||||
public final static String COMMON_EXCHANGE = "caiCommonExchange";
|
||||
public final static String COMMON_KEY = "caiCommonKey";
|
||||
|
||||
@Autowired
|
||||
private HandleConfig handleConfig;
|
||||
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = COMMON_QUEUE, durable = "false", autoDelete = "false"),
|
||||
exchange = @Exchange(value = COMMON_EXCHANGE),
|
||||
key = COMMON_KEY)
|
||||
,containerFactory = "customContainerFactory")
|
||||
public void calculateSalesQueue(String message) {
|
||||
log.info("队列消息处理-开始: message=" + message);
|
||||
try {
|
||||
JSONObject object = JSON.parseObject(message);
|
||||
String type = object.getString("type");
|
||||
IHandle handle = handleConfig.getHandle(type);
|
||||
handle.run(message);
|
||||
}catch (Exception e){
|
||||
log.error("队列消息处理-失败: message=" + message,e);
|
||||
}
|
||||
log.info("队列消息处理-结束: message=" + message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.ruoyi.cai.mq.dto;
|
||||
|
||||
public enum CommonConsumerEnum {
|
||||
RANK
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.ruoyi.cai.mq.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CommonDTO {
|
||||
private CommonConsumerEnum type;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.ruoyi.cai.mq.handle;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class HandleConfig {
|
||||
|
||||
public static Map<String,IHandle> MAP = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
private List<IHandle> handles;
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
for (IHandle handle : handles) {
|
||||
MAP.put(handle.getType().name(),handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IHandle getHandle(String type){
|
||||
return MAP.get(type);
|
||||
}
|
||||
|
||||
}
|
||||
10
ruoyi-cai/src/main/java/com/ruoyi/cai/mq/handle/IHandle.java
Normal file
10
ruoyi-cai/src/main/java/com/ruoyi/cai/mq/handle/IHandle.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.ruoyi.cai.mq.handle;
|
||||
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
|
||||
public interface IHandle {
|
||||
|
||||
void run(String message);
|
||||
|
||||
CommonConsumerEnum getType();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.cai.mq.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
import com.ruoyi.cai.mq.handle.dto.RankDTO;
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RankIHandle implements IHandle {
|
||||
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
@Override
|
||||
public void run(String message) {
|
||||
RankDTO rank = JSON.parseObject(message, RankDTO.class);
|
||||
rankManager.addRank(rank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonConsumerEnum getType() {
|
||||
return CommonConsumerEnum.RANK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ruoyi.cai.mq.handle.dto;
|
||||
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
import com.ruoyi.cai.mq.dto.CommonDTO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class RankDTO extends CommonDTO {
|
||||
|
||||
/**
|
||||
* 1-魅力榜
|
||||
* 2-邀请榜
|
||||
*/
|
||||
private Integer rankType;
|
||||
private Long userId;
|
||||
private Long price;
|
||||
private LocalDateTime happenTime;
|
||||
private Long traceId;
|
||||
|
||||
public RankDTO() {
|
||||
this.setType(CommonConsumerEnum.RANK);
|
||||
this.happenTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
}
|
||||
277
ruoyi-cai/src/main/java/com/ruoyi/cai/rank/RankManager.java
Normal file
277
ruoyi-cai/src/main/java/com/ruoyi/cai/rank/RankManager.java
Normal file
@@ -0,0 +1,277 @@
|
||||
package com.ruoyi.cai.rank;
|
||||
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.mq.AmqpProducer;
|
||||
import com.ruoyi.cai.mq.handle.dto.RankDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RScoredSortedSet;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.client.protocol.ScoredEntry;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RankManager {
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public static final String LOVE_KEY_FORMAT = RedisConstant.LOVE_RANK_REDIS;
|
||||
public static final String INVITE_KEY_FORMAT = RedisConstant.INVITE_RANK_REDIS;
|
||||
|
||||
public static final String DAY = "Day";
|
||||
public static final String WEEK = "Week";
|
||||
public static final String MONTH = "Month";
|
||||
public static final String TOTAL = "Total";
|
||||
|
||||
private String dateString(LocalDate time){
|
||||
return time.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
}
|
||||
|
||||
private String getKeyInviteDay(LocalDate time){
|
||||
String day = dateString(time);
|
||||
return String.format(INVITE_KEY_FORMAT,DAY,day);
|
||||
}
|
||||
|
||||
private String getKeyInviteWeek(LocalDate time){
|
||||
LocalDate monday = time.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||
LocalDate sunday = time.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
||||
String mondayStr = dateString(monday);
|
||||
String sundayStr = dateString(sunday);
|
||||
return String.format(INVITE_KEY_FORMAT,WEEK,mondayStr+"-"+sundayStr);
|
||||
}
|
||||
|
||||
private String getKeyInviteMonth(LocalDate time){
|
||||
String month = time.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
||||
return String.format(INVITE_KEY_FORMAT,MONTH,month);
|
||||
}
|
||||
|
||||
private String getKeyInviteTotal(){
|
||||
return String.format(INVITE_KEY_FORMAT,TOTAL,TOTAL);
|
||||
}
|
||||
|
||||
private String getKeyLoveDay(LocalDate time){
|
||||
String day = dateString(time);
|
||||
return String.format(LOVE_KEY_FORMAT,DAY,day);
|
||||
}
|
||||
|
||||
private String getKeyLoveWeek(LocalDate time){
|
||||
LocalDate monday = time.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||
LocalDate sunday = time.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
||||
String mondayStr = dateString(monday);
|
||||
String sundayStr = dateString(sunday);
|
||||
return String.format(LOVE_KEY_FORMAT,WEEK,mondayStr+"-"+sundayStr);
|
||||
}
|
||||
|
||||
private String getKeyLoveMonth(LocalDate time){
|
||||
String month = time.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
||||
return String.format(LOVE_KEY_FORMAT,MONTH,month);
|
||||
}
|
||||
|
||||
private String getKeyLoveTotal(){
|
||||
return String.format(LOVE_KEY_FORMAT,TOTAL,TOTAL);
|
||||
}
|
||||
|
||||
public void addRank(RankDTO dto){
|
||||
if(dto.getRankType() == null){
|
||||
return;
|
||||
}
|
||||
if(dto.getRankType() == 1){
|
||||
LocalDate localDate = dto.getHappenTime().toLocalDate();
|
||||
String dayKey = getKeyLoveDay(localDate);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(dayKey);
|
||||
daySet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
|
||||
String weekKey = getKeyLoveWeek(localDate);
|
||||
RScoredSortedSet<String> weekSet = redissonClient.getScoredSortedSet(weekKey);
|
||||
weekSet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
|
||||
String monthKey = getKeyLoveMonth(localDate);
|
||||
RScoredSortedSet<String> monthSet = redissonClient.getScoredSortedSet(monthKey);
|
||||
monthSet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
|
||||
String totalKey = getKeyLoveTotal();
|
||||
RScoredSortedSet<String> totalSet = redissonClient.getScoredSortedSet(totalKey);
|
||||
totalSet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
}else if(dto.getRankType() == 2){
|
||||
LocalDate localDate = dto.getHappenTime().toLocalDate();
|
||||
String dayKey = getKeyInviteDay(localDate);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(dayKey);
|
||||
daySet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
|
||||
String weekKey = getKeyInviteWeek(localDate);
|
||||
RScoredSortedSet<String> weekSet = redissonClient.getScoredSortedSet(weekKey);
|
||||
weekSet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
|
||||
String monthKey = getKeyInviteMonth(localDate);
|
||||
RScoredSortedSet<String> monthSet = redissonClient.getScoredSortedSet(monthKey);
|
||||
monthSet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
|
||||
String totalKey = getKeyInviteTotal();
|
||||
RScoredSortedSet<String> totalSet = redissonClient.getScoredSortedSet(totalKey);
|
||||
totalSet.addScore(dto.getUserId()+"",dto.getPrice());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<RankNode> getLoveRankDayLastDay(int limit){
|
||||
return getLoveRankDay(LocalDate.now().plusDays(-1),limit);
|
||||
}
|
||||
public List<RankNode> getLoveRankDayLastWeek(int limit){
|
||||
return getLoveRankWeek(LocalDate.now().plusWeeks(-7),limit);
|
||||
}
|
||||
|
||||
public List<RankNode> getLoveRankDayToday(int limit){
|
||||
return getLoveRankDay(LocalDate.now(),limit);
|
||||
}
|
||||
public List<RankNode> getLoveRankDayWeek(int limit){
|
||||
return getLoveRankWeek(LocalDate.now(),limit);
|
||||
}
|
||||
public List<RankNode> getLoveRankDayMonth(int limit){
|
||||
return getLoveRankMonth(LocalDate.now(),limit);
|
||||
}
|
||||
|
||||
public List<RankNode> getLoveRankDay(LocalDate date, int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyLoveDay(date);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getLoveRankWeek(LocalDate date,int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyLoveWeek(date);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getLoveRankMonth(LocalDate date,int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyLoveMonth(date);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getLoveRankTotal(int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyLoveTotal();
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getInviteRankDayLastDay(int limit){
|
||||
return getInviteRankDay(LocalDate.now().plusDays(-1),limit);
|
||||
}
|
||||
public List<RankNode> getInviteRankDayLastWeek(int limit){
|
||||
return getInviteRankWeek(LocalDate.now().plusWeeks(-7),limit);
|
||||
}
|
||||
|
||||
public List<RankNode> getInviteRankDayToday(int limit){
|
||||
return getInviteRankDay(LocalDate.now(),limit);
|
||||
}
|
||||
public List<RankNode> getInviteRankDayWeek(int limit){
|
||||
return getInviteRankWeek(LocalDate.now(),limit);
|
||||
}
|
||||
public List<RankNode> getInviteRankDayMonth(int limit){
|
||||
return getInviteRankMonth(LocalDate.now(),limit);
|
||||
}
|
||||
|
||||
public List<RankNode> getInviteRankDay(LocalDate date, int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyInviteDay(date);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getInviteRankWeek(LocalDate date,int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyInviteWeek(date);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getInviteRankMonth(LocalDate date,int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyInviteMonth(date);
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RankNode> getInviteRankTotal(int limit){
|
||||
List<RankNode> res = new ArrayList<>();
|
||||
String key = getKeyInviteTotal();
|
||||
RScoredSortedSet<String> daySet = redissonClient.getScoredSortedSet(key);
|
||||
Collection<ScoredEntry<String>> entries = daySet.entryRangeReversed(0, limit-1);
|
||||
for (ScoredEntry<String> entry : entries) {
|
||||
res.add(RankNode.getNode(entry));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private AmqpProducer amqpProducer;
|
||||
|
||||
public void sendLoveRankMq(Long userId,Long value,Long traceId){
|
||||
try {
|
||||
RankDTO rank = new RankDTO();
|
||||
rank.setUserId(userId);
|
||||
rank.setPrice(value);
|
||||
rank.setTraceId(traceId);
|
||||
rank.setRankType(1);
|
||||
amqpProducer.sendCommonMq(rank);
|
||||
}catch (Exception e){
|
||||
log.error("发送魅力榜 rank mq失败",e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendInviteRankMq(Long userId,Long value,Long traceId){
|
||||
try {
|
||||
RankDTO rank = new RankDTO();
|
||||
rank.setUserId(userId);
|
||||
rank.setPrice(value);
|
||||
rank.setTraceId(traceId);
|
||||
rank.setRankType(2);
|
||||
amqpProducer.sendCommonMq(rank);
|
||||
}catch (Exception e){
|
||||
log.error("发送邀请榜 rank mq失败",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
ruoyi-cai/src/main/java/com/ruoyi/cai/rank/RankNode.java
Normal file
20
ruoyi-cai/src/main/java/com/ruoyi/cai/rank/RankNode.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.ruoyi.cai.rank;
|
||||
|
||||
import lombok.Data;
|
||||
import org.redisson.client.protocol.ScoredEntry;
|
||||
|
||||
@Data
|
||||
public class RankNode {
|
||||
private Long score;
|
||||
private Long userId;
|
||||
|
||||
public RankNode() {
|
||||
}
|
||||
|
||||
public static RankNode getNode(ScoredEntry<String> entry){
|
||||
RankNode rankNode = new RankNode();
|
||||
rankNode.setScore(entry.getScore().longValue());
|
||||
rankNode.setUserId(Long.valueOf(entry.getValue()));
|
||||
return rankNode;
|
||||
}
|
||||
}
|
||||
@@ -310,6 +310,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
private UserCallService userCallService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public VideoSettleResp videoSettle(Room room) {
|
||||
RoomData roomData = room.getRoomData();
|
||||
UserCall userCall = userCallService.getById(roomData.getRoomId());
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.ruoyi.cai.manager.IdManager;
|
||||
import com.ruoyi.cai.manager.LockManager;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.mapper.GuardTotalMapper;
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import com.ruoyi.cai.service.*;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
@@ -51,6 +52,8 @@ public class GuardTotalServiceImpl extends ServiceImpl<GuardTotalMapper, GuardTo
|
||||
private SystemConfigManager systemConfigManager;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -140,6 +143,7 @@ public class GuardTotalServiceImpl extends ServiceImpl<GuardTotalMapper, GuardTo
|
||||
this.save(one);
|
||||
}
|
||||
baseMapper.incs(fromUserId,query.getToUserId(),query.getGuardNum(),guardValue);
|
||||
rankManager.sendLoveRankMq(anchor.getUserId(),consumeLog.getAnchorAmount(),consumeLog.getTraceId());
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import com.ruoyi.cai.enums.ConsumeLogType;
|
||||
import com.ruoyi.cai.manager.IdManager;
|
||||
import com.ruoyi.cai.manager.LockManager;
|
||||
import com.ruoyi.cai.mapper.UserGiftMapper;
|
||||
import com.ruoyi.cai.mq.AmqpProducer;
|
||||
import com.ruoyi.cai.mq.dto.CommonDTO;
|
||||
import com.ruoyi.cai.mq.handle.dto.RankDTO;
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import com.ruoyi.cai.service.*;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
@@ -42,6 +46,8 @@ public class UserGiftServiceImpl extends ServiceImpl<UserGiftMapper, UserGift> i
|
||||
private AnchorService anchorService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -95,6 +101,7 @@ public class UserGiftServiceImpl extends ServiceImpl<UserGiftMapper, UserGift> i
|
||||
userGift.setGiftAmount(giftAmount);
|
||||
userGift.setTraceId(traceId);
|
||||
this.save(userGift);
|
||||
rankManager.sendLoveRankMq(anchor.getUserId(),consumeLog.getAnchorAmount(),consumeLog.getTraceId());
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.ruoyi.cai.domain.Account;
|
||||
import com.ruoyi.cai.dto.video.VideoSettleResp;
|
||||
import com.ruoyi.cai.dto.video.WithholdingFeeUserResp;
|
||||
import com.ruoyi.cai.manager.ConsumerManager;
|
||||
import com.ruoyi.cai.manager.LockManager;
|
||||
import com.ruoyi.cai.service.AccountService;
|
||||
import com.ruoyi.cai.trd.ImDataRes;
|
||||
@@ -127,6 +128,9 @@ public class SettleService {
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ConsumerManager consumerManager;
|
||||
|
||||
/**
|
||||
* 结算内部整合逻辑
|
||||
* @param room
|
||||
@@ -144,7 +148,7 @@ public class SettleService {
|
||||
roomDataCache.hMSet(roomId,"settleTime", DateUtil.currentSeconds());
|
||||
return;
|
||||
}
|
||||
VideoSettleResp resp = accountService.videoSettle(room);
|
||||
VideoSettleResp resp = consumerManager.videoSettle(room);
|
||||
// 修改房间缓存
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("payCoin",resp.getPayCoin());
|
||||
|
||||
Reference in New Issue
Block a user