xiatian 5 жил өмнө
parent
commit
47d002cb1a

+ 3 - 5
src/main/java/cn/com/qmth/export/Export.java

@@ -8,22 +8,20 @@ public class Export {
 
 	public static void main(String[] args) {
 		if(args==null||args.length==0) {
-			logger.error("需要输入导出参数 1:byCourse,2:byAllPaper,3:byAllQues");
+			logger.error("need param input as 1:byCourse,2:byAllQues");
 			return;
 		}
 		String type=args[0];
-		logger.debug("导出开始");
+		logger.debug("export start.............");
 		try {
 			if("1".equals(type)) {
 				ExportPaperByCourseCode.dispose();
 			}else if("2".equals(type)) {
-				ExportPaperByAllPaper.dispose();
-			}else if("3".equals(type)) {
 				ExportPaperByAllQuestions.dispose();
 			}
 		} catch (Exception e) {
 			logger.error(e.getCause(),e);
 		}
-		logger.debug("导出结束");
+		logger.debug("export end.............");
 	}
 }

+ 0 - 18
src/main/java/cn/com/qmth/export/ExportPaperByAllPaper.java

@@ -1,18 +0,0 @@
-package cn.com.qmth.export;
-
-import java.io.IOException;
-import java.sql.SQLException;
-
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-
-public class ExportPaperByAllPaper {
-	private static Logger logger = LogManager.getLogger(Export.class);
-	private static String excelDir;
-	private static String quesDir;
-
-	public static void dispose() throws InvalidFormatException, IOException, SQLException {
-
-	}
-}

+ 55 - 41
src/main/java/cn/com/qmth/export/ExportPaperByAllQuestions.java

@@ -15,14 +15,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 
 import oracle.jdbc.driver.OracleDriver;
 
 public class ExportPaperByAllQuestions {
-	private static Logger logger = LogManager.getLogger(Export.class);
+	private static int batchCount=100;
 	private static String courseCode="AAAAA";
 	private static String excelDir;
 	private static String quesDir;
@@ -78,45 +76,65 @@ public class ExportPaperByAllQuestions {
 		}
 	}
 
-
+	private static void exportPaper(Connection connect,String questionType) throws SQLException, IOException {
+		List<TestQuestion> tqs=exportQuestion(connect, questionType);
+		if(tqs==null||tqs.size()==0) {
+			return;
+		}
+		int batch=0;
+		int flag=0;
+		List<TestQuestion> temtps = new ArrayList<TestQuestion>();
+		for(int i=0;i<tqs.size();i++) {
+			batch++;
+			temtps.add(tqs.get(i));
+			if(batch==batchCount||i==tqs.size()-1) {
+				flag++;
+				createPaper(questionType, temtps, flag,quesTypes.get(questionType));
+				temtps = new ArrayList<TestQuestion>();
+				batch=0;
+			}
+		}
+	}
 	private static void exportFuhePaper(Connection connect,String questionType) throws SQLException, IOException {
-
-		List<TestPaper> tps = new ArrayList<TestPaper>();
-		TestPaper tp = new TestPaper();
-		tp.setId(questionType);
-		tp.setName(mutiQuesTypes.get(questionType)+"试卷(202)");
-		tp.setTestPaperContentId(questionType);
-		tp.setScore(100.0);
-		tps.add(tp);
-		List<SheetData> sheets = new ArrayList<SheetData>();
-		List<String> paperheader = new ArrayList<String>();
-		paperheader.addAll(Arrays.asList(new String[] { "试卷ID", "试卷名称", "试卷内容ID", "试卷满分" }));
-		fillPaperData(sheets, tps, paperheader);
-		int flag = 1;
-		exportFuheQuestion(connect, questionType, sheets, flag);
-		ExportUtils.exportExcel(excelDir, courseCode, sheets);
+		List<TestQuestion> tqs=exportFuheQuestion(connect, questionType);
+		if(tqs==null||tqs.size()==0) {
+			return;
+		}
+		int batch=0;
+		int flag=0;
+		List<TestQuestion> temtps = new ArrayList<TestQuestion>();
+		for(int i=0;i<tqs.size();i++) {
+			batch++;
+			temtps.add(tqs.get(i));
+			if(batch==batchCount||i==tqs.size()-1) {
+				flag++;
+				createPaper(questionType, temtps, flag,mutiQuesTypes.get(questionType));
+				temtps = new ArrayList<TestQuestion>();
+				batch=0;
+			}
+		}
 	}
-
-	private static void exportPaper(Connection connect,String questionType) throws SQLException, IOException {
-
+	
+	private static void createPaper(String questionType,List<TestQuestion> temtps,int flag,String questionTypeName) throws SQLException, IOException{
+		List<SheetData> sheets = new ArrayList<SheetData>();
 		List<TestPaper> tps = new ArrayList<TestPaper>();
 		TestPaper tp = new TestPaper();
 		tp.setId(questionType);
-		tp.setName(quesTypes.get(questionType)+"试卷(202)");
+		tp.setName(questionTypeName+"试卷-"+flag+"(202)");
 		tp.setTestPaperContentId(questionType);
-		tp.setScore(100.0);
+		tp.setScore(Double.valueOf(temtps.size()));
 		tps.add(tp);
-		List<SheetData> sheets = new ArrayList<SheetData>();
 		List<String> paperheader = new ArrayList<String>();
 		paperheader.addAll(Arrays.asList(new String[] { "试卷ID", "试卷名称", "试卷内容ID", "试卷满分" }));
 		fillPaperData(sheets, tps, paperheader);
-		int flag = 1;
-		exportQuestion(connect, questionType, sheets, flag);
-		ExportUtils.exportExcel(excelDir, courseCode, sheets);
+		List<String> header = new ArrayList<String>();
+		header.addAll(Arrays.asList(new String[] { "试题ID", "大题号", "大题名称", "小题号", "题分", "题父ID", "题类型" }));
+		fillQuestionData(sheets, temtps, header);
+		ExportUtils.exportExcel(excelDir, courseCode+"."+questionType+"."+flag, sheets);
 	}
 
 
-	private static void exportFuheQuestion(Connection connect, String questionType, List<SheetData> sheets, int flag)
+	private static List<TestQuestion> exportFuheQuestion(Connection connect, String questionType)
 			throws SQLException, IOException {
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
@@ -124,7 +142,7 @@ public class ExportPaperByAllQuestions {
 		try {
 			String sql = "with tem as (select h.question_content_id qid from question_info h  where h.question_type_enum ='"
 					+ questionType + "' and h.batch_type='1' )"
-					+ "SELECT q.ID id,'0' dNumber,'"+mutiQuesTypes.get(questionType)+"' dName,q.sequence number1,'1' score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
+					+ "SELECT q.ID id,'0' dNumber,'"+mutiQuesTypes.get(questionType)+"' dname,q.sequence number1,'1' score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
 					+ "					FROM QUESTION_CONTENT q,tem"
 					+ "          where q.id in tem.qid or q.parent_id in tem.qid"
 					+ "          order by q.create_time,q.parent_id,q.sequence";
@@ -144,9 +162,7 @@ public class ExportPaperByAllQuestions {
 				tq.setJson(resultSet.getString("json"));
 				tqs.add(tq);
 			}
-			List<String> header = new ArrayList<String>();
-			header.addAll(Arrays.asList(new String[] { "试题ID", "大题号", "大题名称", "小题号", "题分", "题父ID", "题类型" }));
-			fillQuestionData(sheets, tqs, header, flag);
+			return tqs;
 		} finally {
 			if (resultSet != null) {
 				resultSet.close();
@@ -175,15 +191,15 @@ public class ExportPaperByAllQuestions {
 		sheets.add(sheet);
 	}
 
-	private static void exportQuestion(Connection connect, String questionType, List<SheetData> sheets, int flag)
+	private static List<TestQuestion> exportQuestion(Connection connect, String questionType)
 			throws SQLException, IOException {
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
 
 		try {
-			String sql = "SELECT q.ID id,'0' dNumber,'"+mutiQuesTypes.get(questionType)+"' dName,q.sequence number1,'1' score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON" + 
+			String sql = "SELECT q.ID id,'0' dNumber,'"+quesTypes.get(questionType)+"' dname,q.sequence number1,'1' score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON" + 
 					"					FROM QUESTION_CONTENT q,question_info h" + 
-					"          where h.question_type_enum ='11' and h.batch_type='1'" + 
+					"          where h.question_type_enum ='"+questionType+"' and h.batch_type='1'" + 
 					"          and q.id =h.question_content_id and q.parent_id ='00000000000000000000000000000000'" + 
 					"          order by q.create_time";
 			preState = connect.prepareStatement(sql);
@@ -202,9 +218,7 @@ public class ExportPaperByAllQuestions {
 				tq.setJson(resultSet.getString("json"));
 				tqs.add(tq);
 			}
-			List<String> header = new ArrayList<String>();
-			header.addAll(Arrays.asList(new String[] { "试题ID", "大题号", "大题名称", "小题号", "题分", "题父ID", "题类型" }));
-			fillQuestionData(sheets, tqs, header, flag);
+			return tqs;
 		} finally {
 			if (resultSet != null) {
 				resultSet.close();
@@ -215,11 +229,11 @@ public class ExportPaperByAllQuestions {
 		}
 	}
 
-	public static void fillQuestionData(List<SheetData> sheets, List<TestQuestion> list, List<String> header, int flag)
+	public static void fillQuestionData(List<SheetData> sheets, List<TestQuestion> list, List<String> header)
 			throws IOException {
 		SheetData sheet = new SheetData();
 		sheet.setHeader(header);
-		sheet.setName("试卷" + flag);
+		sheet.setName("试卷");
 		List<Object[]> data = new ArrayList<Object[]>();
 		for (TestQuestion b : list) {
 			Object[] ob = new Object[header.size()];