package com.sdut.labex.Factory;

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

/**
 * File: ExperimentFactory
 * Created: 2023/6/13
 * Author: springforest
 * Description:
 */
@Slf4j
public class ExperimentFactory {
    public static Experiment createExperiment(JSONObject jsonObject) {
        Experiment experiment = new Experiment();
        log.info("解析实验信息");
        log.info("实验信息为：{}", jsonObject);
        try {
            experiment.setId(jsonObject.getInteger("id"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析实验id失败");
        }

        try {
            experiment.setName(jsonObject.getString("name"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析实验名称失败");
        }

        try {
            experiment.setStatus(jsonObject.getInteger("status"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析实验状态失败");
        }

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

        try {
            experiment.setApplyTime(jsonObject.getDate("applyTime"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析实验申请时间失败");
        }

        try {
            experiment.setApplyUser(jsonObject.getString("applyUser"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析实验申请用户失败");
        }

        try {
            experiment.setAnnex(jsonObject.getString("annex"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("解析实验申请附件失败");
        }
        return experiment;
    }
}
