Commit 0189e45b authored by 陈家荣's avatar 陈家荣

导出板块excel表英文名称改成中文名称

parent 07765f17
......@@ -342,102 +342,126 @@ router.get('/info/report/exportXlsReport/:id', function(req, res, next) {
all_data_array = get_all_date(begin_time, end_time);
if (begin_time && end_time) {
var uv_datas = [];
var thread_datas = [];
//统计UV
var uv_tasks = [];
_.forEach(all_data_array, function(d) {
uv_tasks.push(function(cont) {
var match = {
ent_code:ent_code,
created: {
$gte: new Date(d + ' 00:00:00'),
$lte: new Date(d + ' 23:59:59')
},
info: info_id
};
var group = {
_id: {
user: '$user'
},
count: {
$sum: 1
}
};
mapReduce(ForumUvLog, match, group, d, cont);
});
});
forumInfoService.getInfoById(info_id,function(err,info){
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
var uv_datas = [];
var thread_datas = [];
//统计发帖数
var thread_tasks = [];
_.forEach(all_data_array, function(d) {
thread_tasks.push(function(cont) {
var match = {
ent_code:ent_code,
created: {
$gte: new Date(d + ' 00:00:00'),
$lte: new Date(d + ' 23:59:59')
}
};
var group = {
_id: {
_id: '$_id'
},
count: {
$sum: 1
//统计UV
var uv_tasks = [];
_.forEach(all_data_array, function(d) {
uv_tasks.push(function(cont) {
var match = {
ent_code:ent_code,
created: {
$gte: new Date(d + ' 00:00:00'),
$lte: new Date(d + ' 23:59:59')
},
info: info_id
};
var group = {
_id: {
user: '$user'
},
count: {
$sum: 1
}
};
mapReduce(ForumUvLog, match, group, d, cont);
});
});
//统计发帖数
var thread_tasks = [];
_.forEach(all_data_array, function(d) {
thread_tasks.push(function(cont) {
var match = {
ent_code:ent_code,
created: {
$gte: new Date(d + ' 00:00:00'),
$lte: new Date(d + ' 23:59:59')
}
};
var group = {
_id: {
_id: '$_id'
},
count: {
$sum: 1
}
};
mapReduce(ForumThread, match, group, d, cont);
});
});
then.parallel([function(con) {
//UV
then.parallel(uv_tasks).then(function(cont, datas) {
uv_datas = datas;
con();
}).fail(function(cont, err) {
con();
});
}, function(con) {
//发帖数
then.parallel(thread_tasks).then(function(cont, datas) {
// console.log(datas);
thread_datas = datas;
con();
}).fail(function(cont, err) {
console.log(err);
con();
});
}]).then(function(cont, datas) {
var conf = {};
conf.cols = [
{caption:'日期', type:'string'},
{caption:'浏览人数', type:'number'},
{caption:'发帖数', type:'number'}
];
conf.rows = [];
for(var i =0;i<all_data_array.length;i+=1){
conf.rows.push(
[
all_data_array[i],
uv_datas[i].count,
thread_datas[i].count
]
);
}
var filename = info.name + '报表.xlsx';
var userAgent = (req.headers['user-agent']||'').toLowerCase();
if(userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURIComponent(filename));
} else if(userAgent.indexOf('firefox') >= 0) {
res.setHeader('Content-Disposition', 'attachment; filename*="utf8\'\'' + encodeURIComponent(filename)+'"');
} else {
/* safari等其他非主流浏览器只能自求多福了 */
res.setHeader('Content-Disposition', 'attachment; filename=' + new Buffer(filename).toString('binary'));
}
};
mapReduce(ForumThread, match, group, d, cont);
});
});
then.parallel([function(con) {
//UV
then.parallel(uv_tasks).then(function(cont, datas) {
uv_datas = datas;
con();
}).fail(function(cont, err) {
con();
});
}, function(con) {
//发帖数
then.parallel(thread_tasks).then(function(cont, datas) {
// console.log(datas);
thread_datas = datas;
con();
}).fail(function(cont, err) {
console.log(err);
con();
});
}]).then(function(cont, datas) {
var conf = {};
conf.cols = [
{caption:'日期', type:'string'},
{caption:'浏览人数', type:'number'},
{caption:'发帖数', type:'number'}
];
conf.rows = [];
for(var i =0;i<all_data_array.length;i+=1){
conf.rows.push(
[
all_data_array[i],
uv_datas[i].count,
thread_datas[i].count
]
);
}
var result = nodeExcel.execute(conf);
res.setHeader('Content-Type', 'application/vnd.ms-excel');
res.setHeader('Content-Disposition', 'attachment; filename=InfoReport.xlsx');
res.end(result, 'binary');
}).fail(function(cont, err) {
console.error(err);
res.json({
result: false,
err: err
});
var result = nodeExcel.execute(conf);
res.setHeader('Content-Type', 'application/vnd.ms-excel;charset=utf-8');
// res.setHeader('Content-Disposition', 'attachment; filename=InfoReport.xlsx');
res.end(result, 'binary');
}).fail(function(cont, err) {
console.error(err);
res.json({
result: false,
err: err
});
});
}
});
} else {
res.json({
result: false,
......
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