|
@@ -0,0 +1,54 @@
|
|
|
|
+package com.mooctest.service;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
+import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
+
|
|
|
|
+public final class UpdateScore {
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
|
+
|
|
|
|
+ File excelFile = new File("/Users/insomnialee/Downloads/chrome/1.xlsx");
|
|
|
|
+ XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(excelFile));
|
|
|
|
+ XSSFSheet sheet = wb.getSheetAt(0);
|
|
|
|
+ boolean flag = true;
|
|
|
|
+ int count = 0;
|
|
|
|
+ for (Row row : sheet) {
|
|
|
|
+ if(flag){
|
|
|
|
+ flag = false;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Cell id = row.getCell(0);
|
|
|
|
+ Cell score = row.getCell(8);
|
|
|
|
+ count++;
|
|
|
|
+ getSinglePaper( (int)Double.parseDouble( id.toString()),(int)Double.parseDouble( score.toString()));
|
|
|
|
+ }
|
|
|
|
+ System.out.println(count);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void getSinglePaper(int userId,int score) {
|
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
|
+ String url = "http://www.mooctest.net/api/common/uploadCaseScore";
|
|
|
|
+ MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
|
|
|
|
+ paramMap.add("examId", 4386);
|
|
|
|
+ paramMap.add("caseId", 3041);
|
|
|
|
+ paramMap.add("userId", userId);
|
|
|
|
+ paramMap.add("score", score);
|
|
|
|
+ template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);
|
|
|
|
+ template.put(url, httpEntity);
|
|
|
|
+ }
|
|
|
|
+}
|