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 11ee48e0..112c4e0b 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 @@ -29,28 +29,34 @@ import com.red.circle.other.infra.convertor.material.PropsMaterialInfraConvertor import com.red.circle.other.infra.database.cache.key.AdminFreeKeys; import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile; -import com.red.circle.other.infra.database.mongo.entity.user.profile.UserSpecialId; -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.entity.team.BusinessDevelopmentBaseInfo; -import com.red.circle.other.infra.database.rds.entity.team.BusinessDevelopmentTeam; -import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService; -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.inner.asserts.user.UserErrorCode; -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.ConsolePropsTypeEnum; -import com.red.circle.other.inner.enums.material.PropsCommodityType; -import com.red.circle.other.inner.enums.team.TeamMemberRole; -import com.red.circle.other.inner.model.cmd.material.GivePropsBackpackCmd; -import com.red.circle.other.inner.model.cmd.team.TeamMemberBackQryCmd; -import com.red.circle.other.inner.model.dto.material.PropsResourcesDTO; +import com.red.circle.other.infra.database.mongo.entity.user.profile.UserSpecialId; +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.badge.BadgeConfig; +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.entity.team.BusinessDevelopmentBaseInfo; +import com.red.circle.other.infra.database.rds.entity.team.BusinessDevelopmentTeam; +import com.red.circle.other.infra.database.rds.service.badge.BadgeConfigService; +import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService; +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.inner.asserts.user.UserErrorCode; +import com.red.circle.other.inner.endpoint.material.props.BadgeBackpackClient; +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.BadgeBackpackExpireTypeEnum; +import com.red.circle.other.inner.enums.material.ConsolePropsTypeEnum; +import com.red.circle.other.inner.enums.material.PropsCommodityType; +import com.red.circle.other.inner.enums.team.TeamMemberRole; +import com.red.circle.other.inner.enums.sys.SysBadgeConfigTypeEnum; +import com.red.circle.other.inner.model.cmd.material.GiveBadgeCmd; +import com.red.circle.other.inner.model.cmd.material.GivePropsBackpackCmd; +import com.red.circle.other.inner.model.cmd.team.TeamMemberBackQryCmd; +import com.red.circle.other.inner.model.dto.material.PropsResourcesDTO; import com.red.circle.other.inner.model.dto.material.props.NobleVipAbility; import com.red.circle.other.inner.model.dto.material.props.PropsNobleVipAbilityDTO; import com.red.circle.tool.core.collection.CollectionUtils; @@ -73,18 +79,21 @@ import java.util.stream.Collectors; @Service @RequiredArgsConstructor @Slf4j -public class ManagerAuthServiceImpl implements ManagerAuthService { - - private final RoomManagerAuthsQueryExe roomManagerAuthsQueryExe; +public class ManagerAuthServiceImpl implements ManagerAuthService { + + private static final int MANAGER_BADGE_GIFT_DAYS = 7; + + private final RoomManagerAuthsQueryExe roomManagerAuthsQueryExe; private final ManagerApprovalNotPassCmdExe managerApprovalNotPassCmdExe; private final PropsSourceRecordService propsSourceRecordService; private final AdministratorService administratorService; private final PropsMaterialInfraConvertor propsMaterialInfraConvertor; private final UserProfileGateway userProfileGateway; private final UserRegionGateway userRegionGateway; - private final RedisService redisService; - private final PropsBackpackClient propsBackpackClient; - private final PropsStoreGateway propsStoreGateway; + private final RedisService redisService; + private final PropsBackpackClient propsBackpackClient; + private final BadgeBackpackClient badgeBackpackClient; + private final PropsStoreGateway propsStoreGateway; private final BusinessDevelopmentBaseInfoService businessDevelopmentBaseInfoService; private final TeamMemberService teamMemberService; private final TeamProfileService teamProfileService; @@ -92,8 +101,9 @@ public class ManagerAuthServiceImpl implements ManagerAuthService { private final PropsNobleVipGateway propsNobleVipGateway; private final UserProfileClient userProfileClient; private final OfficialNoticeClient officialNoticeClient; - private final AdministratorAuthService administratorAuthService; - private final PropsNobleVipClient propsNobleVipClient; + private final AdministratorAuthService administratorAuthService; + private final PropsNobleVipClient propsNobleVipClient; + private final BadgeConfigService badgeConfigService; @Override public RoomManagerAuthsCO managerAuths(RoomManageCommonCmd roomManageCommonCmd) { @@ -300,8 +310,18 @@ public class ManagerAuthServiceImpl implements ManagerAuthService { // UserProfile admin = userProfileGateway.getByUserId(cmd.requiredReqUserId()); - int days = PropsCommodityType.NOBLE_VIP.name().equals(propsSourceRecord.getType()) ? 3 : 7; - sendPropsRecord(cmd, propsSourceRecord.getType(), days); + if (PropsCommodityType.BADGE.name().equals(propsSourceRecord.getType())) { + if (!Boolean.TRUE.equals(propsSourceRecord.getAdminFree())) { + ResponseAssert.failure(CommonErrorCode.SEND_FAILURE, + "badge is not admin free."); + } + sendBadgeRecord(cmd, resolveBadgeType(propsSourceRecord.getId()), + MANAGER_BADGE_GIFT_DAYS); + return; + } + + int days = PropsCommodityType.NOBLE_VIP.name().equals(propsSourceRecord.getType()) ? 3 : 7; + sendPropsRecord(cmd, propsSourceRecord.getType(), days); //vip单独处理 if (propsSourceRecord.getType().equals(PropsCommodityType.NOBLE_VIP.name())) { PropsNobleVipAbilityDTO vipAbility = propsNobleVipGateway.getAbilityDTO(propsSourceRecord.getId()); @@ -377,11 +397,11 @@ public class ManagerAuthServiceImpl implements ManagerAuthService { userProfileClient.removeCacheAll(receiverId); } - private void sendPropsRecord(PropsGiveAwayCmd cmd, String sourceType, Integer days) { - //开始赠送道具 - log.info("admin free props start.{}", cmd); -// 赠送的都是7天 - propsBackpackClient.giveProps(new GivePropsBackpackCmd() + private void sendPropsRecord(PropsGiveAwayCmd cmd, String sourceType, Integer days) { + //开始赠送道具 + log.info("admin free props start.{}", cmd); +// 赠送的都是7天 + propsBackpackClient.giveProps(new GivePropsBackpackCmd() .setAcceptUserId(cmd.getAcceptUserId()) .setPropsId(cmd.getPropsId()) .setType(sourceType) @@ -398,13 +418,41 @@ public class ManagerAuthServiceImpl implements ManagerAuthService { .append(cmd.getPropsId()) .append(" 道具 给 ").append(cmd.getAcceptUserId()); // sendTelegram(stringBuilder); - } catch (Exception e) { - log.error("赠送道具 发送机器人失败", e); - } - RegionConfig region = userRegionGateway.getRegionConfigByUserId(cmd.getAcceptUserId()); - if (region == null) { - return; - } + } catch (Exception e) { + log.error("赠送道具 发送机器人失败", e); + } + sendGiftNotice(cmd, sourceType, days); + } + + private void sendBadgeRecord(PropsGiveAwayCmd cmd, SysBadgeConfigTypeEnum badgeType, Integer days) { + log.info("admin free badge start.{}", cmd); + badgeBackpackClient.giveBadge(new GiveBadgeCmd() + .setAcceptUserId(cmd.getAcceptUserId()) + .setBadgeId(cmd.getPropsId()) + .setExpireType(BadgeBackpackExpireTypeEnum.TEMPORARY) + .setDays(days) + .setBadgeType(badgeType)); + sendGiftNotice(cmd, badgeType.getName(), days); + } + + private SysBadgeConfigTypeEnum resolveBadgeType(Long badgeId) { + BadgeConfig badgeConfig = badgeConfigService.getById(badgeId); + if (Objects.isNull(badgeConfig) || StringUtils.isBlank(badgeConfig.getType())) { + return SysBadgeConfigTypeEnum.ACTIVITY; + } + try { + return SysBadgeConfigTypeEnum.valueOf(badgeConfig.getType()); + } catch (IllegalArgumentException e) { + log.warn("unknown badge type: {}, badgeId: {}", badgeConfig.getType(), badgeId); + return SysBadgeConfigTypeEnum.ACTIVITY; + } + } + + private void sendGiftNotice(PropsGiveAwayCmd cmd, String sourceType, Integer days) { + RegionConfig region = userRegionGateway.getRegionConfigByUserId(cmd.getAcceptUserId()); + if (region == null) { + return; + } String url = null; PropsSourceRecord props = propsSourceRecordService.getPropsById(cmd.getPropsId());