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 f7c51bd1..71744a51 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) {