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