xiatian vor 2 Jahren
Ursprung
Commit
de145a126c

+ 2 - 2
src/main/java/cn/com/qmth/export/ExportByCourseCode.java → src/main/java/cn/com/qmth/export/ExportPaperByCourseCode.java

@@ -6,8 +6,8 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 
-public class ExportByCourseCode {
-	private static Logger logger = LogManager.getLogger(ExportByCourseCode.class);
+public class ExportPaperByCourseCode {
+	private static Logger logger = LogManager.getLogger(ExportPaperByCourseCode.class);
 	private static AtomicInteger count=new AtomicInteger(0);
 	
 	public static void main(String[] args) {

+ 25 - 19
src/main/java/cn/com/qmth/export/ExportProperty.java

@@ -9,10 +9,8 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.log4j.LogManager;
@@ -26,8 +24,7 @@ import com.alibaba.fastjson.JSONObject;
 
 public class ExportProperty {
 	private static Logger logger = LogManager.getLogger(ExportProperty.class);
-	
-	private static String dirPath="d:/yunkai/prop/";
+	private final static String sourceDir = "d:/yunkai/";
 	public static void main(String[] args) {
 		logger.debug("导出开始");
 		try {
@@ -39,9 +36,9 @@ public class ExportProperty {
 	}
 	
 	private static void dispose() {
-		File dir=new File(dirPath);
+		File dir=new File(sourceDir+"prop/");
 		if(dir.exists()) {
-			FileUtil.clearDirectory(dirPath);
+			FileUtil.clearDirectory(sourceDir+"prop/");
 		}else {
 			dir.mkdirs();
 		}
@@ -70,37 +67,46 @@ public class ExportProperty {
 	}
 
 	private static void exportProperty(Connection connect) throws InvalidFormatException, IOException, SQLException {
-		List<Long> subIds=readSubjectId();
+		List<Course> subIds=readSubject();
 		if(CollectionUtils.isEmpty(subIds)) {
 			return;
 		}
-		for(Long subid:subIds) {
-			List<PropertyDto> props=getProperty(connect, subid);
+		System.out.println("总科目数:"+subIds.size());
+		for(Course c:subIds) {
+			List<PropertyDto> props=getProperty(connect, c.getId());
 			if(CollectionUtils.isNotEmpty(props)) {
-				FileUtil.writeFile(dirPath, subid+".json", JSONObject.toJSONString(props));
+				FileUtil.writeFile(sourceDir+"prop/", c.getId()+".json", JSONObject.toJSONString(props));
 			}
 		}
 	}
-	private static List<Long> readSubjectId() throws InvalidFormatException, IOException {
-		File directory = new File("");
-		List<Long> list = new ArrayList<>();
-		Set<Long> set = new LinkedHashSet<>();
+	private static List<Course> readSubject() {
+		List<Course> list = new ArrayList<>();
 		XSSFWorkbook wb = null;
 		try {
-			wb = new XSSFWorkbook(directory.getAbsolutePath() + "\\subject.xlsx");
+			wb = new XSSFWorkbook(sourceDir + "subject.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 tem = row.getCell(0).getStringCellValue().trim();
-				set.add(Long.valueOf(tem));
+				String id = row.getCell(0).getStringCellValue().trim();
+				String name = row.getCell(1).getStringCellValue().trim();
+				String code = row.getCell(2).getStringCellValue().trim();
+				c.setId(Long.valueOf(id));
+				c.setCode(code);
+				c.setName(name);
+				list.add(c);
 			}
+		} catch (IOException e) {
+			throw new RuntimeException(e);
 		} finally {
 			if (wb != null) {
-				wb.close();
+				try {
+					wb.close();
+				} catch (IOException e) {
+				}
 			}
 		}
-		list.addAll(set);
 		return list;
 	}
 	

+ 1 - 1
src/main/java/cn/com/qmth/export/MyConsumer.java

@@ -44,7 +44,7 @@ public class MyConsumer extends Consumer<Course> {
 			String password = "123456";
 			connect = DriverManager.getConnection(url, user, password);
 			exportPaper(connect, course);
-			ExportByCourseCode.addDisposeCount();
+			ExportPaperByCourseCode.addDisposeCount();
 		} catch (Exception e) {
 			throw new RuntimeException(e);
 		} finally {

BIN
subject.xlsx