Merge branch 'main' of http://10.10.14.176:3000/huanghai/QingLong
commit
48c4723be9
Binary file not shown.
@ -0,0 +1,78 @@
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
||||
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImportExcelLbsb {
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
//告之配置文件位置
|
||||
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();
|
||||
// Excel文件的路径
|
||||
String filePath = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\向装备中心汇报\\各学校填充完\\长春市朝鲜族中学.xlsx";
|
||||
|
||||
try {
|
||||
FileInputStream file = new FileInputStream(filePath);
|
||||
Workbook workbook = new XSSFWorkbook(file);
|
||||
|
||||
String sql = "truncate table t_zbdc_table_lbsb RESTART IDENTITY";
|
||||
Db.update(sql);
|
||||
|
||||
int lb_id = 0;
|
||||
Map<String, Integer> _map = new HashMap<>();
|
||||
for (int i = 0; i < workbook.getNumberOfSheets() - 1; i++) {
|
||||
Sheet sheet = workbook.getSheetAt(i);
|
||||
int cnt = 0;
|
||||
for (Row row : sheet) {
|
||||
cnt++;
|
||||
if (cnt < 4) continue;
|
||||
String lb_name = row.getCell(1).getStringCellValue().replace("\n", "");
|
||||
String lb_sb_name = row.getCell(2).getStringCellValue().replace("\n", "");
|
||||
System.out.println(sheet.getSheetName() + " " + lb_name + " " + lb_sb_name);
|
||||
|
||||
if (_map.containsKey(lb_name)) lb_id = _map.get(lb_name);
|
||||
else {
|
||||
lb_id++;
|
||||
_map.put(lb_name,lb_id);
|
||||
}
|
||||
Record record = new Record();
|
||||
record.set("lb_id", lb_id);
|
||||
record.set("lb_name", lb_name);
|
||||
record.set("lb_sb_name", lb_sb_name);
|
||||
record.set("dcb_id", i + 1);
|
||||
Db.save("t_zbdc_table_lbsb", "lb_sb_id", record);
|
||||
}
|
||||
}
|
||||
workbook.close();
|
||||
file.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in new issue