fix:bug修改

This commit is contained in:
dzc committed 2026-07-30 20:20:55 +08:00
1 parent f2e2469b61
commit 00a0ab327c
8 files changed
+65 -2

No files matched your search

@@ -26,7 +26,11 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 第三方用户
@@ -111,12 +115,29 @@ public class ThirdUserServiceImpl extends ServiceImpl<UserMapper, User> implemen
.select(User::getId)
.in(User::getId, dto.getUserIdList())
);
List<Long> userIds = userIdList.stream().map(User::getId).toList();
Set<Long> onlineUserIds = new HashSet<>(imClient.getOnlineUser(userIds));
Map<Long, Long> lastActiveTimes = getLastActiveTimeSafely(userIds);
long now = System.currentTimeMillis();
return userIdList.stream().map(item -> {
ThirdUserOnLineStatusVo entity = new ThirdUserOnLineStatusVo();
entity.setId(item.getId());
entity.setOnline(imClient.isOnline(item.getId()));
entity.setOnline(onlineUserIds.contains(item.getId()));
entity.setLastActiveTime(lastActiveTimes.get(item.getId()));
if (Boolean.TRUE.equals(entity.getOnline()) && entity.getLastActiveTime() == null) {
entity.setLastActiveTime(now);
}
return entity;
}).toList();
}
private Map<Long, Long> getLastActiveTimeSafely(List<Long> userIds) {
try {
return imClient.getLastActiveTime(userIds);
} catch (Exception e) {
log.warn("查询用户最后活跃时间失败,userIds:{}", userIds, e);
return Collections.emptyMap();
}
}
}
@@ -15,4 +15,7 @@ public class ThirdUserOnLineStatusVo {
@Schema(description = "是否在线")
private Boolean online;
@Schema(description = "最后活跃时间,毫秒时间戳")
private Long lastActiveTime;
}