Commit 4589ac08 authored by strong's avatar strong

Merge commit 'da6694ac' into bugfix_0311_share_log

parents 74398475 da6694ac
...@@ -322,7 +322,7 @@ router.post('/thread/:tid/:fid/unTop', function(req, res, next) { ...@@ -322,7 +322,7 @@ router.post('/thread/:tid/:fid/unTop', function(req, res, next) {
} }
}); });
//文章推荐 //文章加精
router.post('/thread/:tid/:fid/recommend', function(req, res, next) { router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
var tid = req.params.tid, var tid = req.params.tid,
fid = req.params.fid, fid = req.params.fid,
...@@ -364,7 +364,7 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) { ...@@ -364,7 +364,7 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
} }
}); });
//文章取消推荐 //文章取消加精
router.post('/thread/:tid/:fid/unRecommend', function(req, res, next) { router.post('/thread/:tid/:fid/unRecommend', function(req, res, next) {
var tid = req.params.tid; //文章ID var tid = req.params.tid; //文章ID
var fid = req.params.fid; //板块ID var fid = req.params.fid; //板块ID
...@@ -398,6 +398,9 @@ router.get('/threads/list', function(req, res, next) { ...@@ -398,6 +398,9 @@ router.get('/threads/list', function(req, res, next) {
var eventStatus = req.query.eventStatus; var eventStatus = req.query.eventStatus;
var recommend_threads = req.query.recommend_threads;//推荐帖子 var recommend_threads = req.query.recommend_threads;//推荐帖子
var top_threads = req.query.top_threads;//置顶帖子 var top_threads = req.query.top_threads;//置顶帖子
var begin_time=req.query.begin_time;
var end_time=req.query.end_time;
var title = req.query.title;
var sortBy = { var sortBy = {
top:-1, top:-1,
top_order_idx:-1, top_order_idx:-1,
...@@ -476,6 +479,22 @@ router.get('/threads/list', function(req, res, next) { ...@@ -476,6 +479,22 @@ router.get('/threads/list', function(req, res, next) {
conditions['event.eventEndTime'] = {$gt : today}; conditions['event.eventEndTime'] = {$gt : today};
} }
} }
if(begin_time && end_time){
conditions.created = {$gte : begin_time, $lte : end_time};
} else if(end_time){
conditions.created = {$lte : end_time};
} else if(begin_time){
conditions.created = {$gte : begin_time};
}
if (title) {
conditions.title = {
$regex: title,
$options: 'i'
}
}
if (mid) { if (mid) {
forumThreadService.getAllThreadByFidAndMid(mid, conditions, pageNo, pageSize, sortBy, function(err, results) { forumThreadService.getAllThreadByFidAndMid(mid, conditions, pageNo, pageSize, sortBy, function(err, results) {
if (err) { if (err) {
...@@ -536,11 +555,17 @@ router.get('/threads/list', function(req, res, next) { ...@@ -536,11 +555,17 @@ router.get('/threads/list', function(req, res, next) {
//直接修改序号 //直接修改序号
function updateThreadTopIdx(id,idx,callback){ function updateThreadTopIdx(id,idx,callback){
ForumThread.update( // ForumThread.update({_id:id},{ top_order_idx: idx },
{_id:id}, // null,
{ top_order_idx: idx }, // function(err,result){
null, // if(err){
function(err,result){ // console.error(err);
// callback(err,null);
// }else{
// callback(null,true);
// }
// });
forumThreadService.updateThread({_id:id}, { top_order_idx: idx }, function(err, doc) {
if(err){ if(err){
console.error(err); console.error(err);
callback(err,null); callback(err,null);
...@@ -550,11 +575,16 @@ function updateThreadTopIdx(id,idx,callback){ ...@@ -550,11 +575,16 @@ function updateThreadTopIdx(id,idx,callback){
}); });
} }
function updateThreadNewRecommendIdx(id,idx,callback){ function updateThreadNewRecommendIdx(id,idx,callback){
ForumThread.update( // ForumThread.update({_id:id},{ new_recommend_order_idx: idx },null, function(err,result){
{_id:id}, // if(err){
{ new_recommend_order_idx: idx }, // console.error(err);
null, // callback(err,null);
function(err,result){ // }else{
// callback(null,true);
// }
// });
forumThreadService.updateThread({_id:id}, { new_recommend_order_idx: idx }, function(err, doc) {
if(err){ if(err){
console.error(err); console.error(err);
callback(err,null); callback(err,null);
...@@ -587,7 +617,6 @@ router.put('/recommend_threads/orderIDX/:id/:order', function(req, res, next) { ...@@ -587,7 +617,6 @@ router.put('/recommend_threads/orderIDX/:id/:order', function(req, res, next) {
}); });
//评论列表 //评论列表
router.get('/thread/:tid/comment/list', function(req, res, next) { router.get('/thread/:tid/comment/list', function(req, res, next) {
var tid = req.params.tid || null; var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1; var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10; var pageSize = req.query.pageSize || 10;
...@@ -619,10 +648,24 @@ router.get('/thread/:tid/comment/list', function(req, res, next) { ...@@ -619,10 +648,24 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
if (e.level == 1) { if (e.level == 1) {
cb(null, e); cb(null, e);
} else { } else {
forumCommentService.getCommentParent(e._id, function(err, p_comment) { forumCommentService.getCommentParent(new mongoose.Types.ObjectId(e._id), function(err, p_comment) {
if(p_comment && p_comment.floor){
var comment = e.toObject(); var comment = e.toObject();
comment.floor = p_comment.floor; comment.floor = p_comment.floor;
cb(null, comment); cb(null, comment);
} else if(p_comment && !p_comment.floor){ //上一级没有楼层就再查上一级的评论
forumCommentService.getCommentParent(new mongoose.Types.ObjectId(p_comment._id), function(err, p_p_comment) {
if(p_comment){
var comment = e.toObject();
comment.floor = p_p_comment.floor;
cb(null, comment);
}else{
cb(null, e);
}
});
}else{
cb(null, e);
}
}); });
} }
}); });
...@@ -887,16 +930,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) { ...@@ -887,16 +930,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
var tid = req.body.tid || null; var tid = req.body.tid || null;
var cid = req.params.cid || null; var cid = req.params.cid || null;
var replayComment_id = req.body.replayComment_id; var replayComment_id = req.body.replayComment_id;
// 获取评论的子评论列表
// 更新文章评论 + 1
forumThreadService.updateThreadCommentCountInc(tid, function(err, thread) {
if (err) {
console.error(err);
}
});
// 更新评论对象
// result.comment_count+=1; // 回复评论+1
forumCommentService.updateCommentById(cid, { forumCommentService.updateCommentById(cid, {
$push: { $push: {
comments: replayComment_id comments: replayComment_id
...@@ -915,53 +948,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) { ...@@ -915,53 +948,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
}); });
}); });
// 更新评论的子评论列表
router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
var cid = req.params.cid || null;
var replayComment_id = req.body.replayComment_id;
forumCommentService.updateCommentById(cid, {
$push: {
comments: replayComment_id
}
},
function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
// 获取评论的子评论列表
// forumCommentService.getCommentById(cid, function(err, result) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// // var commentList = result.comments;
// // result.comments.push(replayComment_id);
// forumCommentService.updateCommentById(cid, {
// $push: {
// comments: replayComment_id
// }
// },
// function(err, result) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// res.json(returnCode.SUCCESS);
// }
// });
// }
// });
});
//添加评论 //添加评论
router.post('/thread/comment/add', function(req, res, next) { router.post('/thread/comment/add', function(req, res, next) {
var tid = req.body.tid || null; var tid = req.body.tid || null;
...@@ -1009,7 +995,6 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -1009,7 +995,6 @@ router.post('/thread/comment/add', function(req, res, next) {
}); });
} }
} }
entity.from = user; entity.from = user;
callback(); callback();
} }
......
...@@ -506,8 +506,6 @@ router.post('/thread/create', function(req, res, next) { ...@@ -506,8 +506,6 @@ router.post('/thread/create', function(req, res, next) {
} }
} }
}); });
// httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'post');
var rs = {}; var rs = {};
rs.data = { rs.data = {
'id': thread._id 'id': thread._id
...@@ -525,20 +523,22 @@ router.post('/thread/create', function(req, res, next) { ...@@ -525,20 +523,22 @@ router.post('/thread/create', function(req, res, next) {
}); });
}); });
//获取目标论坛文章 //获取文章
router.get('/thread/:tid/get', function(req, res, next) { router.get('/thread/:tid/get', function(req, res, next) {
var tid = req.params.tid || null; var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code; var ent_code = req.session.user.ent_code;
if (tid) { if (tid) {
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
forumThreadService.getThreadById(tid, function(err, thread) { forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙 //文章类型 1、文章 2、话题 3、照片墙
if (err || !thread) { if (err) {
callback(err, null); callback(err, null);
} else { } else {
callback(null, thread); callback(null, thread);
} }
if(thread && thread.info){
var info_id = thread.info._id, var info_id = thread.info._id,
pid = thread.pid, pid = thread.pid,
source = req.session.mobileForumUser.source; source = req.session.mobileForumUser.source;
...@@ -551,6 +551,7 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -551,6 +551,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
} else if (thread.type == 3 && thread.level == 1) { } else if (thread.type == 3 && thread.level == 1) {
httpService.createLog(req, source, info_id, 3, 3, tid); httpService.createLog(req, source, info_id, 3, 3, tid);
} }
}
}); });
forumThreadService.updateThreadPvCount(tid, function(err, doc) { forumThreadService.updateThreadPvCount(tid, function(err, doc) {
if (err) { if (err) {
...@@ -563,16 +564,27 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -563,16 +564,27 @@ router.get('/thread/:tid/get', function(req, res, next) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
if (thread.toObject) {
thread = thread.toObject();
}
//获取等级最高的荣誉
if(thread.from && thread.from.honorTitles && thread.from.honorTitles.length > 0){
var temp_honorTitles = _.sortBy(thread.from.honorTitles, 'order_idx');
for(var m = temp_honorTitles.length - 1; m >= 0; m-=1){
var honor = temp_honorTitles[m]
if(honor.is_show == 1){
thread.from.honorTitles = honor;
break;
}
}
}
var threads = []; var threads = [];
threads.push(thread); threads.push(thread);
util.loadLevel(req.session.user.ent_code, threads, function() { util.loadLevel(req.session.user.ent_code, threads, function() {
if (threads && threads.length > 0) { if (threads && threads.length > 0) {
thread = threads[0]; thread = threads[0];
} }
//console.log(thread);
//console.log(thread.type == 2 && thread.level == 1&&thread.subThreads.items.length>0);
if (thread.type == 2 && thread.level == 1&&thread.subThreads.items.length>0) { if (thread.type == 2 && thread.level == 1&&thread.subThreads.items.length>0) {
//console.log(thread.subThreads);
util.loadLevel(req.session.user.ent_code, thread.subThreads.items, function() { util.loadLevel(req.session.user.ent_code, thread.subThreads.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) { redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) {
if (thread.toObject) { if (thread.toObject) {
...@@ -616,7 +628,7 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -616,7 +628,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
} }
}); });
//获取目标论坛文章 //获取文章
router.get('/thread/photo/:pid/get', function(req, res, next) { router.get('/thread/photo/:pid/get', function(req, res, next) {
var pid = req.params.pid || null, var pid = req.params.pid || null,
userId = user.getMobileUser(req); userId = user.getMobileUser(req);
...@@ -665,43 +677,16 @@ router.post('/thread/:tid/update', function(req, res, next) { ...@@ -665,43 +677,16 @@ router.post('/thread/:tid/update', function(req, res, next) {
router.post('/thread/:tid/delete', function(req, res, next) { router.post('/thread/:tid/delete', function(req, res, next) {
var tid = req.params.tid; var tid = req.params.tid;
if (tid) { if (tid) {
forumThreadService.deleteThreadById(tid, function(err, thread) { //注销此方法
if (err) {
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//文章点赞
router.post('/thread/:tid/raise', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
var mid = req.session.openUser.mid;
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
if (tid) {
raiseOrcancelRaise(req, ent_code, tid, userId,function(result){
res.json(result);
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//文章取消点赞 // forumThreadService.deleteThreadById(tid, function(err, thread) {
router.post('/thread/:tid/cancelRaise', function(req, res, next) { // if (err) {
var userId = req.session.mobileForumUser.userId; // res.json(returnCode.BUSY);
var mid = req.session.openUser.mid; // } else {
var tid = req.params.tid || null; // res.json(returnCode.SUCCESS);
var ent_code = req.session.user.ent_code; // }
if (tid) { // });
raiseOrcancelRaise(req, ent_code, tid, userId,function(result){ res.json(returnCode.BUSY);
res.json(result);
});
} else { } else {
res.json(returnCode.WRONG_PARAM); res.json(returnCode.WRONG_PARAM);
} }
...@@ -709,7 +694,7 @@ router.post('/thread/:tid/cancelRaise', function(req, res, next) { ...@@ -709,7 +694,7 @@ router.post('/thread/:tid/cancelRaise', function(req, res, next) {
//文章点赞和取消点赞 //文章点赞和取消点赞
router.post('/thread/:tid/praiseOrCancelPraise', function(req, res, next) { router.post('/thread/:tid/praiseOrCancelPraise', function(req, res, next) {
var userId = req.session.mobileForumUser.userId; var userId = user.getMobileUser(req);
var mid = req.session.openUser.mid; var mid = req.session.openUser.mid;
var tid = req.params.tid || null; var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code; var ent_code = req.session.user.ent_code;
...@@ -1469,7 +1454,115 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) { ...@@ -1469,7 +1454,115 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
} }
}); });
//不过滤掉已删除的二级评论
router.get('/thread/:tid/comment/list/all', function(req, res, next) {
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var ent_code = req.session.user.ent_code;
var conditions = {
ent_code: ent_code,
thread: tid,
level: '1'
};
if (tid) {
//获取最新5条评论
forumCommentService.getAllComment_allstatus(conditions, pageNo, pageSize, function(err, results) {
if (err) {
console.log(err);
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'comment', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
};
});
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//不过滤掉已删除的二级评论
router.get('/thread/:tid/comment/list/byFloor/all', function(req, res, next) {
var tid = req.params.tid || null;
var floor = req.query.floor || 1;
var ent_code = req.session.user.ent_code;
var countConditions = {
ent_code: ent_code,
thread: tid,
level: '1'
};
var conditions = {
ent_code: ent_code,
thread: tid,
level: '1',
floor: {
'$gte': floor - 9,
'$lte': floor
}
};
if (tid) {
//获取最新5条评论
forumCommentService.count(countConditions, function(err, count) {
if (err) {
console.log(err);
res.json(returnCode.BUSY);
} else {
forumCommentService.getAllComment_allstatus(conditions, 1, 10, function(err, results) {
if (err) {
console.log(err);
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'comment', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
};
});
results.total = count;
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//评论点赞 //评论点赞
router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) { router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
var userId = req.session.mobileForumUser.userId; var userId = req.session.mobileForumUser.userId;
...@@ -1574,9 +1667,7 @@ router.get('/thread/:tid/topics', function(req, res, next) { ...@@ -1574,9 +1667,7 @@ router.get('/thread/:tid/topics', function(req, res, next) {
$ne: 3 $ne: 3
} }
}; };
if (tid) { if (tid) {
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) { forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
...@@ -1820,8 +1911,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) { ...@@ -1820,8 +1911,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
var infoId = req.query.infoId || null; var infoId = req.query.infoId || null;
var ent_code = req.session.user.ent_code; var ent_code = req.session.user.ent_code;
var skip = (pageNo - 1) * pageSize; var skip = (pageNo - 1) * pageSize;
var redis_type = '_thread_essence';
var sort = { var sort = {
new_recommend:-1, new_recommend:-1,
new_recommend_order_idx:-1, new_recommend_order_idx:-1,
...@@ -1850,7 +1939,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) { ...@@ -1850,7 +1939,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
}] }]
}; };
if((pageNo * pageSize) > redisThreadList.getThreadRedisCount() || infoId){ if((pageNo * pageSize) > redisThreadList.getThreadRedisCount() || infoId){
if(infoId){ if(infoId){
conditions.info = infoId; conditions.info = infoId;
...@@ -1869,10 +1957,10 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) { ...@@ -1869,10 +1957,10 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
}); });
}else{ }else{
//更新推荐列表redis //更新推荐列表redis
redisThreadList.get(ent_code, "", redis_type, function(error, docs) { redisThreadList.get(ent_code, function(error, docs) {
var results = JSON.parse(docs); var results = JSON.parse(docs);
if(results.items == null || results.items.length <= 0){ //如果不存在,继续重新获取 if(results.items == null || results.items.length <= 0){ //如果不存在,继续重新获取
redisThreadList.getRedisEsenceThreads(ent_code, "", redis_type, function(error, docs){ redisThreadList.getRedisEsenceThreads(ent_code, function(error, docs){
if(error){ if(error){
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
...@@ -1986,3 +2074,95 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex ...@@ -1986,3 +2074,95 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex
} }
}); });
}); });
//获取话题下子文章
router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
var tid = req.params.tid || null;
var type = req.params.type || null;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var ent_code = req.session.user.ent_code;
var rs = {};
var conditions = {
ent_code: ent_code,
pid: tid,
type: 2,
status: {
$ne: 3
}
};
var sort = null; //排序条件
if(type == 1){ //最新
sort = '-created';
}else if(type == 2){ //最热
sort = '-praise_count -comment_count';
}
if (tid) {
async.waterfall([
function(callback) {
forumThreadService.getByIdSelectyField(tid, 'type', function(err, thread) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, thread);
}
});
},
function(thread, callback) {
forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
if (err) {
console.error(err);
callback(err, null, null);
} else {
if (doc) {
callback(null, thread, doc);
} else {
callback(null, thread, null);
}
}
});
},
function(thread, doc, callback) {
if (thread.type == 2) { //查询子列表
if (doc) {
conditions._id = {
$nin: doc.thread
};
}
//获取子话题数据
forumThreadService.getThreadWithNotPopulateComment(conditions, pageNo, pageSize, sort, function(err, results) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, results);
}
});
} else {
callback(null, null);
}
}
], function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
if(results){
util.loadLevel(ent_code, results.items, function() {
handleThreadList(req, results, ent_code, function(result){
res.json(_.assign(result, returnCode.SUCCESS));
});
});
}else{
res.json(returnCode.SUCCESS);
}
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
\ No newline at end of file
...@@ -616,3 +616,109 @@ exports.getAllCommentByThread = function(conditions, callback) { ...@@ -616,3 +616,109 @@ exports.getAllCommentByThread = function(conditions, callback) {
} }
}); });
}; };
/**
* 20160310
* 查询评论列表(包含已删除的二级评论)
*
* **/
exports.getAllComment_allstatus = function(conditions, pageNo, pageSize, callback) {
countAll(conditions, function(err, count) {
if (err) {
console.error(err);
callback(err, null);
} else {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(conditions,listCommentFields).populate('from','uid mid nickName icon exp').populate('to','uid mid nickName icon exp').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var obj = {};
obj.total = count;
obj.pageNo = pageNo;
obj.pageSize = pageSize;
obj.items = docs;
if (docs && docs.length > 0) {
var asyncTasks = [];
docs.forEach(function(doc) {
asyncTasks.push(function(callback) {
populateComment_allstatus(doc, function(err, c) {
if (err) {
callback(err, null);
} else {
var newobj = doc.toObject();
newobj.comments = (c == null ? [] : c);
callback(null, newobj);
}
});
});
});
async.parallel(asyncTasks, function(err, results) {
if (err) {
console.log(err);
callback(null, null);
} else {
obj.items = results;
callback(null, obj);
}
});
} else {
callback(null, obj);
}
}
});
}
});
};
//评论
function populateComment_allstatus(doc, callback) {
if (doc && doc.comments.length > 0) {
var asyncTasks = [];
doc.comments.forEach(function(comment) {
asyncTasks.push(function(callback) {
ForumComment.findOne({
_id: comment
}).populate({
path: 'from to',
select: 'uid nickName icon mid'
}).exec(function(err, c) {
if (err) {
console.error(err);
callback(null, null);
} else {
if (c) {
callback(null, c);
} else {
callback(null);
}
}
});
});
});
async.parallel(asyncTasks, function(err, results) {
if (err) {
console.log(err);
callback(null, null);
} else {
var comments = [];
for (var i = 0; i < results.length; i += 1) {
if (results[i]) {
comments.push(results[i]);
}
}
callback(null, comments);
}
});
} else {
callback(null, null);
}
}
...@@ -10,6 +10,8 @@ var forumCommentService = require('./forumCommentService'); ...@@ -10,6 +10,8 @@ var forumCommentService = require('./forumCommentService');
var async = require('async'); var async = require('async');
var then = require('thenjs'); var then = require('thenjs');
var redisThreadList = require('../utils/redisThreadList');
var listThreadFields = { var listThreadFields = {
content:1, content:1,
...@@ -53,8 +55,6 @@ var singleThreadFields = { ...@@ -53,8 +55,6 @@ var singleThreadFields = {
}; };
var subThreadFields = { var subThreadFields = {
from:1 from:1
}; };
...@@ -89,14 +89,33 @@ function handleContent(content) { ...@@ -89,14 +89,33 @@ function handleContent(content) {
return content.trim(); return content.trim();
} }
//更新帖子方法, afterOperation为更新之后做的操作的条件
function findOneAndUpdate(id, entity, callback) { function findOneAndUpdate(condition, entity, afterOperation, callback) {
ForumThread.findOneAndUpdate(id, entity, function(err, doc) { ForumThread.findOneAndUpdate(condition, entity, function(err, doc) {
callback(err, doc); callback(err, doc);
if(afterOperation == 'updateRedisRecommentThreads' && doc){ //刷新缓存
redisThreadList.updateRedisEsenceThreads(doc.ent_code);
}
}); });
}; };
//更新帖子方法, afterOperation为更新之后做的操作的条件
function update(condition, entity, operation, afterOperation, callback) {
ForumThread.update(condition, entity, operation,function(err, doc) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
if(afterOperation == 'updateRedisRecommentThreads' && doc && doc.new_recommend == 1){ //刷新缓存
redisThreadList.updateRedisEsenceThreads(doc.ent_code);
}
}
});
};
//分页查询话题列表 //分页查询话题列表
exports.findThread = function(pageNo, pageSize, q, sort, callback) { exports.findThread = function(pageNo, pageSize, q, sort, callback) {
then(function(cont) { then(function(cont) {
...@@ -191,9 +210,6 @@ exports.findCommentByPage = function(pageNo, pageSize, q, callback) { ...@@ -191,9 +210,6 @@ exports.findCommentByPage = function(pageNo, pageSize, q, callback) {
}); });
}; };
//创建文章 //创建文章
exports.createThread = function(entity, callback) { exports.createThread = function(entity, callback) {
if (!entity.share) { if (!entity.share) {
...@@ -231,6 +247,18 @@ exports.createThread = function(entity, callback) { ...@@ -231,6 +247,18 @@ exports.createThread = function(entity, callback) {
} }
}; };
//根据ID获取文章,选择字段
exports.getByIdSelectyField = function(id, fields, callback) {
ForumThread.findOne({_id: id}).select(fields).exec(function(err,result){
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, result);
}
});
}
//根据ID获取文章记录,不查评论,子话题 //根据ID获取文章记录,不查评论,子话题
exports.getById = function(id, callback) { exports.getById = function(id, callback) {
ForumThread.findOne({ ForumThread.findOne({
...@@ -258,7 +286,13 @@ exports.getByConditions = function(conditions, callback) { ...@@ -258,7 +286,13 @@ exports.getByConditions = function(conditions, callback) {
//根据ID获取文章 //根据ID获取文章
exports.getThreadById = function(tid, callback) { exports.getThreadById = function(tid, callback) {
ForumThread.findOne({_id: tid}).populate('from','uid mid nickName icon exp').populate('info','name icon').populate('share').exec(function(err, doc) { ForumThread.findOne({_id: tid}).populate({
path: 'from',
select: 'uid mid nickName icon exp honorTitles',
options: {
populate:"honorTitles" //继续查荣誉
}
}).populate('info','name icon').populate('share').exec(function(err, doc) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -273,7 +307,6 @@ exports.getThreadById = function(tid, callback) { ...@@ -273,7 +307,6 @@ exports.getThreadById = function(tid, callback) {
var conditions = { var conditions = {
thread: tid, thread: tid,
level: '1' level: '1'
// status:1
}; };
//获取最新10条评论 //获取最新10条评论
forumCommentService.getAllComment(conditions, 1, 10, function(err, results) { forumCommentService.getAllComment(conditions, 1, 10, function(err, results) {
...@@ -543,17 +576,12 @@ exports.updateThreadById = function(tid, entity, callback) { ...@@ -543,17 +576,12 @@ exports.updateThreadById = function(tid, entity, callback) {
entity.share = ''; entity.share = '';
} }
if (entity.share) { if (entity.share) {
findOneAndUpdate({_id: tid}, entity, 'updateRedisRecommentThreads', function(err, result) {
ForumThread.update({
_id: tid
}, entity, null, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
} else { } else {
ForumShare.update({ ForumShare.update({_id: shareEntity._id}, shareEntity, null, function(err, se) {
_id: shareEntity._id
}, shareEntity, null, function(err, se) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -561,14 +589,11 @@ exports.updateThreadById = function(tid, entity, callback) { ...@@ -561,14 +589,11 @@ exports.updateThreadById = function(tid, entity, callback) {
callback(null, entity); callback(null, entity);
} }
}); });
} }
}); });
} else { } else {
if (shareEntity && (shareEntity.title || shareEntity.description || shareEntity.icon)) { if (shareEntity && (shareEntity.title || shareEntity.description || shareEntity.icon)) {
shareEntity.ent_code = entity.ent_code; shareEntity.ent_code = entity.ent_code;
var forumShare = new ForumShare(shareEntity); var forumShare = new ForumShare(shareEntity);
forumShare.save(function(err, forumShare) { forumShare.save(function(err, forumShare) {
entity.share = forumShare._id; entity.share = forumShare._id;
...@@ -580,34 +605,39 @@ exports.updateThreadById = function(tid, entity, callback) { ...@@ -580,34 +605,39 @@ exports.updateThreadById = function(tid, entity, callback) {
callback(err, null); callback(err, null);
} else { } else {
callback(null, entity); callback(null, entity);
} }
}); });
}); });
} else { } else {
delete entity.share; delete entity.share;
ForumThread.update({ findOneAndUpdate({_id: tid}, entity, 'updateRedisRecommentThreads', function(err, result) {
_id: tid
}, entity, null, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
} else { } else {
callback(null, entity); callback(null, entity);
} }
}); });
} }
} }
}; };
//逻辑删除文章 //逻辑删除文章
exports.logicDeleteThreadById = function(tid, callback) { exports.logicDeleteThreadById = function(tid, callback) {
ForumThread.update({ // ForumThread.update({
_id: mongoose.Types.ObjectId(tid) // _id: mongoose.Types.ObjectId(tid)
}, { // }, {
status : 3 // status : 3
}, null, function(err, result) { // }, null, function(err, result) {
// if (err) {
// console.error(err);
// callback(err, false);
// } else {
// callback(null, true);
// }
// });
findOneAndUpdate({_id: mongoose.Types.ObjectId(tid)}, {status : 3}, 'updateRedisRecommentThreads', function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, false); callback(err, false);
...@@ -618,11 +648,9 @@ exports.logicDeleteThreadById = function(tid, callback) { ...@@ -618,11 +648,9 @@ exports.logicDeleteThreadById = function(tid, callback) {
}; };
//根据ID更新文章 //根据ID删除文章
exports.deleteThreadById = function(tid, callback) { exports.deleteThreadById = function(tid, callback) {
ForumThread.remove({ ForumThread.remove({_id: tid}, function(err, result) {
_id: tid
}, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -916,41 +944,45 @@ exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callbac ...@@ -916,41 +944,45 @@ exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callbac
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶) //根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
exports.updateTopByThreadId = function(infoId, threadId, callback) { exports.updateTopByThreadId = function(infoId, threadId, callback) {
// ForumThread.update({info:infoId}, {top:0},{multi:true}, function(err, doc) { // ForumThread.findOneAndUpdate({
// if(err){ // _id: threadId
// callback(err,null); // }, {
// }else{ // top: 1,
// ForumThread.findOneAndUpdate({_id:threadId}, {top:1}, function(err, doc) { // topTime: new Date()
// if(err){ // }, function(err, doc) {
// callback(err,null); // if (err) {
// }else{ // callback(err, null);
// callback(null,null); // } else {
// callback(null, null);
// } // }
// }); // });
// }
// }); findOneAndUpdate({ _id: threadId}, {top: 1, topTime: new Date()}, 'updateRedisRecommentThreads', function(err, doc){
ForumThread.findOneAndUpdate({
_id: threadId
}, {
top: 1,
topTime: new Date()
}, function(err, doc) {
if (err) { if (err) {
console.error(err);
callback(err, null); callback(err, null);
} else { } else {
callback(null, null); callback(null, doc);
} }
}); });
}; };
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶) //根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
exports.updateUnTopByThreadId = function(infoId, threadId, callback) { exports.updateUnTopByThreadId = function(infoId, threadId, callback) {
ForumThread.findOneAndUpdate({ // ForumThread.findOneAndUpdate({
_id: threadId // _id: threadId
}, { // }, {
top: 0, // top: 0,
topTime: null // topTime: null
}, function(err, doc) { // }, function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
findOneAndUpdate({ _id: threadId}, {top: 0,topTime: null}, 'updateRedisRecommentThreads', function(err, doc) {
if (err) { if (err) {
callback(err, null); callback(err, null);
} else { } else {
...@@ -958,23 +990,31 @@ exports.updateUnTopByThreadId = function(infoId, threadId, callback) { ...@@ -958,23 +990,31 @@ exports.updateUnTopByThreadId = function(infoId, threadId, callback) {
} }
}); });
}; };
//根据文章ID更新文章为推荐 //根据文章ID更新文章为加精
exports.updateRecommendByThreadId = function(threadId, callback) { exports.updateRecommendByThreadId = function(threadId, callback) {
ForumThread.findOneAndUpdate({ // ForumThread.findOneAndUpdate({
_id: threadId // _id: threadId
}, { // }, {
recommend: 1 // recommend: 1
}, function(err, doc) { // }, function(err, doc) {
// callback(err,doc);
// });
findOneAndUpdate({_id: threadId}, {recommend: 1}, 'updateRedisRecommentThreads', function(err, doc) {
callback(err,doc); callback(err,doc);
}); });
}; };
//根据文章ID更新文章为不推荐 //根据文章ID更新文章为不加精
exports.updateUnRecommendByThreadId = function(threadId, callback) { exports.updateUnRecommendByThreadId = function(threadId, callback) {
ForumThread.findOneAndUpdate({ // ForumThread.findOneAndUpdate({
_id: threadId // _id: threadId
}, { // }, {
recommend: 0 // recommend: 0
}, function(err, doc) { // }, function(err, doc) {
// callback(err,null);
// });
findOneAndUpdate({_id: threadId}, {recommend: 0}, 'updateRedisRecommentThreads', function(err, doc) {
callback(err,null); callback(err,null);
}); });
}; };
...@@ -986,12 +1026,20 @@ exports.updateTagTop = function(tid,tag_top,callback){ ...@@ -986,12 +1026,20 @@ exports.updateTagTop = function(tid,tag_top,callback){
}else{ }else{
time = null; time = null;
} }
ForumThread.findOneAndUpdate({ // ForumThread.findOneAndUpdate({
_id: tid // _id: tid
}, { // }, {
tag_top: tag_top, // tag_top: tag_top,
tag_topTime: time // tag_topTime: time
}, function(err, doc) { // }, function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// callback(null, doc);
// }
// });
findOneAndUpdate({_id: tid}, {tag_top: tag_top, tag_topTime: time}, 'updateRedisRecommentThreads', function(err, doc) {
if (err) { if (err) {
callback(err, null); callback(err, null);
} else { } else {
...@@ -1002,17 +1050,27 @@ exports.updateTagTop = function(tid,tag_top,callback){ ...@@ -1002,17 +1050,27 @@ exports.updateTagTop = function(tid,tag_top,callback){
//更新文章点赞数 //更新文章点赞数
exports.updateThreadRaiseCount = function(threadId, callback) { exports.updateThreadRaiseCount = function(threadId, callback) {
ForumThread.update({ // ForumThread.update({
_id: threadId // _id: threadId
}, { // }, {
$inc: { // $inc: {
praise_count: 1 // praise_count: 1
} // }
}, { // }, {
w: 1, // w: 1,
safe: true // safe: true
}, // },
function(err, result) { // function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update({_id: threadId}, {$inc: {praise_count: 1}}, { w: 1,safe: true}, 'updateRedisRecommentThreads',function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1024,17 +1082,26 @@ exports.updateThreadRaiseCount = function(threadId, callback) { ...@@ -1024,17 +1082,26 @@ exports.updateThreadRaiseCount = function(threadId, callback) {
//减少文章点赞数 //减少文章点赞数
exports.updateThreadRaiseCountDec = function(threadId, callback) { exports.updateThreadRaiseCountDec = function(threadId, callback) {
ForumThread.update({ // ForumThread.update({
_id: threadId // _id: threadId
}, { // }, {
$inc: { // $inc: {
praise_count: -1 // praise_count: -1
} // }
}, { // }, {
w: 1, // w: 1,
safe: true // safe: true
}, // },
function(err, result) { // function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update({_id: threadId}, {$inc: {praise_count: -1}}, { w: 1,safe: true}, 'updateRedisRecommentThreads',function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1046,17 +1113,26 @@ exports.updateThreadRaiseCountDec = function(threadId, callback) { ...@@ -1046,17 +1113,26 @@ exports.updateThreadRaiseCountDec = function(threadId, callback) {
//更新文章分享数 //更新文章分享数
exports.updateThreadShareCount = function(threadId, callback) { exports.updateThreadShareCount = function(threadId, callback) {
ForumThread.update({ // ForumThread.update({
_id: threadId // _id: threadId
}, { // }, {
$inc: { // $inc: {
share_count: 1 // share_count: 1
} // }
}, { // }, {
w: 1, // w: 1,
safe: true // safe: true
}, // },
function(err, result) { // function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update({_id: threadId}, {$inc: {share_count: 1}}, { w: 1,safe: true}, null,function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1068,17 +1144,26 @@ exports.updateThreadShareCount = function(threadId, callback) { ...@@ -1068,17 +1144,26 @@ exports.updateThreadShareCount = function(threadId, callback) {
//更新文章评论数 //更新文章评论数
exports.updateThreadCommentCountInc = function(threadId, callback) { exports.updateThreadCommentCountInc = function(threadId, callback) {
ForumThread.update({ // ForumThread.update({
_id: threadId // _id: threadId
}, { // }, {
$inc: { // $inc: {
comment_count: 1 // comment_count: 1
} // }
}, { // }, {
w: 1, // w: 1,
safe: true // safe: true
}, // },
function(err, result) { // function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update({_id: threadId}, {$inc: {comment_count: 1}}, { w: 1,safe: true}, 'updateRedisRecommentThreads',function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1086,21 +1171,31 @@ exports.updateThreadCommentCountInc = function(threadId, callback) { ...@@ -1086,21 +1171,31 @@ exports.updateThreadCommentCountInc = function(threadId, callback) {
callback(null, null); callback(null, null);
} }
}); });
}; };
//更新文章评论数 //更新文章评论数
exports.updateThreadCommentCount = function(threadId, callback) { exports.updateThreadCommentCount = function(threadId, callback) {
ForumThread.update({ // ForumThread.update({
_id: threadId // _id: threadId
}, { // }, {
$inc: { // $inc: {
comment_count: -1 // comment_count: -1
} // }
}, { // }, {
w: 1, // w: 1,
safe: true // safe: true
}, // },
function(err, result) { // function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update({_id: threadId}, {$inc: {comment_count: -1}}, { w: 1,safe: true}, 'updateRedisRecommentThreads',function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1112,17 +1207,26 @@ exports.updateThreadCommentCount = function(threadId, callback) { ...@@ -1112,17 +1207,26 @@ exports.updateThreadCommentCount = function(threadId, callback) {
//更新文章浏览数 //更新文章浏览数
exports.updateThreadPvCount = function(threadId, callback) { exports.updateThreadPvCount = function(threadId, callback) {
ForumThread.update({ // ForumThread.update({
_id: threadId // _id: threadId
}, { // }, {
$inc: { // $inc: {
pv_count: 1 // pv_count: 1
} // }
}, { // }, {
w: 1, // w: 1,
safe: true // safe: true
}, // },
function(err, result) { // function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update({_id: threadId}, {$inc: {pv_count: 1}}, { w: 1,safe: true}, 'updateRedisRecommentThreads',function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1149,7 +1253,6 @@ exports.remove = function(array,val) { ...@@ -1149,7 +1253,6 @@ exports.remove = function(array,val) {
return array; return array;
}; };
function getAllThreadByFidAndUserHelp(user_ids, conditions, pageNo, pageSize, sort, callback) { function getAllThreadByFidAndUserHelp(user_ids, conditions, pageNo, pageSize, sort, callback) {
conditions.from = { conditions.from = {
"$in" : user_ids "$in" : user_ids
...@@ -1231,10 +1334,9 @@ exports.getAllThreadByFidAndMid = function(mid, conditions, pageNo, pageSize, so ...@@ -1231,10 +1334,9 @@ exports.getAllThreadByFidAndMid = function(mid, conditions, pageNo, pageSize, so
}); });
} }
//更新文章 //更新文章
exports.updateThread = function(condition, entity, callback) { exports.updateThread = function(condition, entity, callback) {
ForumThread.findOneAndUpdate(condition, entity, function(err, doc){ findOneAndUpdate(condition, entity, 'updateRedisRecommentThreads', function(err, doc){
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -1256,8 +1358,6 @@ exports.updateByIdWithOptions = function(condition, entity, options, callback) { ...@@ -1256,8 +1358,6 @@ exports.updateByIdWithOptions = function(condition, entity, options, callback) {
}); });
}; };
//查询列表数据,不获取评论,话题获取参与用户 //查询列表数据,不获取评论,话题获取参与用户
exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, sort, callback) { exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, sort, callback) {
countAllByFid(conditions, function(err, count) { countAllByFid(conditions, function(err, count) {
...@@ -1319,3 +1419,4 @@ exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, ...@@ -1319,3 +1419,4 @@ exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize,
}); });
}; };
'use strict'; 'use strict';
var redis=global.redis; var redis=global.redis;
var expire = 60*10; var expire = 60*30;
//缓存数量 //缓存数量
var ThreadRedisCount = 50; var ThreadRedisCount = 50;
...@@ -12,6 +12,10 @@ var forumThreadService=require('../service/forumThreadService'); ...@@ -12,6 +12,10 @@ var forumThreadService=require('../service/forumThreadService');
var redisPraiseLog=require('./redisPraiseLog'); var redisPraiseLog=require('./redisPraiseLog');
var util=require('./util'); var util=require('./util');
var RefreshFlag = true;
var tyhread_redis_salt = '_tyhread_redis_salt';
var sort = { var sort = {
new_recommend:-1, new_recommend:-1,
new_recommend_order_idx:-1, new_recommend_order_idx:-1,
...@@ -25,13 +29,13 @@ var sort = { ...@@ -25,13 +29,13 @@ var sort = {
created:-1 created:-1
}; };
function getKey(ent_code,keyID,type){ function getKey(ent_code, salt){
var key = ent_code + keyID + type; var key = ent_code + salt;
return key; return key;
} }
function setToRedis(ent_code,keyID,type,value){ function setToRedis(ent_code,salt,value){
var key = getKey(ent_code,keyID,type); var key = getKey(ent_code,salt);
if(!redis){ if(!redis){
console.log('redis error'); console.log('redis error');
return 'error' return 'error'
...@@ -42,8 +46,37 @@ function setToRedis(ent_code,keyID,type,value){ ...@@ -42,8 +46,37 @@ function setToRedis(ent_code,keyID,type,value){
}); });
} }
exports.get=function(ent_code,keyID,type,callback){ function getEsenceThreads(ent_code, salt,callback){
var key = getKey(ent_code,keyID,type); var today = new Date();
var conditions = {
ent_code: ent_code,
level: 1,
status: 1,
new_recommend: 1,
$or: [{
isEvent: 0
}, {
isEvent: null
}, {
isEvent: 1,
'event.eventStartTime' : {$lte : today}
}]
};
forumThreadService.getThreadWithNotPopulateComment(conditions, 1, ThreadRedisCount, sort, function(err, results) {
if (err) {
console.error(err);
callback(err);
} else {
util.loadLevel(ent_code, results.items, function() {
setToRedis(ent_code, salt ,JSON.stringify(results));
callback(null);
});
}
});
};
exports.get=function(ent_code, callback){
var key = getKey(ent_code, tyhread_redis_salt);
if(!redis){ if(!redis){
console.log('redis error'); console.log('redis error');
return callback && callback('error'); return callback && callback('error');
...@@ -51,7 +84,7 @@ exports.get=function(ent_code,keyID,type,callback){ ...@@ -51,7 +84,7 @@ exports.get=function(ent_code,keyID,type,callback){
redis.get(key, function(error, res){ redis.get(key, function(error, res){
if(!res){ if(!res){
//不存在,先获取再返回 //不存在,先获取再返回
getEsenceThreads(ent_code, keyID, type,function(err){ getEsenceThreads(ent_code, tyhread_redis_salt,function(err){
redis.get(key, function(error, res){ redis.get(key, function(error, res){
return callback && callback(error, res.split(",")); return callback && callback(error, res.split(","));
}); });
...@@ -62,8 +95,8 @@ exports.get=function(ent_code,keyID,type,callback){ ...@@ -62,8 +95,8 @@ exports.get=function(ent_code,keyID,type,callback){
}); });
}; };
exports.set=function(ent_code,keyID,type,value,callback){ exports.set=function(ent_code, salt, value, callback){
var key = getKey(ent_code,keyID,type); var key = getKey(ent_code, salt);
if(!redis){ if(!redis){
console.log('redis error'); console.log('redis error');
return callback && callback('error'); return callback && callback('error');
...@@ -74,8 +107,8 @@ exports.set=function(ent_code,keyID,type,value,callback){ ...@@ -74,8 +107,8 @@ exports.set=function(ent_code,keyID,type,value,callback){
}); });
}; };
exports.clear = function(ent_code,keyID,type,callback){ exports.clear = function(ent_code,salt,callback){
var key = getKey(ent_code,keyID,type); var key = getKey(ent_code, salt);
if(!redis){ if(!redis){
console.log('redis error'); console.log('redis error');
return callback && callback('error'); return callback && callback('error');
...@@ -85,53 +118,24 @@ exports.clear = function(ent_code,keyID,type,callback){ ...@@ -85,53 +118,24 @@ exports.clear = function(ent_code,keyID,type,callback){
}); });
}; };
function getEsenceThreads(ent_code,keyID,type,callback){
var today = new Date();
var conditions = {
ent_code: ent_code,
level: 1,
status: 1,
new_recommend: 1,
$or: [{
isEvent: 0
}, {
isEvent: null
}, {
isEvent: 1,
'event.eventStartTime' : {$lte : today}
}]
};
forumThreadService.getThreadWithNotPopulateComment(conditions, 1, ThreadRedisCount, sort, function(err, results) {
if (err) {
console.error(err);
callback(err);
} else {
util.loadLevel(ent_code, results.items, function() {
setToRedis(ent_code,keyID,type,JSON.stringify(results));
callback(null);
});
}
});
};
//获取缓存列表 //获取缓存列表
exports.getRedisEsenceThreads = function(ent_code,keyID,type,callback){ exports.getRedisEsenceThreads = function(ent_code, callback){
var key = getKey(ent_code,keyID,type); var key = getKey(ent_code, tyhread_redis_salt);
getEsenceThreads(ent_code, keyID,type, function(err){ getEsenceThreads(ent_code, tyhread_redis_salt, function(err){
redis.get(key, function(error, res){ redis.get(key, function(error, res){
return callback && callback(error, res.split(",")); return callback && callback(error, res.split(","));
}); });
}); });
}; };
//更新缓存列表
/*exports.updateRedisEsenceThreads = function(ent_code,keyID,type,callback){
getEsenceThreads(ent_code, keyID,type, function(err){
callback();
});
};*/
//获取缓存数值 //获取缓存数值
exports.getThreadRedisCount = function(){ exports.getThreadRedisCount = function(){
return ThreadRedisCount; return ThreadRedisCount;
}; };
//更新缓存列表
exports.updateRedisEsenceThreads = function(ent_code){
if(RefreshFlag){
getEsenceThreads(ent_code, tyhread_redis_salt, function(err){});
}
};
\ No newline at end of file
...@@ -23,7 +23,8 @@ exports.identifyUser=function() { ...@@ -23,7 +23,8 @@ exports.identifyUser=function() {
if(doc){ if(doc){
req.session.mobileForumUser={ req.session.mobileForumUser={
userId:doc._id, userId:doc._id,
openId:doc.uid openId:doc.uid,
mid:doc.mid
}; };
if(req.session.source){ if(req.session.source){
if(req.session.source !== req.session.mobileForumUser.userId){ if(req.session.source !== req.session.mobileForumUser.userId){
...@@ -41,7 +42,8 @@ exports.identifyUser=function() { ...@@ -41,7 +42,8 @@ exports.identifyUser=function() {
uid:req.session.openUser.openId, uid:req.session.openUser.openId,
nickName:req.session.openUser.nickName, nickName:req.session.openUser.nickName,
icon:req.session.openUser.headPic, icon:req.session.openUser.headPic,
ent_code:req.session.user.ent_code ent_code:req.session.user.ent_code,
mid:req.session.openUser.mid
}; };
forumUserService.createUser(entity,function(err,doc){ forumUserService.createUser(entity,function(err,doc){
if(err){ if(err){
...@@ -49,7 +51,8 @@ exports.identifyUser=function() { ...@@ -49,7 +51,8 @@ exports.identifyUser=function() {
}else{ }else{
req.session.mobileForumUser={ req.session.mobileForumUser={
userId:doc._id, userId:doc._id,
openId:doc.uid openId:doc.uid,
mid:doc.mid
}; };
if(req.session.source){ if(req.session.source){
if(req.session.source !== req.session.mobileForumUser.userId){ if(req.session.source !== req.session.mobileForumUser.userId){
......
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