kgdxpr 1 year ago
commit 48c4723be9

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

@ -231,6 +231,7 @@ public class ZbdcController extends Controller {
/**
*
* http://10.10.21.20:9000/QingLong/zbdc/getKmFeiLeiTree?km_code=xxty
*
* @param km_code
*/
@Before({GET.class})
@ -309,4 +310,87 @@ public class ZbdcController extends Controller {
kv.set("message", "保存成功!");
renderJson(kv);
}
/*************************************************************************************************************/
/**
*
*/
@Before({GET.class})
@IsLoginInterface({})
public void getXxzbdcTable() {
List<Record> list = zm.getXxzbdcTable();
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*/
@Before({GET.class})
@IsNumericInterface({"dcb_id"})
@IsLoginInterface({})
public void getXxzbdcLeiBie(int dcb_id) {
List<Record> list = zm.getXxzbdcLeiBie(dcb_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
* +
*/
@Before({GET.class})
@IsNumericInterface({"dcb_id"})
@IsLoginInterface({})
public void getXxzbdcZhuYaoSheBei(int dcb_id, int lb_id) {
List<Record> list = zm.getXxzbdcZhuYaoSheBei(dcb_id, lb_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param dcb_id
* @param year
*/
@Before({GET.class})
@IsNumericInterface({"dcb_id"})
@IsLoginInterface({})
public void getXxzbdcList(int dcb_id, int year) {
if (year == 0) year = DateTime.now().year();//如果没有传入获取的年份,那么就是系统的默认当前年份
String bureau_id = SessionKit.get(getRequest(), getResponse(), "bureau_id");
List<Record> list = zm.getXxzbdcList(bureau_id, year, dcb_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param dcb_id
* @param year
* @param json
* @param id id=0id<>0
*/
@Before({POST.class})
@IsNumericInterface({"dcb_id"})
@IsLoginInterface({})
public void saveXxzbdc(int dcb_id, int id, int year, String json) {
if (year == 0) year = DateTime.now().year();//如果没有传入获取的年份,那么就是系统的默认当前年份
String bureau_id = SessionKit.get(getRequest(), getResponse(), "bureau_id");
zm.saveXxzbdc(dcb_id, id, year, bureau_id, json);
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "保存成功!");
renderJson(kv);
}
/**
*
*
* @param dcb_id
* @param id
*/
@Before({GET.class})
@IsLoginInterface({})
public void getXxzbdcSingle(int dcb_id, int id) {
Record record = zm.getXxzbdcSingle(dcb_id, id);
renderJson(record);
}
}

@ -1,8 +1,10 @@
package com.dsideal.QingLong.Zbdc.Model;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Interceptor.EmptyInterface;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
import com.jfinal.aop.Before;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
@ -311,7 +313,7 @@ public class ZbdcModel {
if (!StrKit.isBlank(level_filter)) {
String[] s = level_filter.split(",");
for (int i = 0; i < s.length; i++) {
c += " and level_" + (i + 1) + "='" + s[i]+"' " ;
c += " and level_" + (i + 1) + "='" + s[i] + "' ";
}
}
@ -471,4 +473,101 @@ public class ZbdcModel {
}
return res;
}
/**
*
*/
public List<Record> getXxzbdcTable() {
String sql = "select * from t_zbdc_table_dict order by dcb_id";
return Db.find(sql);
}
/**
*
*/
public List<Record> getXxzbdcLeiBie(int dcb_id) {
String sql = "select DISTINCT lb_id,lb_name from t_zbdc_table_lbsb where dcb_id = ? order by lb_id";
return Db.find(sql, dcb_id);
}
/**
* +
*/
public List<Record> getXxzbdcZhuYaoSheBei(int dcb_id, int lb_id) {
String sql = "select lb_sb_id,lb_sb_name from t_zbdc_table_lbsb where dcb_id =? and lb_id=? order by lb_sb_id";
return Db.find(sql, dcb_id, lb_id);
}
/**
*
*
* @param dcb_id
* @return
*/
public String getXxzbdcTableName(int dcb_id) {
String sql = "select table_name from t_zbdc_table_dict where dcb_id=?";
return Db.findFirst(sql, dcb_id).getStr("table_name");
}
/**
*
*
* @param dcb_id
* @param year
*/
public List<Record> getXxzbdcList(String bureau_id, int dcb_id, int year) {
String table_name = getXxzbdcTableName(dcb_id);
String sql = "select * from " + table_name + " where bureau_id=? and year=? order by id";
return Db.find(sql, bureau_id, year);
}
/**
*
*
* @param dcb_id
* @param year
* @param json
* @param id id=0id<>0
*/
public void saveXxzbdc(int dcb_id, int id, int year, String bureau_id, String json) {
//哪些物理表
String table_name = getXxzbdcTableName(dcb_id);
Record record = new Record();
if (id > 0) {//修改
record = Db.findById(table_name, "id", id);
} else {
//新增
record.set("year", year);
record.set("school_id", bureau_id);
}
//解析json里面的字段名称和值对record进行填充
JSONObject jsonObject = JSONObject.parseObject(json);
// 将JSONObject转换为Map然后遍历键值对
Map<String, Object> map = jsonObject;
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
record.set(key, value);
}
if (id > 0) {
Db.update(table_name, record);
} else {
Db.save(table_name, "id", record);
}
}
/**
*
*
* @param dcb_id
* @param id
*/
public Record getXxzbdcSingle(int dcb_id, int id) {
//哪些物理表
String table_name = getXxzbdcTableName(dcb_id);
Record record = Db.findById(table_name, "id", id);
return record;
}
}

Loading…
Cancel
Save