Commit f9db50ef authored by jiaorz's avatar jiaorz

点赞评论排序

parent 6a0a77ae
...@@ -83,6 +83,11 @@ public class MsgBiz { ...@@ -83,6 +83,11 @@ public class MsgBiz {
} }
public ObjectRestResponse getHotMsgList(Integer page, Integer limit) { public ObjectRestResponse getHotMsgList(Integer page, Integer limit) {
AppUserDTO appUserDTO = userBiz.getUserInfo();
Integer userId = null;
if(appUserDTO != null) {
userId = appUserDTO.getImUserid();
}
log.info("获取消息列表: page = {}, limit = {}, type = {}", page, limit); log.info("获取消息列表: page = {}, limit = {}, type = {}", page, limit);
page = page == null ? 1 : page; page = page == null ? 1 : page;
limit = limit == null ? 10 : limit; limit = limit == null ? 10 : limit;
...@@ -94,7 +99,7 @@ public class MsgBiz { ...@@ -94,7 +99,7 @@ public class MsgBiz {
int totalSize = mongoTemplate.find(query, Msg.class, "s_msg").size(); int totalSize = mongoTemplate.find(query, Msg.class, "s_msg").size();
query.with(pageable); query.with(pageable);
query.with(new Sort(Sort.Direction.DESC, "count.praise")); query.with(new Sort(Sort.Direction.DESC, "count.praise"));
List<Msg> msgList = mongoTemplate.find(query, Msg.class, "s_msg"); List<Msg> msgList = fetchAndAttach(mongoTemplate.find(query, Msg.class, "s_msg"), userId);
PageInfo<MsgVo> goodPageInfo = new PageInfo<>(replaceMsgResult(msgList)); PageInfo<MsgVo> goodPageInfo = new PageInfo<>(replaceMsgResult(msgList));
goodPageInfo.setPageSize(totalSize%limit == 0 ?totalSize/limit : totalSize/limit + 1); goodPageInfo.setPageSize(totalSize%limit == 0 ?totalSize/limit : totalSize/limit + 1);
return ObjectRestResponse.succ(goodPageInfo); return ObjectRestResponse.succ(goodPageInfo);
...@@ -158,7 +163,7 @@ public class MsgBiz { ...@@ -158,7 +163,7 @@ public class MsgBiz {
public boolean exists(int userId, ObjectId msgId) { public boolean exists(int userId, ObjectId msgId) {
Query query = new Query(Criteria.where("msgId").is(msgId).and("userId").is(userId)); Query query = new Query(Criteria.where("msgId").is(msgId).and("userId").is(userId));
List<Praise> praise = mongoTemplate.find(query, Praise.class, "s_praise"); List<Praise> praise = mongoTemplate.find(query, Praise.class, "s_praise");
return 0 != praise.size(); return praise.size() > 0 ? true :false;
} }
/** /**
...@@ -171,7 +176,7 @@ public class MsgBiz { ...@@ -171,7 +176,7 @@ public class MsgBiz {
public boolean existsCollect(int userId, ObjectId msgId) { public boolean existsCollect(int userId, ObjectId msgId) {
Query query = new Query(Criteria.where("msgId").is(msgId).and("userId").is(userId)); Query query = new Query(Criteria.where("msgId").is(msgId).and("userId").is(userId));
List<Comment> comments = mongoTemplate.find(query, Comment.class, "s_comment"); List<Comment> comments = mongoTemplate.find(query, Comment.class, "s_comment");
return 0 != comments.size(); return comments.size() > 0 ? true :false;
} }
public List<MsgVo> replaceMsgResult(List<Msg> list) { public List<MsgVo> replaceMsgResult(List<Msg> list) {
......
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