package com.qmth.distributed.print.business.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.teachcloud.common.contant.SystemConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 同步考生成绩表
 * </p>
 *
 * @author wangliang
 * @since 2021-10-28
 */
@ApiModel(value = "TSyncExamStudentScore对象", description = "同步考生成绩表")
public class TSyncExamStudentScore implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @ApiModelProperty(value = "学校id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long schoolId;

    @ApiModelProperty(value = "机构id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long orgId;

    @ApiModelProperty(value = "学期id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long semesterId;

    @ApiModelProperty(value = "云阅卷考试id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long examId;

    @ApiModelProperty(value = "云阅卷考试标识")
    private String examCode;

    @ApiModelProperty(value = "准考证号")
    private String examNumber;

    @ApiModelProperty(value = "学号")
    private String studentCode;

    @ApiModelProperty(value = "姓名")
    private String name;

    @ApiModelProperty(value = "科目代码")
    private String subjectCode;

    @ApiModelProperty(value = "科目名称")
    private String subjectName;

    @ApiModelProperty(value = "试卷类型")
    private String paperType;

    @ApiModelProperty(value = "学院")
    private String college;

    @ApiModelProperty(value = "班级")
    private String clazzName;

    @ApiModelProperty(value = "教师")
    private String teacher;

    @ApiModelProperty(value = "考生状态，1-正常，2-缺考(包含未上传)，3-违纪")
    private Integer status;

    @ApiModelProperty(value = "原卷url")
    private String sheetUrls;

    @ApiModelProperty(value = "总分")
    private Double totalScore;

    @ApiModelProperty(value = "客观题分数")
    private Double objectiveScore;

    @ApiModelProperty(value = "主观题分数")
    private Double subjectiveScore;

    @ApiModelProperty(value = "同步数据json")
    private String syncData;

    @ApiModelProperty(value = "轨迹图地址")
    private String trajectoryUrls;

    @ApiModelProperty(value = "创建人id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long createId;

    @ApiModelProperty(value = "创建时间")
    private Long createTime;

    @ApiModelProperty(value = "专业id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long majorId;

    @ApiModelProperty(value = "班级id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long clazzId;

    @ApiModelProperty(value = "轨迹图文件")
    @TableField(exist = false)
    private List<File> trajectoryFileList;

    @ApiModelProperty(value = "轨迹图url")
    @TableField(exist = false)
    private List<String> trailUrls;

    public void setErrorInfo() {
        this.trajectoryFileList = null;
        this.trajectoryUrls = null;
//        this.path = null;
    }

    public TSyncExamStudentScore() {

    }

    public TSyncExamStudentScore(Map map) {
        this.id = SystemConstant.getDbUuid();
        this.schoolId = (Long) map.get(SystemConstant.SCHOOL_ID);
        this.orgId = (Long) map.get("orgId");
        this.semesterId = (Long) map.get("semesterId");
        this.majorId = (Long) map.get("majorId");
        this.clazzId = (Long) map.get("clazzId");
        this.examId = Long.parseLong(String.valueOf(map.get("examId")));
        this.examCode = (String) map.get("examCode");
        this.examNumber = (String) map.get("examNumber");
        this.studentCode = (String) map.get("studentCode");
        this.name = (String) map.get("name");
        this.subjectCode = (String) map.get("subjectCode");
        this.subjectName = (String) map.get("subjectName");
        this.paperType = (String) map.get("paperType");
        this.college = (String) map.get("college");
        this.clazzName = (String) map.get("className");
        this.teacher = (String) map.get("teacher");
        this.status = (Integer) map.get("status");
        JSONArray jsonArray = (JSONArray) map.get("sheetUrls");
        if (Objects.nonNull(jsonArray) && jsonArray.size() > 0) {
            this.sheetUrls = jsonArray.toJSONString();
        }
        this.totalScore = Double.parseDouble(String.valueOf(map.get("totalScore")));
        this.objectiveScore = Double.parseDouble(String.valueOf(map.get("objectiveScore")));
        this.subjectiveScore = Double.parseDouble(String.valueOf(map.get("subjectiveScore")));
        this.createId = (Long) map.get("userId");
        this.createTime = System.currentTimeMillis();

        JSONObject jsonObject = new JSONObject();
        JSONArray objectiveScoreDetailJsonArray = (JSONArray) map.get("objectiveScoreDetail");
        JSONArray subjectiveScoreDetailJsonArray = (JSONArray) map.get("subjectiveScoreDetail");
        JSONObject markTagsJsonObject = (JSONObject) map.get("markTags");
        if (Objects.nonNull(objectiveScoreDetailJsonArray) && objectiveScoreDetailJsonArray.size() > 0) {
            jsonObject.put("objectiveScoreDetail", objectiveScoreDetailJsonArray.toJSONString());
        }
        if (Objects.nonNull(subjectiveScoreDetailJsonArray) && subjectiveScoreDetailJsonArray.size() > 0) {
            jsonObject.put("subjectiveScoreDetail", subjectiveScoreDetailJsonArray.toJSONString());
        }
        if (Objects.nonNull(markTagsJsonObject)) {
            jsonObject.put("markTags", markTagsJsonObject.toJSONString());
        }
        if (!jsonObject.isEmpty()) {
            this.syncData = jsonObject.toJSONString();
        }
    }

    public List<String> getTrailUrls() {
        if (Objects.isNull(trailUrls)) {
            return new ArrayList<>();
        } else {
            return trailUrls;
        }
    }

    public void setTrailUrls(List<String> trailUrls) {
        this.trailUrls = trailUrls;
    }

    public Long getClazzId() {
        return clazzId;
    }

    public void setClazzId(Long clazzId) {
        this.clazzId = clazzId;
    }

    public Long getMajorId() {
        return majorId;
    }

    public void setMajorId(Long majorId) {
        this.majorId = majorId;
    }

    public List<File> getTrajectoryFileList() {
        return trajectoryFileList;
    }

    public void setTrajectoryFileList(List<File> trajectoryFileList) {
        this.trajectoryFileList = trajectoryFileList;
    }

    public Long getSemesterId() {
        return semesterId;
    }

    public void setSemesterId(Long semesterId) {
        this.semesterId = semesterId;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(Long schoolId) {
        this.schoolId = schoolId;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public Long getExamId() {
        return examId;
    }

    public void setExamId(Long examId) {
        this.examId = examId;
    }

    public String getExamCode() {
        return examCode;
    }

    public void setExamCode(String examCode) {
        this.examCode = examCode;
    }

    public String getExamNumber() {
        return examNumber;
    }

    public void setExamNumber(String examNumber) {
        this.examNumber = examNumber;
    }

    public String getStudentCode() {
        return studentCode;
    }

    public void setStudentCode(String studentCode) {
        this.studentCode = studentCode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSubjectCode() {
        return subjectCode;
    }

    public void setSubjectCode(String subjectCode) {
        this.subjectCode = subjectCode;
    }

    public String getSubjectName() {
        return subjectName;
    }

    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }

    public String getPaperType() {
        return paperType;
    }

    public void setPaperType(String paperType) {
        this.paperType = paperType;
    }

    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public String getClazzName() {
        return clazzName;
    }

    public void setClazzName(String clazzName) {
        this.clazzName = clazzName;
    }

    public String getTeacher() {
        return teacher;
    }

    public void setTeacher(String teacher) {
        this.teacher = teacher;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getSheetUrls() {
        return sheetUrls;
    }

    public void setSheetUrls(String sheetUrls) {
        this.sheetUrls = sheetUrls;
    }

    public Double getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Double totalScore) {
        this.totalScore = totalScore;
    }

    public Double getObjectiveScore() {
        return objectiveScore;
    }

    public void setObjectiveScore(Double objectiveScore) {
        this.objectiveScore = objectiveScore;
    }

    public Double getSubjectiveScore() {
        return subjectiveScore;
    }

    public void setSubjectiveScore(Double subjectiveScore) {
        this.subjectiveScore = subjectiveScore;
    }

    public String getSyncData() {
        return syncData;
    }

    public void setSyncData(String syncData) {
        this.syncData = syncData;
    }

    public String getTrajectoryUrls() {
        return trajectoryUrls;
    }

    public void setTrajectoryUrls(String trajectoryUrls) {
        this.trajectoryUrls = trajectoryUrls;
    }

    public Long getCreateId() {
        return createId;
    }

    public void setCreateId(Long createId) {
        this.createId = createId;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
}
