56 lines
1.9 KiB
Java
56 lines
1.9 KiB
Java
package com.bycrm.util;
|
||
|
||
import com.bycrm.dto.SchoolDTO;
|
||
import org.springframework.context.ConfigurableApplicationContext;
|
||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||
|
||
import java.io.File;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* 学校数据导入执行类
|
||
* 使用方法:运行 main 方法,传入 school.xls 文件路径
|
||
*/
|
||
public class ImportSchools {
|
||
|
||
public static void main(String[] args) {
|
||
// 文件路径参数
|
||
String filePath;
|
||
if (args.length > 0) {
|
||
filePath = args[0];
|
||
} else {
|
||
// 默认路径:项目根目录下的 docs/school.xls
|
||
filePath = "docs/school.xls";
|
||
}
|
||
|
||
File file = new File(filePath);
|
||
if (!file.exists()) {
|
||
System.err.println("文件不存在: " + file.getAbsolutePath());
|
||
return;
|
||
}
|
||
|
||
try {
|
||
System.out.println("开始读取文件: " + file.getAbsolutePath());
|
||
List<SchoolDTO> schools = SchoolImporter.importFromXls(filePath);
|
||
System.out.println("成功读取 " + schools.size() + " 条学校数据");
|
||
|
||
// 打印前5条数据预览
|
||
System.out.println("\n数据预览(前5条):");
|
||
int previewCount = Math.min(5, schools.size());
|
||
for (int i = 0; i < previewCount; i++) {
|
||
SchoolDTO dto = schools.get(i);
|
||
System.out.printf("%d. [%s] %s - %s%n",
|
||
i + 1, dto.getSchoolCode(), dto.getSchoolName(), dto.getLocation());
|
||
}
|
||
|
||
// 保存到文件供后续使用
|
||
System.out.println("\n数据已准备好,请通过 API 接口导入到数据库");
|
||
System.out.println("或者使用 SchoolService.batchImport() 方法批量导入");
|
||
|
||
} catch (Exception e) {
|
||
System.err.println("导入失败: " + e.getMessage());
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|