|
@@ -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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|