房间红包增加IM通知

This commit is contained in:
tianfeng 2025-11-26 11:13:41 +08:00
parent 586f89765f
commit f9c6c47f15
6 changed files with 55 additions and 14 deletions

View File

@ -146,4 +146,9 @@ public enum GroupMessageTypeEnum {
*/
ROCKET_REWARD_USER,
/**
* 房间红包
*/
ROOM_RED_PACKET,
}

View File

@ -1,16 +1,26 @@
package com.red.circle.other.app.command.redpacket;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.external.inner.endpoint.message.ImGroupClient;
import com.red.circle.external.inner.model.cmd.message.BroadcastGroupMsgBodyCmd;
import com.red.circle.external.inner.model.cmd.message.CustomGroupMsgBodyCmd;
import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum;
import com.red.circle.other.app.convertor.RoomRedPacketAppConvertor;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.dto.clientobject.RoomRedPacketCO;
import com.red.circle.other.app.dto.cmd.SendRoomRedPacketCmd;
import com.red.circle.other.app.util.OfficialNoticeUtils;
import com.red.circle.other.domain.gateway.RoomRedPacketGateway;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.redpacket.RoomRedPacket;
import com.red.circle.other.domain.redpacket.RoomRedPacketRefundStatus;
import com.red.circle.other.domain.redpacket.RoomRedPacketSourceType;
import com.red.circle.other.domain.redpacket.RoomRedPacketStatus;
import com.red.circle.other.domain.redpacket.RoomRedPacketType;
import com.red.circle.other.infra.database.cache.service.other.RoomRedPacketCacheService;
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
import com.red.circle.other.inner.asserts.OtherErrorCode;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.sequence.IdWorkerUtils;
import com.red.circle.tool.core.tuple.PennyAmount;
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
@ -38,6 +48,10 @@ public class SendRoomRedPacketCmdExe {
private final RoomRedPacketGateway roomRedPacketGateway;
private final RoomRedPacketCacheService roomRedPacketCacheService;
private final WalletGoldClient walletGoldClient;
private final ImGroupClient imGroupClient;
private final UserProfileGateway userProfileGateway;
private final UserProfileAppConvertor userProfileAppConvertor;
private final RoomProfileManagerService roomProfileManagerService;
/**
* 执行发红包
@ -79,14 +93,10 @@ public class SendRoomRedPacketCmdExe {
packetId,
System.currentTimeMillis()
);
// 9. 判断是否需要全服推送金额 >= 10000
if (cmd.getTotalAmount() >= 10000) {
// TODO: 调用IM服务触发全服推送
log.info("触发全服推送 packetId={} roomId={} amount={}",
packetId, cmd.getRoomId(), cmd.getTotalAmount());
}
// 发送飘窗通知
sendMessage(cmd);
log.info("发红包成功 userId={} packetId={} roomId={} type={} amount={} count={}",
userId, packetId, cmd.getRoomId(), cmd.getPacketType(),
cmd.getTotalAmount(), cmd.getTotalCount());
@ -94,6 +104,32 @@ public class SendRoomRedPacketCmdExe {
return RoomRedPacketAppConvertor.toCO(redPacket);
}
private void sendMessage(SendRoomRedPacketCmd cmd) {
try {
String roomAccount = roomProfileManagerService.getRoomAccount(cmd.getRoomId());
UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.getReqUserId()));
Map<Object, Object> build = OfficialNoticeUtils.buildUserProfile(userProfile);
if (cmd.getTotalAmount() >= 10000) {
imGroupClient.sendMessageBroadcast(
BroadcastGroupMsgBodyCmd.builder()
.toPlatform(SysOriginPlatformEnum.LIKEI)
.type(GroupMessageTypeEnum.ROOM_RED_PACKET)
.data(build)
.build()
);
} else {
imGroupClient.sendCustomMessage(roomAccount,
CustomGroupMsgBodyCmd.builder()
.type(GroupMessageTypeEnum.ROOM_RED_PACKET)
.data(build)
.build());
}
} catch (Exception e) {
log.error("发送红包飘窗推送失败, {}", e.getMessage());
}
}
/**
* 参数校验
*/
@ -104,7 +140,7 @@ public class SendRoomRedPacketCmdExe {
}
// 校验过期时间
if (!Arrays.asList(1, 3, 5).contains(cmd.getExpireMinutes())) {
if (!Arrays.asList(1, 3, 5, 10).contains(cmd.getExpireMinutes())) {
throw new RuntimeException(OtherErrorCode.RED_PACKET_EXPIRE_TIME_ERROR.getMessage());
}

View File

@ -28,7 +28,7 @@ public class RoomRedPacketAppConvertor {
RoomRedPacketCO co = new RoomRedPacketCO();
co.setPacketId(domain.getPacketId());
co.setRoomId(domain.getRoomId());
co.setRoomId(String.valueOf(domain.getRoomId()));
co.setUserId(domain.getUserId());
co.setPacketType(domain.getPacketType());
co.setPacketTypeDesc(getPacketTypeDesc(domain.getPacketType()));
@ -108,7 +108,7 @@ public class RoomRedPacketAppConvertor {
GrabRoomRedPacketResultCO co = new GrabRoomRedPacketResultCO();
co.setPacketId(packetId);
co.setAmount(amount);
co.setGrabTime(LocalDateTime.now());
co.setGrabTime(LocalDateTime.now().toString());
co.setRemainCount(remainCount);
co.setTotalCount(totalCount);
return co;

View File

@ -23,7 +23,7 @@ public class GrabRoomRedPacketResultCO {
/**
* 抢红包时间
*/
private LocalDateTime grabTime;
private String grabTime;
/**
* 剩余个数

View File

@ -18,7 +18,7 @@ public class RoomRedPacketCO {
/**
* 房间ID
*/
private Long roomId;
private String roomId;
/**
* 发起人ID

View File

@ -39,7 +39,7 @@ public class SendRoomRedPacketCmd extends AppExtCommand {
private Integer totalCount;
/**
* 过期分钟数1/3/5
* 过期分钟数1/3/5/10
*/
@NotNull(message = "Expire minutes cannot be empty")
private Integer expireMinutes;