package com.sdut.labex.Factory;

import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.entity.BorrowInfo;
import com.sdut.labex.utils.UserHolder;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * File: BorrowInfoFactory
 * Created: 2023/6/13
 * Author: springforest
 * Description:
 */
@Slf4j
public class BorrowInfoFactory {
    public static BorrowInfo createBorrowInfo(JSONObject jsonObject) {
        BorrowInfo borrowInfo = new BorrowInfo();
        try {
            borrowInfo.setId(jsonObject.getInteger("id"));
            borrowInfo.setApplyUser(UserHolder.getUser().getUsername());
            borrowInfo.setDate(jsonObject.getDate("date"));
            borrowInfo.setApplyDate(new Date());
            borrowInfo.setIsAdmit(jsonObject.getInteger("isAdmit"));
            borrowInfo.setRoomName(jsonObject.getString("roomName"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("json解析错误");
            return null;
        }

        return borrowInfo;
    }
}
