|
@@ -10,22 +10,37 @@ import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
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 Logger logger = LogManager.getLogger(Export.class);
|
|
|
+ private static String courseCode="AAAAA";
|
|
|
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", "填空题");
|
|
|
+ quesTypes.put("20", "判断题");
|
|
|
+ quesTypes.put("69", "名词解释");
|
|
|
+ quesTypes.put("12", "多选题");
|
|
|
+ quesTypes.put("60", "问答题");
|
|
|
+ }
|
|
|
+ static {
|
|
|
+ mutiQuesTypes.put("42", "复合题");
|
|
|
+ mutiQuesTypes.put("14", "选词填空");
|
|
|
+ mutiQuesTypes.put("15", "完形填空");
|
|
|
+ }
|
|
|
|
|
|
public static void dispose() throws InvalidFormatException, IOException, SQLException {
|
|
|
File directory = new File("");
|
|
@@ -39,11 +54,6 @@ public class ExportPaperByAllQuestions {
|
|
|
}
|
|
|
File quesFolder = new File(quesDir);
|
|
|
quesFolder.mkdir();
|
|
|
- List<String> codes = readCourseCode();
|
|
|
- if (codes == null || codes.size() == 0) {
|
|
|
- logger.debug("无数据导出");
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
Connection connect = null;
|
|
|
|
|
@@ -55,8 +65,11 @@ 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 code : codes) {
|
|
|
- exportPaper(connect, code);
|
|
|
+ for(String k:mutiQuesTypes.keySet()) {
|
|
|
+ exportFuhePaper(connect, k);
|
|
|
+ }
|
|
|
+ for(String k:quesTypes.keySet()) {
|
|
|
+ exportPaper(connect, k);
|
|
|
}
|
|
|
} finally {
|
|
|
if (connect != null) {
|
|
@@ -65,57 +78,75 @@ public class ExportPaperByAllQuestions {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void exportPaper(Connection connect,String questionType) throws SQLException, IOException {
|
|
|
+
|
|
|
+ List<TestPaper> tps = new ArrayList<TestPaper>();
|
|
|
+ TestPaper tp = new TestPaper();
|
|
|
+ tp.setId(questionType);
|
|
|
+ tp.setName(quesTypes.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;
|
|
|
+ exportQuestion(connect, questionType, sheets, flag);
|
|
|
+ ExportUtils.exportExcel(excelDir, courseCode, sheets);
|
|
|
}
|
|
|
|
|
|
- private static void exportPaper(Connection connect, String code) throws SQLException, IOException {
|
|
|
+
|
|
|
+ private static void exportFuheQuestion(Connection connect, String questionType, List<SheetData> sheets, int flag)
|
|
|
+ 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 '%考试'";
|
|
|
+ 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<TestPaper> tps = new ArrayList<TestPaper>();
|
|
|
+ List<TestQuestion> tqs = new ArrayList<TestQuestion>();
|
|
|
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++;
|
|
|
+ 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);
|
|
|
}
|
|
|
- ExportUtils.exportExcel(excelDir, code, sheets);
|
|
|
+ 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();
|
|
@@ -126,6 +157,7 @@ public class ExportPaperByAllQuestions {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static void fillPaperData(List<SheetData> sheets, List<TestPaper> list, List<String> header) {
|
|
|
SheetData sheet = new SheetData();
|
|
|
sheet.setHeader(header);
|
|
@@ -143,18 +175,17 @@ public class ExportPaperByAllQuestions {
|
|
|
sheets.add(sheet);
|
|
|
}
|
|
|
|
|
|
- private static void exportQuestion(Connection connect, String testPaperContentId, List<SheetData> sheets, int flag)
|
|
|
+ private static void exportQuestion(Connection connect, String questionType, 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";
|
|
|
+ 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" +
|
|
|
+ " FROM QUESTION_CONTENT q,question_info h" +
|
|
|
+ " where h.question_type_enum ='11' 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);
|
|
|
|
|
|
resultSet = preState.executeQuery();
|