main
黄海 9 months ago
parent cfa48d4d9b
commit 1624a9885f

@ -465,7 +465,6 @@ public class DataEaseController extends Controller {
renderJson(CommonUtil.returnMessageJson(true, "保存成功"));
}
/**
* Excel
*
@ -552,4 +551,110 @@ public class DataEaseController extends Controller {
renderJson(kv);
}
/**
*
*/
@Before({GET.class})
@IsLoginInterface({})
public void getDataSetByProvince() {
List<Record> list = dm.getDataSetByIdentityId(2, null);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param id id
*/
@Before(GET.class)
@IsLoginInterface({})
@IsNumericInterface({"id"})
public void getDataSetContentByProvince(int id) {
List<Record> list = dm.getDataSetContentByCity(id, "云南省");
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/**
*
*
* @param id id
* @param data
*/
@Before(POST.class)
@IsLoginInterface({})
public void saveDataSetByProvince(int id, String data) {
JSONArray jsonArray = JSONArray.fromObject(data);
//保存
dm.saveDataSetByCity(id, "云南省", jsonArray);
renderJson(CommonUtil.returnMessageJson(true, "保存成功"));
}
/**
* Excel
*
* @param id id
*/
@Before(GET.class)
@IsLoginInterface({})
@IsNumericInterface({"id"})
public void downloadExcelByProvince(int id) throws IOException {
Record record = dm.getDataSetById(id);
String tableName = record.getStr("table_name");
String dataSetName = record.getStr("dataset_name");
//导出excel
String upPath = BaseApplication.PropKit.get("upload.path") + "/";
String excelFileName = dm.exportExcelByCity(tableName, upPath, "云南省");
//renderFile
renderFile(new File(excelFileName), "【云南省】" + dataSetName + "." + "xlsx");
}
/**
* :Excel
*/
@Before(POST.class)
@IsLoginInterface({})
public void uploadExcelByProvince() {
//上传的文件
UploadFile uploadFile = getFile("file");
//数据集id
int id = getParaToInt("id");
//文件是不是以.xlsx为扩展名
if (!uploadFile.getFileName().endsWith(".xlsx")) {
renderJson(CommonUtil.returnMessageJson(false, "文件格式不正确,请上传.xlsx格式的文件"));
return;
}
//检查上传的excel获取它有哪些列与数据集的列是否一致
String excelPath = uploadFile.getFile().getAbsolutePath();
List<String> excelCols = dm.getColumnNamesFromExcel(excelPath);
//获取指定数据表有哪些列
Record rDataSet = dm.getDataSetById(id);
String tableName = rDataSet.getStr("table_name");
//mysql数据库中真实表有哪些字段
List<String> mysqlCols = dm.getColumns(tableName);
//id列需要特殊处理
mysqlCols.remove("id");
//对比两个数组集是不是一致,就是对比列名是不是完全匹配,使用交集去检查
Set<String> set1 = new HashSet<>(excelCols);
Set<String> set2 = new HashSet<>(mysqlCols);
//是不是完整匹配
boolean match = set1.equals(set2);
if (!match) {
renderJson(CommonUtil.returnMessageJson(false, "上传的Excel列名与数据集列名不一致请重新上传"));
return;
}
//如果一致,那么需要先把数据集的指定行政区划列的表清空,再导入数据
ExcelReader excelReader = new ExcelReader();
List<ExcelRow> rows = excelReader.readXlsxFile(excelPath, excelCols);
dm.saveDataSetTableByCity(id, "云南省", rows);
//返回结果
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "上传成功");
renderJson(kv);
}
}

@ -38,9 +38,6 @@ public class DataEaseModel {
for (Record record : list) {
//这个数据集,当前的区域,已经填写了多少条数据
String table_name = record.getStr("table_name");
if (table_name.equals("excel_区域人口流动分布_374179b760")) {
System.out.println("ddd");
}
sql = "select count(1) as c from `" + table_name + "`";
if (identity_id > 1) {
sql += " where `行政区划`='" + area_name + "' or `上级行政区划`='" + area_name + "'";

Loading…
Cancel
Save