init
This commit is contained in:
@@ -6,6 +6,7 @@ import com.ruoyi.cai.mq.config.RoomSettleDelayMqConfig;
|
||||
import com.ruoyi.cai.mq.config.CommonDelayMqConfig;
|
||||
import com.ruoyi.cai.mq.consumer.CalculateSalesQueueConsumer;
|
||||
import com.ruoyi.cai.mq.consumer.CommonConsumer;
|
||||
import com.ruoyi.cai.mq.consumer.WindowConsumer;
|
||||
import com.ruoyi.cai.mq.dto.CommonDTO;
|
||||
import com.ruoyi.cai.mq.dto.CommonDelayDto;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
@@ -27,6 +28,11 @@ public class AmqpProducer {
|
||||
CommonConsumer.COMMON_KEY, JSON.toJSONString(dto));
|
||||
}
|
||||
|
||||
public <T extends CommonDTO> void sendWindowMq(T dto){
|
||||
rabbitTemplate.convertAndSend(WindowConsumer.WINDOW_EXCHANGE,
|
||||
WindowConsumer.WINDOW_KEY, JSON.toJSONString(dto));
|
||||
}
|
||||
|
||||
public void sendRoomCheckDelay(String message, Integer timeout){
|
||||
rabbitTemplate.convertAndSend(RoomCheckDelayMqConfig.EXCHANGE_NAME,
|
||||
RoomCheckDelayMqConfig.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 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 WindowConsumer {
|
||||
|
||||
public final static String WINDOW_QUEUE = "caiWindowQueue";
|
||||
public final static String WINDOW_EXCHANGE = "caiWindowExchange";
|
||||
public final static String WINDOW_KEY = "caiWindowKey";
|
||||
|
||||
@Autowired
|
||||
private HandleConfig handleConfig;
|
||||
|
||||
|
||||
// ,containerFactory = "customContainerFactory"
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = WINDOW_QUEUE, durable = "false", autoDelete = "false"),
|
||||
exchange = @Exchange(value = WINDOW_EXCHANGE),
|
||||
key = WINDOW_KEY))
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.ruoyi.cai.mq.dto;
|
||||
|
||||
public enum CommonConsumerEnum {
|
||||
RANK
|
||||
RANK,WINDOW_GIFT,WINDOW_RECHARGE
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RankIHandle implements IHandle {
|
||||
public class RankHandle implements IHandle {
|
||||
|
||||
@Autowired
|
||||
private RankManager rankManager;
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.ruoyi.cai.mq.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.ruoyi.cai.domain.Gift;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
import com.ruoyi.cai.mq.handle.dto.WindowGiftDTO;
|
||||
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||
import com.ruoyi.cai.notice.data.child.SendGiftWindowsAmountNoticeData;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.cai.util.CaiDateUtil;
|
||||
import com.ruoyi.framework.OnlineTodayCache;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
public class WindowGiftHandle implements IHandle{
|
||||
|
||||
@Autowired
|
||||
private YunxinHttpService yunxinHttpService;
|
||||
@Autowired
|
||||
private OnlineTodayCache onlineTodayCache;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public void run(String message) {
|
||||
WindowGiftDTO windowGift = JSON.parseObject(message, WindowGiftDTO.class);
|
||||
User fromUser = userService.getById(windowGift.getFromId());
|
||||
User toUser = userService.getById(windowGift.getToId());
|
||||
Gift gift = windowGift.getGift();
|
||||
Set<Long> userIds = onlineTodayCache.getAllOnlineToday();
|
||||
List<Long> userIdList = new ArrayList<>(userIds);
|
||||
List<List<Long>> lists = Lists.partition(userIdList, 300);
|
||||
for (List<Long> list : lists) {
|
||||
SendGiftWindowsAmountNoticeData data = new SendGiftWindowsAmountNoticeData();
|
||||
data.setId(fromUser.getId());
|
||||
data.setNickname(fromUser.getNickname());
|
||||
data.setAvatar(fromUser.getAvatar());
|
||||
data.setToid(toUser.getId());
|
||||
data.setTonickname(toUser.getNickname());
|
||||
data.setToavatar(toUser.getAvatar());
|
||||
data.setAmount(gift.getPrice());
|
||||
data.setGiftname(gift.getName());
|
||||
data.setGiftimg(gift.getImg());
|
||||
data.setGifttotal(windowGift.getGiftNum());
|
||||
data.setTime(CaiDateUtil.getCurrentTimeStr());
|
||||
yunxinHttpService.sendGiftWindowsAmount(list,data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonConsumerEnum getType() {
|
||||
return CommonConsumerEnum.WINDOW_GIFT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.cai.mq.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
import com.ruoyi.cai.mq.handle.dto.WindowRechargeDTO;
|
||||
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||
import com.ruoyi.framework.OnlineTodayCache;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
public class WindowRechargeHandle implements IHandle{
|
||||
|
||||
@Autowired
|
||||
private YunxinHttpService yunxinHttpService;
|
||||
@Autowired
|
||||
private OnlineTodayCache onlineTodayCache;
|
||||
|
||||
@Override
|
||||
public void run(String message) {
|
||||
WindowRechargeDTO windowRecharge = JSON.parseObject(message, WindowRechargeDTO.class);
|
||||
Set<Long> userIds = onlineTodayCache.getAllOnlineToday();
|
||||
List<Long> userIdList = new ArrayList<>(userIds);
|
||||
List<List<Long>> lists = Lists.partition(userIdList, 300);
|
||||
for (List<Long> list : lists) {
|
||||
yunxinHttpService.sendRechargeWindowsAmount(list,windowRecharge);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonConsumerEnum getType() {
|
||||
return CommonConsumerEnum.WINDOW_RECHARGE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.ruoyi.cai.mq.handle.dto;
|
||||
|
||||
import com.ruoyi.cai.domain.Gift;
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
import com.ruoyi.cai.mq.dto.CommonDTO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class WindowGiftDTO extends CommonDTO {
|
||||
private Long fromId;
|
||||
private Long toId;
|
||||
private Gift gift;
|
||||
private Long giftNum;
|
||||
private LocalDateTime time;
|
||||
|
||||
public WindowGiftDTO() {
|
||||
this.setType(CommonConsumerEnum.WINDOW_GIFT);
|
||||
this.time = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class WindowRechargeDTO extends CommonDTO {
|
||||
private Long id;
|
||||
private String nickname;
|
||||
private String avatar;
|
||||
private BigDecimal amount;
|
||||
private LocalDateTime time;
|
||||
public WindowRechargeDTO() {
|
||||
this.setType(CommonConsumerEnum.WINDOW_RECHARGE);
|
||||
this.time = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user