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