diff --git a/src/main/java/com/light/delivery/service/LocationWebSocketHandler.java b/src/main/java/com/light/delivery/service/LocationWebSocketHandler.java index 129cc29..28acabe 100644 --- a/src/main/java/com/light/delivery/service/LocationWebSocketHandler.java +++ b/src/main/java/com/light/delivery/service/LocationWebSocketHandler.java @@ -80,6 +80,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { userInfo.setUserId(userId); userInfo.setName(getUserName(user)); // 使用辅助方法获取姓名 userInfo.setRole(userRole != null ? userRole : null); + userInfo.setAvatarPath(getUserAvatarPath(user)); // 获取用户头像路径 userInfo.setUserStatus(true); // 设置为已签到状态 userInfo.setLastUpdateTime(System.currentTimeMillis()); @@ -134,6 +135,26 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { } } + /** + * 获取用户头像路径的辅助方法 + * @param user 用户对象 + * @return 用户头像路径 + */ + private String getUserAvatarPath(User user) { + // 通过UserService获取完整的用户信息 + try { + com.light.delivery.dto.UserInfoResponse userInfo = userService.toUserInfoResponse(user); + // 通过employeeId查找对应的员工信息获取头像路径 + if (user.getEmployeeId() != null) { + com.light.delivery.model.Employee employee = userService.getEmployeeRepository().findById(user.getEmployeeId()).orElse(null); + return employee != null ? employee.getAvatarPath() : null; + } + } catch (Exception e) { + System.err.println("获取用户头像路径时出错: " + e.getMessage()); + } + return null; + } + /** * 用户签到(重载方法,不带初始位置) * @param userId 用户ID @@ -272,6 +293,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { userInfo.setUserId(userId); userInfo.setName(getUserName(user)); // 使用辅助方法获取姓名 userInfo.setRole(userRole); + userInfo.setAvatarPath(getUserAvatarPath(user)); // 获取用户头像路径 userInfo.setUserStatus(false); // 默认未签到 userInfo.setLastUpdateTime(System.currentTimeMillis()); userFullInfos.put(userId, userInfo); @@ -412,6 +434,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { userInfoWithLocation.setUserId(userInfo.getUserId()); userInfoWithLocation.setName(userInfo.getName()); userInfoWithLocation.setRole(userInfo.getRole()); + userInfoWithLocation.setAvatarPath(userInfo.getAvatarPath()); // 设置头像路径 userInfoWithLocation.setUserStatus(userInfo.isUserStatus()); userInfoWithLocation.setLastUpdateTime(userInfo.getLastUpdateTime()); @@ -461,6 +484,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { userInfoWithLocation.setUserId(userInfo.getUserId()); userInfoWithLocation.setName(userInfo.getName()); userInfoWithLocation.setRole(userInfo.getRole()); + userInfoWithLocation.setAvatarPath(userInfo.getAvatarPath()); // 设置头像路径 userInfoWithLocation.setUserStatus(userInfo.isUserStatus()); userInfoWithLocation.setLastUpdateTime(userInfo.getLastUpdateTime()); @@ -771,6 +795,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { private Long userId; private String name; private UserRole role; + private String avatarPath; private LocationData locationData; private boolean userStatus; private Long lastUpdateTime; @@ -784,6 +809,8 @@ public class LocationWebSocketHandler extends TextWebSocketHandler { public void setName(String name) { this.name = name; } public UserRole getRole() { return role; } public void setRole(UserRole role) { this.role = role; } + public String getAvatarPath() { return avatarPath; } + public void setAvatarPath(String avatarPath) { this.avatarPath = avatarPath; } public LocationData getLocationData() { return locationData; } public void setLocationData(LocationData locationData) { this.locationData = locationData; } public boolean isUserStatus() { return userStatus; }