fix: comment with realtime user info

main
wangqing 9 months ago
parent 99e9fb3e91
commit d1feac6650

@ -27,7 +27,14 @@
<artifactId>mongodb-plus-spring-boot-starter</artifactId> <artifactId>mongodb-plus-spring-boot-starter</artifactId>
<version>1.0.0.RELEASE</version> <version>1.0.0.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>

@ -8,6 +8,7 @@ import com.luoo.comment.pojo.*;
import com.luoo.comment.service.CommentService; import com.luoo.comment.service.CommentService;
import com.luoo.comment.service.ComplaintService; import com.luoo.comment.service.ComplaintService;
import com.luoo.comment.service.LikeService; import com.luoo.comment.service.LikeService;
import com.luoo.comment.service.UserInfoService;
import com.luoo.comment.util.IpUtil; import com.luoo.comment.util.IpUtil;
import constants.Constants; import constants.Constants;
import controller.BaseController; import controller.BaseController;
@ -18,6 +19,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -66,6 +68,9 @@ public class CommentController extends BaseController {
@Autowired @Autowired
private ComplaintService complaintService; private ComplaintService complaintService;
@Autowired
private UserInfoService userInfoService;
@Autowired @Autowired
private IdWorker idWorker; private IdWorker idWorker;
@ -112,12 +117,12 @@ public class CommentController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) { if (null == userLoginDto) {
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size); Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,"")).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size); Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size);
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
} }
@ -131,12 +136,12 @@ public class CommentController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) { if (null == userLoginDto) {
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size); Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,"")).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Page<Comment> pageList = commentService.findNewByJournalId(journalId,page,size); Page<Comment> pageList = commentService.findNewByJournalId(journalId,page,size);
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
} }
@ -148,9 +153,21 @@ public class CommentController extends BaseController {
// 创建查询对象并应用查询条件 // 创建查询对象并应用查询条件
Query query = new Query(criteria); Query query = new Query(criteria);
boolean isExists = mongoTemplate.exists(query, PublicationLike.class); boolean isExists = mongoTemplate.exists(query, PublicationLike.class);
comment.setHaveThumbup(isExists); //是否已点赞 comment.setHaveThumbup(isExists); //
UserInfo commentUserInfo = userInfoService.findById(comment.getUserId());
comment.setNickName(commentUserInfo.getNickName());
comment.setAvatar(Constants.RESOURCE_PREFIX+commentUserInfo.getAvatar());
if(StringUtils.isNotEmpty(comment.getReplyToUserId())){
UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId());
comment.setReplyToNickname(replyToUserInfo.getNickName());
}
CommentResp commentResp = new CommentResp(); CommentResp commentResp = new CommentResp();
BeanUtils.copyProperties(comment,commentResp); BeanUtils.copyProperties(comment,commentResp);
if(comment.getCommentCount()>0){
Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0);
commentResp.setTopChildrenComment(topComment);
}
commentResp.setThumbupCountString(comment.getThumbupCount()+""); commentResp.setThumbupCountString(comment.getThumbupCount()+"");
commentResp.setThumbupCountInt(comment.getThumbupCount()); commentResp.setThumbupCountInt(comment.getThumbupCount());
if(comment.getThumbupCount()>999) { if(comment.getThumbupCount()>999) {
@ -167,8 +184,15 @@ public class CommentController extends BaseController {
@GetMapping("/{commentId}") @GetMapping("/{commentId}")
public Result findById(@PathVariable String commentId){ public Result findById(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = false) String authorization){
return Result.success(commentService.findById(commentId)); //验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
Comment comment = commentService.findById(commentId);
if (null == userLoginDto) {
CommentResp commentResp = getCommentResp(comment,"");
return Result.success(commentResp);
}
return Result.success(getCommentResp(comment,userLoginDto.getUserId()));
} }
@ -229,12 +253,12 @@ public class CommentController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) { if (null == userLoginDto) {
Page<Comment> pageList = commentService.findByParentId(parentId,page,size); Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,"")).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Page<Comment> pageList = commentService.findByParentId(parentId,page,size); Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
} }

@ -0,0 +1,36 @@
package com.luoo.comment.dao;
import client.vo.SimpleUser;
import com.luoo.comment.pojo.UserInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecificationExecutor<UserInfo> {
public UserInfo findByMobile(String mobile);
@Modifying
@Query(value = "update tb_user_info set follow_count=follow_count+? where id = ?", nativeQuery = true)
void updatefollowcount(int x, String appUserInfoId);
@Modifying
@Query(value = "update tb_user_info set fans_count=fans_count+? where id = ?", nativeQuery = true)
void updatefanscount(int x, String friendid);
public long countByNickName(String nickName);
@Query(value = "select * from tb_user_info where id in ?1 order by field(id,?1)", nativeQuery = true)
public List<UserInfo> orderByField(List<String> idList);
@Query(value = "select new client.vo.SimpleUser(id, nickName) from UserInfo where id in ?1 order by field(id,?1)")
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList);
@Query(value = "select * from tb_user_info where id = ?1", nativeQuery = true)
public UserInfo getById(String id);
@Query(value = "select * from tb_user_info where badges like '%1%' ", nativeQuery = true)
public List<UserInfo> getThanks();
}

@ -57,4 +57,6 @@ public class CommentResp implements Serializable {
private String replyToUserId; private String replyToUserId;
private String replyToNickname; private String replyToNickname;
private Comment topChildrenComment;
} }

@ -0,0 +1,135 @@
package com.luoo.comment.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
@Getter
@Setter
@Entity
@Table(name="tb_user_info")
public class UserInfo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@Id
private String id;
/**
*
*/
private String mobile;
/**
*
*/
private String nickName;
/**
*
*/
private String avatar;
/**
*
*/
private String signature;
/**
*
*/
private String password;
/**
*
*/
private String email;
/**
* 0: 1: 2:
*/
private Integer sex;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birthday;
/**
*
*/
private int fansCount;
/**
*
*/
private int followCount;
/**
*
*/
private int thumbUpCount;
/**
*
*/
private int songCount;
/**
*
*/
private int journalCount;
/**
*
*/
private int commentReplyCount;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date joinTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date modifyTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date lastLoginTime;
/**
* 使ID
*/
private String lastUseDeviceId;
/**
*
*/
private String lastUseDeviceBrand;
/**
* IP
*/
private String lastLoginIp;
/**
* 0: 1:
*/
private int status;
/**
* 0: 1:
*/
private int onlineStatus;
private String badges;
}

@ -0,0 +1,38 @@
package com.luoo.comment.service;
import com.luoo.comment.dao.UserInfoDao;
import com.luoo.comment.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
*
* @author Administrator
*
*/
@Service
public class UserInfoService {
@Autowired
private UserInfoDao userInfoDao;
/**
* ID
*
* @param id
* @return
*/
public UserInfo findById(String id) {
return userInfoDao.getById(id);
}
}

@ -336,12 +336,19 @@ public class MyController extends BaseController {
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Page<PublicationLike> pageList = myService.getMyThumbupList(userId,page,size); Page<PublicationLike> pageList = myService.getMyThumbupList(userId,page,size);
List<PublicationLike> list = pageList.stream().parallel().map(x->getPublicationLike(x)).collect(Collectors.toList());
return Result.success(new PageResult<PublicationLike>(pageList.getTotalElements(),pageList.getContent())); return Result.success(new PageResult<PublicationLike>(Long.valueOf(list.size()),list));
} }
private PublicationLike getPublicationLike(PublicationLike publicationLike) {
UserInfo userInfo = userInfoService.findById(publicationLike.getUserId());
publicationLike.setNickName(userInfo.getNickName());
publicationLike.setAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar());
return publicationLike;
}
// 查询我收到的评论 // 查询我收到的评论
@ApiOperation(value = "10.查询我收到的评论分页列表", notes = "游客无法获取") @ApiOperation(value = "10.查询我收到的评论分页列表", notes = "游客无法获取")
@GetMapping("/myCommentReplyList/{page}/{size}") @GetMapping("/myCommentReplyList/{page}/{size}")
@ -354,7 +361,16 @@ public class MyController extends BaseController {
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Page<CommentHis> pageList = myService.getMyCommentReplyList(userId,page,size); Page<CommentHis> pageList = myService.getMyCommentReplyList(userId,page,size);
return Result.success(new PageResult<CommentHis>(pageList.getTotalElements(),pageList.getContent())); List<CommentHis> list = pageList.stream().parallel().map(x->getCommentHis(x)).collect(Collectors.toList());
return Result.success(new PageResult<CommentHis>(Long.valueOf(list.size()),list));
}
private CommentHis getCommentHis(CommentHis commentHis) {
UserInfo userInfo = userInfoService.findById(commentHis.getCommenterId());
commentHis.setNickName(userInfo.getNickName());
commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar());
return commentHis;
} }
// 查询我收到的评论 // 查询我收到的评论

Loading…
Cancel
Save