|
@@ -4,10 +4,13 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
@@ -24,17 +27,17 @@ public class ImportPropByCourse {
|
|
|
private static Logger logger = LogManager.getLogger(ImportPropByCourse.class);
|
|
|
private final static String sourceDir = "d:/yunkai/";
|
|
|
|
|
|
-// private static String batch = "230517";
|
|
|
-// private static String host = "https://192.168.10.240/";
|
|
|
-// private static String rootOrgId = "17286";
|
|
|
-// private static String key = "U_C_17286_605350";
|
|
|
-// private static String token = "03fd149ea5314afdb75c352ab055d1d8";
|
|
|
-
|
|
|
private static String batch = "230517";
|
|
|
- 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 = "8a15aeba624d467baacbea082119f4f6";
|
|
|
+ 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 batch = "230517";
|
|
|
+// 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 = "8a15aeba624d467baacbea082119f4f6";
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
@@ -45,13 +48,18 @@ public class ImportPropByCourse {
|
|
|
|
|
|
int num = 0;
|
|
|
List<Course> cs = readSubject();
|
|
|
+ Map<String,ImportCourse> ics=readSubjectCodes();
|
|
|
for (Course c : cs) {
|
|
|
+ ImportCourse ic=ics.get(c.getCode());
|
|
|
+ if(ic==null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
Date n = new Date();
|
|
|
num++;
|
|
|
File file = new File(sourceDir + "/prop/" + c.getId() + ".json");
|
|
|
try {
|
|
|
if (file.exists()) {
|
|
|
- submit(c, file);
|
|
|
+ submit(ic, file);
|
|
|
Date et = new Date();
|
|
|
logger.debug("导入成功(" + num + "):" + file.getName() + " 耗时:" + (et.getTime() - n.getTime()));
|
|
|
}
|
|
@@ -71,6 +79,43 @@ public class ImportPropByCourse {
|
|
|
logger.debug("**********************导入出错课程:" + sb.toString());
|
|
|
}
|
|
|
|
|
|
+ private static Map<String,ImportCourse> readSubjectCodes() {
|
|
|
+ Map<String,ImportCourse> map=new HashMap<>();
|
|
|
+ XSSFWorkbook wb = null;
|
|
|
+ try {
|
|
|
+ wb = new XSSFWorkbook(sourceDir + "subject_codes.xlsx");
|
|
|
+ XSSFSheet sheet = wb.getSheetAt(0);
|
|
|
+ int rows = sheet.getLastRowNum();
|
|
|
+ for (int i = 1; i <= rows; i++) {
|
|
|
+ Course c = new Course();
|
|
|
+ XSSFRow row = sheet.getRow(i);
|
|
|
+ String ecCode = row.getCell(0).getStringCellValue().trim();
|
|
|
+ String yunCode = row.getCell(1).getStringCellValue().trim();
|
|
|
+ String name = row.getCell(2).getStringCellValue().trim();
|
|
|
+ c.setCode(ecCode);
|
|
|
+ c.setName(name);
|
|
|
+ ImportCourse ic=map.get(yunCode);
|
|
|
+ if(ic==null) {
|
|
|
+ ic=new ImportCourse();
|
|
|
+ ic.setSubjectCode(yunCode);
|
|
|
+ map.put(yunCode,ic);
|
|
|
+ }
|
|
|
+ ic.addCourse(c);
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ if (wb != null) {
|
|
|
+ try {
|
|
|
+ wb.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
private static List<Course> readSubject() {
|
|
|
List<Course> list = new ArrayList<>();
|
|
|
XSSFWorkbook wb = null;
|
|
@@ -102,11 +147,12 @@ public class ImportPropByCourse {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- private static void submit(Course c, File zfile) throws Exception {
|
|
|
+ private static void submit(ImportCourse ic, File zfile) throws Exception {
|
|
|
+ List<String> cs=ic.getCourses().stream().map(e->e.getCode()).collect(Collectors.toList());
|
|
|
Map<String, String> params = Maps.newHashMap();
|
|
|
params.put("rootOrgId", rootOrgId);
|
|
|
params.put("batch", batch);
|
|
|
- params.put("courseCode", c.getCode());
|
|
|
+ params.put("courseCodes", StringUtils.join(cs,","));
|
|
|
Map<String, String> headers = Maps.newHashMap();
|
|
|
headers.put("key", key);
|
|
|
headers.put("token", token);
|