xiatian 2 年之前
父節點
當前提交
bb93fd7275

+ 10 - 0
pom.xml

@@ -102,6 +102,16 @@
 			<artifactId>spring-boot-starter-data-redis</artifactId>
 			<version>2.1.13.RELEASE</version>
 		</dependency>
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.76</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-text</artifactId>
+			<version>1.9</version>
+		</dependency>
 	</dependencies>
 	<repositories>
 		<repository>

+ 10 - 4
src/main/java/cn/com/qmth/importpaper/ClearProp.java

@@ -14,11 +14,17 @@ import okhttp3.Response;
 public class ClearProp {
 
 	private static Logger logger = LogManager.getLogger(ClearProp.class);
+//	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 = "eefd4ae8b29a4a61a85a9e56f56275f9";
+	
 	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 = "eefd4ae8b29a4a61a85a9e56f56275f9";
+	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";
 
 	public static void main(String[] args) {
 		logger.debug("**********************开始");

+ 12 - 10
src/main/java/cn/com/qmth/importpaper/ConsumerDto.java

@@ -1,7 +1,7 @@
 package cn.com.qmth.importpaper;
 
 public class ConsumerDto {
-	private Course course;
+	private ImportCourse ic;
 	private String sourceDir;
 	private String host;
 
@@ -11,13 +11,6 @@ public class ConsumerDto {
 
 	private String token;
 
-	public Course getCourse() {
-		return course;
-	}
-
-	public void setCourse(Course course) {
-		this.course = course;
-	}
 
 	public String getSourceDir() {
 		return sourceDir;
@@ -59,15 +52,24 @@ public class ConsumerDto {
 		this.token = token;
 	}
 
-	public ConsumerDto(Course course, String sourceDir, String host, String rootOrgId, String key, String token) {
+	public ImportCourse getIc() {
+		return ic;
+	}
+
+	public void setIc(ImportCourse ic) {
+		this.ic = ic;
+	}
+
+	public ConsumerDto(ImportCourse ic, String sourceDir, String host, String rootOrgId, String key, String token) {
 		super();
-		this.course = course;
+		this.ic = ic;
 		this.sourceDir = sourceDir;
 		this.host = host;
 		this.rootOrgId = rootOrgId;
 		this.key = key;
 		this.token = token;
 	}
+
 	
 	
 }

+ 45 - 0
src/main/java/cn/com/qmth/importpaper/ImportCourse.java

@@ -0,0 +1,45 @@
+package cn.com.qmth.importpaper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ImportCourse {
+
+	private Long subjectId;
+
+	private String subjectCode;
+
+	private List<Course> courses;
+
+	public String getSubjectCode() {
+		return subjectCode;
+	}
+
+	public void setSubjectCode(String subjectCode) {
+		this.subjectCode = subjectCode;
+	}
+
+	public List<Course> getCourses() {
+		return courses;
+	}
+
+	public void setCourses(List<Course> courses) {
+		this.courses = courses;
+	}
+
+	public void addCourse(Course c) {
+		if (courses == null) {
+			courses = new ArrayList<>();
+		}
+		courses.add(c);
+	}
+
+	public Long getSubjectId() {
+		return subjectId;
+	}
+
+	public void setSubjectId(Long subjectId) {
+		this.subjectId = subjectId;
+	}
+
+}

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

@@ -13,15 +13,15 @@ public class ImportPaperByCourse {
 	private static Logger logger = LogManager.getLogger(ImportPaperByCourse.class);
 	private final static String sourceDir = "d:/yunkai/";
 
-//	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 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 rootOrgId = "17351";
-	private static String key = "U_C_17351_646523";
-	private static String token = "8a15aeba624d467baacbea082119f4f6";
+//	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 AtomicInteger count=new AtomicInteger(0);
 

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

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

+ 6 - 3
src/main/java/cn/com/qmth/importpaper/MyConsumer.java

@@ -4,8 +4,10 @@ import java.io.File;
 import java.util.ArrayList;
 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.log4j.LogManager;
 import org.apache.log4j.Logger;
 
@@ -23,11 +25,11 @@ public class MyConsumer extends Consumer<ConsumerDto> {
 		ImportPaperByCourse.addDisposeCount();
 	}
 	private  void importCoursePaper(ConsumerDto dto){
-		File file = new File(dto.getSourceDir() + "paper/" + dto.getCourse().getId() + "/");
+		File file = new File(dto.getSourceDir() + "paper/" + dto.getIc().getSubjectId() + "/");
 		if(!file.exists()) {
 			return;
 		}
-		File zfile = new File(dto.getSourceDir()+"paper/"+dto.getCourse().getId()+ ".zip");
+		File zfile = new File(dto.getSourceDir()+"paper/"+dto.getIc().getSubjectId()+ ".zip");
 		try {
 			List<File> files = new ArrayList<>();
 			getPaperFile(file, files);
@@ -64,9 +66,10 @@ public class MyConsumer extends Consumer<ConsumerDto> {
 
 	}
 	private  void submitZip(ConsumerDto dto,File zfile) {
+		List<String> cs=dto.getIc().getCourses().stream().map(e->e.getCode()).collect(Collectors.toList());
 		Map<String, String> params = Maps.newHashMap();
 		params.put("rootOrgId", dto.getRootOrgId());
-		params.put("courseCode",dto.getCourse().getCode());
+		params.put("courseCodes",StringUtils.join(cs,","));
 		Map<String, String> headers = Maps.newHashMap();
 		headers.put("key", dto.getKey());
 		headers.put("token", dto.getToken());

+ 46 - 3
src/main/java/cn/com/qmth/importpaper/MyProducer.java

@@ -2,6 +2,7 @@ package cn.com.qmth.importpaper;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -17,7 +18,7 @@ import cn.com.qmth.multithread.Producer;
 
 public class MyProducer extends Producer {
 	private static Logger logger = LogManager.getLogger(MyProducer.class);
-	private static String dir = "d:/yunkai/";
+	private static String sourceDir = "d:/yunkai/";
 
 	@Override
 	protected void produce(Map<String, Object> param) throws Exception {
@@ -28,6 +29,7 @@ public class MyProducer extends Producer {
 		String key=param.get("key").toString();
 		String token=param.get("token").toString();
 		List<Course> cs = readSubject();
+		Map<String,ImportCourse> ics=readSubjectCodes();
 		if (CollectionUtils.isEmpty(cs)) {
 			logger.debug("无数据导入");
 			return;
@@ -35,17 +37,58 @@ public class MyProducer extends Producer {
 			logger.debug(cs.size() + "个课程");
 		}
 		for (Course c : cs) {
-			offer(new ConsumerDto(c, sourceDir, host, rootOrgId, key, token));
+			ImportCourse ic=ics.get(c.getCode());
+			if(ic==null) {
+				continue;
+			}
+			ic.setSubjectId(c.getId());
+			offer(new ConsumerDto(ic, sourceDir, host, rootOrgId, key, token));
 		}
 		logger.info("***************************任务生产结束");
 	}
 	
+	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  List<Course> readSubject() {
 		List<Course> list = new ArrayList<>();
 		XSSFWorkbook wb = null;
 		try {
-			wb = new XSSFWorkbook(dir + "subject.xlsx");
+			wb = new XSSFWorkbook(sourceDir + "subject.xlsx");
 			XSSFSheet sheet = wb.getSheetAt(0);
 			int rows = sheet.getLastRowNum();
 			for (int i = 1; i <= rows; i++) {