Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
07765f17
Commit
07765f17
authored
Aug 03, 2015
by
陈家荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了板块报表的导出板块报表接口
parent
4bdacea3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
274 additions
and
2 deletions
+274
-2
forumInfo.js
app/controllers/admin/forumInfo.js
+274
-2
No files found.
app/controllers/admin/forumInfo.js
View file @
07765f17
...
@@ -3,6 +3,8 @@ var express = require('express'),
...
@@ -3,6 +3,8 @@ var express = require('express'),
router
=
express
.
Router
(),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
),
_
=
require
(
'lodash'
),
moment
=
require
(
'moment'
),
nodeExcel
=
require
(
'excel-export'
),
then
=
require
(
'thenjs'
);
then
=
require
(
'thenjs'
);
var
mongoose
=
require
(
'mongoose'
);
var
mongoose
=
require
(
'mongoose'
);
...
@@ -10,12 +12,60 @@ var ForumInfo = mongoose.model('ForumInfo');
...
@@ -10,12 +12,60 @@ var ForumInfo = mongoose.model('ForumInfo');
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumGroupService
=
require
(
'../../service/forumGroupService'
);
var
forumGroupService
=
require
(
'../../service/forumGroupService'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
ForumUvLog
=
mongoose
.
model
(
'ForumUVLog'
);
module
.
exports
=
function
(
app
)
{
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
app
.
use
(
'/admin/forum'
,
router
);
};
};
//格式化日期 (格式:年-月-日)
function
date_format
(
date
)
{
return
moment
(
date
).
format
(
'YYYY/MM/DD'
);
}
//获取日期之间所有日期
function
get_all_date
(
begin
,
end
)
{
var
date_array
=
[];
// if (begin === end) return date_array;
if
(
begin
===
end
){
date_array
.
push
(
end
.
replace
(
/-/g
,
"/"
));
return
date_array
;
}
var
ab
=
begin
.
split
(
'-'
);
var
ae
=
end
.
split
(
'-'
);
var
db
=
new
Date
();
db
.
setUTCFullYear
(
ab
[
0
],
ab
[
1
]
-
1
,
ab
[
2
]);
var
de
=
new
Date
();
de
.
setUTCFullYear
(
ae
[
0
],
ae
[
1
]
-
1
,
ae
[
2
]);
var
unixDb
=
db
.
getTime
();
var
unixDe
=
de
.
getTime
()
+
24
*
60
*
60
*
1000
;
for
(
var
k
=
unixDb
;
k
<
unixDe
;)
{
date_array
.
push
(
date_format
(
new
Date
(
parseInt
(
k
))));
k
=
k
+
24
*
60
*
60
*
1000
;
}
return
date_array
;
}
//统计
function
mapReduce
(
model
,
match
,
group
,
date
,
callback
)
{
model
.
aggregate
({
$match
:
match
},
{
$group
:
group
},
function
(
err
,
res
)
{
if
(
err
)
callback
(
err
);
else
{
var
data
=
{
date
:
date
,
count
:
res
.
length
};
callback
(
null
,
data
);
}
});
}
//新增论坛板块
//新增论坛板块
router
.
post
(
'/info/create'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/info/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
var
rs
=
{};
...
@@ -31,7 +81,7 @@ router.post('/info/create', function(req, res, next) {
...
@@ -31,7 +81,7 @@ router.post('/info/create', function(req, res, next) {
if
(
groups
&&
groups
.
items
.
length
>
0
){
if
(
groups
&&
groups
.
items
.
length
>
0
){
cont
(
null
,
groups
.
items
[
0
]);
cont
(
null
,
groups
.
items
[
0
]);
}
else
{
}
else
{
//创建默认版块组
//创建默认版块组
1
var
group
=
{
var
group
=
{
name
:
'默认分组'
,
name
:
'默认分组'
,
ent_code
:
ent_code
ent_code
:
ent_code
...
@@ -173,3 +223,225 @@ router.get('/infos/list', function(req, res, next) {
...
@@ -173,3 +223,225 @@ router.get('/infos/list', function(req, res, next) {
}
}
});
});
});
});
//板块报表
router
.
post
(
'/info/report/:id'
,
function
(
req
,
res
,
next
)
{
// 1.获取文章的创建日期,和今天的日期,转换成日期数组
var
info_id
=
req
.
body
.
id
,
ent_code
=
req
.
session
.
user
.
ent_code
,
begin_time
=
req
.
body
.
begin_time
,
end_time
=
req
.
body
.
end_time
,
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
);
});
});
//统计发帖数
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
data
=
{
uv_datas
:
uv_datas
,
thread_datas
:
thread_datas
}
res
.
json
({
result
:
true
,
errcode
:
0
,
data
:
data
,
date_array
:
all_data_array
});
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
res
.
json
({
result
:
false
,
err
:
err
});
});
}
else
{
res
.
json
({
result
:
false
,
err
:
'参数不合法'
});
}
});
//导出板块报表
router
.
get
(
'/info/report/exportXlsReport/:id'
,
function
(
req
,
res
,
next
)
{
var
info_id
=
req
.
params
.
id
,
ent_code
=
req
.
session
.
user
.
ent_code
,
begin_time
=
req
.
query
.
begin_time
,
end_time
=
req
.
query
.
end_time
,
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
);
});
});
//统计发帖数
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
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
});
});
}
else
{
res
.
json
({
result
:
false
,
err
:
'参数不合法'
});
}
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment