# 登录功能时序图

## 1. 用户登录时序图

```mermaid
sequenceDiagram
    participant 用户 as 用户
    participant SysLoginController as SysLoginController
    participant SysLoginService as SysLoginService
    participant ConfigService as ISysConfigService
    participant RedisCache as RedisCache
    participant AuthenticationManager as AuthenticationManager
    participant UserService as ISysUserService
    participant TokenService as TokenService
    participant AsyncManager as AsyncManager

    用户->>SysLoginController: 发送登录请求(/login)
    SysLoginController->>SysLoginController: 解析LoginBody参数
    SysLoginController->>ConfigService: 查询AES加密配置
    ConfigService-->>SysLoginController: 返回加密配置
    SysLoginController->>SysLoginController: 解密用户名、密码、验证码
    SysLoginController->>SysLoginService: 调用login方法
    SysLoginService->>SysLoginService: 验证码校验(validateCaptcha)
    SysLoginService->>ConfigService: 查询验证码开关
    ConfigService-->>SysLoginService: 返回验证码开关状态
    SysLoginService->>RedisCache: 获取缓存验证码
    RedisCache-->>SysLoginService: 返回验证码
    SysLoginService->>RedisCache: 删除已使用的验证码
    SysLoginService->>SysLoginService: 登录前置校验(loginPreCheck)
    SysLoginService->>ConfigService: 查询IP黑名单
    ConfigService-->>SysLoginService: 返回IP黑名单
    SysLoginService->>AuthenticationManager: 认证用户(authenticate)
    AuthenticationManager->>UserDetailsServiceImpl: 加载用户详情(loadUserByUsername)
    UserDetailsServiceImpl->>UserService: 查询用户(selectUserByUserName)
    UserService-->>UserDetailsServiceImpl: 返回用户信息
    UserDetailsServiceImpl->>SysPasswordService: 验证用户状态
    SysPasswordService-->>UserDetailsServiceImpl: 验证结果
    UserDetailsServiceImpl-->>AuthenticationManager: 返回LoginUser
    AuthenticationManager-->>SysLoginService: 返回认证结果
    SysLoginService->>AsyncManager: 记录登录日志(recordLogininfor)
    SysLoginService->>UserService: 记录登录信息(updateLoginInfo)
    SysLoginService->>TokenService: 创建Token(createToken)
    TokenService->>TokenService: 生成UUID令牌
    TokenService->>TokenService: 设置用户代理信息
    TokenService->>TokenService: 刷新Token(refreshToken)
    TokenService->>RedisCache: 缓存LoginUser
    TokenService-->>SysLoginService: 返回Token
    SysLoginService-->>SysLoginController: 返回Token
    SysLoginController-->>用户: 返回登录结果{token: "..."}
```

## 2. 初始密码修改时序图

```mermaid
sequenceDiagram
    participant 用户 as 用户
    participant SysLoginController as SysLoginController
    participant SysLoginService as SysLoginService
    participant ConfigService as ISysConfigService
    participant UserService as ISysUserService
    participant SecurityUtils as SecurityUtils

    用户->>SysLoginController: 发送初始密码修改请求(/initPassword)
    SysLoginController->>SysLoginController: 解析LoginBody参数
    SysLoginController->>ConfigService: 查询AES加密配置
    ConfigService-->>SysLoginController: 返回加密配置
    SysLoginController->>SysLoginController: 解密参数
    SysLoginController->>SysLoginService: 验证用户登录(login)
    SysLoginService->>AuthenticationManager: 认证用户
    AuthenticationManager-->>SysLoginService: 认证结果
    SysLoginController->>ConfigService: 查询初始密码配置
    ConfigService-->>SysLoginController: 返回初始密码
    SysLoginController->>SecurityUtils: 验证新密码强度(validatePassword)
    SecurityUtils-->>SysLoginController: 返回验证结果
    SysLoginController->>UserService: 查询用户(selectUserByUserName)
    UserService-->>SysLoginController: 返回用户信息
    SysLoginController->>SecurityUtils: 加密新密码(encryptPassword)
    SecurityUtils-->>SysLoginController: 返回加密后的密码
    SysLoginController->>UserService: 重置用户密码(resetUserPwd)
    UserService-->>SysLoginController: 返回更新结果
    SysLoginController-->>用户: 返回密码修改结果
```

## 3. 获取用户信息时序图

```mermaid
sequenceDiagram
    participant 用户 as 用户
    participant SysLoginController as SysLoginController
    participant SecurityUtils as SecurityUtils
    participant SysPermissionService as SysPermissionService
    participant TokenService as TokenService
    participant PostService as ISysPostService
    participant ConfigService as ISysConfigService

    用户->>SysLoginController: 请求用户信息(/getInfo)
    
    SysLoginController->>SecurityUtils: 获取当前登录用户(getLoginUser)
    SecurityUtils-->>SysLoginController: 返回LoginUser
    SysLoginController->>SysPermissionService: 获取角色权限(getRolePermission)
    SysPermissionService-->>SysLoginController: 返回角色权限集合
    SysLoginController->>SysPermissionService: 获取菜单权限(getMenuPermission)
    SysPermissionService-->>SysLoginController: 返回菜单权限集合
    SysLoginController->>TokenService: 刷新Token(refreshToken)
    SysLoginController->>PostService: 获取岗位类型(getHomePostType)
    PostService-->>SysLoginController: 返回岗位类型
    SysLoginController->>ConfigService: 查询密码配置
    ConfigService-->>SysLoginController: 返回密码配置
    SysLoginController-->>用户: 返回用户信息{user, roles, permissions, ...}
```

## 4. 获取路由信息时序图

```mermaid
sequenceDiagram
    participant 用户 as 用户
    participant SysLoginController as SysLoginController
    participant SecurityUtils as SecurityUtils
    participant MenuService as ISysMenuService

    用户->>SysLoginController: 请求路由信息(/getRouters)
    
    SysLoginController->>SecurityUtils: 获取用户ID(getUserId)
    SecurityUtils-->>SysLoginController: 返回用户ID
    SysLoginController->>MenuService: 查询菜单树(selectMenuTreeByUserId)
    MenuService-->>SysLoginController: 返回菜单列表
    SysLoginController->>MenuService: 构建路由(buildMenus)
    MenuService-->>SysLoginController: 返回路由结构
    SysLoginController-->>用户: 返回路由信息
```
