package com.qmth.qrzk.repository.user.service.impl;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qmth.qrzk.repository.common.base.BaseDao;
import com.qmth.qrzk.repository.exception.BizException;
import com.qmth.qrzk.repository.exp.BaseData;
import com.qmth.qrzk.repository.exp.Teacher;
import com.qmth.qrzk.repository.exp.TkjsBatchData;
import com.qmth.qrzk.repository.exp.TkjsTaskBatch;
import com.qmth.qrzk.repository.learnCenter.model.LearnCenter;
import com.qmth.qrzk.repository.pager.model.PagerConstruct;
import com.qmth.qrzk.repository.pager.model.PagerConstructDetail;
import com.qmth.qrzk.repository.pager.model.PagerConstructQtype;
import com.qmth.qrzk.repository.pager.model.PaperDifficultyEstimateDetail;
import com.qmth.qrzk.repository.pager.model.PaperSkeleton;
import com.qmth.qrzk.repository.pager.model.PaperSkeletonDetail;
import com.qmth.qrzk.repository.quartz.LoadParamsQuartz;
import com.qmth.qrzk.repository.service.query.QueryParams;
import com.qmth.qrzk.repository.service.query.UserQueryParams;
import com.qmth.qrzk.repository.task.PaperTask;
import com.qmth.qrzk.repository.task.TaskBatch;
import com.qmth.qrzk.repository.task.TaskFlowLog;
import com.qmth.qrzk.repository.task.WordHistory;
import com.qmth.qrzk.repository.user.model.Attachment;
import com.qmth.qrzk.repository.user.model.AuditQuesTask;
import com.qmth.qrzk.repository.user.model.AuditQuesTaskUserLink;
import com.qmth.qrzk.repository.user.model.Book;
import com.qmth.qrzk.repository.user.model.Course;
import com.qmth.qrzk.repository.user.model.CourseBook;
import com.qmth.qrzk.repository.user.model.CourseQuestionType;
import com.qmth.qrzk.repository.user.model.InputQuesTask;
import com.qmth.qrzk.repository.user.model.InputQuesTaskUserLink;
import com.qmth.qrzk.repository.user.model.OperLog;
import com.qmth.qrzk.repository.user.model.Question;
import com.qmth.qrzk.repository.user.model.QuestionOption;
import com.qmth.qrzk.repository.user.model.QuestionType;
import com.qmth.qrzk.repository.user.model.Role;
import com.qmth.qrzk.repository.user.model.TeacherAssessment;
import com.qmth.qrzk.repository.user.model.TeacherAssessmentDetail;
import com.qmth.qrzk.repository.user.model.TkjsTask;
import com.qmth.qrzk.repository.user.model.User;
import com.qmth.qrzk.repository.user.model.UserCourse;
import com.qmth.qrzk.repository.user.model.UserRole;
import com.qmth.qrzk.repository.utils.CipherUtil;
import com.qmth.qrzk.repository.utils.Consts;
import com.qmth.qrzk.repository.utils.DESCoder;
import com.qmth.qrzk.repository.utils.DateHelper;
import com.qmth.qrzk.repository.utils.General;
import com.qmth.qrzk.repository.utils.Md5EncryptUtils;

@Service
public class TaskBatchImpl {
	
	private static final Logger log = Logger.getLogger(TaskBatchImpl.class);

	@Autowired
	private BaseDao dao;
	
	@Autowired
	private LoadParamsQuartz loadParamsQuartz;
	
	@Autowired
	private QuestionServiceImpl questionService;
	
	public void addTaskBatch(TaskBatch taskBath) throws BizException{
		TaskBatch tmp = findByName(taskBath.getName());
		if(tmp != null){
			throw new BizException("批次名称已存在");
		}
		taskBath.setPlanStartTime(DateHelper.parseLongString(DateHelper.formatDate(taskBath.getPlanStartTime(), DateHelper.shortSimpleDateFormat) + " 00:00:00"));
		taskBath.setPlanEndTime(DateHelper.parseLongString(DateHelper.formatDate(taskBath.getPlanEndTime(), DateHelper.shortSimpleDateFormat) + " 23:59:59"));
		dao.insert("addTaskBatch", taskBath);
	}
	
	public void updateTaskBatch(TaskBatch taskBath) throws BizException{
		TaskBatch tmp = findByName(taskBath.getName());
		if(tmp != null && !tmp.getId().equals(taskBath.getId())){
			throw new BizException("批次名称已存在");
		}
		taskBath.setPlanStartTime(DateHelper.parseLongString(DateHelper.formatDate(taskBath.getPlanStartTime(), DateHelper.shortSimpleDateFormat) + " 00:00:00"));
		taskBath.setPlanEndTime(DateHelper.parseLongString(DateHelper.formatDate(taskBath.getPlanEndTime(), DateHelper.shortSimpleDateFormat) + " 23:59:59"));
		dao.update("updateTaskBatch", taskBath);
		taskBath = findById(taskBath.getId());
		if(Consts.TaskBatchType.RU_WEI_MING_TI.equals(taskBath.getBatchType())){
			dao.update("updatePaperTaskPlanTime", taskBath);
		}else if(Consts.TaskBatchType.SHEN_TI.equals(taskBath.getBatchType())){
			dao.update("updateAuditQuesTaskPlanTime", taskBath);
		}else if(Consts.TaskBatchType.TI_KA_LU_RU.equals(taskBath.getBatchType())){
			dao.update("updateInputQuesTaskPlanTime", taskBath);
		}
	}
	
	public List<TaskBatch> queryTaskBatchs(QueryParams params){
		return dao.getPagerList("queryTaskBatchs",params);
	}
	
	public TaskBatch findById(int id){
		return dao.get("findTaskBatchById", id);
	}
	
	public TaskBatch findLatestTaskBatch(){
		return dao.get("findLatestTaskBatch", null);
	}
	
	public TaskBatch findByName(String batchName){
		return dao.get("findTaskBatchByName", batchName);
	}
	
	public void delTaskBatch(int batchId){
		dao.delete("deleteTaskBatchById",batchId);
	}
	
	public void emptyData(){
		General.backupDB();
		dao.delete("delAllPaperDifficultyEstimates", null);
		dao.delete("delAllWordHistorys", null);
		dao.delete("delAllPaperDetails", null);
		dao.delete("delAllPaperQtypes", null);
		dao.delete("delAllPapers", null);
		dao.delete("delAllSkeletonDetails", null);
		dao.delete("delAllSkeletons", null);
		dao.delete("delAllTeacherAssessmentDetails", null);
		dao.delete("delAllTeacherAssessments", null);
		dao.delete("delAllPaperTasks", null);
		dao.delete("delAllAuditQuesTaskUserLinks", null);
		dao.delete("delAllAuditQuesTasks", null);
		dao.delete("delAllInputQuesTaskUserLinks", null);
		dao.delete("delAllInputQuesTasks", null);
		dao.delete("delAllQuesOptions", null);
		dao.delete("delAllQuestions",null);
		dao.delete("delAllOperLogs", null);
		dao.delete("delAllFlowLogs", null);
		dao.delete("delAllTaskBatchs", null);
		dao.delete("delAllUserCourseLinks", null);
		dao.delete("delAllNormalUsers", null);
	}
	
	public Attachment expTkjsForClient(int tkjsBatchId,User curUser) throws BizException{
		TaskBatch tb = dao.get("findTaskBatchById", tkjsBatchId);
		if(!Consts.TaskBatchType.TI_KU_JIAN_SHE.equals(tb.getBatchType())){
			throw new BizException("非法数据");
		}
		Attachment zipAtt = null;
		List<TkjsTask> tkjsTasks = dao.getList("getTkjsTasksByBatchId", tkjsBatchId);
		
		Map<String,com.qmth.qrzk.repository.exp.Book> bookMap = new HashMap<String, com.qmth.qrzk.repository.exp.Book>();
		Map<String,com.qmth.qrzk.repository.exp.QuestionType> quesTypeMap = new HashMap<String, com.qmth.qrzk.repository.exp.QuestionType>();
		
		List<com.qmth.qrzk.repository.exp.Course> allExpCourses = new ArrayList<com.qmth.qrzk.repository.exp.Course>(tkjsTasks.size());
		for(TkjsTask t:tkjsTasks){
			Course c = t.getCourse();
			List<com.qmth.qrzk.repository.exp.CourseBook> cbs = new ArrayList<com.qmth.qrzk.repository.exp.CourseBook>();
			List<String> quesTypeGuids = new ArrayList<String>();
			List<Book> books = dao.getList("selectBooksInCourse", c.getId());
			for(Book b:books){
				com.qmth.qrzk.repository.exp.Book bTmp = new com.qmth.qrzk.repository.exp.Book(b.getGuid(),
						b.getName(), b.getCode(), b.getEditor(), b.getPress(), b.getVersion(), b.getPrice(), b.getChapterSize(), b.getEnableDate());
				bookMap.put(bTmp.getGuid(), bTmp);
				com.qmth.qrzk.repository.exp.CourseBook cb = new com.qmth.qrzk.repository.exp.CourseBook(b.getGuid(), b.getInCourseStatus());
				cbs.add(cb);
			}
			List<QuestionType> quesTypes = dao.getList("queryQuesTypesByCourseId",c.getId());
			for(QuestionType qt:quesTypes){
				com.qmth.qrzk.repository.exp.QuestionType qtTmp = new com.qmth.qrzk.repository.exp.QuestionType(qt.getGuid(), 
						qt.getCode(), qt.getName(), qt.getCorrectOptionsNum(), qt.getDefaultScore());
				quesTypeMap.put(qtTmp.getGuid(), qtTmp);
				quesTypeGuids.add(qtTmp.getGuid());
			}
			allExpCourses.add(new com.qmth.qrzk.repository.exp.Course(c.getGuid(), 
					c.getCode(), c.getName(), cbs, quesTypeGuids));
		}
		List<com.qmth.qrzk.repository.exp.Book> allExpBooks = new ArrayList<com.qmth.qrzk.repository.exp.Book>(bookMap.values());
		List<com.qmth.qrzk.repository.exp.QuestionType> allExpQuesTypes = new ArrayList<com.qmth.qrzk.repository.exp.QuestionType>(quesTypeMap.values());
		
		List<com.qmth.qrzk.repository.exp.TkjsTask> expTasks = new ArrayList<com.qmth.qrzk.repository.exp.TkjsTask>(tkjsTasks.size());
		for(TkjsTask t:tkjsTasks){
			List<String> teacherGuids = new ArrayList<String>(t.getTeacherList().size());
			for(User teacher:t.getTeacherList()){
				teacherGuids.add(teacher.getGuid());
			}
			expTasks.add(new com.qmth.qrzk.repository.exp.TkjsTask(t.getGuid(), 
					t.getPlanStartTime(), t.getPlanEndTime(), t.getCourse().getGuid(), teacherGuids));
		}
		TkjsTaskBatch tkjsTaskBatch = new TkjsTaskBatch(tb.getGuid(), tb.getName(), tb.getPlanStartTime(), tb.getPlanEndTime(), expTasks);
		TkjsBatchData expBean = new TkjsBatchData(allExpBooks, allExpQuesTypes, allExpCourses, tkjsTaskBatch);

		UserQueryParams params = new UserQueryParams();
		params.setUserType(Consts.USER_TYPE_TEACHER);
		List<User> users = dao.getList("queryUsers",params);
		List<Teacher> teachers = new ArrayList<Teacher>(users.size());
		for(User u:users){
			Teacher t = new Teacher(u.getGuid(), u.getName(), u.getLoginName(), Md5EncryptUtils.md5(u.getPassword()));
			teachers.add(t);
		}
		BaseData expData = new BaseData(teachers);
		
		FileOutputStream fos = null;
		ZipOutputStream zos = null;
		try {
            File newFile = General.newTmpFile();
            fos = new FileOutputStream(newFile);
            zos = new ZipOutputStream(fos);
            
            JAXBContext context_tbd = JAXBContext.newInstance(TkjsBatchData.class);
            Marshaller marshaller_tbd = context_tbd.createMarshaller();
            zos.putNextEntry(new ZipEntry("data_task.xml"));
            marshaller_tbd.marshal(expBean, zos);
            
            JAXBContext context_user = JAXBContext.newInstance(BaseData.class);
            Marshaller marshaller_user = context_user.createMarshaller();
            zos.putNextEntry(new ZipEntry("data_user.xml"));
            marshaller_user.marshal(expData, zos);
            
            zos.closeEntry();
        	General.close(zos);
        	General.close(fos);
        	zos = null;
        	fos = null;
        	File destFile = General.newAttFile();
//        	FileUtils.copyFile(newFile, destFile);
        	DESCoder.encrypt(newFile, destFile);
//        	CipherUtil.encrypt(newFile,destFile,Consts.keyForService);
			
			zipAtt = new Attachment();
			zipAtt.setCreatedBy(curUser.getId());
			zipAtt.setOriginalName(tb.getName() + "_client_" + DateHelper.getNow(DateHelper.shortSimpleDateFormatWithoutSplit) + ".qrzk");
			zipAtt.setCurName(destFile.getName());
			zipAtt.setFileLength(destFile.length());
			zipAtt.setStorePath(destFile.getAbsolutePath());
			zipAtt.setStatus(Consts.AttachmentStatus.DRAFT);
			dao.insert("addAttachment", zipAtt);
            
        } catch (Exception e) {
        	throw new RuntimeException("写入zip压缩文件失败，原因：" + e.getMessage(), e);
        } finally{
        	General.close(zos);
        	General.close(fos);
        }
		return zipAtt;
	}
	
	public Attachment exportTask(int batchId,User curUser){
		Attachment zipAtt = null;
		Set<Integer> selectedCourseSet = new HashSet<Integer>();
		Map<Integer,Question> selectedQuesMap = new HashMap<Integer, Question>();
		ExportTaskBean exportTaskBean = null;
		Set<Integer> selectedAttIdSet = new HashSet<Integer>();
		List<Attachment> selectedAttList = new ArrayList<Attachment>();
		
		List<User> allUsers = dao.getList("queryUsers");
		List<Course> allCourses = dao.getList("queryCourses");
		List<CourseBook> allCbs = dao.getList("getAllCourseBooks");
		List<Book> allBooks = dao.getList("queryBooks");
		List<CourseQuestionType> allCqts = dao.getList("getAllCourseQuestionTypes");
		List<QuestionType> allQuesTypes = dao.getList("queryQuestionTypes");
		List<LearnCenter> allLearnCenters = dao.getList("getAllLearnCenters");
		
		for(LearnCenter lc : allLearnCenters){
			if(lc.getAttachmentId() != null){
				for(String attId : lc.getAttachmentId().split(",")){
					if(!attId.trim().equals("")){
						selectedAttIdSet.add(General.toInteger(attId.trim(), 0));
					}
				}
			}
		}
		
		TaskBatch tb = dao.get("findTaskBatchById", batchId);
		if(Consts.TaskBatchType.RU_WEI_MING_TI.equals(tb.getBatchType())){
			Map<Integer,PaperSkeleton> selectedSkelMap = new HashMap<Integer, PaperSkeleton>();
			Map<Integer,PagerConstruct> selectedPaperMap = new HashMap<Integer, PagerConstruct>();
			List<PaperDifficultyEstimateDetail> selectedPdeList = new ArrayList<PaperDifficultyEstimateDetail>();
			List<TeacherAssessment> selectedTaList = new ArrayList<TeacherAssessment>();
			
			List<PaperTask> paperTasks = dao.getList("getPaperTasksByBatchId", batchId);
			for(PaperTask task:paperTasks){
				selectedCourseSet.add(task.getCourseId());
				List<TaskFlowLog> flows = dao.getList("queryPaperTaskFlowLogsByTaskId", task.getId());
				task.setFlows(flows);
				
				List<TeacherAssessment> taList = dao.getList("queryAssessmentByTaskId", task.getId());
				selectedTaList.addAll(taList);
			}
			for(Integer courseId:selectedCourseSet){
				List<Question> quesList = dao.getList("queryQuestionsByCourseId",courseId);
				for(Question ques:quesList){
					ques.setAuditLogs(questionService.getAuditLogs(ques.getId()));
					selectedQuesMap.put(ques.getId(), ques);
				}
				List<PaperSkeleton> skelList = dao.getList("getPaperSkeletonByCourseId",courseId);
				for(PaperSkeleton skel:skelList){
					skel.setBook(null);
					skel.setCourse(null);
					selectedSkelMap.put(skel.getId(), skel);
				}
				List<PagerConstruct> paperList = dao.getList("findPagerConstructsByCourseId",courseId);
				for(PagerConstruct paper:paperList){
					List<PaperDifficultyEstimateDetail> pdeList = dao.getList("getPaperDifficultyEstimateByPaperId",paper.getId());
					selectedPdeList.addAll(pdeList);
					paper.setSkeleton(null);
					if(paper.getQtypeList() != null){
						for(PagerConstructQtype qt:paper.getQtypeList()){
							if(qt.getConstructDetails() != null){
								for(PagerConstructDetail d:qt.getConstructDetails()){
									d.setQuestion(null);
								}
							}
						}
					}
					selectedPaperMap.put(paper.getId(), paper);
	
					WordHistory param1 = new WordHistory();
					param1.setPaperId(paper.getId());
					param1.setAttType(Consts.WordType.PAPER);
					List<WordHistory> paperWordHistories = dao.getList("queryPaperWordHistorysByPaperId",param1);
					paper.setPaperWordHistories(paperWordHistories);
					
					WordHistory param2 = new WordHistory();
					param2.setPaperId(paper.getId());
					param2.setAttType(Consts.WordType.ANSWER);
					List<WordHistory> answerWordHistories = dao.getList("queryPaperWordHistorysByPaperId",param2);
					paper.getPaperWordHistories().addAll(answerWordHistories);
					
					for(WordHistory h:paper.getPaperWordHistories()){
						selectedAttIdSet.add(h.getAttId());
					}
					selectedAttIdSet.add(paper.getLastPaperWord());
					selectedAttIdSet.add(paper.getLastAnswerWord());
				}
			}
			for(Integer attId:selectedAttIdSet){
				if(attId != null){
					Attachment att = dao.get("getAttachmentById", attId);
					if(att != null){
						selectedAttList.add(att);
					}
				}
			}
			List<Question> selectedQuesList = new ArrayList<Question>();
			selectedQuesList.addAll(selectedQuesMap.values());
			List<PaperSkeleton> selectedSkelList = new ArrayList<PaperSkeleton>();
			selectedSkelList.addAll(selectedSkelMap.values());
			List<PagerConstruct> selectedPaperList = new ArrayList<PagerConstruct>();
			selectedPaperList.addAll(selectedPaperMap.values());

			exportTaskBean = new ExportTaskBean(tb, paperTasks, allUsers, allCourses, allCbs, allBooks, allCqts, allQuesTypes,allLearnCenters, selectedAttList, selectedQuesList, selectedSkelList, selectedPaperList,selectedPdeList,selectedTaList);
		}else if(Consts.TaskBatchType.SHEN_TI.equals(tb.getBatchType())){
			List<AuditQuesTask> auditQuesTasks = dao.getList("getAuditQuesTasksByBatchId", batchId);
			for(AuditQuesTask task:auditQuesTasks){
				selectedCourseSet.add(task.getCourseId());
				task.setCourse(null);
			}
			for(Integer courseId:selectedCourseSet){
				List<Question> quesList = dao.getList("queryQuestionsByCourseId",courseId);
				for(Question ques:quesList){
					ques.setAuditLogs(questionService.getAuditLogs(ques.getId()));
					selectedQuesMap.put(ques.getId(), ques);
				}
			}
			List<Question> selectedQuesList = new ArrayList<Question>();
			selectedQuesList.addAll(selectedQuesMap.values());

			exportTaskBean = new ExportTaskBean(tb, auditQuesTasks, null, allUsers, allCourses, allCbs, allBooks, allCqts, allQuesTypes, allLearnCenters, selectedQuesList);
		}else if(Consts.TaskBatchType.TI_KA_LU_RU.equals(tb.getBatchType())){
			List<InputQuesTask> inputQuesTasks = dao.getList("getInputQuesTasksByBatchId", batchId);
			for(InputQuesTask task:inputQuesTasks){
				selectedCourseSet.add(task.getCourseId());
				task.setCourse(null);
			}
			for(Integer courseId:selectedCourseSet){
				List<Question> quesList = dao.getList("queryQuestionsByCourseId",courseId);
				for(Question ques:quesList){
					ques.setAuditLogs(questionService.getAuditLogs(ques.getId()));
					selectedQuesMap.put(ques.getId(), ques);
				}
			}
			List<Question> selectedQuesList = new ArrayList<Question>();
			selectedQuesList.addAll(selectedQuesMap.values());

			exportTaskBean = new ExportTaskBean(tb, null, inputQuesTasks, allUsers, allCourses, allCbs, allBooks, allCqts, allQuesTypes, allLearnCenters, selectedQuesList);
		}
		FileOutputStream fos = null;
		ZipOutputStream zos = null;
		try {
            JAXBContext context = JAXBContext.newInstance(ExportTaskBean.class);  
            Marshaller marshaller = context.createMarshaller();
            File newFile = General.newTmpFile();
            fos = new FileOutputStream(newFile);
            zos = new ZipOutputStream(fos);
            zos.putNextEntry(new ZipEntry("data.xml"));
            marshaller.marshal(exportTaskBean, zos);
            for(Attachment att:selectedAttList){
            	File file = new File(att.getStorePath());
            	FileInputStream fis = null;
            	if(file.exists()){
            		try{
    					fis = new FileInputStream(file);
                		zos.putNextEntry(new ZipEntry("att/" + att.getCurName()));
    					IOUtils.copy(fis, zos);
    				}finally{
    					General.close(fis);
    				}
            	}
            }
            
            zos.closeEntry();
        	General.close(zos);
        	General.close(fos);
        	zos = null;
        	fos = null;
        	File destFile = General.newAttFile();
        	CipherUtil.encrypt(newFile,destFile,Consts.key);
			
			zipAtt = new Attachment();
			zipAtt.setCreatedBy(curUser.getId());
			zipAtt.setOriginalName(tb.getName() + "_" + DateHelper.getNow(DateHelper.shortSimpleDateFormatWithoutSplit) + ".qrzk");
			zipAtt.setCurName(destFile.getName());
			zipAtt.setFileLength(destFile.length());
			zipAtt.setStorePath(destFile.getAbsolutePath());
			zipAtt.setStatus(Consts.AttachmentStatus.DRAFT);
			dao.insert("addAttachment", zipAtt);
            
        } catch (Exception e) {
        	throw new RuntimeException("写入zip压缩文件失败，原因：" + e.getMessage(), e);
        } finally{
        	General.close(zos);
        	General.close(fos);
        }
		return zipAtt;
	}
	
	public void revertTask(int attId,User curUser){
		File decryptedFile = null;
		ZipFile zipFile = null;
		ExportTaskBean taskData = null;
		try {
			Attachment att = dao.get("getAttachmentById", attId);
			try{
				decryptedFile = General.newTmpFile();
				CipherUtil.decrypt(new File(att.getStorePath()), decryptedFile, Consts.key);
				zipFile = new ZipFile(decryptedFile);
			} catch (ZipException e) {
				throw new RuntimeException("不可解析的备份数据文件", e);
			} catch (IOException e) {
				throw new RuntimeException("不可解析的备份数据文件", e);
			} catch (GeneralSecurityException e) {
				throw new RuntimeException("不可解析的备份数据文件", e);
			}
			ZipEntry dataEntry = zipFile.getEntry("data.xml");
			if(dataEntry == null){
				throw new RuntimeException("不可解析的备份数据文件");
			}
			File dataFile1 = null;
			File dataFile2 = null;
			FileInputStream fis1 = null;
			FileOutputStream fos1 = null;
			FileInputStream fis2 = null;
			FileOutputStream fos2 = null;
			try{
				JAXBContext context = JAXBContext.newInstance(ExportTaskBean.class);  
				Unmarshaller unmarshaller = context.createUnmarshaller();
				dataFile1 = General.newTmpFile();
				dataFile2 = General.newTmpFile();
				dataFile1.createNewFile();
				dataFile2.createNewFile();
				fos1 = new FileOutputStream(dataFile1);
				fos2 = new FileOutputStream(dataFile2);
				IOUtils.copyLarge(zipFile.getInputStream(dataEntry), fos1);
				fos1.flush();
				General.close(fos1);
				fos1 = null;
				log.info("数据文件存储地址：" + dataFile1.getPath());
				fis1 = new FileInputStream(dataFile1); 
				char c = 0X16;//备份的xml文件里面的特殊字符，导致程序无法正常解析xml文件，现只能用空格来替换
				BufferedReader bufReader =
	                    new BufferedReader(
	                            new InputStreamReader(fis1 ,"UTF-8"));
				//采用分段字节流读取，防止内存溢出 update by songyue
				BufferedWriter bufWriter = new BufferedWriter(new OutputStreamWriter(fos2 ,"UTF-8"));
				char[] buf = new char[1024*1024];
		        int len = 0 ;
		        while((len = bufReader.read(buf)) != -1){
		        	for(int i = 0;i < len;i++){
		        		if(buf[i] == c){
		        			buf[i] = ' ';
		        		}
		        	}
		        	bufWriter.write(buf, 0, len);
		        } 
//	            for (String tmp1 = null; (tmp1 = bufReader.readLine()) != null; tmp1 = null) {
//	            	fos2.write((tmp1.replace(c, ' ') + "\n").getBytes("UTF-8"));
//	            }
		        bufWriter.flush();
	            fos2.flush();
	            General.close(fos2);
	            fos2 = null;
	            General.close(bufReader);
	            General.close(bufWriter);
				
	            fis2 = new FileInputStream(dataFile2);
				taskData = (ExportTaskBean)unmarshaller.unmarshal(fis2);
			}catch(Exception e){
				throw new RuntimeException("不可解析的备份数据文件", e);
			}finally{
				General.close(fos1);
				General.close(fos2);
				General.close(fis1);
				General.close(fis2);
				General.delete(dataFile1);
				General.delete(dataFile2);
			}
//            List<Attachment> selectedAttList = taskData.getSelectedAttList();
            Map<String,Attachment> selectedAttMap = new HashMap<String, Attachment>();
            if(taskData.getSelectedAttList() != null){
	            for(Attachment tmp : taskData.getSelectedAttList()){
	            	selectedAttMap.put(tmp.getCurName(), tmp);
	            }
            }
            
			@SuppressWarnings("unchecked")
			Enumeration<ZipEntry> entriesIter = (Enumeration<ZipEntry>) zipFile.entries();
			while (entriesIter.hasMoreElements()) {
				ZipEntry entry = entriesIter.nextElement();
				String entryName = entry.getName();
				if(entryName.startsWith("att/")) {
					String attName = entryName.substring("att/".length());
					FileOutputStream fos = null;
					try{
						File newFile = General.newAttFile(attName);
						fos = new FileOutputStream(newFile);
						IOUtils.copyLarge(zipFile.getInputStream(entry), fos);
						fos.flush();
						Attachment tmp = selectedAttMap.get(attName);
						tmp.setStorePath(newFile.getAbsolutePath());
					}catch(Exception e){
						throw new RuntimeException("还原附件文件[" + entryName + "]失败，原因：" + e.getMessage(), e);
					}finally{
						General.close(fos);
					}
				}
			}

			Map<Integer,Integer> userIdMap = new HashMap<Integer, Integer>();
			if(taskData.getAllUsers() != null){
				for(User tmp : taskData.getAllUsers()){
					User localUser = dao.get("findUserByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localUser == null){
						dao.insert("insertUser", tmp);
					}else{
						tmp.setId(localUser.getId());
						dao.update("updateWholeUser", tmp);
					}
					dao.delete("delUserRoleByUserId", tmp.getId());
					if(tmp.getRoles() != null && tmp.getRoles().size() > 0){
						List<UserRole> urs = new ArrayList<UserRole>();
						for(Role r : tmp.getRoles()){
							urs.add(new UserRole(tmp.getId(), r.getId()));
						}
						dao.insert("addLinkRole", urs);
					}
					userIdMap.put(oldId, tmp.getId());
				}
			}
			
			Map<Integer,Integer> attIdMap = new HashMap<Integer, Integer>();
			if(taskData.getSelectedAttList() != null){
				for(Attachment tmp : taskData.getSelectedAttList()){
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					Attachment localAtt = dao.get("getAttachmentByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localAtt == null){
						dao.insert("addAttachment", tmp);
					}else{
						tmp.setId(localAtt.getId());
						dao.update("updateAttachment", tmp);
					}
					attIdMap.put(oldId, tmp.getId());
				}
			}
			
			Map<Integer,Integer> courseIdMap = new HashMap<Integer, Integer>();
			if(taskData.getAllCourses() != null){
				dao.delete("deleteAllSkelCfg",null);
				for(Course tmp : taskData.getAllCourses()){
					Course localCourse = dao.get("findCourseByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localCourse == null){
						dao.insert("addCourse", tmp);
					}else{
						tmp.setId(localCourse.getId());
						dao.update("updateCourse", tmp);
					}
					courseIdMap.put(oldId, tmp.getId());
					dao.delete("delCourseBooksByCourseId", tmp.getId());
					dao.delete("deleteCourseQuestionTypeLink", tmp.getId());
					if(tmp.getSkelCfg() != null){
						tmp.getSkelCfg().setCourseId(tmp.getId());
						dao.insert("addSkelCfg", tmp.getSkelCfg());
					}
				}
			}
			if(taskData.getAllUsers() != null){
				for(User tmp : taskData.getAllUsers()){
					dao.delete("delUserCourseByUserId", tmp.getId());
					if(tmp.getCourses() != null && tmp.getCourses().size() > 0){
						List<UserCourse> ucs = new ArrayList<UserCourse>();
						for(Course c: tmp.getCourses()){
							Course localCourse = dao.get("findCourseByGuid", c.getGuid());
							ucs.add(new UserCourse(tmp.getId(), localCourse.getId()));
						}
						dao.insert("addUserCourses", ucs);
					}
				}
			}
			
			Map<Integer,Integer> bookIdMap = new HashMap<Integer, Integer>();
			if(taskData.getAllBooks() != null){
				for(Book tmp : taskData.getAllBooks()){
					Book localBook = dao.get("getBookByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localBook == null){
						dao.insert("addBook", tmp);
					}else{
						tmp.setId(localBook.getId());
						dao.update("updateBook", tmp);
					}
					bookIdMap.put(oldId, tmp.getId());
				}
			}
			if(taskData.getAllCbs() != null && taskData.getAllCbs().size() > 0){//处理课程-教材关联数据
				for(CourseBook cb : taskData.getAllCbs()){
					cb.setCourseId(courseIdMap.get(cb.getCourseId()));
					cb.setBookId(bookIdMap.get(cb.getBookId()));
				}
				dao.insert("addCourseBooks", taskData.getAllCbs());
			}
			
			Map<Integer,Integer> quesTypeIdMap = new HashMap<Integer, Integer>();
			if(taskData.getAllQuesTypes() != null){
				for(QuestionType tmp : taskData.getAllQuesTypes()){
					tmp.setCreateBy(userIdMap.get(tmp.getCreateBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					QuestionType localQuesType = dao.get("findQuestionTypeByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localQuesType == null){
						dao.insert("addQuestionType", tmp);
					}else{
						tmp.setId(localQuesType.getId());
						dao.update("updateQuestionType", tmp);
					}
					quesTypeIdMap.put(oldId, tmp.getId());
				}
			}
			if(taskData.getAllCqts() != null && taskData.getAllCqts().size() > 0){//处理课程-题型关联数据
				for(CourseQuestionType cq : taskData.getAllCqts()){
					cq.setCourseId(courseIdMap.get(cq.getCourseId()));
					cq.setQuestionTypeId(quesTypeIdMap.get(cq.getQuestionTypeId()));
				}
				dao.insert("addCourseQuestionType", taskData.getAllCqts());
			}
			
			Map<Integer,Integer> learnCenterIdMap = new HashMap<Integer, Integer>();
			if(taskData.getAllLearnCenters() != null){
				for(LearnCenter tmp : taskData.getAllLearnCenters()){
					if(tmp.getAttachmentId() != null){
						Set<Integer> attIdSet = new HashSet<Integer>();
						for(String attTmpId : tmp.getAttachmentId().split(",")){
							if(!attTmpId.trim().equals("")){
								attIdSet.add(attIdMap.get(General.toInteger(attTmpId.trim(), 0)));
							}
						}
						String attachmentId = "";
						for(Integer a:attIdSet){
							attachmentId = attachmentId + a + ",";
						}
						if(attachmentId.length() > 0){
							attachmentId = attachmentId.substring(0,attachmentId.length() - 1);
						}
						tmp.setAttachmentId(attachmentId);
					}
					LearnCenter localLearnCenter = dao.get("getLearnCenterByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localLearnCenter == null){
						dao.insert("addLearnCenter", tmp);
					}else{
						tmp.setId(localLearnCenter.getId());
						dao.update("updateLearnCenter", tmp);
					}
					learnCenterIdMap.put(oldId, tmp.getId());
				}
			}
			
			Map<Integer,Integer> quesIdMap = new HashMap<Integer, Integer>();
			if(taskData.getSelectedQuesList() != null){
				for(Question tmp : taskData.getSelectedQuesList()){
					tmp.setCourseId(courseIdMap.get(tmp.getCourseId()));
					tmp.setTypeId(quesTypeIdMap.get(tmp.getTypeId()));
					tmp.setBookId(bookIdMap.get(tmp.getBookId()));
					tmp.setSetBy(userIdMap.get(tmp.getSetBy()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					Question localQues = dao.get("findQuestionByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localQues == null){
						dao.insert("saveQuestion", tmp);
					}else{
						tmp.setId(localQues.getId());
						dao.update("updateQuestion", tmp);
						dao.delete("deleteOptionsByQuesId",tmp.getId());
						OperLog operLog = new OperLog();
						operLog.setObjType(Consts.OperLogObjType.Question);
						operLog.setObjId(tmp.getId());
						dao.delete("deleteOperLogByObjType", operLog);
					}
					if(tmp.getOptions() != null){
						for(QuestionOption opt:tmp.getOptions()){
							opt.setQuestionId(tmp.getId());
							opt.setCreatedBy(userIdMap.get(opt.getCreatedBy()));
							opt.setUpdatedBy(userIdMap.get(opt.getUpdatedBy()));
							dao.insert("saveOption", opt);
						}
					}
					if(tmp.getAuditLogs() != null){
						for(OperLog log:tmp.getAuditLogs()){
							log.setObjId(tmp.getId());
							log.setCreatedBy(userIdMap.get(log.getCreatedBy()));
							dao.insert("addOperLog", log);
						}
					}
					quesIdMap.put(oldId, tmp.getId());
				}
			}
			
			Map<Integer,Integer> tbIdMap = new HashMap<Integer, Integer>();
			{
				TaskBatch tmp = taskData.getTb();
				tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
				tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
				TaskBatch localTb = dao.get("getTaskBatchByGuid", tmp.getGuid());
				int oldId = tmp.getId();
				if(localTb == null){
					dao.insert("addTaskBatch", tmp);
				}else{
					tmp.setId(localTb.getId());
					dao.update("updateTaskBatch", tmp);
				}
				tbIdMap.put(oldId, tmp.getId());
			}

			if(taskData.getAuditQuesTasks() != null){
				for(AuditQuesTask tmp : taskData.getAuditQuesTasks()){
					tmp.setBatchId(tbIdMap.get(tmp.getBatchId()));
					tmp.setCourseId(courseIdMap.get(tmp.getCourseId()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					AuditQuesTask localTask = dao.get("getAuditQuesTaskByGuid", tmp.getGuid());
					if(localTask == null){
						dao.insert("addAuditQuesTask", tmp);
					}else{
						tmp.setId(localTask.getId());
						dao.update("updateAuditQuesTask", tmp);
						dao.delete("delAuditQuesTaskUserLinksByTaskId", tmp.getId());
					}
					if(tmp.getAuditorLinks() != null){
						for(AuditQuesTaskUserLink flow:tmp.getAuditorLinks()){
							flow.setAuditQuesTaskId(tmp.getId());
							flow.setAuditorId(userIdMap.get(flow.getAuditorId()));
							dao.insert("addAuditQuesTaskUserLink", flow);
						}
					}
				}
			}

			if(taskData.getInputQuesTasks() != null){
				for(InputQuesTask tmp : taskData.getInputQuesTasks()){
					tmp.setBatchId(tbIdMap.get(tmp.getBatchId()));
					tmp.setCourseId(courseIdMap.get(tmp.getCourseId()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					InputQuesTask localTask = dao.get("getInputQuesTaskByGuid", tmp.getGuid());
					if(localTask == null){
						dao.insert("addInputQuesTask", tmp);
					}else{
						tmp.setId(localTask.getId());
						dao.update("updateInputQuesTask", tmp);
						dao.delete("delInputQuesTaskUserLinksByTaskId", tmp.getId());
					}
					if(tmp.getInputerLinks() != null){
						for(InputQuesTaskUserLink flow:tmp.getInputerLinks()){
							flow.setInputQuesTaskId(tmp.getId());
							flow.setInputerId(userIdMap.get(flow.getInputerId()));
							dao.insert("addInputQuesTaskUserLink", flow);
						}
					}
				}
			}
			
			Map<Integer,Integer> taskIdMap = new HashMap<Integer, Integer>();
			if(taskData.getPaperTasks() != null){
				for(PaperTask tmp : taskData.getPaperTasks()){
					tmp.setBatchId(tbIdMap.get(tmp.getBatchId()));
					tmp.setCourseId(courseIdMap.get(tmp.getCourseId()));
					tmp.setBookId(bookIdMap.get(tmp.getBookId()));
					tmp.setPropositionTeacher(userIdMap.get(tmp.getPropositionTeacher()));
					tmp.setAuditTeacher(userIdMap.get(tmp.getAuditTeacher()));
					tmp.setTypesetter(userIdMap.get(tmp.getTypesetter()));
					tmp.setPrimarySecretary(userIdMap.get(tmp.getPrimarySecretary()));
					tmp.setAssistantSecretary(userIdMap.get(tmp.getAssistantSecretary()));
					tmp.setCurDealer(userIdMap.get(tmp.getCurDealer()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					PaperTask localTask = dao.get("getPaperTaskByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localTask == null){
						dao.insert("addPaperTask", tmp);
					}else{
						tmp.setId(localTask.getId());
						dao.update("updatePaperTask", tmp);
						dao.delete("deleteTaskFlowLogsByTaskId", tmp.getId());
					}
					if(tmp.getFlows() != null){
						for(TaskFlowLog flow:tmp.getFlows()){
							flow.setTaskId(tmp.getId());
							flow.setCreatedBy(userIdMap.get(flow.getCreatedBy()));
							dao.insert("addTaskFlowLog", flow);
						}
					}
					taskIdMap.put(oldId, tmp.getId());
				}
			}
			
			Map<Integer,Integer> skelIdMap = new HashMap<Integer, Integer>();
			if(taskData.getSelectedSkelList() != null){
				for(PaperSkeleton tmp : taskData.getSelectedSkelList()){
					tmp.setTaskId(taskIdMap.get(tmp.getTaskId()));
					tmp.setCourseId(courseIdMap.get(tmp.getCourseId()));
					tmp.setBookId(bookIdMap.get(tmp.getBookId()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					{
						String quesTypeScores = tmp.getQuesTypeScores();
						String newQuesTypeScores = "";
						for(String qtScore:quesTypeScores.split(",")){
							String[] arrTmp = qtScore.split(":");
							int qtId = General.toInteger(arrTmp[0], 0);
							int newQtId = quesTypeIdMap.get(qtId);
							String newQtScore = newQtId + ":" + arrTmp[1];
							newQuesTypeScores = newQuesTypeScores + newQtScore + ",";
						}
						if(newQuesTypeScores.length() > 0){
							newQuesTypeScores = newQuesTypeScores.substring(0,newQuesTypeScores.length() - 1);
						}
						tmp.setQuesTypeScores(newQuesTypeScores);
					}
					
					PaperSkeleton localSkel = dao.get("getPaperSkeletonByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localSkel == null){
						dao.insert("addPaperSkeleton", tmp);
					}else{
						tmp.setId(localSkel.getId());
						dao.update("updatePaperSkeleton", tmp);
						dao.delete("deleteDetailsBySkeletonId", tmp.getId());
					}
					if(tmp.getSkeletonDetailArr() != null){
						for(PaperSkeletonDetail detail : tmp.getSkeletonDetailArr()){
							detail.setSkeletonId(tmp.getId());
						}
						dao.insert("addPaperSkeletonDetail", tmp.getSkeletonDetailArr());
					}
					skelIdMap.put(oldId, tmp.getId());
				}
			}
			
			Map<Integer,Integer> paperIdMap = new HashMap<Integer, Integer>();
			if(taskData.getSelectedPaperList() != null){
				for(PagerConstruct tmp : taskData.getSelectedPaperList()){
					tmp.setSkeletonId(skelIdMap.get(tmp.getSkeletonId()));
					tmp.setTaskId(taskIdMap.get(tmp.getTaskId()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					tmp.setLastPaperWord(attIdMap.get(tmp.getLastPaperWord()));
					tmp.setLastAnswerWord(attIdMap.get(tmp.getLastAnswerWord()));
					
					PagerConstruct localPaper = dao.get("findPagerConstructByGuid", tmp.getGuid());
					int oldId = tmp.getId();
					if(localPaper == null){
						dao.insert("addPagerConstruct", tmp);
					}else{
						tmp.setId(localPaper.getId());
						dao.update("updatePagerConstruct", tmp);
						dao.delete("deleteWordHistoryByPaperId", tmp.getId());
						dao.delete("deletePaperDetailsByPaperId", tmp.getId());
						dao.delete("deletePaperQtypesByPaperId", tmp.getId());
					}
					if(tmp.getPaperWordHistories() != null){
						for(WordHistory h:tmp.getPaperWordHistories()){
							h.setPaperId(tmp.getId());
							h.setAttId(attIdMap.get(h.getAttId()));
							h.setCreatedBy(userIdMap.get(h.getCreatedBy()));
							dao.insert("addWordHistory", h);
						}
					}
					if(tmp.getQtypeList() != null){
						for(PagerConstructQtype qt:tmp.getQtypeList()){
							qt.setPagerConstructId(tmp.getId());
							qt.setQuestionTypeId(quesIdMap.get(qt.getQuestionTypeId()));
							qt.setCreatedBy(userIdMap.get(qt.getCreatedBy()));
							qt.setUpdatedBy(userIdMap.get(qt.getUpdatedBy()));
							dao.insert("addPagerConstructQtype", qt);
							if(qt.getConstructDetails() != null){
								for(PagerConstructDetail detail:qt.getConstructDetails()){
									detail.setPagerConstructId(tmp.getId());
									detail.setPagerQtypeId(qt.getId());
									detail.setQuestionId(quesIdMap.get(detail.getQuestionId()));
									detail.setCreatedBy(userIdMap.get(detail.getCreatedBy()));
									detail.setUpdatedBy(userIdMap.get(detail.getUpdatedBy()));
									dao.insert("addPagerConstructDetail", detail);
								}
							}
						}
					}
					paperIdMap.put(oldId, tmp.getId());
				}
			}
			
			if(taskData.getSelectedPdeList() != null){
				for(PaperDifficultyEstimateDetail tmp : taskData.getSelectedPdeList()){
					tmp.setPagerConstructId(paperIdMap.get(tmp.getPagerConstructId()));
					tmp.setQuestionId(quesIdMap.get(tmp.getQuestionId()));
					tmp.setCreatedBy(userIdMap.get(tmp.getCreatedBy()));
					tmp.setUpdatedBy(userIdMap.get(tmp.getUpdatedBy()));
					PaperDifficultyEstimateDetail localPde = dao.get("getPaperDifficultyEstimateByGuid", tmp.getGuid());
	//				int oldId = tmp.getId();
					if(localPde == null){
						dao.insert("insertDifficultyEstimate", tmp);
					}else{
						tmp.setId(localPde.getId());
						dao.update("updatePaperDifficultyEstimate", tmp);
					}
				}
			}
			
			if(taskData.getSelectedTaList() != null){
				for(TeacherAssessment tmp : taskData.getSelectedTaList()){
					tmp.setTaskId(taskIdMap.get(tmp.getTaskId()));
					tmp.setTeacherId(userIdMap.get(tmp.getTeacherId()));
					tmp.setCreateById(userIdMap.get(tmp.getCreateById()));
					tmp.setUpdateById(userIdMap.get(tmp.getUpdateById()));
					TeacherAssessment localTa = dao.get("queryAssessmentByGuid", tmp.getGuid());
	//				int oldId = tmp.getId();
					if(localTa == null){
						dao.insert("addTeacherAssessment", tmp);
					}else{
						tmp.setId(localTa.getId());
						dao.update("updateTeacherAssessment", tmp);
						dao.delete("deleteTeacherAssessmentDetails", tmp.getId());
					}
					if(tmp.getDetails() != null){
						for(TeacherAssessmentDetail detail:tmp.getDetails()){
							detail.setTeacherAssessmentId(tmp.getId());
						}
						dao.insert("addTeacherAssessmentDetail", tmp.getDetails());
					}
				}
			}
			loadParamsQuartz.loadParamsAndCache();
		}finally{
			General.close(zipFile);
		}
	}

	public List<TaskBatch> queryAllBatchs() {
		return dao.getList("queryTaskBatchs");
	}
}

@XmlRootElement
class ExportTaskBean{
	private TaskBatch tb;
	private List<PaperTask> paperTasks;
	private List<AuditQuesTask> auditQuesTasks;
	private List<InputQuesTask> inputQuesTasks;
	private List<User> allUsers;
	private List<Course> allCourses;
	private List<CourseBook> allCbs;
	private List<Book> allBooks;
	private List<CourseQuestionType> allCqts;
	private List<QuestionType> allQuesTypes;
	private List<LearnCenter> allLearnCenters;
	private List<Attachment> selectedAttList;
	private List<Question> selectedQuesList;
	private List<PaperSkeleton> selectedSkelList;
	private List<PagerConstruct> selectedPaperList;
	private List<PaperDifficultyEstimateDetail> selectedPdeList;
	private List<TeacherAssessment> selectedTaList;
	
	public ExportTaskBean() {
		//do nothing
	}

	public ExportTaskBean(TaskBatch tb, 
			List<AuditQuesTask> auditQuesTasks,List<InputQuesTask> inputQuesTasks,
			List<User> allUsers, List<Course> allCourses,
			List<CourseBook> allCbs, List<Book> allBooks,
			List<CourseQuestionType> allCqts, List<QuestionType> allQuesTypes,
			List<LearnCenter> allLearnCenters, List<Question> selectedQuesList) {
		this.tb = tb;
		this.auditQuesTasks = auditQuesTasks;
		this.inputQuesTasks = inputQuesTasks;
		this.allUsers = allUsers;
		this.allCourses = allCourses;
		this.allCbs = allCbs;
		this.allBooks = allBooks;
		this.allCqts = allCqts;
		this.allQuesTypes = allQuesTypes;
		this.allLearnCenters = allLearnCenters;
		this.selectedQuesList = selectedQuesList;
	}

	public ExportTaskBean(TaskBatch tb, List<PaperTask> paperTasks,
			List<User> allUsers, List<Course> allCourses,
			List<CourseBook> allCbs, List<Book> allBooks,
			List<CourseQuestionType> allCqts, List<QuestionType> allQuesTypes,
			List<LearnCenter> allLearnCenters,
			List<Attachment> selectedAttList, List<Question> selectedQuesList,
			List<PaperSkeleton> selectedSkelList,
			List<PagerConstruct> selectedPaperList,
			List<PaperDifficultyEstimateDetail> selectedPdeList,
			List<TeacherAssessment> selectedTaList) {
		this.tb = tb;
		this.paperTasks = paperTasks;
		this.allUsers = allUsers;
		this.allCourses = allCourses;
		this.allCbs = allCbs;
		this.allBooks = allBooks;
		this.allCqts = allCqts;
		this.allQuesTypes = allQuesTypes;
		this.allLearnCenters = allLearnCenters;
		this.selectedAttList = selectedAttList;
		this.selectedQuesList = selectedQuesList;
		this.selectedSkelList = selectedSkelList;
		this.selectedPaperList = selectedPaperList;
		this.selectedPdeList = selectedPdeList;
		this.selectedTaList = selectedTaList;
	}

	public List<User> getAllUsers() {
		return allUsers;
	}

	public void setAllUsers(List<User> allUsers) {
		this.allUsers = allUsers;
	}

	public List<Course> getAllCourses() {
		return allCourses;
	}

	public void setAllCourses(List<Course> allCourses) {
		this.allCourses = allCourses;
	}

	public List<CourseBook> getAllCbs() {
		return allCbs;
	}

	public void setAllCbs(List<CourseBook> allCbs) {
		this.allCbs = allCbs;
	}

	public List<Book> getAllBooks() {
		return allBooks;
	}

	public void setAllBooks(List<Book> allBooks) {
		this.allBooks = allBooks;
	}

	public List<CourseQuestionType> getAllCqts() {
		return allCqts;
	}

	public void setAllCqts(List<CourseQuestionType> allCqts) {
		this.allCqts = allCqts;
	}

	public List<QuestionType> getAllQuesTypes() {
		return allQuesTypes;
	}

	public void setAllQuesTypes(List<QuestionType> allQuesTypes) {
		this.allQuesTypes = allQuesTypes;
	}

	public List<Attachment> getSelectedAttList() {
		return selectedAttList;
	}

	public void setSelectedAttList(List<Attachment> selectedAttList) {
		this.selectedAttList = selectedAttList;
	}

	public List<Question> getSelectedQuesList() {
		return selectedQuesList;
	}

	public void setSelectedQuesList(List<Question> selectedQuesList) {
		this.selectedQuesList = selectedQuesList;
	}

	public List<PaperSkeleton> getSelectedSkelList() {
		return selectedSkelList;
	}

	public void setSelectedSkelList(List<PaperSkeleton> selectedSkelList) {
		this.selectedSkelList = selectedSkelList;
	}

	public List<PagerConstruct> getSelectedPaperList() {
		return selectedPaperList;
	}

	public void setSelectedPaperList(List<PagerConstruct> selectedPaperList) {
		this.selectedPaperList = selectedPaperList;
	}

	public TaskBatch getTb() {
		return tb;
	}

	public void setTb(TaskBatch tb) {
		this.tb = tb;
	}

	public List<LearnCenter> getAllLearnCenters() {
		return allLearnCenters;
	}

	public void setAllLearnCenters(List<LearnCenter> allLearnCenters) {
		this.allLearnCenters = allLearnCenters;
	}

	public List<PaperDifficultyEstimateDetail> getSelectedPdeList() {
		return selectedPdeList;
	}

	public void setSelectedPdeList(
			List<PaperDifficultyEstimateDetail> selectedPdeList) {
		this.selectedPdeList = selectedPdeList;
	}

	public List<TeacherAssessment> getSelectedTaList() {
		return selectedTaList;
	}

	public void setSelectedTaList(List<TeacherAssessment> selectedTaList) {
		this.selectedTaList = selectedTaList;
	}

	public List<PaperTask> getPaperTasks() {
		return paperTasks;
	}

	public void setPaperTasks(List<PaperTask> paperTasks) {
		this.paperTasks = paperTasks;
	}

	public List<AuditQuesTask> getAuditQuesTasks() {
		return auditQuesTasks;
	}

	public void setAuditQuesTasks(List<AuditQuesTask> auditQuesTasks) {
		this.auditQuesTasks = auditQuesTasks;
	}

	public List<InputQuesTask> getInputQuesTasks() {
		return inputQuesTasks;
	}

	public void setInputQuesTasks(List<InputQuesTask> inputQuesTasks) {
		this.inputQuesTasks = inputQuesTasks;
	}

}
