package cn.com.qmth.examcloud.core.questions.dao.entity;

import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import cn.com.qmth.examcloud.core.questions.base.em.enums.ExamType;
import cn.com.qmth.examcloud.core.questions.base.enums.ExamFileType;
import cn.com.qmth.examcloud.core.questions.dao.entity.base.MongoBaseEntity;
import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.ComputerTestPaper;

/**
 * @author chenken
 * @date 2017年7月13日 下午4:22:24
 * @company QMTH
 * @description 考试文件
 */
public class ExamFile extends MongoBaseEntity {

    /**
	 * 
	 */
	private static final long serialVersionUID = -6244613661379455829L;
	
	/**
	 * 试卷ID
	 */
	private String paperId;
	/**
     * 机构ID
     */
    private String orgId;
    /**
     * 机构名称
     */
    private String orgName;
    /**
     * 考试ID
     */
    private String examId;
    /**
     * 考试名称
     */
    private String examName;
    /**
     * 考试类型
     */
    private ExamType examType;
    /**
     * 试卷类型
     */
    private String groupCode;
    /**
     * 课程ID
     */
    private String courseId;
    /**
     * 课程名称
     */
    private String courseName;
    /**
     * 文件名称
     */
    private String fileName;
    /**
     * 文件类型
     * 试卷
     * 答案
     * 试卷结构
     * 音频文件
     * 加密数据包
     */
    private ExamFileType examFileType;
    /**
     * 文件存储路径
     */
    private String filePath;
    /**
     * 创建人
     */
    private String createUser;
    /**
     * 创建时间
     */
    private Date createTime;

    public ExamFile() {

    }

    /**
     * 普通
     *
     * @param paperId
     * @param extractConfig
     * @param filePath
     * @param examFileType
     * @param fileSuffix
     */
    public ExamFile(String paperId, ExtractConfig extractConfig, String filePath, ExamFileType examFileType, String fileSuffix) {
    	this.paperId=paperId;
    	this.orgId = extractConfig.getOrgId();
        this.orgName = extractConfig.getOrgName();
        this.examId = extractConfig.getExamId() + "";
        this.examName = extractConfig.getExamName();
        this.examType = ExamType.strToEnum(extractConfig.getExamType());
        this.courseId = extractConfig.getCourseCode();
        this.courseName = extractConfig.getCourseName();
        //this.groupCode = findGroupCode(extractConfig,paperId);
        //this.fileName = extractConfig.getCourseName()+"_"+extractConfig.getCourseCode()+"_"+examFileType.getName()+"_"+this.groupCode+fileSuffix;
        this.filePath = filePath;
        this.examFileType = examFileType;
    }

    /**
     * 机考
     *
     * @param extractConfig
     * @param filePath
     * @param examFileType
     * @param computerTestPaper
     * @param fileSuffix
     */
    public ExamFile(ComputerTestPaper computerTestPaper, ExtractConfig extractConfig, String filePath, ExamFileType examFileType, String fileSuffix) {
        this.paperId=computerTestPaper.getId();
    	this.orgId = extractConfig.getOrgId();
        this.orgName = extractConfig.getOrgName();
        this.examId = extractConfig.getExamId() + "";
        this.examName = extractConfig.getExamName();
        this.examType = ExamType.strToEnum(extractConfig.getExamType());
        this.courseId = extractConfig.getCourseCode();
        this.courseName = extractConfig.getCourseName();
        //this.groupCode = findGroupCode(extractConfig,computerTestPaper.getId());
        this.fileName = extractConfig.getCourseCode() + "_" + computerTestPaper.getName() + fileSuffix;
        this.filePath = filePath;
        this.examFileType = examFileType;
    }

    /**
     * 筛选出groupCode
     *
     * @param extractConfig
     * @param paperId
     * @return
     */
    private String findGroupCode(ExtractConfig extractConfig, String paperId) {
        String groupCode = "";
        Map<String, String> paperIdMap = extractConfig.getFinishedPaperIdMap();
        Set<Entry<String, String>> entry = paperIdMap.entrySet();
        Iterator<Entry<String, String>> iterator = entry.iterator();
        while (iterator.hasNext()) {
            Entry<String, String> next = iterator.next();
            if (paperId.equals(next.getValue())) {
                groupCode = next.getKey();
                break;
            }
        }
        return groupCode;
    }

    public ExamFile(String examId, String orgId) {
        this.examId = examId;
        this.orgId = orgId;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public String getExamId() {
        return examId;
    }

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

    public String getExamName() {
        return examName;
    }

    public void setExamName(String examName) {
        this.examName = examName;
    }

    public ExamType getExamType() {
        return examType;
    }

    public void setExamType(ExamType examType) {
        this.examType = examType;
    }

    public String getCourseId() {
        return courseId;
    }

    public void setCourseId(String courseId) {
        this.courseId = courseId;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public ExamFileType getExamFileType() {
        return examFileType;
    }

    public void setExamFileType(ExamFileType examFileType) {
        this.examFileType = examFileType;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public Date getCreateTime() {
        return createTime;
    }

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

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getOrgId() {
        return orgId;
    }

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

    public String getGroupCode() {
        return groupCode;
    }

    public void setGroupCode(String groupCode) {
        this.groupCode = groupCode;
    }

	public String getPaperId() {
		return paperId;
	}

	public void setPaperId(String paperId) {
		this.paperId = paperId;
	}

    
}

