|
|
|
|
package UnitTest.ImportExcel;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.QingLong.Util.AsposeUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.GenericTemplateUtil;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class ImportExcelData {
|
|
|
|
|
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";
|
|
|
|
|
|
|
|
|
|
//模拟上传文件的文件名称
|
|
|
|
|
public static String upload_excel_filename = "b61a2af2-223f-4058-a675-b212e4dd9487" + ".xlsx";
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
//加载License
|
|
|
|
|
AsposeUtil.getLicense();
|
|
|
|
|
|
|
|
|
|
//告之配置文件位置
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
HikariCpPlugin hp = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
|
|
|
|
|
PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
|
|
|
|
hp.start();
|
|
|
|
|
// 配置ActiveRecord插件
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
|
|
|
|
//配置默认小写
|
|
|
|
|
arp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
|
|
|
|
|
arp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
arp.start();
|
|
|
|
|
|
|
|
|
|
//模板文件
|
|
|
|
|
String f1 = path + File.separator + upload_excel_filename;
|
|
|
|
|
//用户上传的填充完的EXCEL文件
|
|
|
|
|
String f2 = path + File.separator + "school.xlsx";
|
|
|
|
|
//对比两个EXCEL文件 是不是格式一致,也就是是不是上传了正确的模板文件
|
|
|
|
|
int sheetCnt = GenericTemplateUtil.getExcelSheetCount(upload_excel_filename);
|
|
|
|
|
for (int i = 0; i < sheetCnt; i++) {
|
|
|
|
|
List<Map.Entry<Integer, Integer>> chayi = GenericTemplateUtil.checkYiZhi(f1, f2, i);
|
|
|
|
|
if (chayi.size() > 0) {
|
|
|
|
|
System.out.println("第" + (i + 1) + "个Sheet表检查过程中发现与要求上传的模板不一致,请重新下载模板填写完成后再次上传!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("OK,是好模板!");
|
|
|
|
|
|
|
|
|
|
// 检查是不是非空项目未填写
|
|
|
|
|
|
|
|
|
|
// 检查是不是下拉列表不是从下拉列表中选择的
|
|
|
|
|
|
|
|
|
|
// 检查数据类型是不是和规定的不兼容
|
|
|
|
|
|
|
|
|
|
// 全都通过,导入数据
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|