From 5d50c4d1aba0c4d871c000970f595a1a77bd04ad Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 16 Oct 2025 10:05:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E6=B3=A8=E5=8A=A0=E5=A5=BD=E5=8F=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...erSupportRelationFollowOrCancelCmdExe.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserSupportRelationFollowOrCancelCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserSupportRelationFollowOrCancelCmdExe.java index b99efb83..e9368292 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserSupportRelationFollowOrCancelCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserSupportRelationFollowOrCancelCmdExe.java @@ -1,18 +1,35 @@ package com.red.circle.other.app.command.user; import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; +import com.red.circle.external.inner.endpoint.message.ImGroupClient; +import com.red.circle.external.inner.model.cmd.message.GroupUnbanCmd; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; +import com.red.circle.mq.rocket.business.producer.TaskMqMessage; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.ability.UserRelationsCalculatorGateway; import com.red.circle.other.domain.model.user.ability.UserRelationsCalculator; import com.red.circle.other.domain.model.user.ability.UserRelationsCalculator.CounterEnum; +import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile; +import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService; +import com.red.circle.other.infra.database.mongo.service.live.RoomUserBlacklistService; +import com.red.circle.other.infra.database.mongo.service.user.friend.FriendsApplyListService; +import com.red.circle.other.infra.database.rds.entity.user.user.RelationshipFriend; +import com.red.circle.other.infra.database.rds.service.user.user.RelationshipFriendService; +import com.red.circle.other.infra.database.rds.service.user.user.ShieldBlackService; import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptionService; +import com.red.circle.other.inner.asserts.user.UserRelationErrorCode; +import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.text.StringUtils; import com.red.circle.other.inner.asserts.user.UserErrorCode; import lombok.RequiredArgsConstructor; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Component; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + /** * 用户关系订阅. * @@ -25,6 +42,11 @@ public class UserSupportRelationFollowOrCancelCmdExe { private final UserProfileGateway userProfileGateway; private final UserSubscriptionService userSubscriptionService; private final UserRelationsCalculatorGateway userRelationsCalculatorGateway; + private final ImGroupClient imGroupClient; + private final ShieldBlackService shieldBlackService; + private final RoomUserBlacklistService roomUserBlacklistService; + private final RoomProfileManagerService roomProfileManagerService; + private final RelationshipFriendService relationshipFriendService; public Boolean execute(AppUserIdCmd cmd) { // 不可操作自己 @@ -52,9 +74,62 @@ public class UserSupportRelationFollowOrCancelCmdExe { .setIncr(Boolean.TRUE) .setType(CounterEnum.SUBSCRIPTION) ); + + Long userId = cmd.requiredReqUserId(); + Long subUserId = cmd.getUserId(); + boolean mutual = userSubscriptionService.checkSubscription(subUserId, userId); + + // 如果是相互关注 则自动加为好友 + if (mutual) { + try { + relationshipFriendService + .saveBatch(createRelationshipFriend(cmd.requiredReqUserId(), subUserId)); + userRelationsCalculatorGateway.process( + new UserRelationsCalculator() + .setUserId(cmd.requiredReqUserId()) + .setSubUserId(subUserId) + .setIncr(Boolean.TRUE) + .setType(CounterEnum.FRIEND) + ); + } catch (DuplicateKeyException ignore) { + // 已经是好友 + ResponseAssert.failure(UserRelationErrorCode.ALREADY_FRIENDS); + } + // 将自己从对方的房间黑名单移除 + shieldBlackService.removeShieldBlackBothSides(cmd.requiredReqUserId(), subUserId); + + RoomProfile roomProfile = roomProfileManagerService.getProfileByUserId(subUserId); + if (Objects.nonNull(roomProfile)) { + + Boolean status = ResponseAssert.requiredSuccess( + imGroupClient.unBanGroupMember(new GroupUnbanCmd() + .setGroupId(Objects.toString(roomProfile.getRoomAccount())) + .setUserId(cmd.requiredReqUserId()) + ) + ); + if (Objects.equals(status, Boolean.TRUE)) { + roomUserBlacklistService.removeBlack(roomProfile.getId(), cmd.requiredReqUserId()); + } + } + } + return Boolean.TRUE; } + private List createRelationshipFriend(Long userId, Long applyUserId) { + return Arrays.asList(newRelationshipFriend(userId, applyUserId), + newRelationshipFriend(applyUserId, userId)); + } + + private RelationshipFriend newRelationshipFriend(Long userId, Long applyUserId) { + RelationshipFriend relationshipFriend = new RelationshipFriend() + .setUserId(userId) + .setFriendUserId(applyUserId); + relationshipFriend.setCreateTime(TimestampUtils.now()); + relationshipFriend.setUpdateTime(TimestampUtils.now()); + return relationshipFriend; + } + private Boolean cancelSubscription(AppUserIdCmd cmd) { if (!userSubscriptionService.remove(cmd.requiredReqUserId(), cmd.getUserId())) {