xiatian há 2 anos atrás
pai
commit
73f26a988e

+ 103 - 0
src/main/java/cn/com/qmth/importpaper/DeleteImportPaperQuestion.java

@@ -0,0 +1,103 @@
+package cn.com.qmth.importpaper;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import com.google.common.collect.Maps;
+
+import okhttp3.Response;
+
+public class DeleteImportPaperQuestion {
+
+	private static Logger logger = LogManager.getLogger(DeleteImportPaperQuestion.class);
+	private final static String sourceDir = "d:/yunkai/";
+
+//	private static String batch = "230517";
+//	private static String host = "http://localhost:8008";
+//	private static String rootOrgId = "149";
+//	private static String key = "U_C_149_170";
+//	private static String token = "cac2f518a68346fe860fcb8a616bb458";
+
+	private static String host = "http://192.168.1.249:8008";
+	private static String key = "U_C_17351_646523";
+	private static String token = "3eb43a9ad3f34bb08f1f2a2e1c7fcbd8";
+
+	public static void main(String[] args){
+		logger.debug("**********************删除开始");
+		Date start = new Date();
+
+		List<QuestionId> cs = readSubject();
+		int index = 0;
+		for (QuestionId c : cs) {
+			try {
+				submit(c);
+				index++;
+				logger.debug("**********************完成:" + index);
+			} catch (IOException e) {
+				logger.error("删除失败:"+c.getUnitId() + " | " + c.getQuestionId(),e);
+			}
+		}
+
+		Date end = new Date();
+		logger.debug("**********************删除结束  耗时:" + (end.getTime() - start.getTime()));
+		OKHttpUtil.close();
+	}
+
+
+	private static List<QuestionId> readSubject() {
+		List<QuestionId> list = new ArrayList<>();
+		XSSFWorkbook wb = null;
+		try {
+			wb = new XSSFWorkbook(sourceDir + "question.xlsx");
+			XSSFSheet sheet = wb.getSheetAt(0);
+			int rows = sheet.getLastRowNum();
+			for (int i = 1; i <= rows; i++) {
+				QuestionId c = new QuestionId();
+				XSSFRow row = sheet.getRow(i);
+				String uid = row.getCell(0).getStringCellValue().trim();
+				String qid = row.getCell(1).getStringCellValue().trim();
+				c.setUnitId(uid);
+				c.setQuestionId(qid);
+				list.add(c);
+			}
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (wb != null) {
+				try {
+					wb.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+		return list;
+	}
+
+	private static void submit(QuestionId ic) throws IOException{
+		Map<String, String> params = Maps.newHashMap();
+		Map<String, String> headers = Maps.newHashMap();
+		headers.put("key", key);
+		headers.put("token", token);
+		Response resp = null;
+		try {
+			resp = OKHttpUtil.call(HttpMethod.DELETE,
+					host + "/api/ecs_ques/paper/deleteQuestion/" + ic.getUnitId() + "/" + ic.getQuestionId(), headers,
+					params);
+			if (resp.code() != 200) {
+				throw new RuntimeException(ic.getUnitId() + " | " + ic.getQuestionId() + ":body:" + resp.body().string());
+			}
+		} finally {
+			IOUtils.closeQuietly(resp);
+		}
+	}
+}

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

@@ -21,7 +21,7 @@ public class ImportPaperByCourse {
 	private static String host = "http://192.168.1.249:8008";
 	private static String rootOrgId = "17351";
 	private static String key = "U_C_17351_646523";
-	private static String token = "96eca58f7102483f97ea4f1c8fbeca64";
+	private static String token = "6537edc191d546349fd5a4cb9e74b94b";
 	
 	private static AtomicInteger count=new AtomicInteger(0);
 

+ 2 - 2
src/main/java/cn/com/qmth/importpaper/ImportPropByCourse.java

@@ -34,10 +34,10 @@ public class ImportPropByCourse {
 //	private static String token = "cac2f518a68346fe860fcb8a616bb458";
 	
 	private static String batch = "230517";
-	private static String host = "https://ynou.exam-cloud.cn";
+	private static String host = "http://192.168.1.249:8008";
 	private static String rootOrgId = "17351";
 	private static String key = "U_C_17351_646523";
-	private static String token = "4982461411c04d15a26cc2130a373a6f";
+	private static String token = "6537edc191d546349fd5a4cb9e74b94b";
 	
 
 	public static void main(String[] args) {

+ 19 - 0
src/main/java/cn/com/qmth/importpaper/QuestionId.java

@@ -0,0 +1,19 @@
+package cn.com.qmth.importpaper;
+
+public class QuestionId {
+	private String unitId;
+	private String questionId;
+	public String getUnitId() {
+		return unitId;
+	}
+	public void setUnitId(String unitId) {
+		this.unitId = unitId;
+	}
+	public String getQuestionId() {
+		return questionId;
+	}
+	public void setQuestionId(String questionId) {
+		this.questionId = questionId;
+	}
+	
+}