main
黄海 9 months ago
parent 6229fded48
commit 010b2ac7af

@ -19,6 +19,7 @@ import io.github.yedaxia.apidocs.ApiDoc;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import java.io.IOException;
import java.util.List; import java.util.List;
public class DataEaseController extends Controller { public class DataEaseController extends Controller {
@ -128,7 +129,7 @@ public class DataEaseController extends Controller {
@Before(GET.class) @Before(GET.class)
@IsLoginInterface({}) @IsLoginInterface({})
@IsNumericInterface({"id"}) @IsNumericInterface({"id"})
public void downloadExcel(int id) { public void downloadExcel(int id) throws IOException {
//根据当前登录人员的身份,获取对应的数据集名称 //根据当前登录人员的身份,获取对应的数据集名称
int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id")); int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id"));
String person_id = CookieUtil.getValue(getRequest(), "person_id"); String person_id = CookieUtil.getValue(getRequest(), "person_id");
@ -138,18 +139,11 @@ public class DataEaseController extends Controller {
//根据区域码,获取区域名称 //根据区域码,获取区域名称
String area_name = rm.getAreaName(area_code); String area_name = rm.getAreaName(area_code);
Record record = dm.getDataSetById(id); Record record = dm.getDataSetById(id);
String table_name = record.getStr("table_name"); String tableName = record.getStr("table_name");
String dataSetName = record.getStr("dataset_name"); String dataSetName = record.getStr("dataset_name");
String tempDir = System.getProperty("java.io.tmpdir");
switch (identity_id) { //导出excel
case 1: dm.exportExcel(identity_id, tableName, dataSetName, tempDir, area_name);
break;
case 2:
break;
case 3:
break;
}
} }
/** /**

@ -1,6 +1,7 @@
package com.dsideal.base.DataEase.Model; package com.dsideal.base.DataEase.Model;
import com.dsideal.base.Util.ExcelCommonUtil; import com.dsideal.base.Util.ExcelCommonUtil;
import com.dsideal.base.Util.FileUtil;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
@ -8,6 +9,7 @@ import com.jfinal.plugin.activerecord.SqlPara;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -334,6 +336,7 @@ public class DataEaseModel {
/** /**
* Excel * Excel
*
* @param identity_id * @param identity_id
* @param tableName * @param tableName
* @param dataSetName * @param dataSetName
@ -349,6 +352,12 @@ public class DataEaseModel {
} }
List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql); List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql);
String excelFileName = "【" + area_name + "】" + dataSetName + ".xlsx"; String excelFileName = "【" + area_name + "】" + dataSetName + ".xlsx";
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true); String filePath = exportPath + excelFileName;
if (new File(filePath).exists()) {
//删除
new File(filePath).delete();
}
//导出
ExcelCommonUtil.writeExcel(tableData, filePath, true);
} }
} }

Loading…
Cancel
Save