xiatian 5 роки тому
батько
коміт
f96287be2a

+ 28 - 23
src/main/java/cn/com/qmth/importpaper/ImportPaperByAllQues.java

@@ -23,6 +23,8 @@ import okhttp3.Response;
 public class ImportPaperByAllQues {
 public class ImportPaperByAllQues {
 
 
 	private static Logger logger = LogManager.getLogger(ImportPaperByAllQues.class);
 	private static Logger logger = LogManager.getLogger(ImportPaperByAllQues.class);
+	
+	private static String paperSuff=null;
 
 
 	private static String sourceDir = "d:\\2020ddimport\\excelDir";
 	private static String sourceDir = "d:\\2020ddimport\\excelDir";
 
 
@@ -43,28 +45,28 @@ public class ImportPaperByAllQues {
 		Date start = new Date();
 		Date start = new Date();
 		int errnum = 0;
 		int errnum = 0;
 		StringBuilder sb = new StringBuilder();
 		StringBuilder sb = new StringBuilder();
-//		int num = 0;
-//		String fname = null;
-//		File dir = new File(sourceDir);
-//		for (File f : dir.listFiles()) {
-//			fname = f.getName();
-//			if (!f.isDirectory() && fname.endsWith(".xlsx")) {
-//				num++;
-//				Date n = new Date();
-//				try {
-//					importCoursePaper(f);
-//					Date et = new Date();
-//					logger.debug("导入成功(" + num + "):" + fname + " 耗时:" + (et.getTime() - n.getTime()));
-//				} catch (Exception e) {
-//					errnum++;
-//					sb.append(fname).append(",");
-//					Date et = new Date();
-//					logger.error(
-//							"导入失败(" + num + "):" + fname + " 耗时:" + (et.getTime() - n.getTime()) + " " + e.getMessage(),
-//							e);
-//				}
-//			}
-//		}
+		int num = 0;
+		String fname = null;
+		File dir = new File(sourceDir);
+		for (File f : dir.listFiles()) {
+			fname = f.getName();
+			if (!f.isDirectory() && fname.endsWith(".xlsx")) {
+				num++;
+				Date n = new Date();
+				try {
+					importCoursePaper(f);
+					Date et = new Date();
+					logger.debug("导入成功(" + num + "):" + fname + " 耗时:" + (et.getTime() - n.getTime()));
+				} catch (Exception e) {
+					errnum++;
+					sb.append(fname).append(",");
+					Date et = new Date();
+					logger.error(
+							"导入失败(" + num + "):" + fname + " 耗时:" + (et.getTime() - n.getTime()) + " " + e.getMessage(),
+							e);
+				}
+			}
+		}
 
 
         try {
         try {
             importCoursePaper(new File("d:\\2020ddimport\\excelDir\\AAAAA.11.15.xlsx"));
             importCoursePaper(new File("d:\\2020ddimport\\excelDir\\AAAAA.11.15.xlsx"));
@@ -101,7 +103,7 @@ public class ImportPaperByAllQues {
 			wb = new XSSFWorkbook(file);
 			wb = new XSSFWorkbook(file);
 			int num = wb.getNumberOfSheets();
 			int num = wb.getNumberOfSheets();
 			if (num == 1) {
 			if (num == 1) {
-				throw new Exception("没有试卷信息:" + file.getName());
+				throw new NoPaperException("1000","没有试卷信息:" + file.getName());
 			}
 			}
 			Set<String> ques = new HashSet<String>();
 			Set<String> ques = new HashSet<String>();
 			for (int i = 1; i < num; i++) {
 			for (int i = 1; i < num; i++) {
@@ -130,6 +132,9 @@ public class ImportPaperByAllQues {
 		Map<String, String> params = Maps.newHashMap();
 		Map<String, String> params = Maps.newHashMap();
 		params.put("rootOrgId", rootOrgId);
 		params.put("rootOrgId", rootOrgId);
 		params.put("courseCode", courseCode);
 		params.put("courseCode", courseCode);
+		if(paperSuff!=null) {
+			params.put("suff", paperSuff);
+		}
 		Map<String, String> headers = Maps.newHashMap();
 		Map<String, String> headers = Maps.newHashMap();
 		headers.put("key", key);
 		headers.put("key", key);
 		headers.put("token", token);
 		headers.put("token", token);

+ 14 - 4
src/main/java/cn/com/qmth/importpaper/ImportPaperByCourse.java

@@ -1,6 +1,7 @@
 package cn.com.qmth.importpaper;
 package cn.com.qmth.importpaper;
 
 
 import java.io.File;
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.HashSet;
@@ -11,6 +12,7 @@ import java.util.Set;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.Logger;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -23,8 +25,11 @@ import okhttp3.Response;
 public class ImportPaperByCourse {
 public class ImportPaperByCourse {
 
 
 	private static Logger logger = LogManager.getLogger(ImportPaperByCourse.class);
 	private static Logger logger = LogManager.getLogger(ImportPaperByCourse.class);
+	
+	private static String paperSuff="(202)";
 
 
-	private static String sourceDir = "d:\\2020ddimport\\excelDir";
+	private static String sourceDir = "D:\\2020ddimport\\course\\excelDir";
+//	private static String sourceDir = "D:\\文档\\temp\\excelDir";
 
 
 	private static String sourceQuesDir = sourceDir + "\\quesDir\\";
 	private static String sourceQuesDir = sourceDir + "\\quesDir\\";
 
 
@@ -65,7 +70,7 @@ public class ImportPaperByCourse {
 		}
 		}
 
 
 //        try {
 //        try {
-//            importCoursePaper(new File("d:\\2020ddimport\\excelDir\\AAAAA.xlsx"));
+//            importCoursePaper(new File("D:\\2020ddimport\\course\\excelDir\\F67020003.xlsx"));
 //        } catch (Exception e) {
 //        } catch (Exception e) {
 //            e.printStackTrace();
 //            e.printStackTrace();
 //        }
 //        }
@@ -85,6 +90,8 @@ public class ImportPaperByCourse {
 			}
 			}
 			createZip(file, zfile);
 			createZip(file, zfile);
 			submitZip(zfile);
 			submitZip(zfile);
+		} catch(NoPaperException e) {
+			logger.debug("忽略:" + e.getDesc() );
 		} finally {
 		} finally {
 			if (zfile.exists()) {
 			if (zfile.exists()) {
 				zfile.delete();
 				zfile.delete();
@@ -92,14 +99,14 @@ public class ImportPaperByCourse {
 		}
 		}
 	}
 	}
 
 
-	private static void createZip(File file, File zfile) throws Exception {
+	private static void createZip(File file, File zfile) throws InvalidFormatException, IOException{
 
 
 		XSSFWorkbook wb = null;
 		XSSFWorkbook wb = null;
 		try {
 		try {
 			wb = new XSSFWorkbook(file);
 			wb = new XSSFWorkbook(file);
 			int num = wb.getNumberOfSheets();
 			int num = wb.getNumberOfSheets();
 			if (num == 1) {
 			if (num == 1) {
-				throw new Exception("没有试卷信息:" + file.getName());
+				throw new NoPaperException("1000","没有试卷信息:" + file.getName());
 			}
 			}
 			Set<String> ques = new HashSet<String>();
 			Set<String> ques = new HashSet<String>();
 			for (int i = 1; i < num; i++) {
 			for (int i = 1; i < num; i++) {
@@ -128,6 +135,9 @@ public class ImportPaperByCourse {
 		Map<String, String> params = Maps.newHashMap();
 		Map<String, String> params = Maps.newHashMap();
 		params.put("rootOrgId", rootOrgId);
 		params.put("rootOrgId", rootOrgId);
 		params.put("courseCode", zfile.getName().split("\\.")[0]);
 		params.put("courseCode", zfile.getName().split("\\.")[0]);
+		if(paperSuff!=null) {
+			params.put("suff", paperSuff);
+		}
 		Map<String, String> headers = Maps.newHashMap();
 		Map<String, String> headers = Maps.newHashMap();
 		headers.put("key", key);
 		headers.put("key", key);
 		headers.put("token", token);
 		headers.put("token", token);

+ 64 - 0
src/main/java/cn/com/qmth/importpaper/NoPaperException.java

@@ -0,0 +1,64 @@
+package cn.com.qmth.importpaper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class NoPaperException extends RuntimeException{
+	
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 2190219930300660360L;
+
+	/**
+	 * 状态码
+	 */
+	private String code;
+
+	/**
+	 * 状态描述
+	 */
+	private String desc;
+
+	/**
+	 * 构造函数
+	 */
+	public NoPaperException(String code, String desc) {
+		super("[code: " + code + "; desc: " + desc + "]");
+		this.code = code;
+		this.desc = desc;
+	}
+
+	/**
+	 * 构造函数
+	 */
+	public NoPaperException(String code, String desc, Throwable cause) {
+		super("[code: " + code + "; desc: " + desc + "]", cause);
+		this.code = code;
+		this.desc = desc;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+
+	/**
+	 * @return
+	 */
+	public String toJson() {
+		Map<String, Object> map = new HashMap<String, Object>();
+		map.put("code", code);
+		map.put("desc", desc);
+		return JsonUtil.toJson(map);
+	}
+
+	@Override
+	public String toString() {
+		return toJson();
+	}
+}