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