From 1deda4c663cfd6bdfbdb10c69af8d7b936d610f3 Mon Sep 17 00:00:00 2001 From: zhx Date: Tue, 14 Jul 2026 19:01:43 +0800 Subject: [PATCH] fix: grant work-center VIP for seven days --- .../service/user/ManagerAuthServiceImpl.java | 14 ++- .../user/ManagerAuthServiceImplTest.java | 103 ++++++++++++++++++ 2 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/service/user/ManagerAuthServiceImplTest.java diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/ManagerAuthServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/ManagerAuthServiceImpl.java index 38a45c86..a5492157 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/ManagerAuthServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/ManagerAuthServiceImpl.java @@ -75,6 +75,9 @@ import java.util.stream.Collectors; @Slf4j public class ManagerAuthServiceImpl implements ManagerAuthService { + /** work-center 赠送道具的固定有效期,需与 H5 展示保持一致。 */ + private static final int WORK_CENTER_PROPS_VALID_DAYS = 7; + private final RoomManagerAuthsQueryExe roomManagerAuthsQueryExe; private final ManagerApprovalNotPassCmdExe managerApprovalNotPassCmdExe; private final PropsSourceRecordService propsSourceRecordService; @@ -300,7 +303,8 @@ public class ManagerAuthServiceImpl implements ManagerAuthService { // UserProfile admin = userProfileGateway.getByUserId(cmd.requiredReqUserId()); - int days = PropsCommodityType.NOBLE_VIP.name().equals(propsSourceRecord.getType()) ? 3 : 7; + // work-center 每次只赠送 7 天;VIP 主权益与其附带权益必须使用同一期限。 + int days = WORK_CENTER_PROPS_VALID_DAYS; sendPropsRecord(cmd, propsSourceRecord.getType(), days); //vip单独处理 if (propsSourceRecord.getType().equals(PropsCommodityType.NOBLE_VIP.name())) { @@ -309,25 +313,25 @@ public class ManagerAuthServiceImpl implements ManagerAuthService { .equals(vipAbility.getCarId(), 0L)) { cmd.setPropsId(vipAbility.getCarId()); - sendPropsRecord(cmd, ConsolePropsTypeEnum.RIDE.getName(), 3); + sendPropsRecord(cmd, ConsolePropsTypeEnum.RIDE.getName(), days); } if (Objects.nonNull(vipAbility.getAvatarFrameId()) && !Objects.equals(vipAbility.getAvatarFrameId(), 0L)) { cmd.setPropsId(vipAbility.getAvatarFrameId()); - sendPropsRecord(cmd, ConsolePropsTypeEnum.AVATAR_FRAME.getName(), 3); + sendPropsRecord(cmd, ConsolePropsTypeEnum.AVATAR_FRAME.getName(), days); } if (Objects.nonNull(vipAbility.getChatBubbleId()) && !Objects.equals(vipAbility.getChatBubbleId(), 0L)) { cmd.setPropsId(vipAbility.getChatBubbleId()); - sendPropsRecord(cmd, ConsolePropsTypeEnum.CHAT_BUBBLE.getName(), 3); + sendPropsRecord(cmd, ConsolePropsTypeEnum.CHAT_BUBBLE.getName(), days); } if (Objects.nonNull(vipAbility.getDataCardId()) && !Objects.equals(vipAbility.getDataCardId(), 0L)) { cmd.setPropsId(vipAbility.getDataCardId()); - sendPropsRecord(cmd, ConsolePropsTypeEnum.DATA_CARD.getName(), 3); + sendPropsRecord(cmd, ConsolePropsTypeEnum.DATA_CARD.getName(), days); } // 使用最大等级的VIP diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/service/user/ManagerAuthServiceImplTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/service/user/ManagerAuthServiceImplTest.java new file mode 100644 index 00000000..6797d90b --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/service/user/ManagerAuthServiceImplTest.java @@ -0,0 +1,103 @@ +package com.red.circle.other.app.service.user; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.red.circle.component.redis.service.RedisService; +import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; +import com.red.circle.framework.dto.ResultResponse; +import com.red.circle.other.app.command.user.ManagerApprovalNotPassCmdExe; +import com.red.circle.other.app.command.user.query.RoomManagerAuthsQueryExe; +import com.red.circle.other.app.dto.cmd.material.PropsGiveAwayCmd; +import com.red.circle.other.domain.gateway.props.PropsNobleVipGateway; +import com.red.circle.other.domain.gateway.props.PropsStoreGateway; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; +import com.red.circle.other.infra.convertor.material.PropsMaterialInfraConvertor; +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.mongo.service.user.profile.UserSpecialIdService; +import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord; +import com.red.circle.other.infra.database.rds.entity.sys.Administrator; +import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService; +import com.red.circle.other.infra.database.rds.service.sys.AdministratorAuthService; +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.inner.endpoint.material.props.PropsBackpackClient; +import com.red.circle.other.inner.endpoint.material.props.PropsNobleVipClient; +import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; +import com.red.circle.other.inner.enums.material.PropsCommodityType; +import com.red.circle.other.inner.model.cmd.material.GivePropsBackpackCmd; +import com.red.circle.other.inner.model.dto.material.props.PropsNobleVipAbilityDTO; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class ManagerAuthServiceImplTest { + + @Mock private RoomManagerAuthsQueryExe roomManagerAuthsQueryExe; + @Mock private ManagerApprovalNotPassCmdExe managerApprovalNotPassCmdExe; + @Mock private PropsSourceRecordService propsSourceRecordService; + @Mock private AdministratorService administratorService; + @Mock private PropsMaterialInfraConvertor propsMaterialInfraConvertor; + @Mock private UserProfileGateway userProfileGateway; + @Mock private UserRegionGateway userRegionGateway; + @Mock private RedisService redisService; + @Mock private PropsBackpackClient propsBackpackClient; + @Mock private PropsStoreGateway propsStoreGateway; + @Mock private BusinessDevelopmentBaseInfoService businessDevelopmentBaseInfoService; + @Mock private TeamMemberService teamMemberService; + @Mock private TeamProfileService teamProfileService; + @Mock private UserSpecialIdService userSpecialIdService; + @Mock private PropsNobleVipGateway propsNobleVipGateway; + @Mock private UserProfileClient userProfileClient; + @Mock private OfficialNoticeClient officialNoticeClient; + @Mock private AdministratorAuthService administratorAuthService; + @Mock private PropsNobleVipClient propsNobleVipClient; + @InjectMocks private ManagerAuthServiceImpl managerAuthService; + + @Test + void shouldGrantVipAndAllBundledBenefitsForSevenDays() { + long operatorId = 1001L; + long receiverId = 2001L; + long vipId = 3001L; + PropsGiveAwayCmd cmd = new PropsGiveAwayCmd(); + cmd.setReqUserId(operatorId); + cmd.setAcceptUserId(receiverId); + cmd.setPropsId(vipId); + + when(administratorService.getByUserId(operatorId)) + .thenReturn(new Administrator().setUserId(operatorId).setStatus(Boolean.TRUE)); + when(userRegionGateway.checkEqRegion(receiverId, operatorId)).thenReturn(Boolean.TRUE); + when(redisService.lock(anyString(), anyLong())).thenReturn(Boolean.TRUE); + when(propsSourceRecordService.getById(vipId)) + .thenReturn(new PropsSourceRecord().setId(vipId).setType(PropsCommodityType.NOBLE_VIP.name())); + PropsNobleVipAbilityDTO vipAbility = new PropsNobleVipAbilityDTO(); + vipAbility.setCarId(3002L); + vipAbility.setAvatarFrameId(3003L); + vipAbility.setChatBubbleId(3004L); + vipAbility.setDataCardId(3005L); + when(propsNobleVipGateway.getAbilityDTO(vipId)).thenReturn(vipAbility); + when(propsNobleVipClient.getUserMaxAbilityDTO(receiverId)) + .thenReturn(ResultResponse.success(null)); + + managerAuthService.sendProps(cmd); + + ArgumentCaptor grantCaptor = + ArgumentCaptor.forClass(GivePropsBackpackCmd.class); + verify(propsBackpackClient, times(5)).giveProps(grantCaptor.capture()); + List grants = grantCaptor.getAllValues(); + assertThat(grants).extracting(GivePropsBackpackCmd::getDays).containsOnly(7); + assertThat(grants).extracting(GivePropsBackpackCmd::getPropsId) + .containsExactly(3001L, 3002L, 3003L, 3004L, 3005L); + } +}