mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
bugfix
This commit is contained in:
@@ -180,14 +180,13 @@ public class LoginUserService extends BaseService<LoginUserEntity, LoginUserRepo
|
||||
|
||||
lastActivateTime.clear();
|
||||
|
||||
|
||||
for (Map.Entry<String, LocalDateTime> entry : copy.entrySet()) {
|
||||
|
||||
int count = repository.updateLastActiveTimeByIdAndLastActiveTimeLessThan(
|
||||
entry.getValue(), entry.getKey(), entry.getValue());
|
||||
int count =
|
||||
repository.updateLastActiveTimeByIdAndLastActiveTimeLessThan(
|
||||
entry.getValue(), entry.getKey(), entry.getValue());
|
||||
log.info("更新会话最后活跃时间: {} to {}, count:{}", entry.getKey(), entry.getValue(), count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void touch(LoginUserDto loginDto) {
|
||||
@@ -250,25 +249,28 @@ public class LoginUserService extends BaseService<LoginUserEntity, LoginUserRepo
|
||||
public void deleteLogin(String sessionId) {
|
||||
|
||||
try {
|
||||
LoginUserEntity loginUser = this.get(sessionId);
|
||||
|
||||
if (this.repository.existsById(sessionId)) {
|
||||
|
||||
this.repository.deleteById(sessionId);
|
||||
LoginUserEntity loginUser = this.get(sessionId);
|
||||
|
||||
// 如果当前用户没有其他会话, 则清除用户缓存
|
||||
if (this.countByUserId(loginUser.getUser().getId()) == 0) {
|
||||
userService.clearUserCache(loginUser.getUser().getId());
|
||||
rateLimiterService.destroyRL(sessionId, loginUser.getUser().getId());
|
||||
this.repository.deleteById(sessionId);
|
||||
|
||||
// 如果当前用户没有其他会话, 则清除用户缓存
|
||||
if (this.countByUserId(loginUser.getUser().getId()) == 0) {
|
||||
userService.clearUserCache(loginUser.getUser().getId());
|
||||
rateLimiterService.destroyRL(sessionId, loginUser.getUser().getId());
|
||||
|
||||
} else {
|
||||
|
||||
rateLimiterService.destroyRL(sessionId, null);
|
||||
}
|
||||
}else {
|
||||
|
||||
rateLimiterService.destroyRL(sessionId, null);
|
||||
log.warn("会话 {} 不存在, 无需删除登录信息", sessionId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("删除会话失败 {}",sessionId, e);
|
||||
log.warn("删除会话失败 {}", sessionId, e);
|
||||
}
|
||||
|
||||
this.clearCache(sessionId);
|
||||
@@ -276,14 +278,17 @@ public class LoginUserService extends BaseService<LoginUserEntity, LoginUserRepo
|
||||
|
||||
private int countByUserId(String id) {
|
||||
|
||||
|
||||
return Math.toIntExact(this.count(new Specification<LoginUserEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<LoginUserEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.equal(root.get("user").get("id"), id);
|
||||
}
|
||||
}));
|
||||
|
||||
return Math.toIntExact(
|
||||
this.count(
|
||||
new Specification<LoginUserEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<LoginUserEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.equal(root.get("user").get("id"), id);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void logout(IdRequest request) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import jakarta.annotation.PostConstruct;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -131,7 +132,7 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
|
||||
List<String> names = this.repository.findNamesByIds(strings);
|
||||
|
||||
Map<String, String> javaMap = Stream.ofAll(names).toMap(x -> x.split(",")[0], x -> x.split(",")[1]).toJavaMap();
|
||||
Map<String, String> javaMap = Stream.ofAll(names).filter(StringUtils::isNotBlank).toMap(x -> x.split(",")[0], x -> x.split(",")[1]).toJavaMap();
|
||||
|
||||
strings.forEach(x -> javaMap.putIfAbsent(x, null));
|
||||
|
||||
|
||||
@@ -125,11 +125,13 @@ public class SessionService {
|
||||
|
||||
loginDto = loginUserService.getFromCache(sessionId);
|
||||
} catch (Exception e) {
|
||||
log.warn("会话已过期 {}", sessionId, e);
|
||||
log.warn("会话已过期 {}", sessionId);
|
||||
logout(sessionId);
|
||||
throw new BizException("invalidToken", "会话已过期,请重新登录");
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
|
||||
@@ -411,6 +411,7 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
|
||||
Map<String, String> javaMap =
|
||||
Stream.ofAll(names)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.toMap(x -> x.split(",")[0], x -> x.split(",")[1])
|
||||
.toJavaMap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user