报表单个导出、按查询条件导出和全部导出
报表单个导出、按查询条件导出和全部导出
导出的js代码
// 导出
$('#dg-exportBtn').click(function() {
var row = $("#dg").datagrid("getSelected");
// 设置获取日志的类型
getting["data"] = {
"loggerType" : "export"
};
var displayCode = '';
var code = $('#queryDisplayCode').textbox('getValue');
var name = $('#queryContent').textbox('getValue');
var urlContent = contextPathName + "/reportDisplayInfo/export.do?";
var param = "";
if (null == row) {
if (code.length == 0 && name.length == 0 && code == "" && name == "") {
$.messager.confirm("提醒", "确定导出全部图集数据?", function(r) {
if (r) {
displayCode = '';
param = "displayCode=" + encodeURIComponent(encodeURIComponent(displayCode));
// 下载全部xml
content = "导出数据日志:
";
$('#importResultDiv').html(content);
$('#showResult').dialog("open").dialog("setTitle", "导出数据日志信息");
// 初始化进度条
$('#importProgressbar').progressbar("setValue", 0);
// 开始获取
flag = true;
// 定时ajax获取日志信息
if (flag) {
dingShiQiArr.push(window.setInterval(function() {
$.ajax(getting)
}, 200));
}
window.location.href = https://www.it610.com/article/urlContent + param;
} else {
return;
}
});
} else {
$.messager.confirm("提醒", "确定按查询条件导出图集数据?", function(r) {
if (r) {
param = "displayCode=" + encodeURIComponent(encodeURIComponent(code)) +
"&displayName="+encodeURIComponent(encodeURIComponent(name));
content = "导出数据日志:
";
$('#importResultDiv').html(content);
$('#showResult').dialog("open").dialog("setTitle", "导出数据日志信息");
// 初始化进度条
$('#importProgressbar').progressbar("setValue", 0);
// 开始获取
flag = true;
// 定时ajax获取日志信息
if (flag) {
dingShiQiArr.push(window.setInterval(function() {
$.ajax(getting)
}, 200));
}
window.location.href = https://www.it610.com/article/urlContent + param;
} else {
return;
}
});
}
} else {
var id = row.id;
var displayName=row.displayName;
param ="id=" + encodeURIComponent(encodeURIComponent(id))+
"&displayName="+encodeURIComponent(encodeURIComponent(displayName));
content = "导出数据日志:
";
$('#importResultDiv').html(content);
$('#showResult').dialog("open").dialog("setTitle", "导出数据日志信息");
// 初始化进度条
$('#importProgressbar').progressbar("setValue", 0);
// 开始获取
flag = true;
// 定时ajax获取日志信息
if (flag) {
dingShiQiArr.push(window.setInterval(function() {
$.ajax(getting)
}, 200));
}
window.location.href = https://www.it610.com/article/urlContent + param;
}});
导出的controller代码
【报表单个导出、按查询条件导出和全部导出】
@RequestMapping ("/export")
@ResponseBody
public void export (HttpServletRequest request, HttpServletResponse response)
{
List ReportDisplayInfos = new ArrayList ();
ReportDisplayInfo reportDisplayInfo = new ReportDisplayInfo ();
ListexportResultList = new ArrayList();
String title = DateUtil.getNowDate (DATE_FORMAT) + "_图集信息";
try
{
request.setCharacterEncoding ("UTF-8");
String displayCode = request.getParameter ("displayCode");
String displayName = request.getParameter ("displayName");
String idStr = request.getParameter ("id");
if (StringUtils.isNotBlank (idStr))
{
idStr = URLDecoder.decode (idStr, "UTF-8");
reportDisplayInfo.setId (Long.valueOf (idStr) != null ? Long.valueOf (idStr) : null);
if (StringUtils.isNotBlank (displayName))
{
displayName = URLDecoder.decode (displayName, "UTF-8");
title = "导出单个(" + displayName + ")" + "_图集信息";
}
}
else
{
title = "全部导出_图集信息";
if (StringUtils.isNotBlank (displayCode))
{
displayCode = URLDecoder.decode (displayCode, "UTF-8");
title = "条件导出(" + displayCode + ")" + "_图集信息";
}
if (StringUtils.isNotBlank (displayName))
{
displayName = URLDecoder.decode (displayName, "UTF-8");
title = "条件导出(" + displayName + ")" + "_图集信息";
if (StringUtils.isNotBlank (displayCode))
{
title = "条件导出(" + displayCode + "+" + displayName + ")" + "_图集信息";
}
}
reportDisplayInfo.setDisplayCode (displayCode != null ? displayCode : "");
reportDisplayInfo.setDisplayName (displayName != null ? displayName : "");
}
// 获得全部或者单个对象
ReportDisplayInfos = _reportDisplayInfoService.queryReportDisplayInfoWithoutPagingByParams (reportDisplayInfo);
int index = 0;
int exportProgress = 0;
ReportDisplay seportDisplay = new ReportDisplay ();
List ReportDisplayInfoExportDtos = new ArrayList ();
if (CollectionUtils.isNotEmpty (ReportDisplayInfos))
{
exportResultList.add ("数据正在导出!");
for (ReportDisplayInfo reportDisplayInfo2 : ReportDisplayInfos)
{
if (null != reportDisplayInfo2)
{
index++;
ReportDisplayInfoExportDto reportDisplayInfoExportDto = new ReportDisplayInfoExportDto ();
reportDisplayInfoExportDto.setDisplayCode (reportDisplayInfo2.getDisplayCode ());
reportDisplayInfoExportDto.setDisplayName (reportDisplayInfo2.getDisplayName ());
reportDisplayInfoExportDto.setLayoutType (reportDisplayInfo2.getLayoutType ());
reportDisplayInfoExportDto.setEnableStatus (reportDisplayInfo2.getEnableStatus ());
String displayTemplate = reportDisplayInfo2.getDisplayTemplate ();
if (!StringUtils.isBlank (displayTemplate))
{
// 解决静态模板非xml格式的问题
if (!displayTemplate.startsWith ("";
// reportDisplayInfo.setDisplayTemplate
// (displayTemplate);
}String displayTemplateJson = XML.toJSONObject (displayTemplate).toString ();
reportDisplayInfo.setDisplayTemplateJson (displayTemplateJson);
// 加密操作
reportDisplayInfoExportDto.setDisplayTemplate (Encr.encrypt (displayTemplate));
}
String displayTemplateJson = reportDisplayInfo2.getDisplayTemplateJson ();
if (!StringUtils.isBlank (displayTemplateJson))
{
// 加密操作
reportDisplayInfoExportDto.setDisplayTemplateJson (Encr.encrypt (displayTemplateJson));
}
Date curDate1 = reportDisplayInfo2.getCreateTime ();
if (null != curDate1)
{
reportDisplayInfoExportDto.setCreateTime (DateUtil.date2string (curDate1,
DateUtil.DATE_TIME_FORMAT));
}
Date curDate2 = reportDisplayInfo2.getUpdateTime ();
if (null != curDate2)
{
reportDisplayInfoExportDto.setUpdateTime (DateUtil.date2string (curDate2,
DateUtil.DATE_TIME_FORMAT));
}
ReportDisplayInfoExportDtos.add (reportDisplayInfoExportDto);
exportResultList.add (reportDisplayInfo2.getDisplayCode () + "导出成功");
float num = (float) (((float) index) / ((float) (ReportDisplayInfos.size ())));
DecimalFormat df = new DecimalFormat ("0.00");
// 格式化小数
String exportProgressStr = df.format (num);
// 返回的是String类型
exportProgress = (int) (Float.valueOf (exportProgressStr) * 100);
request.getSession ().setAttribute ("exportProgress", exportProgress);
request.getSession ().setAttribute ("exportResultList", exportResultList);
}
}
seportDisplay.setReportDisplayInfos (ReportDisplayInfoExportDtos);
String xmlContent = JaxbUtil.convertToXml (seportDisplay);
String fileName = title + ".xml";
int bufferSize = 65000;
byte[] bytes = xmlContent.getBytes ("utf-8");
ByteArrayInputStream inputstream = new ByteArrayInputStream (bytes);
byte abyte0[] = new byte[bufferSize];
response.setContentType ("application/octet-stream;
charset=utf-8");
response.setContentLength ((int) bytes.length);
response.setHeader ("Content-Disposition",
"attachment;
filename=" + new String (fileName.getBytes ("utf-8"), "ISO8859-1"));
ServletOutputStream out = response.getOutputStream ();
response.setCharacterEncoding ("utf-8");
int sum = 0;
int k = 0;
while ((k = inputstream.read (abyte0, 0, bufferSize)) > -1)
{
out.write (abyte0, 0, k);
sum += k;
}
exportResultList.add ("导出图集数据:" + ReportDisplayInfos.size () + "条");
exportResultList.add ("数据导出完毕!");
exportResultList.add ("OVER");
request.getSession ().setAttribute ("exportResultList", exportResultList);
inputstream.close ();
out.flush ();
out.close ();
}
}
catch (Exception e)
{
_logger.error ("导出图集数据异常", e);
}
}
推荐阅读
- 单点登陆
- 如何将多个小分子文件合并为单个
- javascript|vue使用js-xlsx导出excel,可修改格子样式,例如背景颜色、字体大小、列宽等
- vue|vue js-xlsx导入导出excel文件Demo
- iOS设置单个圆角(cornerRadius)和单边阴影(shaodwRadius)
- Windows平台使用bat脚本导出日志
- jquery导出excel、pdf等[tableExport简单使用]
- Excel读书笔记27——费用分析报表——日期函数的多功能应用示例
- SQL|SQL 导出表结构到Excel
- Springboot|Springboot 注解 @Cacheable自定义单个key设置expire超时时间 并在配置文件里配置