@ -28,17 +28,18 @@ import java.util.List;
import java.util.Optional ;
/ * *
* UserServiceImpl 类 实 现 了 UserService 接 口 , 提 供 了 用 户 信 息 管 理 的 相 关 服 务 。
* /
* UserService 实 现 类
*
* @author xcs
* @date 2024 年 6 月 15 日 16 : 06 : 37
* * /
@Slf4j
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
//注入的 ContactHeadImgUrlRepository, 用于访问用户头像信息。
private final ContactHeadImgUrlRepository contactHeadImgUrlRepository ;
//注入的 ContactRepository, 用于访问用户联系信息。
private final ContactRepository contactRepository ;
//注入的 UserMapping, 用于转换用户信息的数据模型。
private final UserMapping userMapping ;
@Override
@ -63,10 +64,7 @@ public class UserServiceImpl implements UserService {
}
return userMapping . convert ( userBO ) ;
}
/ * *
* 获 取 当 前 登 录 用 户 头 像 的 URL 。
* @return 用 户 头 像 的 URL , 如 果 用 户 不 存 在 则 返 回 null 。
* /
@Override
public String avatar ( ) {
String wxId = currentUser ( ) ;
@ -76,10 +74,7 @@ public class UserServiceImpl implements UserService {
}
return getAvatar ( wxId ) ;
}
/ * *
* 获 取 当 前 登 录 用 户 的 昵 称 。
* @return 用 户 昵 称 , 如 果 用 户 不 存 在 则 返 回 null 。
* /
@Override
public String nickname ( ) {
String wxId = currentUser ( ) ;
@ -89,10 +84,7 @@ public class UserServiceImpl implements UserService {
}
return getNickName ( wxId ) ;
}
/ * *
* 获 取 所 有 用 户 的 信 息 列 表 。
* @return UserVO 列 表 , 包 含 所 有 用 户 的 信 息 。
* /
@Override
public List < UserVO > users ( ) {
// 用户信息
@ -112,18 +104,12 @@ public class UserServiceImpl implements UserService {
}
return users ;
}
/ * *
* 切 换 当 前 登 录 的 用 户 。
* @param wxId 要 切 换 到 的 用 户 微 信 ID 。
* /
@Override
public void switchUser ( String wxId ) {
FileUtil . writeString ( wxId , DirUtil . getSwitchUserDir ( ) , "UTF-8" ) ;
}
/ * *
* 获 取 当 前 登 录 的 用 户 微 信 ID 。
* @return 当 前 登 录 的 用 户 微 信 ID , 如 果 没 有 用 户 登 录 则 返 回 null 。
* /
@Override
public String currentUser ( ) {
// 获取用户切换配置目录
@ -137,19 +123,12 @@ public class UserServiceImpl implements UserService {
}
return FileUtil . readUtf8String ( switchUserDir ) ;
}
/ * *
* 保 存 用 户 信 息 。
* @param userBO 要 保 存 的 用 户 信 息 对 象 。
* /
@Override
public void saveUser ( UserBO userBO ) {
FileUtil . writeString ( JSONUtil . toJsonStr ( userBO ) , DirUtil . getUserDir ( userBO . getWxId ( ) ) , "UTF-8" ) ;
}
/ * *
* 获 取 用 户 的 基 本 信 息 路 径 。
* @param wxId 用 户 的 微 信 ID 。
* @return 用 户 的 基 本 信 息 路 径 , 如 果 用 户 不 存 在 则 返 回 null 。
* /
@Override
public String getBasePath ( String wxId ) {
String userDir = DirUtil . getUserDir ( wxId ) ;
@ -163,8 +142,9 @@ public class UserServiceImpl implements UserService {
}
/ * *
* 获 取 微 信 ID 列 表 。
* @return 包 含 所 有 微 信 ID 的 列 表 。
* 获 取 微 信 Id
*
* @return wxIds
* /
private List < String > getWxIds ( ) {
// 用户信息
@ -191,9 +171,10 @@ public class UserServiceImpl implements UserService {
}
/ * *
* 根 据 微 信 ID 获 取 用 户 头 像 。
* @param wxId 用 户 的 微 信 ID 。
* @return 用 户 头 像 的 URL 。
* 根 据 wxId 获 取 头 像
*
* @param wxId wxId
* @return 头 像
* /
private String getAvatar ( String wxId ) {
DynamicDataSourceContextHolder . push ( DSNameUtil . getDSName ( wxId , DataSourceType . MICRO_MSG_DB ) ) ;
@ -203,9 +184,10 @@ public class UserServiceImpl implements UserService {
}
/ * *
* 根 据 微 信 ID 获 取 用 户 昵 称 。
* @param wxId 用 户 的 微 信 ID 。
* @return 用 户 昵 称 。
* 根 据 wxId 获 取 昵 称
*
* @param wxId wxId
* @return 昵 称
* /
private String getNickName ( String wxId ) {
DynamicDataSourceContextHolder . push ( DSNameUtil . getDSName ( wxId , DataSourceType . MICRO_MSG_DB ) ) ;