From 78a3a34c0e17d48bf714c165fd911ee14e304c11 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 10 Sep 2025 18:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=AF=8F=E6=97=A5=E6=96=B9?= =?UTF-8?q?=E6=B3=95vip=E5=A5=96=E5=8A=B1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../circle/other/app/scheduler/DailyTask.java | 88 +++++++++++++++++++ .../service/props/PropsBackpackService.java | 10 +++ .../props/impl/PropsBackpackServiceImpl.java | 12 +++ 3 files changed, 110 insertions(+) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/DailyTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/DailyTask.java index 69363f1d..c10431a9 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/DailyTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/DailyTask.java @@ -4,26 +4,43 @@ import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.common.business.enums.SendPropsOrigin; import com.red.circle.component.redis.annotation.TaskCacheLock; import com.red.circle.component.redis.service.RedisService; +import com.red.circle.framework.dto.ResultResponse; +import com.red.circle.other.app.command.material.PropsPurchasingCmdExe; +import com.red.circle.other.domain.gateway.props.PropsStoreGateway; import com.red.circle.other.infra.common.activity.PropsActivitySendCommon; import com.red.circle.other.infra.common.activity.send.SendRewardGroup; import com.red.circle.other.infra.database.mongo.entity.activity.RoomFanVotesActivityCount; import com.red.circle.other.infra.database.mongo.service.activity.RoomFanVotesActivityCountService; import com.red.circle.other.infra.database.rds.entity.activity.PropsActivityRuleConfig; +import com.red.circle.other.infra.database.rds.entity.props.PropsBackpack; +import com.red.circle.other.infra.database.rds.entity.props.PropsNobleVipAbility; import com.red.circle.other.infra.database.rds.enums.CacheKeysEnum; import com.red.circle.other.infra.database.rds.service.activity.PropsActivityRuleConfigService; import com.red.circle.other.infra.database.rds.service.family.FamilyDailyTaskTriggerRecordService; +import com.red.circle.other.infra.database.rds.service.props.PropsBackpackService; import com.red.circle.other.infra.utils.ZonedDateTimeUtils; import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum; +import com.red.circle.other.inner.enums.material.PropsCommodityType; +import com.red.circle.other.inner.model.dto.material.props.PropsStoreCommodity; import com.red.circle.tool.core.collection.CollectionUtils; +import com.google.common.collect.Lists; import java.time.Duration; +import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; + +import com.red.circle.tool.core.tuple.ImmutableKeyValuePair; +import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient; +import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd; +import com.red.circle.wallet.inner.model.dto.WalletReceiptResDTO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import static com.red.circle.common.business.core.enums.SysOriginPlatformEnum.LIKEI; + /** * 每日任务数据. * @@ -39,6 +56,10 @@ public class DailyTask { private final PropsActivityRuleConfigService propsActivityRuleConfigService; private final RoomFanVotesActivityCountService roomFanVotesActivityCountService; private final FamilyDailyTaskTriggerRecordService familyDailyTaskTriggerRecordService; + private final PropsStoreGateway propsStoreGateway; + private final PropsBackpackService propsBackpackService; + private final WalletGoldClient walletGoldClient; + private final PropsPurchasingCmdExe propsPurchasingCmdExe; /** * 每日处理数据. @@ -186,6 +207,73 @@ public class DailyTask { log.info("exec room_fan_votes_activity_ar_start_task end with {}",System.currentTimeMillis()-startTime); } + /** + * 贵族每日金币奖励发放 - 沙特时间每日0点执行. + */ + @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Riyadh") + @TaskCacheLock(key = "NOBLE_DAILY_GOLD_REWARD_TASK", expireSecond = 86000 ) + public void nobleDailyGoldRewardTask() { + long startTime = System.currentTimeMillis(); + log.info("exec noble_daily_gold_reward_task start"); + log.warn("Start - 贵族每日金币奖励发放"); + + ImmutableKeyValuePair valuePair = ImmutableKeyValuePair.of("PURCHASE_NOBLE_VIP_GIVEAWAY", "Give Noble"); + try { + List propsStoreCommodities = propsStoreGateway.listReleaseStoreCommodity(LIKEI, PropsCommodityType.NOBLE_VIP); + + // 按照VIP等级从大到小排序 + List commodityList = propsStoreCommodities.stream() + .filter(e -> Objects.nonNull(e.getNobleVipAbility())) + .sorted(Comparator.comparing(e -> { + PropsStoreCommodity commodity = (PropsStoreCommodity) e; + return commodity.getNobleVipAbility().getVipLevel(); + }).reversed()) + .toList(); + + List processedUsers = Lists.newArrayList(); // 记录已处理的用户,避免重复发放 + + commodityList.forEach(propsStoreCommodity -> { + List userIds = propsBackpackService.listUsersByNobleVipAndPropsId(PropsCommodityType.NOBLE_VIP, propsStoreCommodity.getPropsResources().getId()); + + // 给每个用户发送奖励,排除已处理的用户 + for (Long userId : userIds) { + if (!processedUsers.contains(userId)) { + ResultResponse res = walletGoldClient.changeBalance(GoldReceiptCmd.builder() + .appIncome() + .userId(userId) + .eventId(propsStoreCommodity.getId()) + .sysOrigin(LIKEI) + .origin(valuePair.getKey()) + .originDescribe(valuePair.getValue()) + .amount(propsStoreCommodity.getNobleVipAbility().getLoginRewardsAmount()) + .build() + ); + + if (res == null || !res.checkSuccess()) { + log.error("贵族每日金币奖励发放失败 - userId: {}, propsId: {}, amount: {}, error: {}", + userId, propsStoreCommodity.getId(), + propsStoreCommodity.getNobleVipAbility().getLoginRewardsAmount(), + res != null ? res.getErrorMsg() : "响应为空"); + } else { + log.info("贵族每日金币奖励发放成功 - userId: {}, amount: {}", userId, + propsStoreCommodity.getNobleVipAbility().getLoginRewardsAmount()); + } + + processedUsers.add(userId); // 标记为已处理 + } + } + }); + + log.warn("贵族每日金币奖励发放完成"); + + } catch (Exception ex) { + log.error("贵族每日金币奖励发放异常: {}", ex.getMessage(), ex); + } + + log.warn("End - 贵族每日金币奖励发放"); + log.info("exec noble_daily_gold_reward_task end with {}", System.currentTimeMillis() - startTime); + } + private void sendFanVotesReward(String code, String sysOrigin) { List votesCounts = roomFanVotesActivityCountService diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/PropsBackpackService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/PropsBackpackService.java index 2ca53faf..b40d6885 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/PropsBackpackService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/PropsBackpackService.java @@ -208,4 +208,14 @@ public interface PropsBackpackService extends BaseService { * @param userId 用户. */ Boolean countUserNobleProps(Long userId); + + /** + * 查询拥有指定VIP道具且未过期的用户道具信息. + * + * @param propsType VIP道具类型 + * @param propsId 道具ID + * @return 用户列表 + */ + List listUsersByNobleVipAndPropsId(PropsCommodityType propsType, Long propsId); + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/PropsBackpackServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/PropsBackpackServiceImpl.java index f6d75b07..55d93279 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/PropsBackpackServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/PropsBackpackServiceImpl.java @@ -407,4 +407,16 @@ public class PropsBackpackServiceImpl extends : Boolean.FALSE; } + @Override + public List listUsersByNobleVipAndPropsId(PropsCommodityType propsType, Long propsId) { + return query() + .eq(PropsBackpack::getType, propsType) + .eq(PropsBackpack::getPropsId, propsId) + .gt(PropsBackpack::getExpireTime, TimestampUtils.now()) + .list() + .stream() + .map(PropsBackpack::getUserId) + .collect(Collectors.toList()); + } + }