|
@@ -6,7 +6,9 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
|
import com.ruoyi.system.domain.InfoUser;
|
|
import com.ruoyi.system.domain.InfoUser;
|
|
|
import com.ruoyi.system.mapper.InfoUserMapper;
|
|
import com.ruoyi.system.mapper.InfoUserMapper;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
+import com.ruoyi.common.utils.DictUtils;
|
|
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
|
|
+import java.util.List;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
@@ -18,11 +20,8 @@ import java.util.Date;
|
|
|
public class UserCancellationService {
|
|
public class UserCancellationService {
|
|
|
private final InfoUserMapper users;
|
|
private final InfoUserMapper users;
|
|
|
private final RedisCache redis;
|
|
private final RedisCache redis;
|
|
|
- private final int graceDays;
|
|
|
|
|
- public UserCancellationService(InfoUserMapper users, RedisCache redis,
|
|
|
|
|
- @Value("${user.cancellation.grace-days:7}") int graceDays) {
|
|
|
|
|
|
|
+ public UserCancellationService(InfoUserMapper users, RedisCache redis) {
|
|
|
this.users = users; this.redis = redis;
|
|
this.users = users; this.redis = redis;
|
|
|
- this.graceDays = graceDays > 0 && graceDays <= 365 ? graceDays : 7;
|
|
|
|
|
}
|
|
}
|
|
|
public record CancellationView(
|
|
public record CancellationView(
|
|
|
@com.fasterxml.jackson.annotation.JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
@com.fasterxml.jackson.annotation.JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
@@ -34,6 +33,8 @@ public class UserCancellationService {
|
|
|
InfoUser user = users.selectCancellationUserForUpdate(userId);
|
|
InfoUser user = users.selectCancellationUserForUpdate(userId);
|
|
|
requireUser(user);
|
|
requireUser(user);
|
|
|
if (!"0".equals(user.getDelFlag())) throw unavailable();
|
|
if (!"0".equals(user.getDelFlag())) throw unavailable();
|
|
|
|
|
+ // 每次申请读取最新字典;天数只在这里转成截止时间,后续恢复不重新计算。
|
|
|
|
|
+ int graceDays = graceDays();
|
|
|
Date deadline = Date.from(Instant.now().plus(graceDays, ChronoUnit.DAYS));
|
|
Date deadline = Date.from(Instant.now().plus(graceDays, ChronoUnit.DAYS));
|
|
|
if (users.requestUserCancellation(userId, deadline) != 1) throw unavailable();
|
|
if (users.requestUserCancellation(userId, deadline) != 1) throw unavailable();
|
|
|
redis.deleteKeys(CacheConstants.USER_TOKEN_KEY + userId + ":*");
|
|
redis.deleteKeys(CacheConstants.USER_TOKEN_KEY + userId + ":*");
|
|
@@ -52,6 +53,24 @@ public class UserCancellationService {
|
|
|
return user;
|
|
return user;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 复用平台字典缓存;后台修改并刷新后对新申请生效,读取不到或非法均默认7天。 */
|
|
|
|
|
+ private int graceDays() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<SysDictData> rows = DictUtils.getDictCache("user_cancellation_grace_days");
|
|
|
|
|
+ if (rows != null) {
|
|
|
|
|
+ for (SysDictData row : rows) {
|
|
|
|
|
+ if (row == null || !"0".equals(row.getStatus())) continue;
|
|
|
|
|
+ String value = row.getDictValue();
|
|
|
|
|
+ int days = value == null ? 7 : Integer.parseInt(value.trim());
|
|
|
|
|
+ return days >= 1 && days <= 365 ? days : 7;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (RuntimeException ignored) {
|
|
|
|
|
+ // 字典缺失、值非法或缓存不可用不阻断注销,沿用默认7天。
|
|
|
|
|
+ }
|
|
|
|
|
+ return 7;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static boolean canRecover(InfoUser user, Date now) {
|
|
public static boolean canRecover(InfoUser user, Date now) {
|
|
|
return user != null && "0".equals(user.getUserType()) && "0".equals(user.getStatus())
|
|
return user != null && "0".equals(user.getUserType()) && "0".equals(user.getStatus())
|
|
|
&& "1".equals(user.getDelFlag()) && user.getCancellationDeadlineAt() != null
|
|
&& "1".equals(user.getDelFlag()) && user.getCancellationDeadlineAt() != null
|