From 4396f34b3b7fa8a8ebb33c7da546e3bed93b54ca Mon Sep 17 00:00:00 2001 From: hy001 Date: Wed, 22 Apr 2026 21:51:51 +0800 Subject: [PATCH] fix legacy invite message processing --- .../app/command/team/AgentInviteHostExe.java | 20 ++-- .../team/BdInviteMessageProcessExe.java | 24 ++--- .../team/BdInviteMessageProcessExeTest.java | 97 +++++++++++++++++++ 3 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExeTest.java 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 90d77925..e7ee116a 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 @@ -143,12 +143,12 @@ public class AgentInviteHostExe { bdInviteAgentMessageService.remove(id); } - public void processInvite(AgentInviteMessageProcessCmd cmd) { - ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, cmd.getStatus() > 0); - - BdInviteAgentMessage message = bdInviteAgentMessageService.getById(cmd.getId()); - ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, message.getStatus() == 0); - ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_RECORD_INFO, message); + public void processInvite(AgentInviteMessageProcessCmd cmd) { + ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, cmd.getStatus() > 0); + + BdInviteAgentMessage message = bdInviteAgentMessageService.getById(cmd.getId()); + ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_RECORD_INFO, message); + ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, message.getStatus() == 0); ResponseAssert.isTrue(CommonErrorCode.NOT_FOUND_RECORD_INFO, Objects.equals(message.getGroup(), MessageInviteGroup.AGENT_INVITE_HOST.name()) || @@ -165,10 +165,10 @@ public class AgentInviteHostExe { ResponseAssert.isFalse(TeamErrorCode.USER_IS_ALREADY_A_ANCHOR, teamMemberService.existsMember(cmd.requiredReqUserId())); - - ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, - bdInviteAgentMessageService.updateStatus(cmd.getId(), message.getStatus(), - cmd.getStatus(), MessageInviteGroup.AGENT_INVITE_HOST.name())); + + ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, + bdInviteAgentMessageService.updateStatus(cmd.getId(), message.getStatus(), + cmd.getStatus(), message.getGroup())); if (Objects.equals(cmd.getStatus(), 1)) { // 主播设备指纹校验 diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExe.java index 4e343d40..c8eec0bc 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExe.java @@ -79,13 +79,13 @@ public class BdInviteMessageProcessExe { private final AdministratorService administratorService; private final TaskMqMessage taskMqMessage; - public void execute(DbInviteMessageProcessCmd cmd) { - - ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, cmd.getStatus() > 0); - - BdInviteAgentMessage message = bdInviteAgentMessageService.getById(cmd.getId()); - ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, message.getStatus() == 0); - ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_RECORD_INFO, message); + public void execute(DbInviteMessageProcessCmd cmd) { + + ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, cmd.getStatus() > 0); + + BdInviteAgentMessage message = bdInviteAgentMessageService.getById(cmd.getId()); + ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_RECORD_INFO, message); + ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, message.getStatus() == 0); ResponseAssert.isTrue(CommonErrorCode.NOT_FOUND_RECORD_INFO, Objects.equals(message.getGroup(), MessageInviteGroup.BD_INVITE_TEAM.name()) || @@ -98,11 +98,11 @@ public class BdInviteMessageProcessExe { Objects.equals(message.getInviteUserId(), cmd.requiredReqUserId())); ResponseAssert.isTrue(TeamErrorCode.MESSAGE_PROCESSED, Objects.equals(message.getStatus(), 0)); // 6014 用户正在申请加入其他代理 - ResponseAssert.isFalse(TeamErrorCode.USER_APPLY_JOIN_OTHER_AGENT, - teamMemberService.existsMember(cmd.requiredReqUserId())); - ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, - bdInviteAgentMessageService.updateStatus(cmd.getId(), message.getStatus(), - cmd.getStatus(), MessageInviteGroup.BD_INVITE_TEAM.name())); + ResponseAssert.isFalse(TeamErrorCode.USER_APPLY_JOIN_OTHER_AGENT, + teamMemberService.existsMember(cmd.requiredReqUserId())); + ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, + bdInviteAgentMessageService.updateStatus(cmd.getId(), message.getStatus(), + cmd.getStatus(), message.getGroup())); if (Objects.equals(cmd.getStatus(), 1)) { Long teamId = createTeam(cmd, message); diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExeTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExeTest.java new file mode 100644 index 00000000..a8d951df --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/team/BdInviteMessageProcessExeTest.java @@ -0,0 +1,97 @@ +package com.red.circle.other.app.command.team; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.red.circle.framework.core.dto.ReqSysOrigin; +import com.red.circle.mq.rocket.business.producer.TaskMqMessage; +import com.red.circle.mq.rocket.business.producer.UserMqMessageService; +import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; +import com.red.circle.other.app.dto.cmd.team.DbInviteMessageProcessCmd; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.gateway.user.ability.RegisterDeviceGateway; +import com.red.circle.other.domain.model.user.UserProfile; +import com.red.circle.other.infra.database.mongo.entity.team.bd.BdInviteAgentMessage; +import com.red.circle.other.infra.database.mongo.service.team.bd.BdInviteAgentMessageService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamBillCycleService; +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.sys.AdministratorService; +import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentBaseInfoService; +import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentTeamService; +import com.red.circle.other.infra.database.rds.service.team.UserHistoryIdentityService; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import org.junit.jupiter.api.Test; + +class BdInviteMessageProcessExeTest { + + @Test + void executeShouldAcceptLegacyBlankGroupMessage() { + TeamMemberService teamMemberService = mock(TeamMemberService.class); + UserProfileGateway userProfileGateway = mock(UserProfileGateway.class); + TeamProfileService teamProfileService = mock(TeamProfileService.class); + RegisterDeviceGateway registerDeviceGateway = mock(RegisterDeviceGateway.class); + TeamBillCycleService teamBillCycleService = mock(TeamBillCycleService.class); + UserProfileAppConvertor userProfileAppConvertor = mock(UserProfileAppConvertor.class); + UserHistoryIdentityService userHistoryIdentityService = mock(UserHistoryIdentityService.class); + BdInviteAgentMessageService bdInviteAgentMessageService = mock(BdInviteAgentMessageService.class); + BusinessDevelopmentTeamService businessDevelopmentTeamService = + mock(BusinessDevelopmentTeamService.class); + BusinessDevelopmentBaseInfoService businessDevelopmentBaseInfoService = + mock(BusinessDevelopmentBaseInfoService.class); + UserMqMessageService userMqMessageService = mock(UserMqMessageService.class); + AdministratorService administratorService = mock(AdministratorService.class); + TaskMqMessage taskMqMessage = mock(TaskMqMessage.class); + + BdInviteMessageProcessExe exe = new BdInviteMessageProcessExe( + teamMemberService, + userProfileGateway, + teamProfileService, + registerDeviceGateway, + teamBillCycleService, + userProfileAppConvertor, + userHistoryIdentityService, + bdInviteAgentMessageService, + businessDevelopmentTeamService, + businessDevelopmentBaseInfoService, + userMqMessageService, + administratorService, + taskMqMessage + ); + + DbInviteMessageProcessCmd cmd = new DbInviteMessageProcessCmd(); + cmd.setId("legacy-msg"); + cmd.setStatus(2); + cmd.setReqUserId(300L); + cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI", "LIKEI")); + + BdInviteAgentMessage message = new BdInviteAgentMessage(); + message.setId("legacy-msg"); + message.setGroup(""); + message.setUserId(200L); + message.setInviteUserId(300L); + message.setStatus(0); + + UserProfile userProfile = new UserProfile(); + userProfile.setId(300L); + UserProfileDTO userProfileDTO = new UserProfileDTO(); + userProfileDTO.setId(300L); + + when(bdInviteAgentMessageService.getById("legacy-msg")).thenReturn(message); + when(teamMemberService.existsMember(300L)).thenReturn(false); + when(bdInviteAgentMessageService.updateStatus("legacy-msg", 0, 2, "")).thenReturn(true); + when(userProfileGateway.getByUserId(300L)).thenReturn(userProfile); + when(userProfileAppConvertor.toUserProfileDTO(userProfile)).thenReturn(userProfileDTO); + + exe.execute(cmd); + + verify(bdInviteAgentMessageService).updateStatus("legacy-msg", 0, 2, ""); + verify(userProfileAppConvertor).toUserProfileDTO(userProfile); + verify(userMqMessageService, org.mockito.Mockito.never()).sendBadgeOperateEvent(any(), any(), any()); + verify(businessDevelopmentTeamService, org.mockito.Mockito.never()).save(any()); + verify(businessDevelopmentBaseInfoService, org.mockito.Mockito.never()).incrMemberCount(any()); + } +}