2026-04-23 11:59:31 +08:00
|
|
|
|
package com.labelsys.backend.context;
|
|
|
|
|
|
|
|
|
|
|
|
import com.labelsys.backend.entity.SysCompany;
|
|
|
|
|
|
import com.labelsys.backend.entity.SysUser;
|
|
|
|
|
|
import com.labelsys.backend.enums.UserPosition;
|
|
|
|
|
|
import com.labelsys.backend.enums.UserRole;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "当前登录用户上下文")
|
|
|
|
|
|
public record LoginUser(
|
|
|
|
|
|
@Schema(description = "用户ID") Long userId,
|
|
|
|
|
|
@Schema(description = "公司ID") Long companyId,
|
|
|
|
|
|
@Schema(description = "公司编码") String companyCode,
|
|
|
|
|
|
@Schema(description = "公司名称") String companyName,
|
|
|
|
|
|
@Schema(description = "手机号") String phone,
|
|
|
|
|
|
@Schema(description = "用户名,可为空", example = "alpha-reviewer") String username,
|
|
|
|
|
|
@Schema(description = "真实姓名") String realName,
|
|
|
|
|
|
@Schema(description = "角色,枚举值:EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") UserRole role,
|
2026-04-23 12:27:44 +08:00
|
|
|
|
@Schema(description = "岗位,枚举值:ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") UserPosition position,
|
2026-04-23 11:59:31 +08:00
|
|
|
|
@Schema(description = "是否必须修改密码") boolean mustChangePassword,
|
|
|
|
|
|
@Schema(description = "会话版本") Integer sessionVersion
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
public static LoginUser from(SysUser user, SysCompany company) {
|
|
|
|
|
|
return new LoginUser(
|
|
|
|
|
|
user.getId(),
|
|
|
|
|
|
company.getId(),
|
|
|
|
|
|
company.getCompanyCode(),
|
|
|
|
|
|
company.getCompanyName(),
|
|
|
|
|
|
user.getPhone(),
|
|
|
|
|
|
user.getUsername(),
|
|
|
|
|
|
user.getRealName(),
|
|
|
|
|
|
user.getRole(),
|
|
|
|
|
|
user.getPosition(),
|
|
|
|
|
|
Boolean.TRUE.equals(user.getMustChangePassword()),
|
|
|
|
|
|
user.getSessionVersion()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isPlatformAdmin() {
|
|
|
|
|
|
return "PLATFORM".equals(companyCode) && position == UserPosition.ADMIN;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|