bugfix: 最后活跃时间

This commit is contained in:
2023-12-28 17:13:45 +08:00
parent 8ecab2f796
commit cd83b6020e
2 changed files with 7 additions and 5 deletions

View File

@@ -17,7 +17,7 @@ public interface LoginUserRepository extends BaseRepository<LoginUserEntity> {
@Transactional
@Modifying
@Query(
"update LoginUserEntity l set l.lastActiveTime = ?1 where l.id = ?2 and l.lastActiveTime < ?3")
"update LoginUserEntity l set l.lastActiveTime = ?1 where l.id = ?2 and (l.lastActiveTime < ?3 or l.lastActiveTime is null)")
int updateLastActiveTimeByIdAndLastActiveTimeLessThan(
LocalDateTime lastActiveTime, String id, LocalDateTime lastActiveTime1);

View File

@@ -124,12 +124,14 @@ public class LoginUserService extends BaseService<LoginUserEntity, LoginUserRepo
public void newLogin(LoginUserEntity entity) {
entity.setLoginTime(LocalDateTime.now());
LocalDateTime now = LocalDateTime.now();
entity.setLoginTime(now);
int seconds =
Integer.parseInt(
sysConfigService.getConfigVal(Constants.SYSCONFIG_SESSION_TIMEOUT));
entity.setTimeout(seconds);
entity.setExpireTime(LocalDateTime.now().plusSeconds(seconds));
entity.setExpireTime(now.plusSeconds(seconds));
entity.setLastActiveTime(now);
List<LoginUserEntity> exists = this.repository.findAllByUser(entity.getUser());
@@ -181,9 +183,9 @@ public class LoginUserService extends BaseService<LoginUserEntity, LoginUserRepo
for (Map.Entry<String, LocalDateTime> entry : copy.entrySet()) {
repository.updateLastActiveTimeByIdAndLastActiveTimeLessThan(
int count = repository.updateLastActiveTimeByIdAndLastActiveTimeLessThan(
entry.getValue(), entry.getKey(), entry.getValue());
log.info("更新会话最后活跃时间: {} to {}", entry.getKey(), entry.getValue());
log.info("更新会话最后活跃时间: {} to {}, count:{}", entry.getKey(), entry.getValue(), count);
}
}