|
|
|
@ -129,67 +129,68 @@ public class DataEaseController extends Controller {
|
|
|
|
|
renderJson(CommonUtil.renderJsonForLayUI(list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下载指定数据集的Excel文件
|
|
|
|
|
* 下载模板Excel
|
|
|
|
|
*
|
|
|
|
|
* @param id 数据集id
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsLoginInterface({})
|
|
|
|
|
@IsNumericInterface({"id"})
|
|
|
|
|
public void downloadExcel(int id) throws IOException {
|
|
|
|
|
public void downSampleExcel(int id) throws IOException {
|
|
|
|
|
String identity_idStr = CookieUtil.getValue(getRequest(), "identity_id");
|
|
|
|
|
int identity_id = 1;
|
|
|
|
|
if (!StrKit.isBlank(identity_idStr)) {
|
|
|
|
|
identity_id = Integer.parseInt(identity_idStr);
|
|
|
|
|
}
|
|
|
|
|
//根据当前登录人员的身份,获取对应的数据集名称
|
|
|
|
|
String person_id = CookieUtil.getValue(getRequest(), "person_id");
|
|
|
|
|
//获取他是哪个城市或者县区的管理员
|
|
|
|
|
//行政区划码
|
|
|
|
|
String area_code = rm.getAreaCode(identity_id, person_id);
|
|
|
|
|
//根据区域码,获取区域名称
|
|
|
|
|
String area_name = rm.getAreaName(area_code);
|
|
|
|
|
String area_name = "云南省";
|
|
|
|
|
//获取他是哪个城市的管理员
|
|
|
|
|
if (identity_id == 2) {
|
|
|
|
|
area_name = "昆明市";
|
|
|
|
|
}
|
|
|
|
|
//获取他是哪个县区的管理员
|
|
|
|
|
if (identity_id == 3) {
|
|
|
|
|
area_name = "寻甸县";
|
|
|
|
|
}
|
|
|
|
|
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.exportExcel(identity_id, tableName, upPath, area_name);
|
|
|
|
|
String excelFileName = dm.exportExcel(identity_id, tableName, tempDir, area_name);
|
|
|
|
|
//renderFile
|
|
|
|
|
renderFile(new File(excelFileName), "【" + area_name + "】" + dataSetName + "." + "xlsx");
|
|
|
|
|
renderFile(new File(excelFileName), "【样例:" + area_name + "】" + dataSetName + "." + "xlsx");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下载模板Excel
|
|
|
|
|
* 下载指定数据集的Excel文件
|
|
|
|
|
*
|
|
|
|
|
* @param id 数据集id
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsLoginInterface({})
|
|
|
|
|
@IsNumericInterface({"id"})
|
|
|
|
|
public void downSampleExcel(int id) throws IOException {
|
|
|
|
|
public void downloadExcel(int id) throws IOException {
|
|
|
|
|
String identity_idStr = CookieUtil.getValue(getRequest(), "identity_id");
|
|
|
|
|
int identity_id = 1;
|
|
|
|
|
if (!StrKit.isBlank(identity_idStr)) {
|
|
|
|
|
identity_id = Integer.parseInt(identity_idStr);
|
|
|
|
|
}
|
|
|
|
|
String area_name = "云南省";
|
|
|
|
|
//获取他是哪个城市的管理员
|
|
|
|
|
if (identity_id == 2) {
|
|
|
|
|
area_name = "昆明市";
|
|
|
|
|
}
|
|
|
|
|
//获取他是哪个县区的管理员
|
|
|
|
|
if (identity_id == 3) {
|
|
|
|
|
area_name = "寻甸县";
|
|
|
|
|
}
|
|
|
|
|
//根据当前登录人员的身份,获取对应的数据集名称
|
|
|
|
|
String person_id = CookieUtil.getValue(getRequest(), "person_id");
|
|
|
|
|
//获取他是哪个城市或者县区的管理员
|
|
|
|
|
//行政区划码
|
|
|
|
|
String area_code = rm.getAreaCode(identity_id, person_id);
|
|
|
|
|
//根据区域码,获取区域名称
|
|
|
|
|
String area_name = rm.getAreaName(area_code);
|
|
|
|
|
Record record = dm.getDataSetById(id);
|
|
|
|
|
String tableName = record.getStr("table_name");
|
|
|
|
|
String dataSetName = record.getStr("dataset_name");
|
|
|
|
|
//导出excel
|
|
|
|
|
String excelFileName = dm.exportExcel(identity_id, tableName, tempDir, area_name);
|
|
|
|
|
String upPath = BaseApplication.PropKit.get("upload.path") + "/";
|
|
|
|
|
String excelFileName = dm.exportExcel(identity_id, tableName, upPath, area_name);
|
|
|
|
|
//renderFile
|
|
|
|
|
renderFile(new File(excelFileName), "【样例:" + area_name + "】" + dataSetName + "." + "xlsx");
|
|
|
|
|
renderFile(new File(excelFileName), "【" + area_name + "】" + dataSetName + "." + "xlsx");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -403,4 +404,92 @@ public class DataEaseController extends Controller {
|
|
|
|
|
dm.saveDataSetByCity(id, area_name, jsonArray);
|
|
|
|
|
renderJson(CommonUtil.returnMessageJson(true, "保存成功"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 市管理员辅助县区录入:下载指定数据集的Excel文件
|
|
|
|
|
*
|
|
|
|
|
* @param id 数据集id
|
|
|
|
|
*/
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
@IsLoginInterface({})
|
|
|
|
|
@IsNumericInterface({"id"})
|
|
|
|
|
public void downloadExcelByCity(int id) throws IOException {
|
|
|
|
|
int identity_id = 2;
|
|
|
|
|
//根据当前登录人员的身份,获取对应的数据集名称
|
|
|
|
|
String person_id = CookieUtil.getValue(getRequest(), "person_id");
|
|
|
|
|
//获取他是哪个城市或者县区的管理员
|
|
|
|
|
//行政区划码
|
|
|
|
|
String area_code = rm.getAreaCode(identity_id, person_id);
|
|
|
|
|
//根据区域码,获取区域名称
|
|
|
|
|
String area_name = rm.getAreaName(area_code);
|
|
|
|
|
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, area_name);
|
|
|
|
|
//renderFile
|
|
|
|
|
renderFile(new File(excelFileName), "【" + area_name + "】" + dataSetName + "." + "xlsx");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 市管理员辅助县区录入:上传Excel文件
|
|
|
|
|
*/
|
|
|
|
|
@Before(POST.class)
|
|
|
|
|
@IsLoginInterface({})
|
|
|
|
|
public void uploadExcelByCity() {
|
|
|
|
|
//根据当前登录人员的身份,获取对应的数据集名称
|
|
|
|
|
int identity_id = 2;
|
|
|
|
|
String person_id = CookieUtil.getValue(getRequest(), "person_id");
|
|
|
|
|
//获取他是哪个城市或者县区的管理员
|
|
|
|
|
//行政区划码
|
|
|
|
|
String area_code = rm.getAreaCode(identity_id, person_id);
|
|
|
|
|
//根据区域码,获取区域名称
|
|
|
|
|
String area_name = rm.getAreaName(area_code);
|
|
|
|
|
//父亲的区域名称
|
|
|
|
|
String parent_area_name = rm.getParentAreaName(area_name);
|
|
|
|
|
//上传的文件
|
|
|
|
|
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,area_name, rows);
|
|
|
|
|
|
|
|
|
|
//返回结果
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
|
|
kv.set("success", true);
|
|
|
|
|
kv.set("message", "上传成功");
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|