Commit 22adf15b authored by 陈家荣's avatar 陈家荣

111

parent ffa6bd1a
......@@ -675,102 +675,99 @@ var getClientIP = function(req) {
//给以前的已一级评论添加楼层
router.get('/thread/updateConmentFloor', function(req, res, next) {
var ent_code = req.session.user.ent_code;
// var ent_code = req.params.ent_code || null;
if(ent_code){
var conditions = {
ent_code: ent_code
};
async.waterfall([
function(callback) { // 查找文章的总数
forumThreadService.getAllCountByFid(conditions,function(err, count){
if(err){
callback(err, null);
}else{
callback(null, count);
}
});
},
function(count, callback) { //查找所有文章
forumThreadService.getAllThreadByFidNoLimit(conditions, 1, count, null, function(err, datas){
if(err){
callback(err, null);
}else{
callback(null, datas);
}
});
}
], function (err, result) {
var asyncTasks = [];
result.items.forEach(function(doc) { //遍历文章
asyncTasks.push(function(callback2) {
//获取文章所有一级评论,倒数排列
var conditions = {
thread: doc._id,
level: '1'
};
async.waterfall([
function(callback) {
//获取所有评论
forumCommentService.count(conditions, function(err, count) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, count);
}
});
},
function(count, callback) {
//获取所有评论
forumCommentService.getAllComment(conditions, 1, count, function(err, results) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, results.items);
}
});
},
function(comments, callback) {
comments = _.sortBy(comments, function(comment){
return comment.created;
});
if(comments.length > 0){
// 给每一个评论添加楼层
comments.forEach(function(comment,i){
forumCommentService.updateCommentFloorById(comment._id, i + 1, function(err,docc){
if (err) {
console.error(err);
// callback(err,null);
} else {
// callback(null,null);
}
})
});
res.json(returnCode.SUCCESS);
var conditions = {
// ent_code: ent_code
};
async.waterfall([
function(callback) { // 查找文章的总数
forumThreadService.getAllCountByFid(conditions,function(err, count){
if(err){
callback(err, null);
}else{
callback(null, count);
}
});
},
function(count, callback) { //查找所有文章
forumThreadService.getAllThreadByFidNoLimit(conditions, 1, count, null, function(err, datas){
if(err){
callback(err, null);
}else{
callback(null, datas);
}
});
}
], function (err, result) {
var asyncTasks = [];
result.items.forEach(function(doc, t) { //遍历文章
asyncTasks.push(function(callback2) {
//获取文章所有一级评论
var conditions = {
thread: doc._id,
level: '1'
};
async.waterfall([
function(callback) {
//统计评论数
forumCommentService.count(conditions, function(err, count) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, count);
}
});
},
function(count, callback) {
//获取所有评论
forumCommentService.getAllComment(conditions, 1, count, function(err, results) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, results.items);
}
});
},
function(comments, callback) {
comments = _.sortBy(comments, function(comment){
return comment.created;
});
if(comments.length > 0){
// 给每一个评论添加楼层
comments.forEach(function(comment,i){
forumCommentService.updateCommentFloorById(comment._id, i + 1, function(err,docc){
if (err) {
console.error(err);
// callback(err,null);
} else {
callback(null,null);
}
})
});
}
], function(err, resultsss) {
if (err) {
console.error(err);
// callback(err,null);
} else {
// callback(null,null);
}
});
}
], function(err, resultsss) {
if (err) {
console.error(err);
// callback(err,null);
} else {
// callback2(null,null);
}
});
});
async.parallel(asyncTasks, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
});
}else{
res.json(returnCode.BUSY);
}
async.parallel(asyncTasks, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
// console.log("------------update done!-------------");
res.json(returnCode.SUCCESS);
}
});
});
});
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