From 9878d6bf81a1ab66e15ef94edbe70036efc48cf7 Mon Sep 17 00:00:00 2001 From: hy001 Date: Tue, 28 Apr 2026 23:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4=E6=8E=89?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ActivityAgentAnchorCountRewardCmdExe.java | 2 +- .../ActivityAgentAnchorReceiveCmdExe.java | 4 +- .../ActivityAgentMonthTargetRewardCmdExe.java | 2 +- .../query/AgentActivityOwnQueryExe.java | 2 +- .../bd/query/BdTeamMemberDetailQryExe.java | 2 +- .../app/command/team/AgentInviteHostExe.java | 4 +- .../app/command/team/BdAgentInviteExe.java | 6 +- .../team/query/TeamBdProfileQryExe.java | 31 ++-- .../team/query/TeamEntryTeamQryExe.java | 17 +- .../query/TeamExistsMessageTipsQryExe.java | 2 +- .../team/query/TeamMemberExistsQryExe.java | 32 ++-- .../team/query/TeamMemberRoleQryExe.java | 31 ++-- .../team/query/TeamOwnMemberListQryExe.java | 26 +-- .../team/query/TeamOwnProfileQryExe.java | 31 ++-- .../query/TeamProfileByAccountQryExe.java | 2 +- .../team/query/TeamUserIdentityQryExe.java | 35 ++-- .../user/query/UserProfileCardQryExe.java | 24 ++- .../query/UserVoiceRoomAuthCheckQryExe.java | 25 ++- .../service/h5/MemberActiveServiceImpl.java | 9 +- .../query/TeamUserIdentityQryExeTest.java | 54 ++++++ .../common/team/decay/TeamMemberAddDecay.java | 2 +- .../team/decay/UpdateMemberTeamDecay.java | 2 +- .../service/team/team/TeamProfileService.java | 26 ++- .../team/impl/TeamProfileServiceImpl.java | 38 ++-- .../team/impl/AgentTeamClientServiceImpl.java | 171 +++++++++++------- .../impl/TeamProfileClientServiceImpl.java | 13 +- 26 files changed, 376 insertions(+), 217 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExeTest.java diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorCountRewardCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorCountRewardCmdExe.java index 18a41baa..fd373d52 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorCountRewardCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorCountRewardCmdExe.java @@ -39,7 +39,7 @@ public class ActivityAgentAnchorCountRewardCmdExe { public ImmutableTriple>>, Long> execute(AppExtCommand cmd) { - TeamProfile teamProfile = teamProfileService.getByOwnUserId(cmd.getReqUserId()); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(cmd.getReqUserId()); if (Objects.isNull(teamProfile)) { return ImmutableTriple.of(0L, Lists.newArrayList(), null); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorReceiveCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorReceiveCmdExe.java index 191da552..85dd0e4d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorReceiveCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentAnchorReceiveCmdExe.java @@ -137,8 +137,8 @@ public class ActivityAgentAnchorReceiveCmdExe { } private TeamProfile getTeamProfile(AppIdLongCmd cmd) { - TeamProfile teamProfile = - teamProfileService.getByOwnUserId(cmd.getReqUserId()); + TeamProfile teamProfile = + teamProfileService.getAvailableByOwnUserId(cmd.getReqUserId()); ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, teamProfile); return teamProfile; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentMonthTargetRewardCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentMonthTargetRewardCmdExe.java index eab1064b..63a6a76c 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentMonthTargetRewardCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityAgentMonthTargetRewardCmdExe.java @@ -41,7 +41,7 @@ public class ActivityAgentMonthTargetRewardCmdExe { public ImmutableTriple>>, Long> execute(AppExtCommand cmd) { - TeamProfile teamProfile = teamProfileService.getByOwnUserId(cmd.getReqUserId()); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(cmd.getReqUserId()); if (Objects.isNull(teamProfile)) { return ImmutableTriple.of(0L, Lists.newArrayList(), null); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/AgentActivityOwnQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/AgentActivityOwnQueryExe.java index a4c7b2db..8ff2e6c4 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/AgentActivityOwnQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/AgentActivityOwnQueryExe.java @@ -33,7 +33,7 @@ public class AgentActivityOwnQueryExe { public AgentActivityOwnCO execute(AppTypeCmd cmd) { - TeamProfile teamProfile = teamProfileService.getByOwnUserId(cmd.getReqUserId()); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(cmd.getReqUserId()); if (Objects.isNull(teamProfile)) { return null; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamMemberDetailQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamMemberDetailQryExe.java index c27bcd8b..82f16e02 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamMemberDetailQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamMemberDetailQryExe.java @@ -91,7 +91,7 @@ public class BdTeamMemberDetailQryExe { */ private BdTeamMemberDetailCO queryAgencyDetail(Long userId) { BdTeamMemberDetailCO detail = new BdTeamMemberDetailCO(); - TeamProfile teamProfile = teamProfileService.getByOwnUserId(userId); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(userId); ResponseAssert.notNull(TeamErrorCode.NOT_TEAM_MEMBER, teamProfile); // 查询最近2个账单周期 diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/AgentInviteHostExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/AgentInviteHostExe.java index 97225912..86b182c2 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/AgentInviteHostExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/AgentInviteHostExe.java @@ -59,7 +59,7 @@ public class AgentInviteHostExe { public void execute(AgentInviteHostCmd cmd) { // 检查权限 - boolean teamOwn = teamProfileService.existsOwnUserId(cmd.getReqUserId()); + boolean teamOwn = teamProfileService.existsAvailableOwnUserId(cmd.getReqUserId()); ResponseAssert.isTrue(TeamErrorCode.USER_AGENT_ROLE_INVALID_ERROR, teamOwn); UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO( @@ -159,7 +159,7 @@ public class AgentInviteHostExe { Objects.equals(message.getGroup(), MessageInviteGroup.AGENT_INVITE_HOST.name()) || StringUtils.isBlank(message.getGroup())); - TeamProfile teamProfile = teamProfileService.getByOwnUserId(message.getUserId()); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(message.getUserId()); ResponseAssert.notNull(TeamErrorCode.USER_AGENT_ROLE_INVALID_ERROR, teamProfile); ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION, diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdAgentInviteExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdAgentInviteExe.java index c2b18862..07d80eb2 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdAgentInviteExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdAgentInviteExe.java @@ -76,9 +76,9 @@ public class BdAgentInviteExe { // 用户已经是主播 ResponseAssert.isFalse(TeamErrorCode.USER_IS_ALREADY_A_ANCHOR, teamMemberService.existsMember(cmd.getInviteUserId())); - // 历史数据问题: 用户是代理但是在其他用户名下做主播, 导致倒入数据的错误;所有这里加一个验证拦截 - ResponseAssert.isFalse(TeamErrorCode.USER_IS_ALREADY_A_ANCHOR, - teamProfileService.existsOwnUserId(cmd.getInviteUserId())); + // 历史数据问题: 用户是代理但是在其他用户名下做主播, 导致倒入数据的错误;所有这里加一个验证拦截 + ResponseAssert.isFalse(TeamErrorCode.USER_IS_ALREADY_A_ANCHOR, + teamProfileService.existsAvailableOwnUserId(cmd.getInviteUserId())); // 用户正在申请加入其他代理 ResponseAssert.isFalse(TeamErrorCode.USER_APPLY_JOIN_OTHER_AGENT, teamApplicationProcessService.existWaitByUserId(cmd.getInviteUserId())); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamBdProfileQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamBdProfileQryExe.java index df439f85..4ec7b1a2 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamBdProfileQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamBdProfileQryExe.java @@ -2,10 +2,11 @@ package com.red.circle.other.app.command.team.query; import com.red.circle.framework.core.dto.CommonCommand; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentTeamService; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentTeamService; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import java.util.Objects; import lombok.RequiredArgsConstructor; @@ -20,16 +21,18 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class TeamBdProfileQryExe { - private final TeamMemberService teamMemberService; - private final UserProfileGateway userProfileGateway; - private final UserProfileAppConvertor userProfileAppConvertor; - private final BusinessDevelopmentTeamService businessDevelopmentTeamService; - - public UserProfileDTO execute(CommonCommand cmd) { - TeamMember teamMember = teamMemberService.getByMemberId(cmd.getReqUserId()); - if (Objects.isNull(teamMember)) { - return null; - } + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + private final UserProfileGateway userProfileGateway; + private final UserProfileAppConvertor userProfileAppConvertor; + private final BusinessDevelopmentTeamService businessDevelopmentTeamService; + + public UserProfileDTO execute(CommonCommand cmd) { + TeamMember teamMember = teamMemberService.getByMemberId(cmd.getReqUserId()); + if (Objects.isNull(teamMember) + || !teamProfileService.checkStatusAvailable(teamMember.getTeamId())) { + return null; + } Long bdUserId = businessDevelopmentTeamService.getBdUserIdByTeamId(teamMember.getTeamId()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamEntryTeamQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamEntryTeamQryExe.java index 3d3ee79b..871ccd75 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamEntryTeamQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamEntryTeamQryExe.java @@ -18,9 +18,10 @@ import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberSer import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionConfigService; import com.red.circle.other.inner.enums.config.EnumConfigKey; -import com.red.circle.other.inner.model.dto.user.UserProfileDTO; -import com.red.circle.other.inner.asserts.team.TeamErrorCode; -import com.red.circle.other.inner.enums.team.TeamMemberRole; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.inner.asserts.team.TeamErrorCode; +import com.red.circle.other.inner.enums.team.TeamMemberRole; +import com.red.circle.other.inner.model.dto.agency.agency.TeamStatus; import java.util.*; @@ -51,10 +52,12 @@ public class TeamEntryTeamQryExe { TeamMember teamMember = teamMemberService.getByMemberId(cmd.getReqUserId()); ResponseAssert.notNull(TeamErrorCode.NOT_TEAM_MEMBER, teamMember); - TeamProfile teamProfile = teamProfileService.getById(teamMember.getTeamId()); - ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, teamProfile); - - UserProfileDTO teamMemberProfile = userProfileAppConvertor.toUserProfileDTO( + TeamProfile teamProfile = teamProfileService.getById(teamMember.getTeamId()); + ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, teamProfile); + ResponseAssert.isTrue(TeamErrorCode.TEAM_NOT_FOUND, + TeamStatus.AVAILABLE.equals(teamProfile.getStatus())); + + UserProfileDTO teamMemberProfile = userProfileAppConvertor.toUserProfileDTO( userProfileGateway.getByUserId(cmd.getReqUserId())); String reviewUserWhitelist = enumConfigCacheService.getValue(EnumConfigKey.REVIEW_USER_WHITELIST, cmd.getReqSysOrigin().getOrigin()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamExistsMessageTipsQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamExistsMessageTipsQryExe.java index 8a7c3452..a1fa2357 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamExistsMessageTipsQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamExistsMessageTipsQryExe.java @@ -21,7 +21,7 @@ public class TeamExistsMessageTipsQryExe { private final TeamApplicationProcessService teamApplicationProcessService; public Boolean execute(AppExtCommand cmd) { - TeamProfile teamProfile = teamProfileService.getByOwnUserId(cmd.requiredReqUserId()); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(cmd.requiredReqUserId()); if (Objects.isNull(teamProfile)) { return Boolean.FALSE; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberExistsQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberExistsQryExe.java index 81d9a8e6..edc161d7 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberExistsQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberExistsQryExe.java @@ -1,9 +1,12 @@ package com.red.circle.other.app.command.team.query; -import com.red.circle.framework.core.dto.AppCommand; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; +import com.red.circle.framework.core.dto.AppCommand; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import java.util.Objects; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; /** * 是否存在团队成员. @@ -12,12 +15,15 @@ import org.springframework.stereotype.Component; */ @Component @RequiredArgsConstructor -public class TeamMemberExistsQryExe { - - private final TeamMemberService teamMemberService; - - public boolean execute(AppCommand cmd) { - return teamMemberService.existsMember(cmd.requiredReqUserId()); - } - -} +public class TeamMemberExistsQryExe { + + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + + public boolean execute(AppCommand cmd) { + TeamMember teamMember = teamMemberService.getByMemberId(cmd.requiredReqUserId()); + return Objects.nonNull(teamMember) + && teamProfileService.checkStatusAvailable(teamMember.getTeamId()); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberRoleQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberRoleQryExe.java index 34a95980..6e015b4f 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberRoleQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberRoleQryExe.java @@ -1,10 +1,11 @@ package com.red.circle.other.app.command.team.query; -import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import java.util.Objects; -import java.util.Optional; +import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import java.util.Objects; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -15,14 +16,16 @@ import org.springframework.stereotype.Component; */ @Component @RequiredArgsConstructor -public class TeamMemberRoleQryExe { - - private final TeamMemberService teamMemberService; - - public String execute(AppIdLongCmd cmd) { - return Optional.ofNullable(teamMemberService.getMember(cmd.getId(), cmd.getReqUserId())) - .map(TeamMember::getRole) - .map(Objects::toString) - .orElse(""); +public class TeamMemberRoleQryExe { + + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + + public String execute(AppIdLongCmd cmd) { + return Optional.ofNullable(teamMemberService.getMember(cmd.getId(), cmd.getReqUserId())) + .filter(member -> teamProfileService.checkStatusAvailable(member.getTeamId())) + .map(TeamMember::getRole) + .map(Objects::toString) + .orElse(""); } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnMemberListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnMemberListQryExe.java index ed0e50f0..497dd81b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnMemberListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnMemberListQryExe.java @@ -6,10 +6,11 @@ import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.team.TeamOwnMemberCO; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.enums.team.TeamMemberRole; import com.red.circle.tool.core.collection.CollectionUtils; import java.util.List; @@ -28,16 +29,19 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class TeamOwnMemberListQryExe { - private final TeamMemberService teamMemberService; - private final UserProfileGateway userProfileGateway; - private final UserProfileAppConvertor userProfileAppConvertor; + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + private final UserProfileGateway userProfileGateway; + private final UserProfileAppConvertor userProfileAppConvertor; public List execute(AppExtCommand cmd) { - TeamMember teamMember = teamMemberService.getByMemberId(cmd.requiredReqUserId()); - - ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION, - Objects.nonNull(teamMember) && TeamMemberRole.OWN.eq(teamMember.getRole())); + TeamMember teamMember = teamMemberService.getByMemberId(cmd.requiredReqUserId()); + + ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION, + Objects.nonNull(teamMember) + && TeamMemberRole.OWN.eq(teamMember.getRole()) + && teamProfileService.checkStatusAvailable(teamMember.getTeamId())); List teamMembers = teamMemberService.listTeamMember(teamMember.getTeamId(), 3000); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnProfileQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnProfileQryExe.java index b5ee564a..98629bac 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnProfileQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamOwnProfileQryExe.java @@ -2,11 +2,12 @@ package com.red.circle.other.app.command.team.query; import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -20,15 +21,17 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class TeamOwnProfileQryExe { - private final TeamMemberService teamMemberService; - private final UserProfileGateway userProfileGateway; - private final UserProfileAppConvertor userProfileAppConvertor; - - public UserProfileDTO execute(AppExtCommand cmd) { - TeamMember teamMember = teamMemberService.getByMemberId(cmd.getReqUserId()); - if (Objects.isNull(teamMember)) { - return null; - } + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + private final UserProfileGateway userProfileGateway; + private final UserProfileAppConvertor userProfileAppConvertor; + + public UserProfileDTO execute(AppExtCommand cmd) { + TeamMember teamMember = teamMemberService.getByMemberId(cmd.getReqUserId()); + if (Objects.isNull(teamMember) + || !teamProfileService.checkStatusAvailable(teamMember.getTeamId())) { + return null; + } TeamMember teamOwn = teamMemberService.getTeamOwn(teamMember.getTeamId()); if (Objects.isNull(teamOwn)) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamProfileByAccountQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamProfileByAccountQryExe.java index 57eb365f..d02feda8 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamProfileByAccountQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamProfileByAccountQryExe.java @@ -33,7 +33,7 @@ public class TeamProfileByAccountQryExe { cmd.getAccount())); ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, userProfile); - TeamProfile profile = teamProfileService.getByOwnUserId(userProfile.getId()); + TeamProfile profile = teamProfileService.getAvailableByOwnUserId(userProfile.getId()); ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, profile); return new TeamProfileSearchResCO() diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExe.java index db1d064b..b58e3a46 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExe.java @@ -1,11 +1,12 @@ package com.red.circle.other.app.command.team.query; -import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import com.red.circle.other.inner.enums.team.TeamMemberRole; -import com.red.circle.other.inner.enums.team.TeamUserIdentity; -import java.util.Objects; +import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import com.red.circle.other.inner.enums.team.TeamMemberRole; +import com.red.circle.other.inner.enums.team.TeamUserIdentity; +import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -16,16 +17,18 @@ import org.springframework.stereotype.Component; */ @Component @RequiredArgsConstructor -public class TeamUserIdentityQryExe { - - private final TeamMemberService teamMemberService; - - public TeamUserIdentity execute(AppUserIdCmd cmd) { - TeamMember teamMember = teamMemberService.getByMemberId(cmd.getUserId()); - - if (Objects.isNull(teamMember)) { - return TeamUserIdentity.TOURIST; - } +public class TeamUserIdentityQryExe { + + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + + public TeamUserIdentity execute(AppUserIdCmd cmd) { + TeamMember teamMember = teamMemberService.getByMemberId(cmd.getUserId()); + + if (Objects.isNull(teamMember) + || !teamProfileService.checkStatusAvailable(teamMember.getTeamId())) { + return TeamUserIdentity.TOURIST; + } return TeamMemberRole.OWN.eq(teamMember.getRole()) ? TeamUserIdentity.AGENT diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserProfileCardQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserProfileCardQryExe.java index bc5fead1..71d47095 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserProfileCardQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserProfileCardQryExe.java @@ -14,10 +14,11 @@ import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.infra.common.game.GameKtvCommon; import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; -import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; -import com.red.circle.other.infra.database.rds.service.live.RoomMemberService; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import com.red.circle.other.infra.database.rds.service.live.RoomMemberService; import com.red.circle.other.inner.enums.live.RoomUserRolesEnum; import com.red.circle.other.inner.enums.team.TeamMemberRole; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; @@ -43,10 +44,11 @@ public class UserProfileCardQryExe { private final GameKtvCommon gameKtvCommon; private final UserSVipGateway userSVipGateway; private final RoomMemberService roomMemberService; - private final UserProfileGateway userProfileGateway; - private final UserProfileAppConvertor userProfileAppConvertor; - private final TeamMemberService teamMemberService; - private final RedisService redisService; + private final UserProfileGateway userProfileGateway; + private final UserProfileAppConvertor userProfileAppConvertor; + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + private final RedisService redisService; private final RoomProfileManagerService roomProfileManagerService; private final UserRegionGateway userRegionGateway; private final CpRelationshipCacheService cpRelationshipCacheService; @@ -59,8 +61,10 @@ public class UserProfileCardQryExe { AppBusinessUtils.eqSysOrigin(cmd.requireReqSysOrigin())); TeamMember teamMember = teamMemberService.getByMemberId(cmd.getUserId()); - Boolean agent = Objects.nonNull(teamMember) && TeamMemberRole.OWN.eq(teamMember.getRole()); - Boolean anchor = Objects.nonNull(teamMember); + Boolean activeTeamMember = Objects.nonNull(teamMember) + && teamProfileService.checkStatusAvailable(teamMember.getTeamId()); + Boolean agent = activeTeamMember && TeamMemberRole.OWN.eq(teamMember.getRole()); + Boolean anchor = activeTeamMember; UserProfileDTO userProfileDTO = userProfileAppConvertor.toUserProfileDTO(userProfile); boolean eqRegion = userRegionGateway.checkEqRegion(userProfile.getId(), cmd.requiredReqUserId()); userProfileDTO.setSameRegion(eqRegion); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserVoiceRoomAuthCheckQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserVoiceRoomAuthCheckQryExe.java index 539a596d..d59abddc 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserVoiceRoomAuthCheckQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserVoiceRoomAuthCheckQryExe.java @@ -6,9 +6,11 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.domain.model.user.UserProfile; -import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; -import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.domain.model.user.UserProfile; +import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentBaseInfoService; import com.red.circle.other.infra.database.rds.service.team.RoomBdLeadService; import com.red.circle.other.infra.database.rds.service.user.user.InviteUserRegisterService; @@ -29,8 +31,9 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class UserVoiceRoomAuthCheckQryExe { - private final TeamMemberService teamMemberService; - private final RoomBdLeadService roomBdLeadService; + private final TeamMemberService teamMemberService; + private final TeamProfileService teamProfileService; + private final RoomBdLeadService roomBdLeadService; private final UserProfileGateway userProfileGateway; private final FreightSellerClient freightSellerClient; private final FreightBalanceClient freightBalanceClient; @@ -77,11 +80,13 @@ public class UserVoiceRoomAuthCheckQryExe { return inviteUserRegisterService.getUserIdByInviteUserId(cmd.getReqUserId()); } - private Boolean checkAuth(SysOriginPlatformEnum sysOrigin, Long userId) { - - if (Boolean.TRUE.equals(teamMemberService.existsMember(userId))) { - return Boolean.TRUE; - } + private Boolean checkAuth(SysOriginPlatformEnum sysOrigin, Long userId) { + + TeamMember teamMember = teamMemberService.getByMemberId(userId); + if (Objects.nonNull(teamMember) + && Boolean.TRUE.equals(teamProfileService.checkStatusAvailable(teamMember.getTeamId()))) { + return Boolean.TRUE; + } if (Boolean.TRUE.equals(roomBdLeadService.checkBdLeader(userId))) { return Boolean.TRUE; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/h5/MemberActiveServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/h5/MemberActiveServiceImpl.java index c7b3169a..04b1b610 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/h5/MemberActiveServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/h5/MemberActiveServiceImpl.java @@ -77,10 +77,11 @@ public class MemberActiveServiceImpl implements MemberActiveService { // ResponseAssert.isFalse(CommonErrorCode.SAVE_FAILURE, // "Permission denied: Not a guild leader", Objects.isNull(familyBaseInfo)); - //判断是否是 agent - - ResponseAssert.isFalse(CommonErrorCode.SAVE_FAILURE, - "Permission denied: Not a Agent", !teamProfileService.existsOwnUserId(cmd.getReqUserId())); + //判断是否是 agent + + ResponseAssert.isFalse(CommonErrorCode.SAVE_FAILURE, + "Permission denied: Not a Agent", + !teamProfileService.existsAvailableOwnUserId(cmd.getReqUserId())); // 检查工会是否已参与 LambdaQueryWrapper query = new LambdaQueryWrapper<>(); diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExeTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExeTest.java new file mode 100644 index 00000000..1dcecc50 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/query/TeamUserIdentityQryExeTest.java @@ -0,0 +1,54 @@ +package com.red.circle.other.app.command.team.query; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; +import com.red.circle.other.inner.enums.team.TeamMemberRole; +import com.red.circle.other.inner.enums.team.TeamUserIdentity; +import org.junit.jupiter.api.Test; + +class TeamUserIdentityQryExeTest { + + @Test + void executeShouldReturnTouristWhenOwnerTeamIsClosed() { + TeamMemberService teamMemberService = mock(TeamMemberService.class); + TeamProfileService teamProfileService = mock(TeamProfileService.class); + TeamUserIdentityQryExe exe = new TeamUserIdentityQryExe(teamMemberService, teamProfileService); + + AppUserIdCmd cmd = new AppUserIdCmd(); + cmd.setUserId(100L); + TeamMember teamMember = new TeamMember() + .setMemberId(100L) + .setTeamId(200L) + .setRole(TeamMemberRole.OWN); + + when(teamMemberService.getByMemberId(100L)).thenReturn(teamMember); + when(teamProfileService.checkStatusAvailable(200L)).thenReturn(false); + + assertEquals(TeamUserIdentity.TOURIST, exe.execute(cmd)); + } + + @Test + void executeShouldReturnAgentWhenOwnerTeamIsAvailable() { + TeamMemberService teamMemberService = mock(TeamMemberService.class); + TeamProfileService teamProfileService = mock(TeamProfileService.class); + TeamUserIdentityQryExe exe = new TeamUserIdentityQryExe(teamMemberService, teamProfileService); + + AppUserIdCmd cmd = new AppUserIdCmd(); + cmd.setUserId(100L); + TeamMember teamMember = new TeamMember() + .setMemberId(100L) + .setTeamId(200L) + .setRole(TeamMemberRole.OWN); + + when(teamMemberService.getByMemberId(100L)).thenReturn(teamMember); + when(teamProfileService.checkStatusAvailable(200L)).thenReturn(true); + + assertEquals(TeamUserIdentity.AGENT, exe.execute(cmd)); + } +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/TeamMemberAddDecay.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/TeamMemberAddDecay.java index 996b9225..ea2d8340 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/TeamMemberAddDecay.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/TeamMemberAddDecay.java @@ -49,7 +49,7 @@ public class TeamMemberAddDecay { * 添加成员. */ public TeamProfile execute(TeamMemberAddCmd param) { - TeamProfile teamProfile = teamProfileService.getByOwnUserId(param.getOwnUserId()); + TeamProfile teamProfile = teamProfileService.getAvailableByOwnUserId(param.getOwnUserId()); ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, teamProfile); ResponseAssert.isTrue(TeamErrorCode.TEAM_MEMBER_FULL_ERROR, teamProfile.checkAllowJoinTeam()); ResponseAssert.isFalse(TeamErrorCode.USER_ALREADY_TEAM_MEMBER, diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/UpdateMemberTeamDecay.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/UpdateMemberTeamDecay.java index ad249b38..5d8cbb0a 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/UpdateMemberTeamDecay.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/decay/UpdateMemberTeamDecay.java @@ -81,7 +81,7 @@ public class UpdateMemberTeamDecay { TeamMember teamMember = teamMemberService.getByMemberId(param.getMemberUserId()); ResponseAssert.notNull(TeamErrorCode.NOT_TEAM_MEMBER, teamMember); - TeamProfile newTmpTeamProfile = teamProfileService.getByOwnUserId(param.getOwnUserId()); + TeamProfile newTmpTeamProfile = teamProfileService.getAvailableByOwnUserId(param.getOwnUserId()); ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, newTmpTeamProfile); ResponseAssert.isFalse(TeamErrorCode.USER_ALREADY_TEAM_MEMBER, diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamProfileService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamProfileService.java index 072eced1..086125d1 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamProfileService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamProfileService.java @@ -28,10 +28,15 @@ public interface TeamProfileService { */ void create(TeamProfile teamProfile); - /** - * 是否存在团长. - */ - boolean existsOwnUserId(Long ownUserId); + /** + * 是否存在团长. + */ + boolean existsOwnUserId(Long ownUserId); + + /** + * 是否存在可用团队团长. + */ + boolean existsAvailableOwnUserId(Long ownUserId); /** * 修改团队资料. @@ -98,10 +103,15 @@ public interface TeamProfileService { */ Set listIdByRegion(String regionId); - /** - * 获取团队资料. - */ - TeamProfile getByOwnUserId(Long ownUserId); + /** + * 获取团队资料. + */ + TeamProfile getByOwnUserId(Long ownUserId); + + /** + * 获取可用团队资料. + */ + TeamProfile getAvailableByOwnUserId(Long ownUserId); /** * 获取团队资料. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamProfileServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamProfileServiceImpl.java index b252bd89..9e6947fd 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamProfileServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamProfileServiceImpl.java @@ -53,11 +53,18 @@ public class TeamProfileServiceImpl implements TeamProfileService { mongoTemplate.save(teamProfile); } - @Override - public boolean existsOwnUserId(Long ownUserId) { - return mongoTemplate.exists(Query.query(Criteria.where("ownUserId").is(ownUserId)), - TeamProfile.class); - } + @Override + public boolean existsOwnUserId(Long ownUserId) { + return mongoTemplate.exists(Query.query(Criteria.where("ownUserId").is(ownUserId)), + TeamProfile.class); + } + + @Override + public boolean existsAvailableOwnUserId(Long ownUserId) { + return mongoTemplate.exists(Query.query(Criteria.where("ownUserId").is(ownUserId) + .and("status").is(TeamStatus.AVAILABLE)), + TeamProfile.class); + } @Override public void updateByIdSelective(TeamProfile teamProfile) { @@ -271,13 +278,20 @@ public class TeamProfileServiceImpl implements TeamProfileService { @Override - public TeamProfile getByOwnUserId(Long ownUserId) { - return mongoTemplate - .findOne(Query.query(Criteria.where("ownUserId").is(ownUserId)), TeamProfile.class); - } - - @Override - public List getByOwnUserIds(Set ownUserIds) { + public TeamProfile getByOwnUserId(Long ownUserId) { + return mongoTemplate + .findOne(Query.query(Criteria.where("ownUserId").is(ownUserId)), TeamProfile.class); + } + + @Override + public TeamProfile getAvailableByOwnUserId(Long ownUserId) { + return mongoTemplate.findOne(Query.query(Criteria.where("ownUserId").is(ownUserId) + .and("status").is(TeamStatus.AVAILABLE)), + TeamProfile.class); + } + + @Override + public List getByOwnUserIds(Set ownUserIds) { return mongoTemplate.find(Query.query(Criteria.where("ownUserId").in(ownUserIds)), TeamProfile.class); } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/AgentTeamClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/AgentTeamClientServiceImpl.java index 53ed845c..c0f4d986 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/AgentTeamClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/AgentTeamClientServiceImpl.java @@ -5,16 +5,18 @@ import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile; import com.red.circle.other.infra.database.mongo.service.team.team.TeamExchangeSurplusTargetService; import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; -import com.red.circle.other.app.inner.convertor.team.AgencyTeamInnerConvertor; -import com.red.circle.other.app.inner.service.team.AgentTeamClientService; -import com.red.circle.other.inner.model.dto.agency.agency.TeamExchangeSurplusTargetDTO; -import com.red.circle.other.inner.model.dto.agency.agency.TeamMemberDTO; -import com.red.circle.other.inner.model.dto.agency.agency.TeamProfileDTO; -import com.red.circle.other.inner.model.dto.agency.agency.UserTeamRegionDTO; -import com.red.circle.tool.core.collection.CollectionUtils; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import com.red.circle.other.app.inner.convertor.team.AgencyTeamInnerConvertor; +import com.red.circle.other.app.inner.service.team.AgentTeamClientService; +import com.red.circle.other.inner.enums.team.TeamMemberRole; +import com.red.circle.other.inner.model.dto.agency.agency.TeamExchangeSurplusTargetDTO; +import com.red.circle.other.inner.model.dto.agency.agency.TeamMemberDTO; +import com.red.circle.other.inner.model.dto.agency.agency.TeamProfileDTO; +import com.red.circle.other.inner.model.dto.agency.agency.TeamStatus; +import com.red.circle.other.inner.model.dto.agency.agency.UserTeamRegionDTO; +import com.red.circle.tool.core.collection.CollectionUtils; +import java.util.Collection; +import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -33,43 +35,50 @@ public class AgentTeamClientServiceImpl implements AgentTeamClientService { private final TeamMemberService teamMemberService; private final TeamProfileService teamProfileService; private final AgencyTeamInnerConvertor agencyTeamInnerConvertor; - private final TeamExchangeSurplusTargetService exchangeSurplusTargetService; - - @Override - public boolean existsTeamMember(Long userId) { - return teamMemberService.existsMember(userId); - } - - @Override - public boolean existsTeamOwn(Long userId) { - return teamMemberService.existsTeamOwn(userId); - } + private final TeamExchangeSurplusTargetService exchangeSurplusTargetService; + + @Override + public boolean existsTeamMember(Long userId) { + return Objects.nonNull(getAvailableProfile(teamMemberService.getByMemberId(userId))); + } + + @Override + public boolean existsTeamOwn(Long userId) { + TeamMember teamMember = teamMemberService.getByMemberId(userId); + return Objects.nonNull(getAvailableProfile(teamMember)) + && TeamMemberRole.OWN.eq(teamMember.getRole()); + } @Override public void refreshActiveTime(Long userId) { teamMemberService.updateActiveTimeNow(userId); } - @Override - public TeamMemberDTO getByMemberId(Long memberId) { - return agencyTeamInnerConvertor.toTeamMemberDTO(teamMemberService.getByMemberId(memberId)); - } - - @Override - public TeamProfileDTO getProfileByOwnUserId(Long ownUserId) { - return agencyTeamInnerConvertor.toTeamProfileDTO(teamProfileService.getByOwnUserId(ownUserId)); - } - - @Override - public TeamProfileDTO getProfileByMemberId(Long memberId) { - TeamMember teamMember = teamMemberService.getByMemberId(memberId); - if (Objects.isNull(teamMember)) { - return null; - } - return agencyTeamInnerConvertor.toTeamProfileDTO( - teamProfileService.getById(teamMember.getTeamId())); - - } + @Override + public TeamMemberDTO getByMemberId(Long memberId) { + TeamMember teamMember = teamMemberService.getByMemberId(memberId); + if (Objects.isNull(getAvailableProfile(teamMember))) { + return null; + } + return agencyTeamInnerConvertor.toTeamMemberDTO(teamMember); + } + + @Override + public TeamProfileDTO getProfileByOwnUserId(Long ownUserId) { + return agencyTeamInnerConvertor.toTeamProfileDTO( + teamProfileService.getAvailableByOwnUserId(ownUserId)); + } + + @Override + public TeamProfileDTO getProfileByMemberId(Long memberId) { + TeamMember teamMember = teamMemberService.getByMemberId(memberId); + TeamProfile teamProfile = getAvailableProfile(teamMember); + if (Objects.isNull(teamProfile)) { + return null; + } + return agencyTeamInnerConvertor.toTeamProfileDTO(teamProfile); + + } @Override public List listUserTeamRegion(Set userIds) { @@ -79,19 +88,23 @@ public class AgentTeamClientServiceImpl implements AgentTeamClientService { return CollectionUtils.newArrayList(); } - Map teamProfilesMap = teamProfileService.mapProfileByIds( - teamMembers.stream().map(TeamMember::getTeamId).collect(Collectors.toSet())); - - if (CollectionUtils.isEmpty(teamProfilesMap)) { - return CollectionUtils.newArrayList(); - } - - return teamMembers.stream().map(member -> new UserTeamRegionDTO() - .setUserId(member.getMemberId()) - .setSysOrigin(member.getSysOrigin()) - .setTeamId(member.getTeamId()) - .setRegionId(teamProfilesMap.get(member.getTeamId()).getRegion()) - ).toList(); + Map teamProfilesMap = teamProfileService.listStatusAvailable( + teamMembers.stream().map(TeamMember::getTeamId).collect(Collectors.toSet())) + .stream() + .collect(Collectors.toMap(TeamProfile::getId, v -> v)); + + if (CollectionUtils.isEmpty(teamProfilesMap)) { + return CollectionUtils.newArrayList(); + } + + return teamMembers.stream() + .filter(member -> teamProfilesMap.containsKey(member.getTeamId())) + .map(member -> new UserTeamRegionDTO() + .setUserId(member.getMemberId()) + .setSysOrigin(member.getSysOrigin()) + .setTeamId(member.getTeamId()) + .setRegionId(teamProfilesMap.get(member.getTeamId()).getRegion()) + ).toList(); } @Override @@ -104,10 +117,27 @@ public class AgentTeamClientServiceImpl implements AgentTeamClientService { return agencyTeamInnerConvertor.toMapTeamMemberDTO(teamMemberService.mapByMemberIds(memberIds)); } - @Override - public List listMemberIds(Set userIds) { - return teamMemberService.listMemberIds(userIds); - } + @Override + public List listMemberIds(Set userIds) { + List teamMembers = teamMemberService.listByMemberIds(userIds); + if (CollectionUtils.isEmpty(teamMembers)) { + return CollectionUtils.newArrayList(); + } + + Set availableTeamIds = teamProfileService.listStatusAvailable( + teamMembers.stream().map(TeamMember::getTeamId).collect(Collectors.toSet())) + .stream() + .map(TeamProfile::getId) + .collect(Collectors.toSet()); + if (CollectionUtils.isEmpty(availableTeamIds)) { + return CollectionUtils.newArrayList(); + } + + return teamMembers.stream() + .filter(member -> availableTeamIds.contains(member.getTeamId())) + .map(TeamMember::getMemberId) + .toList(); + } @Override public TeamProfileDTO getProfileById(Long id) { @@ -125,10 +155,21 @@ public class AgentTeamClientServiceImpl implements AgentTeamClientService { @Override - public String getTotalAmountUsd(Long userId, String sysOrigin, Integer dateNumber) { - - return exchangeSurplusTargetService.getTotalAmountUsd(userId, sysOrigin, dateNumber); - } - - -} + public String getTotalAmountUsd(Long userId, String sysOrigin, Integer dateNumber) { + + return exchangeSurplusTargetService.getTotalAmountUsd(userId, sysOrigin, dateNumber); + } + + private TeamProfile getAvailableProfile(TeamMember teamMember) { + if (Objects.isNull(teamMember)) { + return null; + } + + TeamProfile teamProfile = teamProfileService.getById(teamMember.getTeamId()); + if (Objects.isNull(teamProfile) || !TeamStatus.AVAILABLE.equals(teamProfile.getStatus())) { + return null; + } + return teamProfile; + } + +} diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/TeamProfileClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/TeamProfileClientServiceImpl.java index 5241d639..f398bb5b 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/TeamProfileClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/team/impl/TeamProfileClientServiceImpl.java @@ -135,10 +135,15 @@ public class TeamProfileClientServiceImpl implements TeamProfileClientService { return teamInfraConvertor.toListTeamMemberDTO(teamMemberService.listByMemberIds(memberIds)); } - @Override - public TeamMemberDTO getByMemberId(Long userId) { - return teamInfraConvertor.toTeamMemberDTO(teamMemberService.getByMemberId(userId)); - } + @Override + public TeamMemberDTO getByMemberId(Long userId) { + TeamMember teamMember = teamMemberService.getByMemberId(userId); + if (Objects.isNull(teamMember) + || !teamProfileService.checkStatusAvailable(teamMember.getTeamId())) { + return null; + } + return teamInfraConvertor.toTeamMemberDTO(teamMember); + } @Override public List listProcessApprovalByCondition(