补卡次数bug修复

This commit is contained in:
aikai 2024-11-08 17:17:50 +08:00
parent 234b6411f0
commit 89a56ac998
2 changed files with 7 additions and 3 deletions

View File

@ -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格式
*/

View File

@ -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) {