配置统计Excel调整为后台导出
This commit is contained in:
@@ -264,15 +264,15 @@ public class ExcelCsv {
|
||||
* @param <E>
|
||||
* @return list 数据列表
|
||||
*/
|
||||
public static <E> Map<String, List<String>> setDataList(Properties msgProp, Map<String,List> dataMap, Map<Object,Object> map){
|
||||
Map<String, List<String>> dataList=new HashMap<String, List<String>>();
|
||||
public static <E> Map<String,List<List<String>>> setDataList(Properties msgProp, Map<String,List> dataMap, Map<Object,Object> map){
|
||||
Map<String,List<List<String>>> dataList=new HashMap<String, List<List<String>>>();
|
||||
Set<String> keyList=dataMap.keySet();
|
||||
for (String key : keyList) {
|
||||
List<E> list=dataMap.get(key);
|
||||
List<String> listT=new ArrayList<String>();
|
||||
List<List<String>> listT=new ArrayList<List<String>>();
|
||||
for (E e : list){
|
||||
int colunm = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<String> lisb=new ArrayList<String>();
|
||||
for (Object[] os : annotationMap.get(key)){
|
||||
ExcelField ef = (ExcelField)os[0];
|
||||
Object val = null;
|
||||
@@ -332,16 +332,17 @@ public class ExcelCsv {
|
||||
log.error("Get entity value failed",ex);
|
||||
val = "";
|
||||
}
|
||||
sb.append(val + "┆~");
|
||||
lisb.add(String.valueOf(val));
|
||||
}
|
||||
listT.add(String.valueOf(sb));
|
||||
listT.add(lisb);
|
||||
//listT.add(String.valueOf(sb));
|
||||
}
|
||||
dataList.put(key, listT);
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public static <T> void writeCSVFile(HttpServletResponse response,List<String> titleList,Map<String, List<String>> headMap, Map<String, List<String>> dataMap,String fileName,
|
||||
public static <T> void writeCSVFile(HttpServletResponse response,List<String> titleList,Map<String, List<String>> headMap, Map<String,List<List<String>>> dataMap,String fileName,
|
||||
String titleTime,Properties msgProp) {
|
||||
try {
|
||||
// 写入临时文件
|
||||
@@ -369,9 +370,9 @@ public class ExcelCsv {
|
||||
// 写入文件头部
|
||||
writeHead(heads, cs);
|
||||
//获取文件内容
|
||||
List<String> datas=dataMap.get(titleList.get(i));
|
||||
List<List<String>> datas=dataMap.get(titleList.get(i));
|
||||
// 写入文件内容
|
||||
for (String row : datas) {
|
||||
for (List<String> row: datas) {
|
||||
writeRow(row, cs);
|
||||
}
|
||||
}
|
||||
@@ -421,12 +422,11 @@ public class ExcelCsv {
|
||||
csvWriter.newLine();
|
||||
}
|
||||
|
||||
private static <T> void writeRow(String data, BufferedWriter csvWriter) throws Exception {
|
||||
private static <T> void writeRow(List<String> data, BufferedWriter csvWriter) throws Exception {
|
||||
// 写入文件内容
|
||||
//Html 解码
|
||||
data = Encodes.unescapeHtml(data.toString());
|
||||
String [] datas=data.split("┆~");
|
||||
for (String tag : datas) {
|
||||
for (String tag : data) {
|
||||
tag = Encodes.unescapeHtml(tag.toString());
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if("null".equals(tag.trim())){
|
||||
tag=null;
|
||||
|
||||
@@ -2273,8 +2273,7 @@ public class BaseController {
|
||||
}
|
||||
String titleTime=noExportMap.get("timeRange");
|
||||
Map<String, List<String>> headMap=ExcelCsv.ExcelCsvHeader(msgProp, titleList, noExportMap, classMap, 1);
|
||||
Map<String, List<String>> dataList=ExcelCsv.setDataList(msgProp, dataMap, map);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Map<String,List<List<String>>> dataList=ExcelCsv.setDataList(msgProp, dataMap, map);
|
||||
ExcelCsv.writeCSVFile(response,titleList,headMap,dataList,fileName,titleTime,msgProp);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ function toPage(pageNo, pageSize, funcParam) {
|
||||
$('tbody').children().css('display', 'none');
|
||||
//显示元素
|
||||
$('tbody').children().slice((pageNo-1)*pageSize, pageNo*pageSize).css('display', '');
|
||||
totaltb(pageNo,pageSize);
|
||||
showTotal();
|
||||
}
|
||||
|
||||
//底部跳页按钮
|
||||
|
||||
@@ -249,6 +249,73 @@
|
||||
append: null
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getTitl(tableMark){
|
||||
var tb=document.getElementsByName(tableMark)[0];
|
||||
var rows = tb.rows;
|
||||
var cells = tb.cells;
|
||||
var colums = tb.rows[0].cells.length;
|
||||
$("."+tableMark+" .count").empty();
|
||||
$("."+tableMark+" .count").append("<td><spring:message code='report_total' /></td>");
|
||||
for(var j = 1; j < colums; j++){
|
||||
var sum = 0;
|
||||
for(var i = 1;i<rows.length-1;i++){
|
||||
var a = parseInt(rows[i].cells[j].innerHTML.trim());
|
||||
sum = sum + a;
|
||||
}
|
||||
$("."+tableMark+" .count").append("<td>"+sum+"</td>");
|
||||
}
|
||||
}
|
||||
|
||||
function getExport(tableId,url,titleName){
|
||||
loading('<spring:message code="onloading"/>');
|
||||
getTitl(tableId);
|
||||
var tb=document.getElementsByName(tableId);
|
||||
var rows=tb[0].rows;
|
||||
var list=new Array();
|
||||
list.splice(0,list.length);
|
||||
var column=[]; //获取标题
|
||||
var index=[];//获取数据列下标
|
||||
var num=0;
|
||||
$("table[name='"+tableId+"']").find("tr th").each(function(){
|
||||
if($(this).is(":visible")){
|
||||
column.push($(this).text().trim());
|
||||
index.push(num);
|
||||
}
|
||||
num++;
|
||||
});
|
||||
for(var i=1 ; i<rows.length;i++){
|
||||
var rowMap=[];
|
||||
for (var j = 0; j <index.length ; j++) {
|
||||
var n=index[j];
|
||||
if(rows[i].cells[n]!=null){
|
||||
if(rows[i].cells[n].innerText.indexOf("...") !=-1){
|
||||
if(rows[i].cells[n].title.length > 20){
|
||||
rowMap.push(rows[i].cells[n].title);
|
||||
}else{
|
||||
rowMap.push(rows[i].cells[n].innerText);
|
||||
}
|
||||
}else{
|
||||
rowMap.push(rows[i].cells[n].innerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
list[i-1]=rowMap;
|
||||
}
|
||||
var menuName = $("#menuName").val();
|
||||
var fileName = menuName + "_" + getNowFormatDate();
|
||||
var pztitle =$("#"+titleName).text();
|
||||
var map={};
|
||||
map.heard=column;
|
||||
map.book=list;
|
||||
map.titleTime=pztitle;
|
||||
map.titleCode="config_service_statistics";
|
||||
var exports=JSON.stringify(map);
|
||||
aJaxImportPost(url,{"exports":exports});
|
||||
$("."+tableId+" .count").empty();
|
||||
closeTip();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<title>index</title>
|
||||
@@ -260,9 +327,7 @@
|
||||
<form id="searchForm" action="${ctx}/configure/statistics/configureStateStatistics" >
|
||||
<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
|
||||
<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
|
||||
<font size="4"><i class="fa fa-cogs"> <spring:message code="letter_statistics_info"/>
|
||||
[<spring:message code="statistic_time"/>:${requestStatisticTime }]
|
||||
</i>
|
||||
<font size="4"><i class="fa fa-cogs" id="pzTitle"> <spring:message code="letter_statistics_info"/> [<spring:message code="statistic_time"/>:${requestStatisticTime }]</i>
|
||||
</font>
|
||||
<a style="color:#333333" href="javascript:page(${page.pageNo},${page.pageSize});" class="icon-refresh"> </a>
|
||||
<div class="pull-right">
|
||||
@@ -272,7 +337,7 @@
|
||||
<i class="fa fa-angle-down"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu pull-right" style="min-width: 110px;" >
|
||||
<li><a href="javascript:;" class="export-btn" data-export-type="xlsx" data-export-table="cfgMenuTable"><i class="fa fa-download"> <spring:message code="Excel"/></i></a></li>
|
||||
<li><a href="javascript:;" onclick="getExport('cfgMenuTable','${ctx}/export/ajaxExport','pzTitle')" data-export-table="cfgMenuTable" ><i class="fa fa-download"> <spring:message code="Excel"/></i></a></li>
|
||||
<li><a href="javascript:;" class="export-btn" data-export-type="csv" data-export-table="cfgMenuTable"><i class="fa fa-download"> <spring:message code="CSV"/></i></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -329,8 +394,7 @@
|
||||
</div>
|
||||
<div id="statisticsStatus" class="statisticsStatus">
|
||||
<font size="4">
|
||||
<i class="fa fa-cogs"> <spring:message code="configure_statistics_info"/>
|
||||
[<spring:message code="statistic_time"/>:${configStatisticTime }]</i>
|
||||
<i class="fa fa-cogs" id="statusTitle"><spring:message code="configure_statistics_info"/> [<spring:message code="statistic_time"/>:${configStatisticTime }]</i>
|
||||
</font>
|
||||
<a style="color:#333333" href="javascript:page(${page.pageNo},${page.pageSize});" class="icon-refresh "> </a>
|
||||
<div class="pull-right">
|
||||
@@ -340,7 +404,7 @@
|
||||
<i class="fa fa-angle-down"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu pull-right" style="min-width: 110px;" >
|
||||
<li><a href="javascript:;" class="export-btn" data-export-type="xlsx" data-export-table="statisticsStatusTable"><i class="fa fa-download"> <spring:message code="Excel"/></i></a></li>
|
||||
<li><a href="javascript:;" onclick="getExport('statisticsStatusTable','${ctx}/export/ajaxExport','statusTitle')" data-export-table="statisticsStatusTable"><i class="fa fa-download"> <spring:message code="Excel"/></i></a></li>
|
||||
<li><a href="javascript:;" class="export-btn" data-export-type="csv" data-export-table="statisticsStatusTable"><i class="fa fa-download"> <spring:message code="CSV"/></i></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -101,7 +101,7 @@ $(document).ready(function() {
|
||||
var lipx=Number(li/6);
|
||||
lipx=lipx-3;
|
||||
$(".lireport").css({'width':lipx+'px','text-overflow':'ellipsis','overflow':'hidden'});
|
||||
|
||||
totaltb(1,-1);
|
||||
});
|
||||
function getExportHead(){
|
||||
// 报表导出 文件增加表头
|
||||
@@ -372,6 +372,13 @@ function customColumnClick(){
|
||||
$('#total').html(trtotal);
|
||||
}
|
||||
}
|
||||
function showTotal(){
|
||||
if($("#total")!=null){
|
||||
$("#total").show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
window.onload=function (){
|
||||
setTimeout(function (){
|
||||
var height=document.documentElement.clientHeight;
|
||||
@@ -477,7 +484,7 @@ function customColumnClick(){
|
||||
var column=[]; //获取标题
|
||||
var index=[];//获取数据列下标
|
||||
var num=0;
|
||||
$("#"+tableId+" thead tr th").each(function(){
|
||||
$("#"+tableId).find("tr th").each(function(){
|
||||
if($(this).is(":visible")){
|
||||
column.push($(this).text().trim());
|
||||
index.push(num);
|
||||
|
||||
Reference in New Issue
Block a user