xiatian 5 жил өмнө
parent
commit
95a0083c07

+ 0 - 40
pom.xml

@@ -164,47 +164,7 @@
 					</execution>
 				</executions>
 			</plugin>
-			<plugin>
-				<groupId>io.github.swagger2markup</groupId>
-				<artifactId>swagger2markup-maven-plugin</artifactId>
-				<version>1.2.0</version>
-				<configuration>
-					<!--此处端口一定要是当前项目启动所用的端口 -->
-					<swaggerInput>http://192.168.1.91:8090/v2/api-docs</swaggerInput>
-					<outputDir>src/docs/asciidoc/generated</outputDir>
-					<config>
-						<!-- 除了ASCIIDOC之外,还有MARKDOWN和CONFLUENCE_MARKUP可选 -->
-						<swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
-					</config>
-				</configuration>
-			</plugin>
 		</plugins>
 	</build>
 
-	<repositories>
-		<repository>
-			<id>nexus</id>
-			<name>Nexus</name>
-			<url>http://nexus-host:8081/repository/maven-public/</url>
-		</repository>
-	</repositories>
-
-	<pluginRepositories>
-		<pluginRepository>
-			<id>nexus</id>
-			<name>Nexus</name>
-			<url>http://nexus-host:8081/repository/maven-public/</url>
-		</pluginRepository>
-	</pluginRepositories>
-
-	<distributionManagement>
-		<repository>
-			<id>releases</id>
-			<url>http://nexus-host:8081/repository/maven-releases/</url>
-		</repository>
-		<snapshotRepository>
-			<id>snapshots</id>
-			<url>http://nexus-host:8081/repository/maven-snapshots/</url>
-		</snapshotRepository>
-	</distributionManagement>
 </project>

+ 35 - 0
src/main/java/cn/com/qmth/export/CourseInfo.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.export;
+
+public class CourseInfo {
+	private String id;
+	private String name;
+	private String code;
+	public String getId() {
+		return id;
+	}
+	public void setId(String id) {
+		this.id = id;
+	}
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getCode() {
+		return code;
+	}
+	public void setCode(String code) {
+		this.code = code;
+	}
+	public CourseInfo(String id, String name, String code) {
+		super();
+		this.id = id;
+		this.name = name;
+		this.code = code;
+	}
+	public CourseInfo() {
+		super();
+	}
+	
+}

+ 99 - 109
src/main/java/cn/com/qmth/export/ExportPaperByAllQuestions.java

@@ -15,17 +15,21 @@ 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 org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 import oracle.jdbc.driver.OracleDriver;
 
 public class ExportPaperByAllQuestions {
-	private static int batchCount=100;
-	private static String courseCode="AAAAA";
+	private static Logger logger = LogManager.getLogger(Export.class);
 	private static String excelDir;
 	private static String quesDir;
+	
 	private static Map<String, String> quesTypes = new HashMap<String, String>();
-	private static Map<String, String> mutiQuesTypes = new HashMap<String, String>();
 	static {
 		quesTypes.put("11", "单选题");
 		quesTypes.put("13", "填空题");
@@ -33,11 +37,21 @@ public class ExportPaperByAllQuestions {
 		quesTypes.put("69", "名词解释");
 		quesTypes.put("12", "多选题");
 		quesTypes.put("60", "问答题");
+		quesTypes.put("42", "复合题");
+		quesTypes.put("14", "选词填空");
+		quesTypes.put("15", "完形填空");
+		quesTypes.put("61", "分析题");
+		
 	}
-	static {
-		mutiQuesTypes.put("42", "复合题");
-		mutiQuesTypes.put("14", "选词填空");
-		mutiQuesTypes.put("15", "完形填空");
+
+	public static void main(String[] args) {
+		logger.debug("export start...");
+		try {
+			dispose();
+		} catch (Exception e) {
+			logger.error(e.getCause(),e);
+		}
+		logger.debug("export end...");
 	}
 
 	public static void dispose() throws InvalidFormatException, IOException, SQLException {
@@ -52,6 +66,11 @@ public class ExportPaperByAllQuestions {
 		}
 		File quesFolder = new File(quesDir);
 		quesFolder.mkdir();
+		List<CourseInfo> codes = readCourseCode();
+		if (codes == null || codes.size() == 0) {
+			logger.debug("no data export");
+			return;
+		}
 
 		Connection connect = null;
 
@@ -63,11 +82,8 @@ public class ExportPaperByAllQuestions {
 			pro.put("user", "qspad");
 			pro.put("password", "qspad1");
 			connect = driver.connect("jdbc:oracle:thin:@202.114.196.115:1521:qspad", pro);
-			for(String k:mutiQuesTypes.keySet()) {
-				exportFuhePaper(connect, k);
-			}
-			for(String k:quesTypes.keySet()) {
-				exportPaper(connect, k);
+			for (CourseInfo code : codes) {
+				exportPaper(connect, code);
 			}
 		} finally {
 			if (connect != null) {
@@ -76,93 +92,43 @@ 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 List<CourseInfo> readCourseCode() throws InvalidFormatException, IOException {
+		File directory = new File("");
+		List<CourseInfo> list = new ArrayList<CourseInfo>();
+		XSSFWorkbook wb = null;
+		try {
+			wb = new XSSFWorkbook(directory.getAbsolutePath() + "\\CourseCode.xlsx");
+			XSSFSheet sheet = wb.getSheetAt(0);
+			int rows = sheet.getLastRowNum();
+			for (int i = 1; i <= rows; i++) {
+				XSSFRow row = sheet.getRow(i);
+				list.add(new CourseInfo(row.getCell(2).getStringCellValue(), row.getCell(0).getStringCellValue(), row.getCell(1).getStringCellValue()));
 			}
-		}
-	}
-	private static void exportFuhePaper(Connection connect,String questionType) throws SQLException, IOException {
-		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;
+		} finally {
+			if (wb != null) {
+				wb.close();
 			}
 		}
+		return list;
 	}
-	
-	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(questionTypeName+"试卷-"+flag+"(202)");
-		tp.setTestPaperContentId(questionType);
-		tp.setScore(Double.valueOf(temtps.size()));
-		tps.add(tp);
-		List<String> paperheader = new ArrayList<String>();
-		paperheader.addAll(Arrays.asList(new String[] { "试卷ID", "试卷名称", "试卷内容ID", "试卷满分" }));
-		fillPaperData(sheets, tps, paperheader);
-		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 List<TestQuestion> exportFuheQuestion(Connection connect, String questionType)
-			throws SQLException, IOException {
+	private static void exportPaper(Connection connect, CourseInfo course) throws SQLException, IOException {
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
 
 		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 "
-					+ "					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";
-			preState = connect.prepareStatement(sql);
-
-			resultSet = preState.executeQuery();
-			List<TestQuestion> tqs = new ArrayList<TestQuestion>();
-			while (resultSet.next()) {
-				TestQuestion tq = new TestQuestion();
-				tq.setId(resultSet.getString("id"));
-				tq.setdNumber(resultSet.getInt("dnumber"));
-				tq.setdName(resultSet.getString("dname"));
-				tq.setNumber(resultSet.getInt("number1"));
-				tq.setScore(resultSet.getDouble("score"));
-				tq.setParentId(resultSet.getString("parent_id"));
-				tq.setType(resultSet.getInt("type"));
-				tq.setJson(resultSet.getString("json"));
-				tqs.add(tq);
-			}
-			return tqs;
+			TestPaper tp = new TestPaper();
+			tp.setId("none");
+			tp.setName(course.getName()+"试题库试卷");
+			tp.setTestPaperContentId("none");
+			tp.setScore(0.0);
+			List<SheetData> sheets = new ArrayList<SheetData>();
+			List<String> paperheader = new ArrayList<String>();
+			paperheader.addAll(Arrays.asList(new String[] { "试卷ID", "试卷名称", "试卷内容ID", "试卷满分" }));
+			fillPaperData(sheets, tp, paperheader);
+			exportQuestion(connect, course.getId(), sheets);
+			fillScore(sheets);
+			ExportUtils.exportExcel(excelDir, course.getCode(), sheets);
 		} finally {
 			if (resultSet != null) {
 				resultSet.close();
@@ -172,36 +138,59 @@ public class ExportPaperByAllQuestions {
 			}
 		}
 	}
+	
+	private static void fillScore(List<SheetData> sheets) {
+		SheetData s1=sheets.get(1);
+		List<Object[]> data1=s1.getData();
+		Map<String,Integer> sc=new HashMap<String,Integer>();
+		for(Object[] obs:data1) {
+			String pid=(String)obs[5];
+			if(!"00000000000000000000000000000000".equals(pid)) {
+				Integer scr=sc.get(pid);
+				if(scr==null) {
+					sc.put(pid, 1);
+				}else {
+					sc.put(pid, scr+1);
+				}
+			}
+		}
+		for(Object[] obs:data1) {
+			String id=(String)obs[0];
+			if(sc.get(id)!=null) {
+				obs[4]=sc.get(id)+".0";
+			}
+		}
+		
+		SheetData s0=sheets.get(0);
+		List<Object[]> data0=s0.getData();
+		data0.get(0)[3]=(data1.size()-sc.size())+".0";
+	}
 
-
-	public static void fillPaperData(List<SheetData> sheets, List<TestPaper> list, List<String> header) {
+	public static void fillPaperData(List<SheetData> sheets, TestPaper tp, List<String> header) {
 		SheetData sheet = new SheetData();
 		sheet.setHeader(header);
 		sheet.setName("课程试卷信息");
 		List<Object[]> data = new ArrayList<Object[]>();
-		for (TestPaper b : list) {
-			Object[] ob = new Object[header.size()];
-			ob[0] = b.getId();
-			ob[1] = b.getName();
-			ob[2] = b.getTestPaperContentId();
-			ob[3] = b.getScore();
-			data.add(ob);
-		}
+		Object[] ob = new Object[header.size()];
+		ob[0] = tp.getId();
+		ob[1] = tp.getName();
+		ob[2] = tp.getTestPaperContentId();
+		ob[3] = tp.getScore();
+		data.add(ob);
 		sheet.setData(data);
 		sheets.add(sheet);
 	}
 
-	private static List<TestQuestion> exportQuestion(Connection connect, String questionType)
+	private static void exportQuestion(Connection connect, String courseId, List<SheetData> sheets)
 			throws SQLException, IOException {
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
 
 		try {
-			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 ='"+questionType+"' and h.batch_type='1'" + 
-					"          and q.id =h.question_content_id and q.parent_id ='00000000000000000000000000000000'" + 
-					"          order by q.create_time";
+			String sql = "SELECT t.question_type_enum qtype,q.ID id,t.question_type_enum dNumber,q.sequence number1,'1' score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON" + 
+					"	FROM QUESTION_CONTENT q,question_info t" + 
+					"	where t.id(+)=q.question_info_id" + 
+					"   and  t.batch_type='1' and t.course_id='"+courseId+"'	order by q.parent_id,t.question_type_enum,q.sequence";
 			preState = connect.prepareStatement(sql);
 
 			resultSet = preState.executeQuery();
@@ -210,7 +199,7 @@ public class ExportPaperByAllQuestions {
 				TestQuestion tq = new TestQuestion();
 				tq.setId(resultSet.getString("id"));
 				tq.setdNumber(resultSet.getInt("dnumber"));
-				tq.setdName(resultSet.getString("dname"));
+				tq.setdName(quesTypes.get(resultSet.getString("qtype")));
 				tq.setNumber(resultSet.getInt("number1"));
 				tq.setScore(resultSet.getDouble("score"));
 				tq.setParentId(resultSet.getString("parent_id"));
@@ -218,7 +207,9 @@ public class ExportPaperByAllQuestions {
 				tq.setJson(resultSet.getString("json"));
 				tqs.add(tq);
 			}
-			return tqs;
+			List<String> header = new ArrayList<String>();
+			header.addAll(Arrays.asList(new String[] { "试题ID", "大题号", "大题名称", "小题号", "题分", "题父ID", "题类型" }));
+			fillQuestionData(sheets, tqs, header);
 		} finally {
 			if (resultSet != null) {
 				resultSet.close();
@@ -253,5 +244,4 @@ public class ExportPaperByAllQuestions {
 		sheet.setData(data);
 		sheets.add(sheet);
 	}
-
 }

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

@@ -28,13 +28,13 @@ public class ExportPaperByCourseCode {
 	private static String quesDir;
 
 	public static void main(String[] args) {
-		logger.debug("导出开始");
+		logger.debug("export start...");
 		try {
 			dispose();
 		} catch (Exception e) {
 			logger.error(e.getCause(),e);
 		}
-		logger.debug("导出结束");
+		logger.debug("export end...");
 	}
 
 	public static void dispose() throws InvalidFormatException, IOException, SQLException {
@@ -51,7 +51,7 @@ public class ExportPaperByCourseCode {
 		quesFolder.mkdir();
 		List<String> codes = readCourseCode();
 		if (codes == null || codes.size() == 0) {
-			logger.debug("无数据导出");
+			logger.debug("no data export");
 			return;
 		}