parent
abffc680cc
commit
731e12435b
@ -1,29 +0,0 @@
|
||||
package com.luoo.comment.config;
|
||||
|
||||
import api.Result;
|
||||
import api.StatusCode;
|
||||
import com.luoo.comment.exception.AuthorityLoginException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 统一异常处理类
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class BaseExceptionHandler {
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Result<Void> error(Exception e) {
|
||||
log.error("执行出错", e);
|
||||
return Result.failed(StatusCode.MUSIC_COMMON_FAILED);
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = AuthorityLoginException.class)
|
||||
@ResponseBody
|
||||
public Result<String> error(AuthorityLoginException e) {
|
||||
return Result.unauthorized(null);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.luoo.comment.config;
|
||||
|
||||
import com.luoo.comment.constant.GlobalConstant;
|
||||
import com.luoo.comment.utils.ThreadLocalMap;
|
||||
import dto.UserLoginDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import util.JwtUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TokenInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
|
||||
String token = request.getHeader("token");
|
||||
UserLoginDto loginUser = jwtUtil.getUserLoginDto(token);
|
||||
if (loginUser == null) {
|
||||
log.error("获取用户信息失败, 不允许操作,需重新登录");
|
||||
throw new RuntimeException("获取用户信息失败, 不允许操作,需重新登录");
|
||||
}
|
||||
log.info("请求uri => {} method => {} userId => {} token => {}",
|
||||
request.getRequestURI(), request.getMethod(), loginUser.getUserId(),token);
|
||||
ThreadLocalMap.put(GlobalConstant.TOKEN_AUTH_DTO, loginUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
ThreadLocalMap.remove(GlobalConstant.TOKEN_AUTH_DTO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.luoo.comment.constant;
|
||||
|
||||
public class GlobalConstant {
|
||||
|
||||
/**
|
||||
* 全局用户名
|
||||
*/
|
||||
public static final String TOKEN_AUTH_DTO = "CURRENT_USER_DTO";
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.luoo.comment.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.luoo.comment.exception.AuthorityLoginException;
|
||||
import com.luoo.comment.utils.ThreadLocalMap;
|
||||
import dto.UserLoginDto;
|
||||
|
||||
public class BaseController {
|
||||
|
||||
/**
|
||||
* 全局用户名
|
||||
*/
|
||||
public static final String TOKEN_AUTH_DTO = "CURRENT_USER_DTO";
|
||||
|
||||
protected UserLoginDto getLoginAuthDto() {
|
||||
UserLoginDto loginAuthDto = (UserLoginDto) ThreadLocalMap.get(TOKEN_AUTH_DTO);
|
||||
if (ObjectUtil.isEmpty(loginAuthDto)) {
|
||||
throw new AuthorityLoginException("登录信息已失效,请重新登录");
|
||||
}
|
||||
return loginAuthDto;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.luoo.comment.enums;
|
||||
|
||||
public enum CommentStatusEnum {
|
||||
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL(1),
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
DELETE(2),
|
||||
|
||||
/**
|
||||
* 审核中
|
||||
*/
|
||||
AUDITING(3);
|
||||
|
||||
private final int value;
|
||||
|
||||
CommentStatusEnum(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.luoo.comment.enums;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
public enum Province {
|
||||
BEIJING("Beijing", "北京"),
|
||||
TIANJIN("Tianjin", "天津"),
|
||||
SHANGHAI("Shanghai", "上海"),
|
||||
CHONGQING("Chongqing", "重庆"),
|
||||
HEBEI("Hebei", "河北"),
|
||||
SHANXI("Shanxi", "山西"),
|
||||
LIAONING("Liaoning", "辽宁"),
|
||||
JILIN("Jilin", "吉林"),
|
||||
HEILONGJIANG("Heilongjiang", "黑龙江"),
|
||||
JIANGSU("Jiangsu", "江苏"),
|
||||
ZHEJIANG("Zhejiang", "浙江"),
|
||||
ANHUI("Anhui", "安徽"),
|
||||
FUJIAN("Fujian", "福建"),
|
||||
JIANGXI("Jiangxi", "江西"),
|
||||
SHANDONG("Shandong", "山东"),
|
||||
HENAN("Henan", "河南"),
|
||||
HUBEI("Hubei", "湖北"),
|
||||
HUNAN("Hunan", "湖南"),
|
||||
GUANGDONG("Guangdong", "广东"),
|
||||
GUANGXI("Guangxi", "广西"),
|
||||
HAINAN("Hainan", "海南"),
|
||||
SICHUAN("Sichuan", "四川"),
|
||||
GUIZHOU("Guizhou", "贵州"),
|
||||
YUNNAN("Yunnan", "云南"),
|
||||
TIBET("Tibet", "西藏"),
|
||||
SHAANXI("Shaanxi", "陕西"),
|
||||
GANSU("Gansu", "甘肃"),
|
||||
QINGHAI("Qinghai", "青海"),
|
||||
NINGXIA("Ningxia", "宁夏"),
|
||||
XINJIANG("Xinjiang", "新疆");
|
||||
|
||||
private final String englishName;
|
||||
private final String chineseName;
|
||||
|
||||
Province(String englishName, String chineseName) {
|
||||
this.englishName = englishName;
|
||||
this.chineseName = chineseName;
|
||||
}
|
||||
|
||||
public String getEnglishName() {
|
||||
return englishName;
|
||||
}
|
||||
|
||||
public String getChineseName() {
|
||||
return chineseName;
|
||||
}
|
||||
|
||||
public static String getCityName(String englishName) {
|
||||
if (ObjectUtil.isEmpty(englishName)) {
|
||||
return "未知IP";
|
||||
}
|
||||
for (Province province : Province.values()) {
|
||||
if (englishName.equalsIgnoreCase(province.englishName)) {
|
||||
return province.chineseName;
|
||||
}
|
||||
}
|
||||
return "未知IP";
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.luoo.comment.enums;
|
||||
|
||||
public enum ThumbupActionEnum {
|
||||
|
||||
/**
|
||||
* 确认
|
||||
*/
|
||||
CONFIRM(1),
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
CANCEL(0);
|
||||
|
||||
private final int value;
|
||||
|
||||
ThumbupActionEnum(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.luoo.comment.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CommentDto implements Serializable {
|
||||
|
||||
/**
|
||||
* 文章 ID
|
||||
*/
|
||||
private String articleId;
|
||||
|
||||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 父节点 ID
|
||||
*/
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 目标 ID
|
||||
*/
|
||||
private String targetId;
|
||||
|
||||
/**
|
||||
* IP 地址
|
||||
*/
|
||||
private String ipAddress;
|
||||
|
||||
private String userId;
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.luoo.comment.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 点赞 DTO
|
||||
*/
|
||||
@Data
|
||||
public class CommentThumbupDto {
|
||||
|
||||
@NotNull
|
||||
private String commentId;
|
||||
|
||||
private Integer action;
|
||||
|
||||
private String userId;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.luoo.comment.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CommentThumbupVo {
|
||||
|
||||
/**
|
||||
* 点赞数量
|
||||
*/
|
||||
private Long thumbupNum;
|
||||
|
||||
|
||||
/**
|
||||
* 评论数量
|
||||
*/
|
||||
private Long commentNum;
|
||||
|
||||
/**
|
||||
* 用户 ID
|
||||
*/
|
||||
private String userId;
|
||||
}
|
@ -1,29 +1,96 @@
|
||||
package com.luoo.comment.service;
|
||||
|
||||
|
||||
import com.luoo.comment.pojo.*;
|
||||
import com.luoo.comment.dao.CommentDao;
|
||||
import com.luoo.comment.pojo.Comment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import util.IdWorker;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface CommentService {
|
||||
@Service
|
||||
@Transactional
|
||||
public class CommentService {
|
||||
|
||||
Comment findById(String id);
|
||||
@Autowired
|
||||
private CommentDao commentDao;
|
||||
|
||||
void save(CommentDto commentDto);
|
||||
@Autowired
|
||||
private IdWorker idWorker;
|
||||
|
||||
void update(Comment comment);
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
void deleteById(String id);
|
||||
@Autowired
|
||||
|
||||
Page<CommentVo> findByParentId(String parentId, int page, int size);
|
||||
public List<Comment> findAll(){
|
||||
return commentDao.findAll();
|
||||
}
|
||||
|
||||
void thumbup(CommentThumbupDto commentThumbupDto);
|
||||
public Comment findById(String id) {
|
||||
return commentDao.findById(id).get();
|
||||
}
|
||||
|
||||
List<CommentVo> findByVolid(String volid);
|
||||
public void save(Comment comment) {
|
||||
comment.set_id(idWorker.nextId()+"");
|
||||
comment.setPublishTime(new Date());
|
||||
comment.setThumbupCount(0); //点赞数
|
||||
comment.setCommentCount(0); //回复数
|
||||
comment.setState(1);
|
||||
|
||||
/**
|
||||
* 获取用户评论信息
|
||||
*/
|
||||
CommentThumbupVo getUserCommentInfo(String userId);
|
||||
// 如果当前添加的评论,有父节点,那么父节点的评论回复数要加一
|
||||
if (comment.getParentId()!=null && !"".equals(comment.getParentId())){
|
||||
|
||||
comment.setJournalId("");//如果有父节点,将期刊号置为空
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("_id").is(comment.getParentId()));
|
||||
Update update = new Update();
|
||||
update.inc("commentCount",1);
|
||||
mongoTemplate.updateFirst(query,update,"comment");
|
||||
}
|
||||
|
||||
commentDao.save(comment);
|
||||
}
|
||||
|
||||
public void update (Comment comment) {
|
||||
commentDao.save(comment);
|
||||
}
|
||||
|
||||
|
||||
public void deleteById(String id) {
|
||||
commentDao.deleteById(id);
|
||||
}
|
||||
|
||||
public Page<Comment> findByParentId(String parentId, int page, int size) {
|
||||
|
||||
Pageable pageable = PageRequest.of(page-1,size);
|
||||
return commentDao.findByParentId(parentId,pageable);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Page<Comment> findByJournalId(String journalId, int page, int size) {
|
||||
|
||||
Pageable pageable = PageRequest.of(page-1,size);
|
||||
return commentDao.findByJournalId(journalId,pageable);
|
||||
}
|
||||
|
||||
public void thumbup(String commentId) {
|
||||
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("_id").is(commentId));
|
||||
Update update = new Update();
|
||||
update.inc("thumbupCount",1);
|
||||
mongoTemplate.updateFirst(query,update,"comment");
|
||||
}
|
||||
}
|
||||
|
@ -1,233 +0,0 @@
|
||||
package com.luoo.comment.service.impl;
|
||||
|
||||
|
||||
import api.Result;
|
||||
import client.vo.SimpleUser;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.luoo.comment.dao.CommentDao;
|
||||
import com.luoo.comment.enums.CommentStatusEnum;
|
||||
import com.luoo.comment.enums.Province;
|
||||
import com.luoo.comment.enums.ThumbupActionEnum;
|
||||
import com.luoo.comment.pojo.*;
|
||||
import com.luoo.comment.service.CommentService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.renfei.ip2location.IP2Location;
|
||||
import net.renfei.ip2location.IPResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import util.IdWorker;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
@Slf4j
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
|
||||
// @Autowired
|
||||
// private UserClient userClient;
|
||||
|
||||
@Autowired
|
||||
private CommentDao commentDao;
|
||||
|
||||
@Autowired
|
||||
private IdWorker idWorker;
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
|
||||
public Comment findById(String id) {
|
||||
return commentDao.findById(id).get();
|
||||
}
|
||||
|
||||
public String getCityNameByIp(String ip) {
|
||||
IP2Location loc = new IP2Location();
|
||||
String binFile = "classpath:/IP2LOCATION-LITE-DB11.BIN";
|
||||
try {
|
||||
loc.Open(binFile, true);
|
||||
IPResult rec = loc.IPQuery(ip);
|
||||
String city = rec.getCity();
|
||||
return Province.getCityName(city);
|
||||
} catch (IOException e) {
|
||||
log.info("getCityNameByIp error {}",ip,e);
|
||||
return "未知 IP";
|
||||
}
|
||||
}
|
||||
|
||||
public void save(CommentDto commentDto){
|
||||
Comment comment = new Comment();
|
||||
comment.setContent(commentDto.getContent());
|
||||
comment.setPublishTime(new Date());
|
||||
comment.setUserId(commentDto.getUserId());
|
||||
comment.setComment(0);
|
||||
comment.setParentId(commentDto.getParentId());
|
||||
comment.setArticleId(commentDto.getArticleId());
|
||||
comment.setLevel(1);
|
||||
comment.setTargetId(commentDto.getTargetId());
|
||||
comment.setType(0);
|
||||
comment.setCity(getCityNameByIp(commentDto.getIpAddress()));
|
||||
comment.setId(String.valueOf(idWorker.nextId()));
|
||||
comment.setShare(0);
|
||||
comment.setThumbup(0);
|
||||
comment.setComment(0);
|
||||
comment.setState(CommentStatusEnum.NORMAL.getValue());
|
||||
// 如果当前添加的吐槽,有父节点,那么父节点的吐槽回复数要加一
|
||||
if (ObjectUtil.isNotEmpty(comment.getParentId())) {
|
||||
// 更新父节点的评论回复数
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("_id").is(comment.getParentId()));
|
||||
Update update = new Update();
|
||||
update.inc("comment",1);
|
||||
mongoTemplate.updateFirst(query,update,Comment.class);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(comment.getTargetId())) {
|
||||
Comment parentIdComment = mongoTemplate.findById(comment.getTargetId(), Comment.class);
|
||||
comment.setLevel(parentIdComment.getLevel()+1);
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("_id").is(comment.getTargetId()));
|
||||
Update update = new Update();
|
||||
update.inc("comment",1);
|
||||
mongoTemplate.updateFirst(query,update,Comment.class);
|
||||
}
|
||||
commentDao.save(comment);
|
||||
}
|
||||
|
||||
public void update(Comment comment) {
|
||||
commentDao.save(comment);
|
||||
}
|
||||
|
||||
public void deleteById(String id) {
|
||||
commentDao.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
public Page<CommentVo> findByParentId(String parentId,int page,int size){
|
||||
Pageable pageable = PageRequest.of(page, size);
|
||||
Query query = new Query();
|
||||
Criteria criteria = Criteria.where("parentId").is(parentId);
|
||||
query.addCriteria(criteria);
|
||||
Sort sort = Sort.by(Sort.Direction.ASC, "age");
|
||||
query.with(sort);
|
||||
query.with(pageable);
|
||||
List<Comment> comments = mongoTemplate.find(query, Comment.class);
|
||||
|
||||
List<String> userIds = comments.stream().map(Comment::getUserId).collect(Collectors.toList());
|
||||
|
||||
// Result<List<SimpleUser>> userByIds = userClient.findUserByIds(userIds);
|
||||
Result<List<SimpleUser>> userByIds = Result.success(null);
|
||||
|
||||
Map<String, SimpleUser> userIdAndInfoMap = userByIds.getData().stream().collect(Collectors.toMap(SimpleUser::getUserId, Function.identity()));
|
||||
|
||||
List<CommentVo> commentVos = comments.stream().map(Comment::convertVo).collect(Collectors.toList());
|
||||
|
||||
// List<String> targetComments = comments.stream().map(Comment::getTargetId).collect(Collectors.toList());
|
||||
|
||||
Map<String, CommentVo> idCommentMap = commentVos.stream().collect(Collectors.toMap(CommentVo::getId, Function.identity()));
|
||||
|
||||
long total = mongoTemplate.count(query, Comment.class);
|
||||
|
||||
// boolean isChange = targetComments.removeAll(idCommentMap.keySet());
|
||||
|
||||
for (CommentVo commentVo : commentVos) {
|
||||
|
||||
// 处理昵称
|
||||
SimpleUser simpleUser = userIdAndInfoMap.get(commentVo.getUserId());
|
||||
|
||||
if (ObjectUtil.isNotEmpty(simpleUser)) {
|
||||
commentVo.setNickName(simpleUser.getNickName());
|
||||
}
|
||||
// 处理叠楼评论回复
|
||||
if (commentVo.getLevel() > 2 && ObjectUtil.isNotEmpty(commentVo.getTargetId())) {
|
||||
CommentVo targetCommentVo = idCommentMap.get(commentVo.getTargetId());
|
||||
if (targetCommentVo != null) {
|
||||
commentVo.setTargetComment(targetCommentVo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new PageImpl<>(commentVos, pageable, total);
|
||||
}
|
||||
|
||||
public void thumbup(CommentThumbupDto commentThumbupDto) {
|
||||
String userId = commentThumbupDto.getUserId();
|
||||
|
||||
Long count = (Long)redisTemplate.opsForValue().get("thumbup_" + userId);
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("_id").is(commentThumbupDto.getCommentId()));
|
||||
Update update = new Update();
|
||||
if (commentThumbupDto.getAction().equals(ThumbupActionEnum.CONFIRM.getValue())) {
|
||||
update.inc("thumbup",1);
|
||||
if (ObjectUtil.isNotEmpty(count)) {
|
||||
redisTemplate.opsForValue().set("thumbup_"+userId,++count);
|
||||
} else {
|
||||
redisTemplate.opsForValue().set("thumbup_"+userId,1L);
|
||||
}
|
||||
} else {
|
||||
update.inc("thumbup",-1);
|
||||
}
|
||||
mongoTemplate.updateFirst(query,update,Comment.class);
|
||||
}
|
||||
|
||||
public List<CommentVo> findByVolid(String volid) {
|
||||
List<Comment> byArticleId = commentDao.findByArticleId(volid);
|
||||
|
||||
if (ObjectUtil.isEmpty(byArticleId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<CommentVo> commentVos = byArticleId.stream().map(Comment::convertVo).collect(Collectors.toList());
|
||||
|
||||
List<String> userIds = byArticleId.stream().map(Comment::getUserId).collect(Collectors.toList());
|
||||
// Result<List<SimpleUser>> userByIds = userClient.findUserByIds(userIds);
|
||||
Result<List<SimpleUser>> userByIds = Result.success(null);
|
||||
Map<String, SimpleUser> userIdAndInfoMap = userByIds.getData().stream().collect(Collectors.toMap(SimpleUser::getUserId, Function.identity()));
|
||||
|
||||
for (CommentVo commentVo : commentVos) {
|
||||
// 处理昵称
|
||||
SimpleUser simpleUser = userIdAndInfoMap.get(commentVo.getUserId());
|
||||
|
||||
if (ObjectUtil.isNotEmpty(simpleUser)) {
|
||||
commentVo.setNickName(simpleUser.getNickName());
|
||||
}
|
||||
}
|
||||
return commentVos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentThumbupVo getUserCommentInfo(String userId) {
|
||||
// 获取用户点赞数量
|
||||
CommentThumbupVo commentThumbupVo = new CommentThumbupVo();
|
||||
Long count = (Long)redisTemplate.opsForValue().get("thumbup_" + userId);
|
||||
if (ObjectUtil.isEmpty(count)) {
|
||||
count = 0L;
|
||||
}
|
||||
commentThumbupVo.setThumbupNum(count);
|
||||
|
||||
// 获取评论数量
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("userId").is(userId));
|
||||
long commentCount = mongoTemplate.count(query, Comment.class);
|
||||
commentThumbupVo.setCommentNum(commentCount);
|
||||
return commentThumbupVo;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue