package com.sdut.labex.Factory;

import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.entity.User;
import lombok.extern.slf4j.Slf4j;

/**
 * File: UserFactory
 * Created: 2023/6/15
 * Author: springforest
 * Description:
 */
@Slf4j
public class UserFactory {
    public static User createUser(JSONObject jsonObject) {
        User user = new User();
        log.info("解析用户信息");
        try {
            user.setId(jsonObject.getString("id"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析用户id失败");
        }

        try {
            user.setUsername(jsonObject.getString("username"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析用户姓名失败");
        }

        try {
            user.setPassword(jsonObject.getString("password"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析用户密码失败");
        }

        try {
            user.setClassName(jsonObject.getString("className"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析班级失败");
        }

        try {
            user.setEmail(jsonObject.getString("email"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析邮箱失败");
        }

        try {
            user.setDepartment(jsonObject.getString("department"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析学院失败");
        }

        try {
            user.setRole(jsonObject.getString("role"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析用户角色失败");
        }

        return user;
    }
}
