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
d0cbc1e9
Commit
d0cbc1e9
authored
Oct 08, 2015
by
陈志良
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'SANDBOX'
parents
7ede338d
8666689d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
100 deletions
+130
-100
forumThread.js
app/controllers/admin/forumThread.js
+119
-100
forumPraiseLogService.js
app/service/forumPraiseLogService.js
+11
-0
No files found.
app/controllers/admin/forumThread.js
View file @
d0cbc1e9
...
@@ -3,7 +3,9 @@ var express = require('express'),
...
@@ -3,7 +3,9 @@ var express = require('express'),
router
=
express
.
Router
(),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
),
_
=
require
(
'lodash'
),
then
=
require
(
'thenjs'
);
then
=
require
(
'thenjs'
),
moment
=
require
(
'moment'
),
nodeExcel
=
require
(
'excel-export'
);
var
mongoose
=
require
(
'mongoose'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
),
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
),
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
);
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
);
...
@@ -43,6 +45,11 @@ var getClientIP = function(req) {
...
@@ -43,6 +45,11 @@ var getClientIP = function(req) {
return
ipAddress
;
return
ipAddress
;
};
};
//格式化日期 (格式:年-月-日)
function
date_format
(
date
)
{
return
moment
(
date
).
format
(
'YYYY-MM-DD hh:mm:ss'
);
}
//新增论坛文章
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{},
var
rs
=
{},
...
@@ -1011,102 +1018,114 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) {
...
@@ -1011,102 +1018,114 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) {
});
});
//给以前的已一级评论添加楼层
// 导出文章评论内容
// router.get('/thread/updateConmentFloor', function(req, res, next) {
router
.
get
(
'/thread/:tid/exportComments'
,
function
(
req
,
res
,
next
)
{
// res.json(returnCode.SUCCESS);
var
tid
=
req
.
params
.
tid
||
null
;
// var conditions = {
var
ent_code
=
req
.
query
.
ent_code
||
null
;
// // ent_code: ent_code
// };
if
(
tid
&&
ent_code
){
// async.waterfall([
var
conditions
=
{
// function(callback) { // 查找文章的总数
ent_code
:
ent_code
,
// forumThreadService.getAllCountByFid(conditions,function(err, count){
thread
:
tid
,
// if(err){
level
:
1
// callback(err, null);
};
// }else{
// callback(null, count);
//查询所有评论
// }
forumCommentService
.
getAllCommentByThread
(
conditions
,
function
(
err
,
results
)
{
// });
if
(
err
)
{
// },
console
.
log
(
err
);
// function(count, callback) { //查找所有文章
res
.
json
(
returnCode
.
BUSY
);
// forumThreadService.getAllThreadByFidNoLimit(conditions, 1, count, null, function(err, datas){
}
else
{
// if(err){
//查询每个一级评论点赞
// callback(err, null);
var
asyncTasks
=
[];
// }else{
_
.
forEach
(
results
,
function
(
e
)
{
// callback(null, datas);
asyncTasks
.
push
(
function
(
cb
)
{
// }
if
(
e
.
level
!=
1
)
{
// });
cb
(
null
,
e
);
// }
}
else
{
// ], function (err, result) {
var
con
=
{
// var asyncTasks = [];
ent_code
:
ent_code
,
// result.items.forEach(function(doc, t) { //遍历文章
thread
:
tid
,
// asyncTasks.push(function(callback2) {
type
:
2
,
// //获取文章所有一级评论
comment
:
e
.
_id
// var conditions = {
}
// thread: doc._id,
// level: '1'
forumPraiseLogService
.
queryPraiseLogV2
(
con
,
function
(
err
,
results
){
// };
if
(
err
){
// async.waterfall([
console
.
log
(
err
);
// function(callback) {
cb
(
null
,
e
);
// //统计评论数
}
else
{
// forumCommentService.count(conditions, function(err, count) {
if
(
results
){
// if (err) {
var
praiseNames
=
[];
// console.log(err);
_
.
forEach
(
results
,
function
(
e2
)
{
// callback(err, null);
praiseNames
.
push
(
e2
.
user
.
nickName
);
// } else {
});
// callback(null, count);
e
.
praiseNames
=
praiseNames
;
// }
e
.
praiseCount
=
results
.
length
;
// });
}
// },
cb
(
null
,
e
);
// function(count, callback) {
}
// //获取所有评论
});
// forumCommentService.getAllComment(conditions, 1, count, function(err, results) {
}
// if (err) {
});
// console.log(err);
});
// callback(err, null);
async
.
parallel
(
asyncTasks
,
function
(
err
,
items
)
{
// } else {
// callback(null, results.items);
//表头
// }
var
conf
=
{};
// });
conf
.
cols
=
[
// },
{
caption
:
'楼层'
,
type
:
'string'
},
// function(comments, callback) {
{
caption
:
'发布时间'
,
type
:
'Date'
},
// comments = _.sortBy(comments, function(comment){
{
caption
:
'会员名'
,
type
:
'string'
},
// return comment.created;
{
caption
:
'内容'
,
type
:
'string'
},
// });
{
caption
:
'点赞数'
,
type
:
'number'
},
// if(comments.length > 0){
{
caption
:
'点赞人'
,
type
:
'string'
},
// // 给每一个评论添加楼层
];
// comments.forEach(function(comment,i){
// forumCommentService.updateCommentFloorById(comment._id, i + 1, function(err,docc){
//内容
// if (err) {
var
rows
=
[];
// console.error(err);
// // callback(err,null);
for
(
var
i
=
items
.
length
-
1
;
i
>=
0
;
i
--
)
{
// } else {
var
comment
=
items
[
i
];
// console.log('update '+i+1+' comment');
// // callback(null,null);
var
floor
=
comment
.
floor
;
// }
var
time
=
date_format
(
comment
.
created
);
var
nickName
=
comment
.
from
.
nickName
||
''
;
// })
var
content
=
comment
.
content
||
''
;
// });
var
praiseCount
=
comment
.
praiseCount
||
0
;
// }
var
praiseNames
=
''
;
// }
if
(
comment
.
praiseNames
){
// ], function(err, resultsss) {
praiseNames
=
comment
.
praiseNames
.
toString
();
// if (err) {
}
// console.error(err);
// // callback(err,null);
var
this_row
=
[
floor
+
''
,
time
,
nickName
,
content
,
praiseCount
,
praiseNames
];
// } else {
rows
.
push
(
this_row
);
// // callback2(null,null);
// }
if
(
comment
.
comments
.
length
>
0
){
// });
for
(
var
k
=
0
;
k
<
comment
.
comments
.
length
;
k
++
)
{
// });
var
sub_comment
=
comment
.
comments
[
k
];
// });
var
time
=
date_format
(
sub_comment
.
created
);
// async.parallel(asyncTasks, function(err, results) {
var
nickName
=
sub_comment
.
from
.
nickName
||
''
;
// if (err) {
var
content
=
sub_comment
.
content
||
''
;
// console.error(err);
// res.json(returnCode.BUSY);
var
this_row
=
[
'子评论'
,
time
,
nickName
,
content
,
null
,
null
];
// } else {
rows
.
push
(
this_row
);
// // console.log("------------update done!-------------");
};
// res.json(returnCode.SUCCESS);
}
// }
};
// });
// });
conf
.
rows
=
rows
;
// });
var
result
=
nodeExcel
.
execute
(
conf
);
res
.
setHeader
(
'Content-Type'
,
'application/vnd.ms-excel'
);
res
.
setHeader
(
'Content-Disposition'
,
'attachment; filename=commentsReport.xlsx'
);
res
.
end
(
result
,
'binary'
);
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/service/forumPraiseLogService.js
View file @
d0cbc1e9
...
@@ -32,3 +32,14 @@ exports.queryPraiseLog=function(tid,cid,user,type,callback){
...
@@ -32,3 +32,14 @@ exports.queryPraiseLog=function(tid,cid,user,type,callback){
}
}
});
});
};
};
exports
.
queryPraiseLogV2
=
function
(
conditions
,
callback
){
ForumPraiseLog
.
find
(
conditions
).
populate
(
'user'
).
exec
(
function
(
err
,
docs
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
docs
);
}
});
};
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