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 c10431a9..de352e73 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 @@ -1,5 +1,6 @@ package com.red.circle.other.app.scheduler; +import com.alibaba.fastjson.JSON; 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; @@ -14,10 +15,12 @@ import com.red.circle.other.infra.database.mongo.service.activity.RoomFanVotesAc 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.entity.props.RunningWaterUserProps; 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.database.rds.service.props.RunningWaterUserPropsService; 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; @@ -25,11 +28,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.util.Comparator; -import java.util.List; -import java.util.Objects; +import java.time.format.DateTimeFormatter; +import java.util.*; import java.util.concurrent.TimeUnit; +import com.red.circle.tool.core.date.LocalDateTimeUtils; 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; @@ -56,10 +59,11 @@ 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; + private final PropsStoreGateway propsStoreGateway; + private final RunningWaterUserPropsService runningWaterUserPropsService; + private final PropsBackpackService propsBackpackService; + private final WalletGoldClient walletGoldClient; + private final PropsPurchasingCmdExe propsPurchasingCmdExe; /** * 每日处理数据. @@ -233,9 +237,17 @@ public class DailyTask { List processedUsers = Lists.newArrayList(); // 记录已处理的用户,避免重复发放 commodityList.forEach(propsStoreCommodity -> { - List userIds = propsBackpackService.listUsersByNobleVipAndPropsId(PropsCommodityType.NOBLE_VIP, propsStoreCommodity.getPropsResources().getId()); + List propsBackpackList = propsBackpackService.listUsersByNobleVipAndPropsId(PropsCommodityType.NOBLE_VIP, propsStoreCommodity.getPropsResources().getId()); + log.info("VIP用户: {}", JSON.toJSONString(propsStoreCommodity)); - // 给每个用户发送奖励,排除已处理的用户 + 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)); + + // 给每个用户发送奖励,排除已处理的用户 for (Long userId : userIds) { if (!processedUsers.contains(userId)) { ResultResponse res = walletGoldClient.changeBalance(GoldReceiptCmd.builder() @@ -260,6 +272,8 @@ public class DailyTask { } processedUsers.add(userId); // 标记为已处理 + } else { + log.warn("已处理过不再重复处理: {}", userId); } } }); 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 b40d6885..1ef72306 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 @@ -216,6 +216,6 @@ public interface PropsBackpackService extends BaseService { * @param propsId 道具ID * @return 用户列表 */ - List listUsersByNobleVipAndPropsId(PropsCommodityType propsType, Long propsId); + 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/RunningWaterUserPropsService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/RunningWaterUserPropsService.java index 52c8f2a0..40fc1db3 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/RunningWaterUserPropsService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/RunningWaterUserPropsService.java @@ -15,4 +15,10 @@ import com.red.circle.other.inner.model.cmd.material.RunningWaterUserPropsQryCmd public interface RunningWaterUserPropsService extends BaseService { PageResult pageRunningWaterUserProps(RunningWaterUserPropsQryCmd query); + + + /** + * 同分钟内赠送的VIP + */ + RunningWaterUserProps selectRunningWaterUserProps(String type, Long userId, Long propsId, String createTime); } 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 55d93279..0cfd06a3 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 @@ -408,14 +408,14 @@ public class PropsBackpackServiceImpl extends } @Override - public List listUsersByNobleVipAndPropsId(PropsCommodityType propsType, Long propsId) { + public List listUsersByNobleVipAndPropsId(PropsCommodityType propsType, Long propsId) { return query() .eq(PropsBackpack::getType, propsType) .eq(PropsBackpack::getPropsId, propsId) + .eq(PropsBackpack::getUseProps, Boolean.TRUE) .gt(PropsBackpack::getExpireTime, TimestampUtils.now()) .list() .stream() - .map(PropsBackpack::getUserId) .collect(Collectors.toList()); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/RunningWaterUserPropsServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/RunningWaterUserPropsServiceImpl.java index 6994ed00..93f6af75 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/RunningWaterUserPropsServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/props/impl/RunningWaterUserPropsServiceImpl.java @@ -44,4 +44,14 @@ public class RunningWaterUserPropsServiceImpl extends .orderByDesc(RunningWaterUserProps::getCreateTime) .page(query.getPageQuery()); } + + @Override + public RunningWaterUserProps selectRunningWaterUserProps(String type, Long userId, Long propsId, String createTime) { + return query() + .eq(RunningWaterUserProps::getType, type) + .eq(RunningWaterUserProps::getUserId, userId) + .eq(RunningWaterUserProps::getPropsId, propsId) + .apply("DATE_FORMAT(create_time, '%Y-%m-%d %H:%i') = {0}", createTime) + .last("LIMIT 1").getOne(); + } }