Commit 39d6eb99 by fudahua

feat:自定义查询zip测试

parent c1ac971c
package com.gic.cloud.data.hook.service; package com.gic.cloud.data.hook.service;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
...@@ -47,4 +50,13 @@ public class FileUtil { ...@@ -47,4 +50,13 @@ public class FileUtil {
} }
} }
} }
/**
* 获取限制调试
* @return
*/
public static Integer getLimitSize(){
Config appConfig = ConfigService.getAppConfig();
return appConfig.getIntProperty("xls.size.limit", 1000000);
}
} }
...@@ -811,7 +811,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -811,7 +811,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
if (conn != null) { if (conn != null) {
try { try {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
Integer limitSize = FileUtil.getLimitSize();
// stat.setQueryTimeout(60 * 1000); // stat.setQueryTimeout(60 * 1000);
stat.execute("REFRESH TABLE " + condition.getTableId()); // 强制刷新表结构 stat.execute("REFRESH TABLE " + condition.getTableId()); // 强制刷新表结构
ResultSet rs = stat.executeQuery(fullQuery); ResultSet rs = stat.executeQuery(fullQuery);
...@@ -840,8 +840,8 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -840,8 +840,8 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} else { // 如果指定为 XLS 格式 } else { // 如果指定为 XLS 格式
logger.info("[ runDownloadTask.run ]: {}", "准备生成自助指标下载文件 " + condition.getTaskId() + ".xlsx"); logger.info("[ runDownloadTask.run ]: {}", "准备生成自助指标下载文件 " + condition.getTaskId() + ".xlsx");
int filePos=0; int filePos=0;
if (condition.getAmount()>XLS_SIZE){ if (condition.getAmount()>limitSize){
int num = (condition.getAmount() / XLS_SIZE)+(condition.getAmount()%XLS_SIZE>0?1:0); int num = (condition.getAmount() / limitSize)+(condition.getAmount()%limitSize>0?1:0);
while (num-->0) { while (num-->0) {
originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId()+"-"+filePos + ".xlsx"; originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId()+"-"+filePos + ".xlsx";
filePos++; filePos++;
...@@ -963,6 +963,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -963,6 +963,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
private void saveXlsSplit(String originalFilePath,ResultSetHelper helper,ResultSet rs,FlatQueryTaskCondition condition){ private void saveXlsSplit(String originalFilePath,ResultSetHelper helper,ResultSet rs,FlatQueryTaskCondition condition){
try { try {
Integer limitSize = FileUtil.getLimitSize();
// String originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId() + ".xlsx"; // String originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId() + ".xlsx";
SXSSFWorkbook wb = new SXSSFWorkbook(100); // 内存中保留 100 行 SXSSFWorkbook wb = new SXSSFWorkbook(100); // 内存中保留 100 行
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
...@@ -975,7 +976,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -975,7 +976,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} }
// 遍历输出行 // 遍历输出行
int rowCount = 0; int rowCount = 0;
while (rowCount<XLS_SIZE&&rs.next()) { while (rowCount<limitSize&&rs.next()) {
rowCount++; rowCount++;
row = sheet.createRow(rowCount); row = sheet.createRow(rowCount);
String[] columnValues = helper.getColumnValues(rs, true, "", ""); String[] columnValues = helper.getColumnValues(rs, true, "", "");
......
...@@ -398,6 +398,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -398,6 +398,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
} // IF OVER } // IF OVER
} // FOR OVER } // FOR OVER
if (condition != null) { if (condition != null) {
Integer limitSize = FileUtil.getLimitSize();
// 更新任务状态 // 更新任务状态
DownloadTask task = DownloadTaskServiceImpl.getInstance().getDownloadTaskById(condition.getTaskId()); DownloadTask task = DownloadTaskServiceImpl.getInstance().getDownloadTaskById(condition.getTaskId());
task.setStatus(DownloadTaskStatus.BUILDING); task.setStatus(DownloadTaskStatus.BUILDING);
...@@ -439,8 +441,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -439,8 +441,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
} else { } else {
log.debug("runDownloadTask.run", "准备生成自定义查询下载文件 " + condition.getTaskId() + ".xlsx"); log.debug("runDownloadTask.run", "准备生成自定义查询下载文件 " + condition.getTaskId() + ".xlsx");
int filePos=0; int filePos=0;
if (condition.getAmount()>XLS_SIZE){ if (condition.getAmount()>limitSize){
int num = (condition.getAmount() / XLS_SIZE)+(condition.getAmount()%XLS_SIZE>0?1:0); int num = (condition.getAmount() / limitSize)+(condition.getAmount()%limitSize>0?1:0);
while (num-->0) { while (num-->0) {
originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId()+"-"+filePos + ".xlsx"; originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId()+"-"+filePos + ".xlsx";
filePos++; filePos++;
...@@ -591,6 +593,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -591,6 +593,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
} }
private void saveXlsx(FreeQueryTaskCondition condition,String originalFilePath,ResultSet rs,DownloadTask task) throws Exception{ private void saveXlsx(FreeQueryTaskCondition condition,String originalFilePath,ResultSet rs,DownloadTask task) throws Exception{
Integer limitSize = FileUtil.getLimitSize();
originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId() + ".xlsx"; originalFilePath = SAVE_FOLDER + "/" + condition.getTaskId() + ".xlsx";
SXSSFWorkbook wb = new SXSSFWorkbook(100); // 内存中保留 100 行 SXSSFWorkbook wb = new SXSSFWorkbook(100); // 内存中保留 100 行
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
...@@ -603,7 +606,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -603,7 +606,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
} }
// 遍历输出行 // 遍历输出行
int rowCount = 0; int rowCount = 0;
while (rs.next()) { while (rs.next()&&rowCount<limitSize) {
rowCount++; rowCount++;
row = sheet.createRow(rowCount); row = sheet.createRow(rowCount);
for (int j = 0; j < rs.getMetaData().getColumnCount(); ++j) { for (int j = 0; j < rs.getMetaData().getColumnCount(); ++j) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment