From 3a7031f1e8a39c45c2a1ebd58127c042e0180836 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 11 Sep 2025 21:07:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1):=20=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E8=B5=A0=E9=80=81=E9=87=91=E5=B8=81=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../circle/other/app/scheduler/DailyTask.java | 98 +++++++++++++++++-- 1 file changed, 89 insertions(+), 9 deletions(-) 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 de352e73..6543dd9d 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 @@ -12,6 +12,7 @@ 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.dao.props.RunningWaterUserPropsDAO; 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; @@ -28,9 +29,11 @@ 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.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import com.red.circle.tool.core.date.LocalDateTimeUtils; import com.red.circle.tool.core.tuple.ImmutableKeyValuePair; @@ -61,6 +64,7 @@ public class DailyTask { private final FamilyDailyTaskTriggerRecordService familyDailyTaskTriggerRecordService; private final PropsStoreGateway propsStoreGateway; private final RunningWaterUserPropsService runningWaterUserPropsService; + private final RunningWaterUserPropsDAO runningWaterUserPropsDAO; private final PropsBackpackService propsBackpackService; private final WalletGoldClient walletGoldClient; private final PropsPurchasingCmdExe propsPurchasingCmdExe; @@ -214,7 +218,7 @@ public class DailyTask { /** * 贵族每日金币奖励发放 - 沙特时间每日0点执行. */ - @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Riyadh") + @Scheduled(cron = "0 * * * * *", zone = "Asia/Riyadh") @TaskCacheLock(key = "NOBLE_DAILY_GOLD_REWARD_TASK", expireSecond = 86000 ) public void nobleDailyGoldRewardTask() { long startTime = System.currentTimeMillis(); @@ -238,17 +242,19 @@ public class DailyTask { commodityList.forEach(propsStoreCommodity -> { List propsBackpackList = propsBackpackService.listUsersByNobleVipAndPropsId(PropsCommodityType.NOBLE_VIP, propsStoreCommodity.getPropsResources().getId()); - log.info("VIP用户: {}", JSON.toJSONString(propsStoreCommodity)); + log.info("VIP用户: {}", JSON.toJSONString(propsBackpackList)); - List userIds = propsBackpackList.stream().map(e -> { - RunningWaterUserProps runningWaterUserProps = runningWaterUserPropsService.selectRunningWaterUserProps(e.getType(), e.getUserId(), e.getPropsId(), - LocalDateTimeUtils.format(e.getCreateTime().toLocalDateTime(), "yyyy-MM-dd HH:mm")); - return runningWaterUserProps == null ? e.getUserId() : null; - }).filter(Objects::nonNull).toList(); - log.info("userIds: {}", JSON.toJSONString(userIds)); + // 提取用户ID列表 + List allUsers = propsBackpackList.stream() + .map(PropsBackpack::getUserId) + .distinct() + .collect(Collectors.toList()); + + // 查询用户是否处于可赠送金币区间 + List eligibleUsers = getEligibleGiftUsers(allUsers); // 给每个用户发送奖励,排除已处理的用户 - for (Long userId : userIds) { + for (Long userId : eligibleUsers) { if (!processedUsers.contains(userId)) { ResultResponse res = walletGoldClient.changeBalance(GoldReceiptCmd.builder() .appIncome() @@ -288,6 +294,80 @@ public class DailyTask { log.info("exec noble_daily_gold_reward_task end with {}", System.currentTimeMillis() - startTime); } + /** + * 查询用户是否处于可赠送金币区间 + * 规则: + * 1. 查询NOBLE_VIP的origin为PURCHASING_GOLD_PROPS类型的,按照创建时间加天数计算 + * 2. 如果当前时间在范围内则为有效赠送用户 + * 3. 如果没有PURCHASING_GOLD_PROPS类型,则其余不赠送 + */ + private List getEligibleGiftUsers(List allUsers) { + if (CollectionUtils.isEmpty(allUsers)) { + return Lists.newArrayList(); + } + + List eligibleUsers = Lists.newArrayList(); + LocalDateTime now = LocalDateTime.now(); + + for (Long userId : allUsers) { + if (isUserEligibleForGift(userId, now)) { + eligibleUsers.add(userId); + } + } + + log.info("所有贵族用户数: {}, 符合赠送条件的用户数: {}", allUsers.size(), eligibleUsers.size()); + return eligibleUsers; + } + + /** + * 判断单个用户是否符合赠送条件 + */ + private boolean isUserEligibleForGift(Long userId, LocalDateTime currentTime) { + try { + // 查询用户NOBLE_VIP类型且origin为PURCHASING_GOLD_PROPS的流水记录 + List purchasingRecords = runningWaterUserPropsService.query() + .eq(RunningWaterUserProps::getUserId, userId) + .eq(RunningWaterUserProps::getType, "NOBLE_VIP") + .eq(RunningWaterUserProps::getOrigin, "PURCHASING_GOLD_PROPS") + .orderByDesc(RunningWaterUserProps::getCreateTime) + .list(); + + if (CollectionUtils.isEmpty(purchasingRecords)) { + log.debug("用户 {} 没有PURCHASING_GOLD_PROPS类型的流水记录,不符合赠送条件", userId); + return false; + } + + // 检查是否有有效的购买记录(在有效期内) + for (RunningWaterUserProps record : purchasingRecords) { + LocalDateTime createTime = record.getCreateTime().toLocalDateTime(); + Integer days = record.getDays(); + + // days为-1表示永久有效 + if (days != null && days == -1) { + log.debug("用户 {} 有永久有效的购买记录,符合赠送条件", userId); + return true; + } + + // 计算有效期 + if (days != null && days > 0) { + LocalDateTime expireTime = createTime.plusDays(days); + if (currentTime.isBefore(expireTime) || currentTime.isEqual(expireTime)) { + log.debug("用户 {} 购买记录在有效期内,符合赠送条件。购买时间: {}, 有效天数: {}, 过期时间: {}", + userId, createTime, days, expireTime); + return true; + } + } + } + + log.debug("用户 {} 所有购买记录都已过期,不符合赠送条件", userId); + return false; + + } catch (Exception e) { + log.error("检查用户 {} 赠送资格时发生异常: {}", userId, e.getMessage(), e); + return false; + } + } + private void sendFanVotesReward(String code, String sysOrigin) { List votesCounts = roomFanVotesActivityCountService