diff --git a/rc-service/rc-inner-api/external-inner/external-inner-model/src/main/java/com/red/circle/external/inner/model/enums/message/GroupMessageTypeEnum.java b/rc-service/rc-inner-api/external-inner/external-inner-model/src/main/java/com/red/circle/external/inner/model/enums/message/GroupMessageTypeEnum.java index 46450130..059113b7 100644 --- a/rc-service/rc-inner-api/external-inner/external-inner-model/src/main/java/com/red/circle/external/inner/model/enums/message/GroupMessageTypeEnum.java +++ b/rc-service/rc-inner-api/external-inner/external-inner-model/src/main/java/com/red/circle/external/inner/model/enums/message/GroupMessageTypeEnum.java @@ -146,4 +146,9 @@ public enum GroupMessageTypeEnum { */ ROCKET_REWARD_USER, + /** + * 房间红包 + */ + ROOM_RED_PACKET, + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java index a812ed9f..50431dae 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java @@ -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 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()); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/RoomRedPacketAppConvertor.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/RoomRedPacketAppConvertor.java index 3dbe53e3..c29128bd 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/RoomRedPacketAppConvertor.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/RoomRedPacketAppConvertor.java @@ -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; diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/GrabRoomRedPacketResultCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/GrabRoomRedPacketResultCO.java index 2f188cde..814259b0 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/GrabRoomRedPacketResultCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/GrabRoomRedPacketResultCO.java @@ -23,7 +23,7 @@ public class GrabRoomRedPacketResultCO { /** * 抢红包时间 */ - private LocalDateTime grabTime; + private String grabTime; /** * 剩余个数 diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/RoomRedPacketCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/RoomRedPacketCO.java index d834054e..536a1b3a 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/RoomRedPacketCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/RoomRedPacketCO.java @@ -18,7 +18,7 @@ public class RoomRedPacketCO { /** * 房间ID */ - private Long roomId; + private String roomId; /** * 发起人ID diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/SendRoomRedPacketCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/SendRoomRedPacketCmd.java index fd2620cb..43af1392 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/SendRoomRedPacketCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/SendRoomRedPacketCmd.java @@ -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;