xiatian il y a 5 ans
commit
8ccbfeba51

+ 20 - 0
.gitignore

@@ -0,0 +1,20 @@
+*.class
+
+# Proguard folder generated by ide
+.project
+.classpath
+.settings
+target/
+.idea/
+*.iml
+
+# Log Files
+*.log
+*.class
+
+
+# Package Files #
+*.jar
+*.war
+*.ear
+logs/

+ 210 - 0
pom.xml

@@ -0,0 +1,210 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>export-data</groupId>
+	<artifactId>export-data</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<properties>  
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
+        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>  
+    </properties> 
+	<dependencies>
+	<dependency>
+			<groupId>nl.jworks.markdown_to_asciidoc</groupId>
+			<artifactId>markdown_to_asciidoc</artifactId>
+			<version>1.0</version>
+			<scope>system</scope>
+			<systemPath>${project.basedir}/src/lib/markdown_to_asciidoc-1.0.jar</systemPath>
+
+		</dependency>
+		<dependency>
+			<groupId>io.github.swagger2markup</groupId>
+			<artifactId>swagger2markup</artifactId>
+			<version>1.3.1</version>
+		</dependency>
+		<dependency>
+        <groupId>io.swagger</groupId>
+        <artifactId>swagger-annotations</artifactId>
+        <version>1.5.24</version>
+      </dependency>
+      <dependency>
+        <groupId>io.swagger</groupId>
+        <artifactId>swagger-models</artifactId>
+        <version>1.5.24</version>
+      </dependency>
+      <dependency>
+        <groupId>io.springfox</groupId>
+        <artifactId>springfox-swagger2</artifactId>
+        <version>2.9.2</version>
+      </dependency>
+      <dependency>
+        <groupId>com.github.xiaoymin</groupId>
+        <artifactId>swagger-bootstrap-ui</artifactId>
+        <version>1.9.6</version>
+      </dependency>
+      <dependency>
+        <groupId>io.springfox</groupId>
+        <artifactId>springfox-swagger-ui</artifactId>
+        <version>2.9.2</version>
+      </dependency>
+		<dependency>
+			<groupId>com.oracle</groupId>
+			<artifactId>ojdbc6</artifactId>
+			<version>11.2.0.4.0-atlassian-hosted</version>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>8.0.17</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-1.2-api</artifactId>
+			<version>2.3</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi</artifactId>
+			<version>3.17</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml</artifactId>
+			<version>3.17</version>
+		</dependency>
+		<dependency>
+			<groupId>com.squareup.okhttp3</groupId>
+			<artifactId>okhttp</artifactId>
+			<version>3.11.0</version>
+		</dependency>
+		<dependency>
+			<groupId>com.google.guava</groupId>
+			<artifactId>guava</artifactId>
+			<version>23.0</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>2.5</version>
+		</dependency>
+		<dependency>
+			<groupId>com.google.code.gson</groupId>
+			<artifactId>gson</artifactId>
+			<version>2.8.5</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<configuration>
+					<testFailureIgnore>true</testFailureIgnore>
+					<skipTests>true</skipTests>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+					<compilerArgument>-proc:none</compilerArgument>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-source-plugin</artifactId>
+				<configuration>
+					<attach>true</attach>
+				</configuration>
+				<executions>
+					<execution>
+						<phase>compile</phase>
+						<goals>
+							<goal>jar</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>2.6</version>
+				<configuration>
+					<archive>
+						<manifest>
+							<addClasspath>true</addClasspath>
+							<classpathPrefix>lib/</classpathPrefix>
+							<mainClass>cn.com.qmth.export.Export</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<version>2.10</version>
+				<executions>
+					<execution>
+						<id>copy-dependencies</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-dependencies</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>${project.build.directory}/lib</outputDirectory>
+						</configuration>
+					</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>

+ 29 - 0
src/main/java/cn/com/qmth/export/Export.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.export;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+public class Export {
+	private static Logger logger = LogManager.getLogger(Export.class);
+
+	public static void main(String[] args) {
+		if(args==null||args.length==0) {
+			logger.error("需要输入导出参数 1:byCourse,2:byAllPaper,3:byAllQues");
+			return;
+		}
+		String type=args[0];
+		logger.debug("导出开始");
+		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("导出结束");
+	}
+}

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

@@ -0,0 +1,18 @@
+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 {
+
+	}
+}

+ 212 - 0
src/main/java/cn/com/qmth/export/ExportPaperByAllQuestions.java

@@ -0,0 +1,212 @@
+package cn.com.qmth.export;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+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 Logger logger = LogManager.getLogger(Export.class);
+	private static String excelDir;
+	private static String quesDir;
+
+	public static void dispose() throws InvalidFormatException, IOException, SQLException {
+		File directory = new File("");
+		excelDir = directory.getAbsolutePath() + "\\excelDir\\";
+		quesDir = excelDir + "quesDir\\";
+		File excelFolder = new File(excelDir);
+		if (excelFolder.exists()) {
+			FileUtil.clearDirectory(excelDir);
+		} else {
+			excelFolder.mkdir();
+		}
+		File quesFolder = new File(quesDir);
+		quesFolder.mkdir();
+		List<String> codes = readCourseCode();
+		if (codes == null || codes.size() == 0) {
+			logger.debug("无数据导出");
+			return;
+		}
+
+		Connection connect = null;
+
+		try {
+			Driver driver = new OracleDriver();
+			DriverManager.deregisterDriver(driver);
+
+			Properties pro = new Properties();
+			pro.put("user", "qspad");
+			pro.put("password", "qspad1");
+			connect = driver.connect("jdbc:oracle:thin:@202.114.196.115:1521:qspad", pro);
+			for (String code : codes) {
+				exportPaper(connect, code);
+			}
+		} finally {
+			if (connect != null) {
+				connect.close();
+			}
+		}
+	}
+
+	private static List<String> readCourseCode() throws InvalidFormatException, IOException {
+		File directory = new File("");
+		List<String> list = new ArrayList<String>();
+		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(row.getCell(1).getStringCellValue());
+			}
+		} finally {
+			if (wb != null) {
+				wb.close();
+			}
+		}
+		return list;
+	}
+
+	private static void exportPaper(Connection connect, String code) throws SQLException, IOException {
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+
+		try {
+			String sql = "SELECT * from TEST_PAPER_INFO p WHERE p.COURSE_ID in "
+					+ "(SELECT c.ID FROM PE_TCH_COURSE c WHERE c.code = '" + code
+					+ "') and (p.INVALID_REASON is null or p.INVALID_REASON='') and p.PAPER_STATUS = 0 "
+					+ "and p.NAME not like '%考试'";
+			preState = connect.prepareStatement(sql);
+
+			resultSet = preState.executeQuery();
+			List<TestPaper> tps = new ArrayList<TestPaper>();
+			while (resultSet.next()) {
+				TestPaper tp = new TestPaper();
+				tp.setId(resultSet.getString("id"));
+				tp.setName(resultSet.getString("name"));
+				tp.setTestPaperContentId(resultSet.getString("test_paper_content_id"));
+				tp.setScore(resultSet.getDouble("score"));
+				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;
+			for (TestPaper tp : tps) {
+				exportQuestion(connect, tp.getTestPaperContentId(), sheets, flag);
+				flag++;
+			}
+			ExportUtils.exportExcel(excelDir, code, sheets);
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+
+	public static void fillPaperData(List<SheetData> sheets, List<TestPaper> list, 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);
+		}
+		sheet.setData(data);
+		sheets.add(sheet);
+	}
+
+	private static void exportQuestion(Connection connect, String testPaperContentId, List<SheetData> sheets, int flag)
+			throws SQLException, IOException {
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+
+		try {
+			String sql = "SELECT q.ID id,d.dNumber,d.NAME dName,d.number1 number1,d.score score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
+					+ "FROM QUESTION_CONTENT q ,(SELECT b.QUESTION_CONTENT_ID question_id, b.SCORE score, b.SEQUENCE number1, c.NAME name, c.dNumber dNumber "
+					+ "FROM TEST_PAPER_QUESTION b ,(SELECT a.ID id, a.NAME name,a.SEQUENCE dNumber,a.TEST_PAPER_CONTENT_ID "
+					+ "FROM TEST_PAPER_QUESTION_GROUP a WHERE a.TEST_PAPER_CONTENT_ID = '" + testPaperContentId
+					+ "' ORDER BY a.SEQUENCE) c "
+					+ "WHERE b.TEST_PAPER_QUESTION_GROUP_ID = c.id ORDER BY c.dNumber,b.SEQUENCE) d WHERE q.ID = d.question_id ORDER BY d.dNumber,d.number1";
+			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);
+			}
+			List<String> header = new ArrayList<String>();
+			header.addAll(Arrays.asList(new String[] { "试题ID", "大题号", "大题名称", "小题号", "题分", "题父ID", "题类型" }));
+			fillQuestionData(sheets, tqs, header, flag);
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+
+	public static void fillQuestionData(List<SheetData> sheets, List<TestQuestion> list, List<String> header, int flag)
+			throws IOException {
+		SheetData sheet = new SheetData();
+		sheet.setHeader(header);
+		sheet.setName("试卷" + flag);
+		List<Object[]> data = new ArrayList<Object[]>();
+		for (TestQuestion b : list) {
+			Object[] ob = new Object[header.size()];
+			ob[0] = b.getId();
+			ob[1] = b.getdNumber();
+			ob[2] = b.getdName();
+			ob[3] = b.getNumber();
+			ob[4] = b.getScore();
+			ob[5] = b.getParentId();
+			ob[6] = b.getType();
+			File txtFile = new File(quesDir + b.getId() + ".txt");
+			if (!txtFile.exists()) {
+				FileUtil.writeTxt(quesDir, b.getId(), b.getJson());
+			}
+			data.add(ob);
+		}
+		sheet.setData(data);
+		sheets.add(sheet);
+	}
+
+}

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

@@ -0,0 +1,221 @@
+package cn.com.qmth.export;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+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 ExportPaperByCourseCode {
+	private static Logger logger = LogManager.getLogger(Export.class);
+	private static String excelDir;
+	private static String quesDir;
+
+	public static void main(String[] args) {
+		logger.debug("导出开始");
+		try {
+			dispose();
+		} catch (Exception e) {
+			logger.error(e.getCause(),e);
+		}
+		logger.debug("导出结束");
+	}
+
+	public static void dispose() throws InvalidFormatException, IOException, SQLException {
+		File directory = new File("");
+		excelDir = directory.getAbsolutePath() + "\\excelDir\\";
+		quesDir = excelDir + "quesDir\\";
+		File excelFolder = new File(excelDir);
+		if (excelFolder.exists()) {
+			FileUtil.clearDirectory(excelDir);
+		} else {
+			excelFolder.mkdir();
+		}
+		File quesFolder = new File(quesDir);
+		quesFolder.mkdir();
+		List<String> codes = readCourseCode();
+		if (codes == null || codes.size() == 0) {
+			logger.debug("无数据导出");
+			return;
+		}
+
+		Connection connect = null;
+
+		try {
+			Driver driver = new OracleDriver();
+			DriverManager.deregisterDriver(driver);
+
+			Properties pro = new Properties();
+			pro.put("user", "qspad");
+			pro.put("password", "qspad1");
+			connect = driver.connect("jdbc:oracle:thin:@202.114.196.115:1521:qspad", pro);
+			for (String code : codes) {
+				exportPaper(connect, code);
+			}
+		} finally {
+			if (connect != null) {
+				connect.close();
+			}
+		}
+	}
+
+	private static List<String> readCourseCode() throws InvalidFormatException, IOException {
+		File directory = new File("");
+		List<String> list = new ArrayList<String>();
+		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(row.getCell(1).getStringCellValue());
+			}
+		} finally {
+			if (wb != null) {
+				wb.close();
+			}
+		}
+		return list;
+	}
+
+	private static void exportPaper(Connection connect, String code) throws SQLException, IOException {
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+
+		try {
+			String sql = "SELECT * from TEST_PAPER_INFO p WHERE p.COURSE_ID in "
+					+ "(SELECT c.ID FROM PE_TCH_COURSE c WHERE c.code = '" + code
+					+ "') and (p.INVALID_REASON is null or p.INVALID_REASON='') and p.PAPER_STATUS = 0 "
+					+ "and p.NAME not like '%考试'";
+			preState = connect.prepareStatement(sql);
+
+			resultSet = preState.executeQuery();
+			List<TestPaper> tps = new ArrayList<TestPaper>();
+			while (resultSet.next()) {
+				TestPaper tp = new TestPaper();
+				tp.setId(resultSet.getString("id"));
+				tp.setName(resultSet.getString("name"));
+				tp.setTestPaperContentId(resultSet.getString("test_paper_content_id"));
+				tp.setScore(resultSet.getDouble("score"));
+				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;
+			for (TestPaper tp : tps) {
+				exportQuestion(connect, tp.getTestPaperContentId(), sheets, flag);
+				flag++;
+			}
+			ExportUtils.exportExcel(excelDir, code, sheets);
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+
+	public static void fillPaperData(List<SheetData> sheets, List<TestPaper> list, 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);
+		}
+		sheet.setData(data);
+		sheets.add(sheet);
+	}
+
+	private static void exportQuestion(Connection connect, String testPaperContentId, List<SheetData> sheets, int flag)
+			throws SQLException, IOException {
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+
+		try {
+			String sql = "SELECT q.ID id,d.dNumber,d.NAME dName,d.number1 number1,d.score score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
+					+ "FROM QUESTION_CONTENT q ,(SELECT b.QUESTION_CONTENT_ID question_id, b.SCORE score, b.SEQUENCE number1, c.NAME name, c.dNumber dNumber "
+					+ "FROM TEST_PAPER_QUESTION b ,(SELECT a.ID id, a.NAME name,a.SEQUENCE dNumber,a.TEST_PAPER_CONTENT_ID "
+					+ "FROM TEST_PAPER_QUESTION_GROUP a WHERE a.TEST_PAPER_CONTENT_ID = '" + testPaperContentId
+					+ "' ORDER BY a.SEQUENCE) c "
+					+ "WHERE b.TEST_PAPER_QUESTION_GROUP_ID = c.id ORDER BY c.dNumber,b.SEQUENCE) d WHERE q.ID = d.question_id ORDER BY d.dNumber,d.number1";
+			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);
+			}
+			List<String> header = new ArrayList<String>();
+			header.addAll(Arrays.asList(new String[] { "试题ID", "大题号", "大题名称", "小题号", "题分", "题父ID", "题类型" }));
+			fillQuestionData(sheets, tqs, header, flag);
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+
+	public static void fillQuestionData(List<SheetData> sheets, List<TestQuestion> list, List<String> header, int flag)
+			throws IOException {
+		SheetData sheet = new SheetData();
+		sheet.setHeader(header);
+		sheet.setName("试卷" + flag);
+		List<Object[]> data = new ArrayList<Object[]>();
+		for (TestQuestion b : list) {
+			Object[] ob = new Object[header.size()];
+			ob[0] = b.getId();
+			ob[1] = b.getdNumber();
+			ob[2] = b.getdName();
+			ob[3] = b.getNumber();
+			ob[4] = b.getScore();
+			ob[5] = b.getParentId();
+			ob[6] = b.getType();
+			File txtFile = new File(quesDir + b.getId() + ".txt");
+			if (!txtFile.exists()) {
+				FileUtil.writeTxt(quesDir, b.getId(), b.getJson());
+			}
+			data.add(ob);
+		}
+		sheet.setData(data);
+		sheets.add(sheet);
+	}
+}

+ 146 - 0
src/main/java/cn/com/qmth/export/ExportUtils.java

@@ -0,0 +1,146 @@
+package cn.com.qmth.export;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+/*
+ * excel导出工具
+ */
+public class ExportUtils {
+	private static Logger logger = LogManager.getLogger(ExportUtils.class);
+	private static final String DEFALUT_EXT = ".xlsx";
+
+	public static void exportExcel(String dir, String fileName, List<SheetData> data) {
+		File file = new File(dir + fileName + DEFALUT_EXT);
+		if (file.exists()) {
+			file.delete();
+		}
+		OutputStream outputStream = null;
+		try {
+			outputStream = new FileOutputStream(file);
+			write(data, outputStream);
+			outputStream.flush();
+
+		} catch (Exception e) {
+			logger.error(e);
+		} finally {
+			if (outputStream != null) {
+				try {
+					outputStream.close();
+				} catch (IOException e) {
+					logger.error(e);
+				}
+			}
+		}
+	}
+
+	private static void write(List<SheetData> data, OutputStream out) {
+		// 声明一个工作薄
+		XSSFWorkbook workbook = null;
+		try {
+			workbook = new XSSFWorkbook();
+			for (SheetData sheetData : data) {
+				// 生成一个表格
+				XSSFSheet sheet = workbook.createSheet(sheetData.getName());
+				// 生成一个样式
+				XSSFCellStyle style = workbook.createCellStyle();
+
+				// 产生表格标题行
+				List<String> header = sheetData.getHeader();
+				int[] colwidth = new int[header.size()];
+				XSSFRow row = sheet.createRow(0);
+				for (short i = 0; i < header.size(); i++) {
+					colwidth[i] = 15;
+					XSSFCell cell = row.createCell(i);
+					cell.setCellStyle(style);
+					XSSFRichTextString text = new XSSFRichTextString(header.get(i));
+					cell.setCellValue(text);
+					int textlen = length(header.get(i));
+					if (textlen > colwidth[i]) {
+						colwidth[i] = textlen;
+					}
+				}
+
+				List<Object[]> rows = sheetData.getData();
+				// 遍历集合数据,产生数据行
+				for (short r = 0; r < rows.size(); r++) {
+					row = sheet.createRow(r + 1);
+					Object[] rowdata = rows.get(r);
+					for (short i = 0; i < header.size(); i++) {
+						XSSFCell cell = row.createCell(i);
+						cell.setCellType(CellType.STRING);
+						Object value = rowdata[i];
+						// 判断值的类型后进行强制类型转换
+						String textValue = null;
+						if (value == null) {
+							textValue = "";
+						} else if (value instanceof Boolean) {
+							boolean bValue = (Boolean) value;
+							textValue = "是";
+							if (!bValue) {
+								textValue = "否";
+							}
+						} else if (value instanceof Date) {
+							Date date = (Date) value;
+							SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+							textValue = sdf.format(date);
+						} else {
+							// 其它数据类型都当作字符串简单处理
+							textValue = String.valueOf(value);
+						}
+						cell.setCellValue(textValue);
+						int textlen = length(textValue);
+						if (textlen > colwidth[i]) {
+							colwidth[i] = textlen;
+						}
+					}
+
+				}
+				for (int i = 0; i < colwidth.length; i++) {
+					sheet.setColumnWidth(i, 286 * colwidth[i]);
+				}
+			}
+			workbook.write(out);
+		} catch (Exception e) {
+			logger.error("导出出错", e);
+		} finally {
+			try {
+				if (workbook != null) {
+					workbook.close();
+				}
+			} catch (IOException e) {
+				logger.error("导出出错", e);
+			}
+		}
+
+	}
+
+	private static int length(String value) {
+		int valueLength = 0;
+		String chinese = "[\u4e00-\u9fa5]";
+		for (int i = 0; i < value.length(); i++) {
+			String temp = value.substring(i, i + 1);
+			if (temp.matches(chinese)) {
+				valueLength += 2;
+			} else {
+				valueLength += 1;
+			}
+		}
+		return valueLength;
+	}
+}

+ 83 - 0
src/main/java/cn/com/qmth/export/FileUtil.java

@@ -0,0 +1,83 @@
+package cn.com.qmth.export;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+public class FileUtil {
+	public static void writeTxt(String dir,String name,String content) throws IOException {
+		BufferedWriter out=null;
+		try {
+			File writename = new File(dir+name+".txt");
+			writename.createNewFile();
+			out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writename), "UTF-8"));  
+			out.write(content);
+			out.flush();
+		} finally {
+			if(out!=null) {
+				out.close();
+			}
+		}
+	}
+	public static void deleteFolder(String path) {
+
+		File file = new File(path);
+		if (file.exists()) {
+			if (file.isFile()) {
+				deleteFile(path);
+			} else {
+				deleteDirectory(path);
+			}
+		}
+	}
+
+	public static void deleteFile(String path) {
+		File file = new File(path);
+		if (file.isFile() && file.exists()) {
+			file.delete();
+		}
+	}
+
+	public static void deleteDirectory(String path) {
+		if (!path.endsWith(File.separator)) {
+			path = path + File.separator;
+		}
+		File dirFile = new File(path);
+		if (!dirFile.exists() || !dirFile.isDirectory()) {
+			return;
+		}
+		File[] files = dirFile.listFiles();
+		if (files != null) {
+			for (int i = 0; i < files.length; i++) {
+				if (files[i].isFile()) {
+					deleteFile(files[i].getAbsolutePath());
+				} else {
+					deleteDirectory(files[i].getAbsolutePath());
+				}
+			}
+		}
+
+		dirFile.delete();
+	}
+	public static void clearDirectory(String path) {
+		if (!path.endsWith(File.separator)) {
+			path = path + File.separator;
+		}
+		File dirFile = new File(path);
+		if (!dirFile.exists() || !dirFile.isDirectory()) {
+			return;
+		}
+		File[] files = dirFile.listFiles();
+		if (files != null) {
+			for (int i = 0; i < files.length; i++) {
+				if (files[i].isFile()) {
+					deleteFile(files[i].getAbsolutePath());
+				} else {
+					deleteDirectory(files[i].getAbsolutePath());
+				}
+			}
+		}
+	}
+}

+ 28 - 0
src/main/java/cn/com/qmth/export/SheetData.java

@@ -0,0 +1,28 @@
+package cn.com.qmth.export;
+
+import java.util.List;
+
+public class SheetData {
+	private String name;
+	private List<String> header;
+	private List<Object[]> data;
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public List<Object[]> getData() {
+		return data;
+	}
+	public void setData(List<Object[]> data) {
+		this.data = data;
+	}
+	public List<String> getHeader() {
+		return header;
+	}
+	public void setHeader(List<String> header) {
+		this.header = header;
+	}
+	
+}

+ 63 - 0
src/main/java/cn/com/qmth/export/TestPaper.java

@@ -0,0 +1,63 @@
+package cn.com.qmth.export;
+
+/**
+ * @author weiwenhai
+ * @date 2018.7.19
+ * @company qmth
+ * @describle 地大试卷对象
+ */
+public class TestPaper {
+
+    /**
+     * id
+     */
+    private String id;
+
+    /**
+     * 试卷名称
+     */
+    private String name;
+
+    /**
+     * 试卷详情
+     */
+    private String testPaperContentId;
+
+    /**
+     * 试卷总分
+     */
+    private Double score;
+
+    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 getTestPaperContentId() {
+        return testPaperContentId;
+    }
+
+    public void setTestPaperContentId(String testPaperContentId) {
+        this.testPaperContentId = testPaperContentId;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+}

+ 116 - 0
src/main/java/cn/com/qmth/export/TestQuestion.java

@@ -0,0 +1,116 @@
+package cn.com.qmth.export;
+
+/**
+ * @author weiwenhai
+ * @date 2018.7.19
+ * @company qmth
+ * @describle 地大试题对象
+ */
+public class TestQuestion {
+
+    /**
+     * 试题id
+     */
+    private String id;
+
+    /**
+     * 大题序号
+     */
+    private Integer dNumber;
+
+    /**
+     * 大题名称
+     */
+    private String dName;
+
+    /**
+     * 小题序号
+     */
+    private Integer number1;
+
+    /**
+     * 小题分数
+     */
+    private Double score;
+
+    /**
+     * 小题父id,用于套题
+     */
+    private String parentId;
+
+    /**
+     * 小题类型
+     * 11-单选题;12-多选题;13-填空题;14-选词填空;15-完形填空;20-判断题;42-复合题;60-问答题;69-名词解释
+     */
+    private Integer type;
+
+    /**
+     * 试题内容
+     */
+    private String json;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Integer getdNumber() {
+        return dNumber;
+    }
+
+    public void setdNumber(Integer dNumber) {
+        this.dNumber = dNumber;
+    }
+
+    public String getdName() {
+        return dName;
+    }
+
+    public void setdName(String dName) {
+        this.dName = dName;
+    }
+
+    public Integer getNumber() {
+        return number1;
+    }
+
+    public void setNumber(Integer number1) {
+        this.number1 = number1;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public String getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(String parentId) {
+        this.parentId = parentId;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getJson() {
+        return json;
+    }
+
+    public void setJson(String json) {
+        this.json = json;
+    }
+
+}

+ 32 - 0
src/main/resources/log4j2.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN" monitorInterval="30">
+	<Appenders>
+		<!-- 控制台 日志 -->
+		<Console name="Console" target="SYSTEM_OUT">
+			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}| %level | %X{TRACE_ID} - %X{CALLER} | %m | %l%n" />
+		</Console>
+		<!-- debug 日志 -->
+		<RollingFile name="DEBUG_APPERDER" fileName="./logs/debug/debug.log" filePattern="./logs/debug/debug-%d{yyyy.MM.dd.HH}-%i.log">
+			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}| %level | %X{TRACE_ID} - %X{CALLER} | %m | %l%n" />
+			<Policies>
+				<SizeBasedTriggeringPolicy size="100 MB" />
+			</Policies>
+			<DefaultRolloverStrategy max="10000">
+			</DefaultRolloverStrategy>
+		</RollingFile>
+	</Appenders>
+
+	<Loggers>
+		<Logger name="cn.com.qmth" level="debug" additivity="false">
+			<AppenderRef ref="DEBUG_APPERDER" />
+			<AppenderRef ref="Console" />
+		</Logger>
+
+
+		<Root level="INFO">
+			<AppenderRef ref="Console" />
+			<AppenderRef ref="DEBUG_APPERDER" />
+		</Root>
+	</Loggers>
+
+</Configuration>