From 89a56ac998a414707b957a0fc405fbae023b1d0e Mon Sep 17 00:00:00 2001 From: aikai Date: Fri, 8 Nov 2024 17:17:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=8D=A1=E6=AC=A1=E6=95=B0bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/yudao/framework/common/Constants.java | 4 ++++ .../system/service/attendance/AttendanceServiceImpl.java | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/Constants.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/Constants.java index bb6e957e..ebe41b88 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/Constants.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/Constants.java @@ -58,6 +58,10 @@ public class Constants { * yyyy-MM-dd格式 */ public static final DateTimeFormatter REPO_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + /** + * 年月格式 + */ + public static final DateTimeFormatter YEAR_MONTH_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM"); /** * yyyy-MM-dd HH:mm:ss格式 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java index 2fd3df82..c4203da1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/attendance/AttendanceServiceImpl.java @@ -1018,7 +1018,7 @@ public class AttendanceServiceImpl implements AttendanceService { public Integer getReplacementCardNum() { Long userId = getLoginUserId(); Integer num = 0; - String key = "ReplacementCardNum" + "_" + userId + "_" + LocalDateTime.now().format(Constants.REPO_DATE_FORMAT); + String key = "ReplacementCardNum" + "_" + userId + "_" + LocalDateTime.now().format(Constants.YEAR_MONTH_FORMAT); String value = stringRedisTemplate.opsForValue().get(key); if (StringUtils.isEmpty(value)) { // -- 获取当前用户 @@ -1064,7 +1064,7 @@ public class AttendanceServiceImpl implements AttendanceService { } } catch (Exception e) { // -- 如果有报错的话 - 那么进行回滚操作 - 并且redis 中的补卡次数也要+1 (redis并不会回滚) - String key = "ReplacementCardNum" + "_" + userId + "_" + LocalDateTime.now().format(Constants.REPO_DATE_FORMAT); + String key = "ReplacementCardNum" + "_" + userId + "_" + LocalDateTime.now().format(Constants.YEAR_MONTH_FORMAT); stringRedisTemplate.opsForValue().increment(key, 1); throw exception(ABNORMAL_CARD_REPLENISHMENT); } @@ -1121,7 +1121,7 @@ public class AttendanceServiceImpl implements AttendanceService { @Override public void useReplacementCardNum(Long userId) { userId = userId == null ? getLoginUserId() : userId; - String key = "ReplacementCardNum" + "_" + userId + "_" + LocalDateTime.now().format(Constants.REPO_DATE_FORMAT); + String key = "ReplacementCardNum" + "_" + userId + "_" + LocalDateTime.now().format(Constants.YEAR_MONTH_FORMAT); String value = stringRedisTemplate.opsForValue().get(key); if (StringUtils.isNotEmpty(value)) { if (Integer.parseInt(value) > 0) {