//package com.qmth.jkserver;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.util.List;
//import java.util.Map;
//import java.util.TreeMap;
//
//import org.apache.poi.EncryptedDocumentException;
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.core.query.Query;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import com.qmth.jkserver.model.ExamStudentAdditional;
//import com.qmth.jkserver.model.ExamStudentAnswer;
//
///**
// * 导出每一个省份的考务数据
// * @author tianjun
// *
// */
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes={Application.class})
//public class ExportProvinceKWData {
//
//	private static final String FILE_PATH = "F:\\ACC\\正式考试\\1223";
//	private static final String PROVINCE = "辽宁省";
//	private static final String EXAM_CODE = "3S9v";
//
//	@Autowired
//	private MongoTemplate mongoTemplate;
//
//	@Test
//	public void execute() throws EncryptedDocumentException, InvalidFormatException, IOException {
//		File root = new File(FILE_PATH);
//		File xls  = new File(root,PROVINCE+"考务数据.xls");
//		xls.createNewFile();
//		Workbook workbook = new HSSFWorkbook();
//		Sheet sheet = workbook.createSheet(PROVINCE + "-实考考生汇总");
//		Row row = sheet.createRow(0);
//		String[] headers = new String[]{"省份","城市","学校","姓名","准考证号","身份证号"};
//		//创建表头
//		for (int i=0;i<headers.length;i++) {
//			Cell cell = row.createCell(i);
//			cell.setCellValue(headers[i].trim());
//		}
//		Query query = new Query();
//		query.addCriteria(Criteria.where("examCode").is(EXAM_CODE));
//		List<ExamStudentAdditional> examStudentAdditionals = mongoTemplate.find(query, ExamStudentAdditional.class);
//		Map<String, Object> map = new TreeMap<>();
//		for (ExamStudentAdditional examStudentAdditional : examStudentAdditionals) {
//			if(examStudentAdditional.getData().get("pro").toString().equals(PROVINCE)) {
//				map.put(examStudentAdditional.getStudentId(), examStudentAdditional.getData());
//			}
//		}
//
//		int j=1;
//		for (String ticketNumber : map.keySet()) {
//			Query query2 = new Query();
//			query2.addCriteria(Criteria.where("examCode").is(EXAM_CODE));
//			query2.addCriteria(Criteria.where("student.ticketNo").is(ticketNumber));
//			query2.addCriteria(Criteria.where("isAbsent").is(false));
//			List<ExamStudentAnswer> list = mongoTemplate.find(query2, ExamStudentAnswer.class);
//			Map<String, Object> dataMap = (Map<String, Object>) map.get(ticketNumber);
//			if (list.size() > 0) {
//				//添加到表格中
//				Row myrow = sheet.createRow(j);
//				for (int i=0;i<headers.length;i++) {
//					Cell cell = myrow.createCell(i);
//					if(i==0) {
//						cell.setCellValue(dataMap.get("pro").toString());
//					}
//					if(i==1) {
//						cell.setCellValue(dataMap.get("county").toString());
//					}
//					if(i==2) {
//						cell.setCellValue(dataMap.get("school").toString());
//					}
//					if(i==3) {
//						cell.setCellValue(dataMap.get("name").toString());
//					}
//					if(i==4) {
//						cell.setCellValue(ticketNumber);
//					}
//					if(i==5) {
//						cell.setCellValue(dataMap.get("stuidcardno").toString());
//					}
//				}
//				j++;
//			}
//		}
//		workbook.write(new FileOutputStream(xls));
//	}
//
//}
