送礼完成任务添加锁
This commit is contained in:
@@ -2295,6 +2295,8 @@ public enum RedisKey {
|
||||
|
||||
act_user_complete_task_lock,
|
||||
|
||||
act_user_complete_task_status,
|
||||
|
||||
mq_status,
|
||||
|
||||
act_user_task_score_for_send,
|
||||
|
@@ -183,6 +183,7 @@ public class ActUserTaskConsumer extends AbstractMessageListener<ActUserTaskMqMe
|
||||
context.setGiftId(object.getGiftId());
|
||||
context.setGiftValue(object.getGiftValue());
|
||||
context.setTaskTime(object.getMessTime());
|
||||
context.setGiftSendUuid(object.getGiftSendUuid());
|
||||
context.setActivityStartTime(startTime);
|
||||
context.setActivityEndTime(endTime);
|
||||
context.setTaskStartTime(startTime);
|
||||
|
@@ -64,6 +64,11 @@ public class ActTaskContext {
|
||||
*/
|
||||
private Date taskEndTime;
|
||||
|
||||
/**
|
||||
* 区分是否为同一次送礼操作
|
||||
*/
|
||||
private String giftSendUuid;
|
||||
|
||||
/**
|
||||
* 任务
|
||||
*/
|
||||
|
@@ -6,6 +6,7 @@ import com.accompany.business.activity.enums.ActTaskStatusEnum;
|
||||
import com.accompany.business.activity.model.ActTask;
|
||||
import com.accompany.business.activity.model.ActTaskCondition;
|
||||
import com.accompany.business.activity.model.ActUserTask;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -162,6 +163,7 @@ public class IGiftBoxTaskHandler extends IActTaskHandler {
|
||||
actUserTask.setActivityValue(count);
|
||||
if (conditionValue != null && conditionValue.equals(count)) {
|
||||
actUserTask.setTaskStatus(ActTaskStatusEnum.COMPLETE.ordinal());
|
||||
jedisService.set(RedisKey.act_user_complete_task_status.getKey(context.getGiftSendUuid()), String.valueOf(actUserTask.getId()), 5 * 60);
|
||||
}
|
||||
int taskCount = actUserTaskService.count(Wrappers.<ActUserTask>lambdaQuery()
|
||||
.eq(ActUserTask::getActivityCode, activityCode)
|
||||
|
@@ -106,6 +106,7 @@ public class ActTaskListener implements ApplicationListener<GiftMessageEvent> {
|
||||
message.setGiftValue(giftMessage.getGoldNum());
|
||||
message.setMessTime(now.getTime());
|
||||
message.setGiftNum(giftNum);
|
||||
message.setGiftSendUuid(giftMessage.getGiftSendUuid());
|
||||
mqMessageProducer.send(MqConstant.ACT_USER_TASK_TOPIC, message);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@@ -10,6 +10,7 @@ import com.accompany.business.fools.task.AprilFoolsDayBoxTaskService;
|
||||
import com.accompany.business.service.SendSysMsgService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.vo.message.MessageTemplate;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
@@ -47,6 +48,9 @@ public class AprilFoolsDayBoxHandler extends IGiftBoxTaskHandler {
|
||||
|
||||
@Override
|
||||
protected boolean eq(ActTaskCondition actTaskCondition, ActTaskContext context) {
|
||||
if (jedisService.exits(RedisKey.act_user_complete_task_status.getKey(context.getGiftSendUuid()))) {
|
||||
return false;
|
||||
}
|
||||
boolean isComplete = super.eq(actTaskCondition, context);
|
||||
if (isComplete) {
|
||||
Long roomUid = context.getRoomUid();
|
||||
|
@@ -26,6 +26,11 @@ public class GiftMessage extends BaseMqMessage {
|
||||
@Deprecated
|
||||
private Boolean luckyBagGift; // 是否是福袋开出的礼物
|
||||
|
||||
/**
|
||||
* 判断是否为同一次送礼操作
|
||||
*/
|
||||
private String giftSendUuid;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GiftMessage{" +
|
||||
@@ -174,4 +179,11 @@ public class GiftMessage extends BaseMqMessage {
|
||||
this.luckyBagGift = luckyBagGift;
|
||||
}
|
||||
|
||||
public String getGiftSendUuid() {
|
||||
return giftSendUuid;
|
||||
}
|
||||
|
||||
public void setGiftSendUuid(String giftSendUuid) {
|
||||
this.giftSendUuid = giftSendUuid;
|
||||
}
|
||||
}
|
||||
|
@@ -405,7 +405,15 @@ public class GiftSendService extends BaseService {
|
||||
*/
|
||||
private void sendGiftMessage2MQ(long sendUid, long recvUid, Long roomUid, int giftId, byte giftConsumeType, byte giftType, int giftNum, Long goldNum,
|
||||
byte sendType, Byte roomType, String msg, int giftSource, Boolean luckyBagGift) {
|
||||
GiftMessage message = buildGiftMessage(sendUid, recvUid, roomUid, giftId, giftConsumeType, giftType, giftNum, goldNum, sendType, roomType, msg, giftSource, luckyBagGift);
|
||||
sendGiftMessage2MQ(sendUid, recvUid, roomUid, giftId, giftConsumeType, giftType, giftNum, goldNum, sendType, roomType, msg, giftSource, luckyBagGift, UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送礼物消息到MQ处理(加钻石、写DB记录)
|
||||
*/
|
||||
private void sendGiftMessage2MQ(long sendUid, long recvUid, Long roomUid, int giftId, byte giftConsumeType, byte giftType, int giftNum, Long goldNum,
|
||||
byte sendType, Byte roomType, String msg, int giftSource, Boolean luckyBagGift, String giftSendUuid) {
|
||||
GiftMessage message = buildGiftMessage(sendUid, recvUid, roomUid, giftId, giftConsumeType, giftType, giftNum, goldNum, sendType, roomType, msg, giftSource, luckyBagGift, giftSendUuid);
|
||||
// 缓存消息的消费状态,便于队列消息做幂等处理
|
||||
jedisService.hwrite(RedisKey.mq_gift_status.getKey(), message.getMessId(), gson.toJson(message));
|
||||
rocketMQService.sendGiftMessage(message);
|
||||
@@ -513,7 +521,7 @@ public class GiftSendService extends BaseService {
|
||||
* @return
|
||||
*/
|
||||
private GiftMessage buildGiftMessage(Long sendUid, Long recvUid, Long roomUid, Integer giftId, Byte giftConsumeType, Byte giftType,
|
||||
Integer giftNum, Long goldNum, Byte sendType, Byte roomType, String msg, Integer giftSource, Boolean luckyBagGift) {
|
||||
Integer giftNum, Long goldNum, Byte sendType, Byte roomType, String msg, Integer giftSource, Boolean luckyBagGift, String giftSendUuid) {
|
||||
GiftMessage message = new GiftMessage();
|
||||
message.setSendUid(sendUid);
|
||||
message.setRecvUid(recvUid);
|
||||
@@ -530,6 +538,7 @@ public class GiftSendService extends BaseService {
|
||||
message.setMsg(msg);
|
||||
message.setGiftSource(giftSource);
|
||||
message.setLuckyBagGift(luckyBagGift);
|
||||
message.setGiftSendUuid(giftSendUuid);
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -893,6 +902,8 @@ public class GiftSendService extends BaseService {
|
||||
List<LuckyBagRecord> luckyBagRecordList = new ArrayList<>();
|
||||
Gift displayGift = gifts.get(0);
|
||||
|
||||
String giftSendUuid = UUID.randomUUID().toString();
|
||||
|
||||
// 处理用户抽奖后逻辑
|
||||
for (Long receiveUid : drawMap.keySet()) {
|
||||
// 用户抽到奖池礼物列表
|
||||
@@ -932,7 +943,7 @@ public class GiftSendService extends BaseService {
|
||||
// 发送队列消息
|
||||
sendGiftMessage2MQ(sendUid, receiveUid, roomUid, drawGift.getGiftId(), drawGift.getConsumeType(), drawGift.getGiftType(),
|
||||
record.getGiftNum(), record.getTotalPlatformValue(),
|
||||
sendType, roomType, msg, giftSource, true);
|
||||
sendType, roomType, msg, giftSource, true, giftSendUuid);
|
||||
}
|
||||
|
||||
Long totalPlaformValue = recordList.stream().mapToLong(LuckyBagRecord::getTotalPlatformValue).sum();
|
||||
@@ -1052,6 +1063,8 @@ public class GiftSendService extends BaseService {
|
||||
|
||||
Map<Long, List<LuckyBagRecord>> recordMap = new HashMap<>();
|
||||
|
||||
String giftSendUuid = UUID.randomUUID().toString();
|
||||
|
||||
for (Long recvUid : recvUids) {
|
||||
// 抽奖
|
||||
List<LuckyBagRecord> recordList = luckyBagLinearPoolService.pollReward(luckyBagGiftId, giftNum, sendUid, recvUid);
|
||||
@@ -1085,7 +1098,7 @@ public class GiftSendService extends BaseService {
|
||||
|
||||
// 房间流水根据实际开出的礼物价值,发送队列消息
|
||||
sendGiftMessage2MQ(sendUid, recvUid, roomUid, giftId, g.getConsumeType(), g.getGiftType(), record.getGiftNum(), record.getTotalPlatformValue(),
|
||||
sendType, room != null ? room.getType() : null, msg, giftSource, true);
|
||||
sendType, room != null ? room.getType() : null, msg, giftSource, true, giftSendUuid);
|
||||
}
|
||||
|
||||
recordMap.put(recvUid, recordList);
|
||||
|
@@ -44,4 +44,9 @@ public class ActUserTaskMqMessage extends BaseMqMessage {
|
||||
* 礼物数量
|
||||
*/
|
||||
private Integer giftNum;
|
||||
|
||||
/**
|
||||
* 区分是否为同一次送礼操作
|
||||
*/
|
||||
private String giftSendUuid;
|
||||
}
|
||||
|
Reference in New Issue
Block a user