From 7a009946632c790294861c68138883d512fe8301 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Sun, 9 Nov 2025 17:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=A5=96weekKey=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8C=E5=8E=BB=E9=99=A4weekKey=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=20=E5=B9=B6=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/command/activity/LotteryDrawExe.java | 18 +++++------------- .../command/activity/LotteryMultiDrawExe.java | 14 ++++---------- .../activity/LotteryWithdrawAmountQryExe.java | 4 ++-- .../activity/LotteryWithdrawApplyExe.java | 15 +++------------ .../other/infra/utils/ZonedDateTimeUtils.java | 11 +++++++++++ 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java index 4392d56e..9c9a0165 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java @@ -20,6 +20,7 @@ import com.red.circle.other.infra.database.rds.service.activity.LotteryTicketRec import com.red.circle.other.infra.database.rds.service.activity.LotteryTicketService; import com.red.circle.other.infra.database.rds.service.activity.LotteryUserCountService; import com.red.circle.other.infra.database.rds.service.activity.LotteryUserProgressService; +import com.red.circle.other.infra.utils.ZonedDateTimeUtils; import com.red.circle.other.inner.asserts.lottery.LotteryErrorCode; import com.red.circle.tool.core.date.TimestampUtils; import java.math.BigDecimal; @@ -31,6 +32,7 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; + import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -142,19 +144,19 @@ public class LotteryDrawExe { * 获取或创建用户进度. */ private LotteryUserProgress getOrCreateUserProgress(Long userId, Long activityId) { - String weekKey = getWeekKey(); +// String weekKey = ZonedDateTimeUtils.getWeekKey(); LotteryUserProgress progress = lotteryUserProgressService.query() .eq(LotteryUserProgress::getUserId, userId) .eq(LotteryUserProgress::getActivityId, activityId) - .eq(LotteryUserProgress::getWeekKey, weekKey) +// .eq(LotteryUserProgress::getWeekKey, weekKey) .getOne(); if (progress == null) { progress = new LotteryUserProgress(); progress.setUserId(userId); progress.setActivityId(activityId); - progress.setWeekKey(weekKey); +// progress.setWeekKey(weekKey); progress.setTotalAmount(BigDecimal.ZERO); progress.setTotalDrawCount(0); progress.setBigPrizeCount(0); @@ -530,16 +532,6 @@ public class LotteryDrawExe { .execute(); } - /** - * 生成周标识. - */ - private String getWeekKey() { - LocalDate now = LocalDate.now(); - int year = now.getYear(); - int weekOfYear = now.get(WeekFields.of(Locale.getDefault()).weekOfYear()); - return String.format("%dW%02d", year, weekOfYear); - } - /** * 生成记录编号. */ diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java index 723028b7..44e5c09f 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java @@ -21,6 +21,7 @@ import com.red.circle.other.infra.database.rds.service.activity.LotteryTicketRec import com.red.circle.other.infra.database.rds.service.activity.LotteryTicketService; import com.red.circle.other.infra.database.rds.service.activity.LotteryUserCountService; import com.red.circle.other.infra.database.rds.service.activity.LotteryUserProgressService; +import com.red.circle.other.infra.utils.ZonedDateTimeUtils; import com.red.circle.other.inner.asserts.lottery.LotteryErrorCode; import com.red.circle.tool.core.date.TimestampUtils; import java.math.BigDecimal; @@ -181,17 +182,17 @@ public class LotteryMultiDrawExe { } private LotteryUserProgress getOrCreateUserProgress(Long userId, Long activityId) { - String weekKey = getWeekKey(); +// String weekKey = ZonedDateTimeUtils.getWeekKey(); LotteryUserProgress progress = lotteryUserProgressService.query() .eq(LotteryUserProgress::getUserId, userId) .eq(LotteryUserProgress::getActivityId, activityId) - .eq(LotteryUserProgress::getWeekKey, weekKey) +// .eq(LotteryUserProgress::getWeekKey, weekKey) .getOne(); if (progress == null) { progress = new LotteryUserProgress(); progress.setUserId(userId); progress.setActivityId(activityId); - progress.setWeekKey(weekKey); +// progress.setWeekKey(weekKey); progress.setTotalAmount(BigDecimal.ZERO); progress.setTotalDrawCount(0); progress.setBigPrizeCount(0); @@ -481,13 +482,6 @@ public class LotteryMultiDrawExe { .execute(); } - private String getWeekKey() { - LocalDate now = LocalDate.now(); - int year = now.getYear(); - int weekOfYear = now.get(WeekFields.of(Locale.getDefault()).weekOfYear()); - return String.format("%dW%02d", year, weekOfYear); - } - private LotteryDrawResultCO convertToResultCO(LotteryRecord record, LotteryPrize prize) { LotteryDrawResultCO result = new LotteryDrawResultCO(); result.setRecordNo(record.getRecordNo()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawAmountQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawAmountQryExe.java index c1024d53..baeaf6ad 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawAmountQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawAmountQryExe.java @@ -30,11 +30,11 @@ public class LotteryWithdrawAmountQryExe { public LotteryWithdrawAmountCO execute(Long userId, Long activityId) { // 1. 获取用户本周累计金额 - String weekKey = getCurrentWeekKey(); +// String weekKey = getCurrentWeekKey(); LotteryUserProgress progress = lotteryUserProgressService.query() .eq(LotteryUserProgress::getUserId, userId) .eq(LotteryUserProgress::getActivityId, activityId) - .eq(LotteryUserProgress::getWeekKey, weekKey) +// .eq(LotteryUserProgress::getWeekKey, weekKey) .getOne(); BigDecimal totalAmount = progress != null && progress.getTotalAmount() != null diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java index 41c531ca..2fa17571 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java @@ -6,6 +6,7 @@ import com.red.circle.other.infra.database.rds.entity.activity.LotteryUserProgre import com.red.circle.other.infra.database.rds.entity.activity.LotteryWithdraw; import com.red.circle.other.infra.database.rds.service.activity.LotteryUserProgressService; import com.red.circle.other.infra.database.rds.service.activity.LotteryWithdrawService; +import com.red.circle.other.infra.utils.ZonedDateTimeUtils; import com.red.circle.other.inner.asserts.lottery.LotteryErrorCode; import com.red.circle.tool.core.date.TimestampUtils; import java.math.BigDecimal; @@ -41,11 +42,11 @@ public class LotteryWithdrawApplyExe { amount.compareTo(BigDecimal.valueOf(10)) >= 0); // 1. 获取用户本周累计金额 - String weekKey = getCurrentWeekKey(); +// String weekKey = ZonedDateTimeUtils.getWeekKey(); LotteryUserProgress progress = lotteryUserProgressService.query() .eq(LotteryUserProgress::getUserId, userId) .eq(LotteryUserProgress::getActivityId, activityId) - .eq(LotteryUserProgress::getWeekKey, weekKey) +// .eq(LotteryUserProgress::getWeekKey, weekKey) .getOne(); ResponseAssert.notNull(LotteryErrorCode.NO_WITHDRAWAL_AMOUNT, progress); @@ -109,16 +110,6 @@ public class LotteryWithdrawApplyExe { .reduce(BigDecimal.ZERO, BigDecimal::add); } - /** - * 获取当前周标识. - */ - private String getCurrentWeekKey() { - LocalDate now = LocalDate.now(); - int year = now.getYear(); - int weekOfYear = now.get(WeekFields.of(Locale.getDefault()).weekOfYear()); - return String.format("%dW%02d", year, weekOfYear); - } - /** * 生成提现单号. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/ZonedDateTimeUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/ZonedDateTimeUtils.java index f3f56cb3..5c77356e 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/ZonedDateTimeUtils.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/ZonedDateTimeUtils.java @@ -12,6 +12,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAdjusters; +import java.time.temporal.WeekFields; import java.util.HashMap; import java.util.Map; @@ -472,6 +473,16 @@ public final class ZonedDateTimeUtils { return Timestamp.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); } + /** + * 生成周标识(ISO 8601标准,周一为一周的开始). + */ + public static String getWeekKey() { + LocalDate now = LocalDate.now(); + int year = now.get(WeekFields.ISO.weekBasedYear()); // 使用ISO周年 + int weekOfYear = now.get(WeekFields.ISO.weekOfWeekBasedYear()); // ISO周数 + return String.format("%dW%02d", year, weekOfYear); + } + /** * 转换zoneId *