main
黄海 9 months ago
parent f041f40a38
commit f3fac03d97

@ -7,6 +7,7 @@ import com.dsideal.base.DataEase.Model.DataEaseModel;
import com.dsideal.base.Interceptor.EmptyInterface;
import com.dsideal.base.Interceptor.IsLoginInterface;
import com.dsideal.base.Interceptor.IsNumericInterface;
import com.dsideal.base.Res.Model.ResourceModel;
import com.dsideal.base.Util.CommonUtil;
import com.dsideal.base.Util.CookieUtil;
import com.jfinal.aop.Before;
@ -22,12 +23,14 @@ import java.util.List;
public class DataEaseController extends Controller {
DataEaseModel dm = new DataEaseModel();
ResourceModel rm = new ResourceModel();
BaseModel bm = new BaseModel();
// http://10.10.21.20:9000/dsBase/dataease/route?city_name=昆明市
// http://10.10.21.20:9000/dsBase/dataease/route?city_name=楚雄彝族自治州
// http://10.10.21.20:9000/dsBase/dataease/route?city_name=西双版纳傣族自治州
// !!!必须发布后访问才能做到进入此接口,否则浏览器就走缓存,不进来这个接口了!!!
/**
*
*
@ -117,6 +120,56 @@ public class DataEaseController extends Controller {
renderJson(CommonUtil.returnMessageJson(true, "保存成功"));
}
//@Before(GET.class)
/**
* Excel
*
* @param id id
*/
@Before(GET.class)
@IsLoginInterface({})
@IsNumericInterface({"id"})
public void downloadExcel(int id) {
//根据当前登录人员的身份,获取对应的数据集名称
int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id"));
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 table_name = record.getStr("table_name");
String dataSetName = record.getStr("dataset_name");
switch (identity_id) {
case 1:
break;
case 2:
break;
case 3:
break;
}
}
/**
* Excel
*
* @param type_id 1:2
*/
@Before(GET.class)
@IsLoginInterface({})
public void downSampleExcel(int type_id) {
}
/**
* Excel
*/
@Before(POST.class)
@IsLoginInterface({})
public void uploadExcel() {
}
}

@ -1,5 +1,6 @@
package com.dsideal.base.DataEase.Model;
import com.dsideal.base.Util.ExcelCommonUtil;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
@ -7,6 +8,7 @@ import com.jfinal.plugin.activerecord.SqlPara;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -33,23 +35,13 @@ public class DataEaseModel {
* @return
*/
public List<Record> getDataSetTableContent(int dataset_id) {
Record record = getTableName(dataset_id);
Record record = getDataSetById(dataset_id);
if (record == null) return null;
String sql = "select * from `" + record.getStr("table_name") + "`";
List<Record> list = Db.use(DB_NAME).find(sql);
return list;
}
/**
* id
*
* @param dataset_id id
* @return
*/
public Record getTableName(int dataset_id) {
String sql = "select * from t_dp_dataset where id=?";
return Db.findFirst(sql, dataset_id);
}
/**
*
@ -58,7 +50,7 @@ public class DataEaseModel {
* @param ja json
*/
public void saveDataSetTable(int identity_id, int dataset_id, String xmqh, JSONArray ja) {
String tableName = getTableName(dataset_id).getStr("table_name");
String tableName = getDataSetById(dataset_id).getStr("table_name");
if (identity_id > 1) {
String sql = "delete from dataease.`" + tableName + "` where `行政区划`=?";
Db.update(sql, xmqh);
@ -146,6 +138,16 @@ public class DataEaseModel {
return Db.findFirst(sqlPara).getStr("table_name");
}
/**
* id
*
* @param dataset_id id
* @return
*/
public Record getDataSetById(int dataset_id) {
String sql = "select * from t_dp_dataset where id=?";
return Db.findFirst(sql, dataset_id);
}
/**
*
@ -171,7 +173,7 @@ public class DataEaseModel {
record.set("dataease_id", dataease_id);
Db.save("t_dp_dataset", "id", record);
System.out.println("添加数据集成功,parent_name=" + parent_name + ",table_name=" + table_name + ",dataset_name=" + dataset_name);
}else{
} else {
System.out.println("数据集已存在,跳过添加");
}
}
@ -310,21 +312,43 @@ public class DataEaseModel {
/**
*
*
* @param tableName
* @return
*/
public boolean hasNoColumnName(String tableName, String columnName) {
String sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'dataease' AND TABLE_NAME = ? AND COLUMN_NAME = ?";
return Db.find(sql, tableName,columnName).isEmpty();
return Db.find(sql, tableName, columnName).isEmpty();
}
/**
*
* @param tableName
*
* @param tableName
* @param columnName
*/
public void addColumn(String tableName, String columnName){
String sql="ALTER TABLE `"+tableName+"` ADD COLUMN `"+columnName+"` varchar(255) NULL";
public void addColumn(String tableName, String columnName) {
String sql = "ALTER TABLE `" + tableName + "` ADD COLUMN `" + columnName + "` varchar(255) NULL";
Db.use(DataEaseModel.DB_NAME).update(sql);
}
/**
* Excel
* @param identity_id
* @param tableName
* @param dataSetName
* @param exportPath
* @param area_name
* @throws IOException
*/
public void exportExcel(int identity_id, String tableName, String dataSetName, String exportPath, String area_name) throws IOException {
//对此表中的数据进行直接导出EXCEL
String sql = "select * from `" + tableName + "`";
if (identity_id > 1) {
sql = sql + "where `行政区划`='" + area_name + "'";
}
List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql);
String excelFileName = "【" + area_name + "】" + dataSetName + ".xlsx";
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
}
}

@ -25,6 +25,17 @@ public class ResourceModel {
return Db.findFirst(sql, area_id).getStr("area_code");
}
/**
*
*
* @param area_code
* @return
*/
public String getAreaName(String area_code) {
String sql = "select * from t_dm_area where area_code=?";
return Db.findFirst(sql, area_code).getStr("area_name");
}
/**
*
*
@ -124,11 +135,12 @@ public class ResourceModel {
/**
*
*
* @param id
* @return
*/
public Record getZskDocument(int id){
String sql = "select * from t_zsk_files where id=?";
return Db.findFirst(sql, id);
public Record getZskDocument(int id) {
String sql = "select * from t_zsk_files where id=?";
return Db.findFirst(sql, id);
}
}

@ -37,11 +37,7 @@ public class ExportExcel {
String tableName = record.getStr("table_name");
String dataSetName = record.getStr("dataset_name");
System.out.println("正在处理数据集:" + dataSetName);
//对此表中的数据进行直接导出EXCEL
String sql = "select * from `" + tableName + "`";
List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql);
String excelFileName = "【" + privinceName + "】" + dataSetName + ".xlsx";
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
dm.exportExcel(1, tableName, dataSetName, exportPath, privinceName);
}
//二、导出市的数据集
System.out.println("正在处理市数据集...");
@ -50,15 +46,12 @@ public class ExportExcel {
System.out.println("数据集个数=" + list.size());
for (Record record : list) {
String tableName = record.getStr("table_name");
String dataSetName = record.getStr("dataset_name");
String dataSetName = record.getStr("dataset_name").replace("\\","").replace("/","");
System.out.println("正在处理数据集:" + dataSetName);
Record cityRecord = dm.getAreaByName(city_name);
String cityName = cityRecord.getStr("area_name");
String sql = "select * from `" + tableName + "` where `行政区划`=?";
List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql, cityName);
String excelFileName = "【" + cityName + "】" + dataSetName + ".xlsx";
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
dm.exportExcel(2, tableName, dataSetName, exportPath, cityName);
}
//三、导出县区的数据集
System.out.println("正在处理县区数据集...");
@ -67,15 +60,12 @@ public class ExportExcel {
System.out.println("数据集个数=" + list.size());
for (Record record : list) {
String tableName = record.getStr("table_name");
String dataSetName = record.getStr("dataset_name");
String dataSetName = record.getStr("dataset_name").replace("\\","").replace("/","");
System.out.println("正在处理数据集:" + dataSetName);
Record areaRecord = dm.getAreaByName(area_name);
String areaName = areaRecord.getStr("area_name");
String sql = "select * from `" + tableName + "` where `行政区划`=?";
List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql, areaName);
String excelFileName = "【" + areaName + "】" + dataSetName.replace("\\","").replace("/","") + ".xlsx";
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
dm.exportExcel(3, tableName, dataSetName, exportPath, areaName);
}
System.out.println("导出完成!");
//关闭Ssh链接

Loading…
Cancel
Save