修改头像的方式
All checks were successful
构建并部署 Spring Boot 应用 / build-and-deploy (push) Successful in 23m37s
All checks were successful
构建并部署 Spring Boot 应用 / build-and-deploy (push) Successful in 23m37s
This commit is contained in:
@@ -80,6 +80,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
|
|||||||
userInfo.setUserId(userId);
|
userInfo.setUserId(userId);
|
||||||
userInfo.setName(getUserName(user)); // 使用辅助方法获取姓名
|
userInfo.setName(getUserName(user)); // 使用辅助方法获取姓名
|
||||||
userInfo.setRole(userRole != null ? userRole : null);
|
userInfo.setRole(userRole != null ? userRole : null);
|
||||||
|
userInfo.setAvatarPath(getUserAvatarPath(user)); // 获取用户头像路径
|
||||||
userInfo.setUserStatus(true); // 设置为已签到状态
|
userInfo.setUserStatus(true); // 设置为已签到状态
|
||||||
userInfo.setLastUpdateTime(System.currentTimeMillis());
|
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
|
* @param userId 用户ID
|
||||||
@@ -272,6 +293,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
|
|||||||
userInfo.setUserId(userId);
|
userInfo.setUserId(userId);
|
||||||
userInfo.setName(getUserName(user)); // 使用辅助方法获取姓名
|
userInfo.setName(getUserName(user)); // 使用辅助方法获取姓名
|
||||||
userInfo.setRole(userRole);
|
userInfo.setRole(userRole);
|
||||||
|
userInfo.setAvatarPath(getUserAvatarPath(user)); // 获取用户头像路径
|
||||||
userInfo.setUserStatus(false); // 默认未签到
|
userInfo.setUserStatus(false); // 默认未签到
|
||||||
userInfo.setLastUpdateTime(System.currentTimeMillis());
|
userInfo.setLastUpdateTime(System.currentTimeMillis());
|
||||||
userFullInfos.put(userId, userInfo);
|
userFullInfos.put(userId, userInfo);
|
||||||
@@ -412,6 +434,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
|
|||||||
userInfoWithLocation.setUserId(userInfo.getUserId());
|
userInfoWithLocation.setUserId(userInfo.getUserId());
|
||||||
userInfoWithLocation.setName(userInfo.getName());
|
userInfoWithLocation.setName(userInfo.getName());
|
||||||
userInfoWithLocation.setRole(userInfo.getRole());
|
userInfoWithLocation.setRole(userInfo.getRole());
|
||||||
|
userInfoWithLocation.setAvatarPath(userInfo.getAvatarPath()); // 设置头像路径
|
||||||
userInfoWithLocation.setUserStatus(userInfo.isUserStatus());
|
userInfoWithLocation.setUserStatus(userInfo.isUserStatus());
|
||||||
userInfoWithLocation.setLastUpdateTime(userInfo.getLastUpdateTime());
|
userInfoWithLocation.setLastUpdateTime(userInfo.getLastUpdateTime());
|
||||||
|
|
||||||
@@ -461,6 +484,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
|
|||||||
userInfoWithLocation.setUserId(userInfo.getUserId());
|
userInfoWithLocation.setUserId(userInfo.getUserId());
|
||||||
userInfoWithLocation.setName(userInfo.getName());
|
userInfoWithLocation.setName(userInfo.getName());
|
||||||
userInfoWithLocation.setRole(userInfo.getRole());
|
userInfoWithLocation.setRole(userInfo.getRole());
|
||||||
|
userInfoWithLocation.setAvatarPath(userInfo.getAvatarPath()); // 设置头像路径
|
||||||
userInfoWithLocation.setUserStatus(userInfo.isUserStatus());
|
userInfoWithLocation.setUserStatus(userInfo.isUserStatus());
|
||||||
userInfoWithLocation.setLastUpdateTime(userInfo.getLastUpdateTime());
|
userInfoWithLocation.setLastUpdateTime(userInfo.getLastUpdateTime());
|
||||||
|
|
||||||
@@ -771,6 +795,7 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
|
|||||||
private Long userId;
|
private Long userId;
|
||||||
private String name;
|
private String name;
|
||||||
private UserRole role;
|
private UserRole role;
|
||||||
|
private String avatarPath;
|
||||||
private LocationData locationData;
|
private LocationData locationData;
|
||||||
private boolean userStatus;
|
private boolean userStatus;
|
||||||
private Long lastUpdateTime;
|
private Long lastUpdateTime;
|
||||||
@@ -784,6 +809,8 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
|
|||||||
public void setName(String name) { this.name = name; }
|
public void setName(String name) { this.name = name; }
|
||||||
public UserRole getRole() { return role; }
|
public UserRole getRole() { return role; }
|
||||||
public void setRole(UserRole role) { this.role = 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 LocationData getLocationData() { return locationData; }
|
||||||
public void setLocationData(LocationData locationData) { this.locationData = locationData; }
|
public void setLocationData(LocationData locationData) { this.locationData = locationData; }
|
||||||
public boolean isUserStatus() { return userStatus; }
|
public boolean isUserStatus() { return userStatus; }
|
||||||
|
|||||||
Reference in New Issue
Block a user