|
|
package com.ibeetl.jlw.entity;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.auth0.jwt.interfaces.Claim;
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
import com.fasterxml.jackson.annotation.JsonValue;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
import lombok.*;
|
|
|
import lombok.experimental.Accessors;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* 第三方登录封装实体
|
|
|
*
|
|
|
* @Author: lx
|
|
|
* @Date: 2022/12/11 14:56
|
|
|
*/
|
|
|
@Data
|
|
|
@Builder
|
|
|
@NoArgsConstructor
|
|
|
@AllArgsConstructor
|
|
|
@Accessors(chain = true)
|
|
|
@ToString
|
|
|
public class LoginTodo implements Serializable {
|
|
|
|
|
|
private static final long serialVersionUID = 1257693451422916110L;
|
|
|
|
|
|
/**
|
|
|
* 账号(一般是#{@link CoreUser#getCode})
|
|
|
*/
|
|
|
private String username;
|
|
|
/**
|
|
|
* 密码
|
|
|
*/
|
|
|
private String password;
|
|
|
/**
|
|
|
* 角色ID 3老师 4学生
|
|
|
*/
|
|
|
private String roleid;
|
|
|
/**
|
|
|
* 教师ID
|
|
|
*/
|
|
|
private String teacherId;
|
|
|
/**
|
|
|
* 学生ID
|
|
|
*/
|
|
|
private String studentId;
|
|
|
/**
|
|
|
* 账号(一般是#{@link CoreUser#getName})
|
|
|
*/
|
|
|
private String name;
|
|
|
/**
|
|
|
* 性别
|
|
|
*/
|
|
|
private String sex;
|
|
|
/**
|
|
|
* 学校(院校)
|
|
|
*/
|
|
|
private String school;
|
|
|
/**
|
|
|
* 学校(院校ID)
|
|
|
*/
|
|
|
private String schoolId;
|
|
|
/**
|
|
|
* 应用ID
|
|
|
*/
|
|
|
private String applicationId;
|
|
|
/**
|
|
|
* 院系
|
|
|
*/
|
|
|
private String college;
|
|
|
/**
|
|
|
* 专业
|
|
|
*/
|
|
|
private String major;
|
|
|
/**
|
|
|
* 班级
|
|
|
*/
|
|
|
@JsonProperty("class")
|
|
|
private String schoolClass;
|
|
|
/**
|
|
|
* 学生学号
|
|
|
*/
|
|
|
private String studentNo;
|
|
|
|
|
|
/**
|
|
|
* 第三方系统中定义的权限ID
|
|
|
* 3老师 4学生
|
|
|
*/
|
|
|
@Getter
|
|
|
@RequiredArgsConstructor
|
|
|
public enum ThirdRole {
|
|
|
TEACHER_ROLE("3"), STUDENT_ROLE("4");
|
|
|
|
|
|
@JsonValue
|
|
|
final private String code;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转换成JSON格式
|
|
|
* @return
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
public String toJSONString() {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
|
return mapper.writeValueAsString(this);
|
|
|
}
|
|
|
|
|
|
public Map<String, ?> toMap() {
|
|
|
return JSONUtil.toBean(toJSONString(), HashMap.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* JSON转换成该实体类
|
|
|
*
|
|
|
* @return {@link LoginTodo}
|
|
|
* @Author: lx
|
|
|
* @Date: 2022/12/11 17:33
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
public static LoginTodo jsonToEntity(String json) {
|
|
|
if (ObjectUtil.isNotEmpty(json)) {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
return mapper.readValue(json, LoginTodo.class);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* JSON转换成该实体类
|
|
|
*
|
|
|
* @return {@link LoginTodo}
|
|
|
* @Author: lx
|
|
|
* @Date: 2022/12/11 17:33
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
public static LoginTodo jsonToEntity(Map<String, Claim> claims) {
|
|
|
if (ObjectUtil.isNotEmpty(claims)) {
|
|
|
Map<String, String> tempMap = new HashMap(20);
|
|
|
claims.forEach((key, val) -> {
|
|
|
tempMap.put(key, val.asString());
|
|
|
});
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
return mapper.readValue(JSONUtil.toJsonStr(tempMap), LoginTodo.class);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
} |