修复数据库导出时多次response导致的控制台报错问题

达梦关键词过滤
数据库导出CLOB数据类型处理
This commit is contained in:
diantu
2023-02-13 21:10:58 +08:00
parent f8efca5ee0
commit 41a3760b2a
4 changed files with 18 additions and 5 deletions

View File

@@ -189,10 +189,13 @@ public class DatabaseDocController {
DatabaseExportVo exportVo = new DatabaseExportVo(columnList, tableList);
if (Objects.equals(exportFormat, 1)) {
PoiUtil.exportByText(exportVo, response);
return null;
} else if (Objects.equals(exportFormat, 2)) {
PoiUtil.exportByXlsx(exportVo, response);
return null;
} else if (Objects.equals(exportFormat, 3)) {
PoiUtil.exportByDocx(dbName, exportVo, response);
return null;
}
return DocDbResponseJson.error("导出失败:请先选择导出类型");
} catch (Exception e) {

View File

@@ -127,7 +127,7 @@ public class DbDataViewController {
e.printStackTrace();
return DocDbResponseJson.error("导出失败:" + e.getMessage());
}
return DocDbResponseJson.ok();
return null;
}
/**

View File

@@ -15,6 +15,7 @@ import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteParam;
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteType;
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
import com.zyplayer.doc.db.framework.utils.SQLTransformUtils;
import com.zyplayer.doc.db.service.common.ExecuteAuthService;
import com.zyplayer.doc.db.service.database.DatabaseServiceFactory;
import com.zyplayer.doc.db.service.database.DbBaseService;
@@ -24,11 +25,11 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.net.URLEncoder;
import java.sql.Clob;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
@@ -43,7 +44,7 @@ import java.util.stream.Stream;
@Service(FormatDownloadConst.EXCEL)
public class ExcelFormatDownloadService implements FormatDownloadService {
private static Logger logger = LoggerFactory.getLogger(ExcelFormatDownloadService.class);
@Resource
ExecuteAuthService executeAuthService;
@Resource
@@ -52,7 +53,7 @@ public class ExcelFormatDownloadService implements FormatDownloadService {
BaseDownloadService baseDownloadService;
@Resource
SqlExecutor sqlExecutor;
@Override
public void download(HttpServletResponse response, DataViewParam param, String[] tableNameArr) throws Exception {
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(param.getSourceId());
@@ -112,6 +113,12 @@ public class ExcelFormatDownloadService implements FormatDownloadService {
downloadDataList.add(new LinkedList<Object>() {{
for (TableColumnDescDto columnDto : columnListRetain) {
Object data = dataMap.get(columnDto.getName());
//CLOB类型数据处理
if(columnDto.getType().equals("CLOB")){
if(data!=null){
data = SQLTransformUtils.ClobToString((Clob) data);
}
}
// 数据格式处理,不处理有些格式会造成乱码,打不开文件
if (!(data == null || data instanceof Number || data instanceof CharSequence)) {
if (data instanceof Timestamp) {
@@ -147,7 +154,7 @@ public class ExcelFormatDownloadService implements FormatDownloadService {
}
}
}
private List<List<String>> getSheetHeadList(List<TableColumnDescDto> columnListRetain) {
List<List<String>> sheetHeadList = new ArrayList<>();
for (TableColumnDescDto dataCol : columnListRetain) {

View File

@@ -48,6 +48,9 @@ public class DmServiceImpl extends DbBaseService {
if(queryColumnsArray[i].equalsIgnoreCase("IDENTITY")){
queryColumnsArray[i] = "\"IDENTITY\"";
}
if(queryColumnsArray[i].equalsIgnoreCase("DOMAIN")){
queryColumnsArray[i] = "\"DOMAIN\"";
}
if(i < queryColumnsArray.length-1){
resultString +=queryColumnsArray[i] + ",";
}else{