幸运礼物-mq异步结算,Lucky24Record加上roomUid和messId

This commit is contained in:
khalil
2025-01-10 17:57:49 +08:00
parent a318876075
commit a4b9d4a7bd
13 changed files with 364 additions and 22 deletions

View File

@@ -1,9 +1,15 @@
package com.accompany.scheduler.task.luckyBag;
import com.accompany.business.message.GiftMessage;
import com.accompany.business.message.Lucky24Message;
import com.accompany.business.service.gift.Lucky24MessageService;
import com.accompany.business.service.lucky.Lucky24RecordService;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.model.PartitionInfo;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.partition.PartitionInfoService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -15,6 +21,7 @@ import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;
@Component
@@ -28,6 +35,39 @@ public class Lucky24Task {
@Resource(name = "bizExecutor")
private ThreadPoolExecutor bizExecutor;
@Autowired
private JedisService jedisService;
@Autowired
private Lucky24MessageService lucky24MessageService;
/**
* 重新消费队列的消息
*/
@Scheduled(cron = "0 */5 * * * ?")
public void retryLucky24Queue() {
log.info("retryLucky24Queue start ...");
Map<String, String> map = jedisService.hgetAll(RedisKey.lucky_24_status.getKey());
if (map == null || map.size() == 0) {
return;
}
long curTime = System.currentTimeMillis();
long gapTime = 1000 * 60 * 10; // 十分钟内没被消费
map.entrySet().parallelStream().forEach(entry -> {
try {
String messId = entry.getKey();
String val = entry.getValue();
Lucky24Message giftMessage = JSON.parseObject(val, Lucky24Message.class);
if (curTime - giftMessage.getCreateTime() > gapTime) {
lucky24MessageService.handleGiftMessage(giftMessage);
}
} catch (Exception e) {
log.error("retryLucky24Queue error", e);
}
});
log.info("retryLucky24Queue end ...");
}
@Scheduled(cron = "0 2 * * * ? ")
public void lucky24RecordStat() {
Date now = new Date();