fix comment page
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyPage;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyView;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.service.CreatableService;
|
||||
import com.imyeyu.spring.service.DeletableService;
|
||||
import com.imyeyu.spring.service.GettableService;
|
||||
import com.imyeyu.spring.service.UpdatableService;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
/**
|
||||
* 评论回复服务
|
||||
@@ -15,7 +9,5 @@ import com.imyeyu.spring.service.UpdatableService;
|
||||
* @author 夜雨
|
||||
* @since 2021-08-24 10:33
|
||||
*/
|
||||
public interface CommentReplyService extends CreatableService<CommentReply>, GettableService<CommentReply, Long>, UpdatableService<CommentReply>, DeletableService<Long> {
|
||||
|
||||
PageResult<CommentReplyView> pageByBizType(CommentReplyPage page);
|
||||
public interface CommentReplyService extends BaseService<CommentReply, Long> {
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentView;
|
||||
import com.imyeyu.api.modules.common.vo.comment.UserCommentPage;
|
||||
import com.imyeyu.api.modules.git.vo.issue.CommentPage;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.service.CreatableService;
|
||||
import com.imyeyu.spring.service.DeletableService;
|
||||
import com.imyeyu.spring.service.GettableService;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
/**
|
||||
* 评论服务
|
||||
@@ -16,16 +9,5 @@ import com.imyeyu.spring.service.GettableService;
|
||||
* @author 夜雨
|
||||
* @since 2021-02-23 21:32
|
||||
*/
|
||||
public interface CommentService extends CreatableService<Comment>, GettableService<Comment, Long>, DeletableService<Long> {
|
||||
|
||||
PageResult<CommentView> pageByBizId(CommentPage page);
|
||||
|
||||
/**
|
||||
* 获取用户评论页面
|
||||
*
|
||||
* @param userCommentPage 页面参数
|
||||
* @return 页面列表
|
||||
* @throws TimiException 服务异常
|
||||
*/
|
||||
PageResult<CommentView> pageByUserId(UserCommentPage userCommentPage);
|
||||
public interface CommentService extends BaseService<Comment, Long> {
|
||||
}
|
||||
|
||||
+24
-48
@@ -1,13 +1,8 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.api.TimiServerAPI;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.blog.entity.Article;
|
||||
import com.imyeyu.api.modules.blog.entity.CommentRemindQueue;
|
||||
import com.imyeyu.api.modules.blog.service.ArticleService;
|
||||
import com.imyeyu.api.modules.blog.service.CommentRemindQueueService;
|
||||
import com.imyeyu.api.modules.common.bean.CommentSupport;
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
@@ -21,23 +16,21 @@ import com.imyeyu.api.modules.common.service.CommentService;
|
||||
import com.imyeyu.api.modules.common.service.EmailQueueService;
|
||||
import com.imyeyu.api.modules.common.service.UserConfigService;
|
||||
import com.imyeyu.api.modules.common.service.UserService;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyPage;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyView;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentView;
|
||||
import com.imyeyu.api.modules.git.service.RepositoryService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import com.imyeyu.spring.service.GettableService;
|
||||
import com.imyeyu.utils.Time;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -52,8 +45,6 @@ public class CommentReplyServiceImplement extends AbstractEntityService<CommentR
|
||||
|
||||
private final UserService userService;
|
||||
private final CommentService commentService;
|
||||
private final ArticleService articleService;
|
||||
private final RepositoryService repositoryService;
|
||||
private final UserConfigService userConfigService;
|
||||
private final EmailQueueService emailQueueService;
|
||||
private final CommentRemindQueueService commentRemindQueueService;
|
||||
@@ -65,11 +56,23 @@ public class CommentReplyServiceImplement extends AbstractEntityService<CommentR
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(Long crId) {
|
||||
super.delete(crId);
|
||||
commentRemindQueueService.destroyByReplyId(crId);
|
||||
public PageResult<CommentReply> page(Page<CommentReply> page) {
|
||||
PageResult<CommentReply> result = super.page(page);
|
||||
for (CommentReply reply : result.getList()) {
|
||||
Comment comment = commentService.get(reply.getCommentId());
|
||||
if (TimiJava.isNotEmpty(comment.getUserId())) {
|
||||
comment.setUser(userService.view(comment.getUserId()));
|
||||
}
|
||||
reply.setComment(comment);
|
||||
if (TimiJava.isNotEmpty(reply.getSenderId())) {
|
||||
reply.setSender(userService.view(reply.getSenderId()));
|
||||
}
|
||||
if (TimiJava.isNotEmpty(reply.getReceiverId())) {
|
||||
reply.setReceiver(userService.view(reply.getReceiverId()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@@ -160,37 +163,10 @@ public class CommentReplyServiceImplement extends AbstractEntityService<CommentR
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public PageResult<CommentReplyView> pageByBizType(CommentReplyPage page) {
|
||||
PageResult<CommentReplyView> result = new PageResult<>();
|
||||
List<CommentReplyView> list = mapper.listByBizType(page.getBizType(), page.getBizId(), page.getOffset(), page.getLimit());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
CommentReplyView reply = list.get(i);
|
||||
CommentView comment = new CommentView();
|
||||
BeanUtils.copyProperties(commentService.get(reply.getCommentId()), comment);
|
||||
if (TimiJava.isNotEmpty(comment.getUserId())) {
|
||||
comment.setUser(userService.view(comment.getUserId()));
|
||||
}
|
||||
switch (comment.getBizType()) {
|
||||
case ARTICLE -> {
|
||||
Article article = articleService.get(comment.getBizId());
|
||||
article.setData(null);
|
||||
article.setExtendData(null);
|
||||
comment.setArticle(article);
|
||||
}
|
||||
// case GIT_ISSUE, GIT_MERGE -> comment.setRepository(repositoryService.get(comment.getBizId()));
|
||||
}
|
||||
reply.setComment(comment);
|
||||
|
||||
if (TimiJava.isNotEmpty(reply.getSenderId())) {
|
||||
reply.setSender(userService.view(reply.getSenderId()));
|
||||
}
|
||||
if (TimiJava.isNotEmpty(reply.getReceiverId())) {
|
||||
reply.setReceiver(userService.view(reply.getReceiverId()));
|
||||
}
|
||||
}
|
||||
result.setList(list);
|
||||
result.setTotal(mapper.countByBizType(page.getBizType(), page.getBizId()));
|
||||
return result;
|
||||
public void delete(Long crId) {
|
||||
super.delete(crId);
|
||||
commentRemindQueueService.destroyByReplyId(crId);
|
||||
}
|
||||
}
|
||||
|
||||
+53
-77
@@ -1,12 +1,8 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.api.TimiServerAPI;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.blog.entity.Article;
|
||||
import com.imyeyu.api.modules.blog.service.ArticleService;
|
||||
import com.imyeyu.api.modules.blog.entity.CommentRemindQueue;
|
||||
import com.imyeyu.api.modules.common.bean.CommentSupport;
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
@@ -16,12 +12,11 @@ import com.imyeyu.api.modules.common.mapper.CommentRemindQueueMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.CommentReplyMapper;
|
||||
import com.imyeyu.api.modules.common.service.CommentService;
|
||||
import com.imyeyu.api.modules.common.service.UserService;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyView;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentView;
|
||||
import com.imyeyu.api.modules.common.vo.comment.UserCommentPage;
|
||||
import com.imyeyu.api.modules.git.service.RepositoryService;
|
||||
import com.imyeyu.api.modules.git.vo.issue.CommentPage;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
@@ -31,7 +26,6 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,8 +39,6 @@ import java.util.List;
|
||||
public class CommentServiceImplement extends AbstractEntityService<Comment, Long> implements CommentService {
|
||||
|
||||
private final UserService userService;
|
||||
private final ArticleService articleService;
|
||||
private final RepositoryService repositoryService;
|
||||
|
||||
private final CommentMapper mapper;
|
||||
private final CommentReplyMapper replyMapper;
|
||||
@@ -57,6 +49,36 @@ public class CommentServiceImplement extends AbstractEntityService<Comment, Long
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Comment> page(Page<Comment> page) {
|
||||
PageResult<Comment> result = super.page(page);
|
||||
for (Comment comment : result.getList()) {
|
||||
if (TimiJava.isNotEmpty(comment.getUserId())) {
|
||||
comment.setUser(userService.view(comment.getUserId()));
|
||||
}
|
||||
Page<CommentReply> replyPage = new Page<>();
|
||||
replyPage.setIndex(0);
|
||||
replyPage.setSize(6);
|
||||
{
|
||||
CommentReply exampleReply = new CommentReply();
|
||||
exampleReply.setCommentId(comment.getId());
|
||||
replyPage.setEqualsExample(exampleReply);
|
||||
}
|
||||
PageResult<CommentReply> replyResult = replyMapper.selectPageResult(replyPage);
|
||||
comment.setReplies(replyResult.getList());
|
||||
comment.setRepliesLength(replyResult.getTotal());
|
||||
for (CommentReply reply : replyResult.getList()) {
|
||||
if (TimiJava.isNotEmpty(reply.getSenderId())) {
|
||||
reply.setSender(userService.view(reply.getSenderId()));
|
||||
}
|
||||
if (TimiJava.isNotEmpty(reply.getReceiverId())) {
|
||||
reply.setReceiver(userService.view(reply.getReceiverId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(Comment comment) {
|
||||
@@ -83,77 +105,31 @@ public class CommentServiceImplement extends AbstractEntityService<Comment, Long
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(Long cId) {
|
||||
public void delete(Long commentId) {
|
||||
User user = userService.getLoginUser();
|
||||
|
||||
Comment comment = get(cId);
|
||||
Comment comment = get(commentId);
|
||||
if (!comment.getUserId().equals(user.getId())) {
|
||||
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("token.illegal");
|
||||
}
|
||||
List<CommentReply> replies = replyMapper.listAllBySenderId(user.getId());
|
||||
for (int i = 0; i < replies.size(); i++) {
|
||||
// 移出被回复者的回复提醒队列
|
||||
remindQueueMapper.destroyByReplyId(replies.get(i).getId());
|
||||
}
|
||||
replyMapper.deleteByCommentId(cId);
|
||||
super.delete(cId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CommentView> pageByBizId(CommentPage page) {
|
||||
if (page.getOrderMap() == null) {
|
||||
page.setOrderMap(new LinkedHashMap<>());
|
||||
}
|
||||
if (page.getOrderMap().isEmpty()) {
|
||||
page.getOrderMap().put("createdAt", BaseMapper.OrderType.DESC);
|
||||
}
|
||||
List<CommentView> list = mapper.list(page.getBizType(), page.getBizId(), page.getOffset(), page.getLimit(), page.getOrderMap());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
CommentView comment = list.get(i);
|
||||
if (TimiJava.isNotEmpty(comment.getUserId())) {
|
||||
comment.setUser(userService.view(comment.getUserId()));
|
||||
}
|
||||
List<CommentReplyView> replies = comment.getReplies();
|
||||
for (int j = 0; j < replies.size(); j++) {
|
||||
CommentReplyView reply = replies.get(j);
|
||||
if (TimiJava.isNotEmpty(reply.getSenderId())) {
|
||||
reply.setSender(userService.view(reply.getSenderId()));
|
||||
}
|
||||
if (TimiJava.isNotEmpty(reply.getReceiverId())) {
|
||||
reply.setReceiver(userService.view(reply.getReceiverId()));
|
||||
}
|
||||
{
|
||||
// 移除被回复者的回复提醒队列
|
||||
CommentReply example = new CommentReply();
|
||||
example.setSenderId(user.getId());
|
||||
List<CommentReply> replies = replyMapper.selectAllByExample(example);
|
||||
for (CommentReply reply : replies) {
|
||||
CommentRemindQueue destroyRemindExample = new CommentRemindQueue();
|
||||
destroyRemindExample.setReplyId(reply.getReplyId());
|
||||
remindQueueMapper.destroyAllByExample(destroyRemindExample);
|
||||
}
|
||||
}
|
||||
PageResult<CommentView> result = new PageResult<>();
|
||||
result.setList(list);
|
||||
result.setTotal(mapper.count(page.getBizType(), page.getBizId()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CommentView> pageByUserId(UserCommentPage page) {
|
||||
if (page.getOrderMap() == null) {
|
||||
page.setOrderMap(new LinkedHashMap<>());
|
||||
{
|
||||
// 删除回复
|
||||
CommentReply example = new CommentReply();
|
||||
example.setCommentId(commentId);
|
||||
replyMapper.deleteAllByExample(example);
|
||||
}
|
||||
if (page.getOrderMap().isEmpty()) {
|
||||
page.getOrderMap().put("createdAt", BaseMapper.OrderType.DESC);
|
||||
}
|
||||
PageResult<CommentView> result = new PageResult<>();
|
||||
result.setList(mapper.listByUserId(page.getUserId(), page.getOffset(), page.getLimit(), page.getOrderMap()));
|
||||
result.setTotal(mapper.countByUserId(page.getUserId()));
|
||||
|
||||
for (int i = 0; i < result.getList().size(); i++) {
|
||||
CommentView view = result.getList().get(i);
|
||||
switch (view.getBizType()) {
|
||||
case ARTICLE -> {
|
||||
Article article = articleService.get(view.getBizId());
|
||||
article.setData(null);
|
||||
article.setExtendData(null);
|
||||
view.setArticle(article);
|
||||
}
|
||||
// case GIT_ISSUE, GIT_MERGE -> view.setRepository(repositoryService.get(view.getBizId()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
// 删除评论
|
||||
super.delete(commentId);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -1,11 +1,9 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.blog.util.UserToken;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
import com.imyeyu.api.modules.common.entity.EmailQueue;
|
||||
import com.imyeyu.api.modules.common.entity.User;
|
||||
import com.imyeyu.api.modules.common.entity.UserConfig;
|
||||
@@ -29,7 +27,11 @@ import com.imyeyu.api.modules.common.vo.user.UserView;
|
||||
import com.imyeyu.api.modules.git.entity.Developer;
|
||||
import com.imyeyu.api.modules.git.service.DeveloperService;
|
||||
import com.imyeyu.api.modules.minecraft.service.PlayerService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.bean.Logic;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
@@ -360,8 +362,13 @@ public class UserServiceImplement extends AbstractEntityService<User, Long> impl
|
||||
}
|
||||
// 删除评论
|
||||
commentMapper.deleteByUserId(user.getId());
|
||||
// 删除回复
|
||||
commentReplyMapper.deleteByUserId(user.getId());
|
||||
{
|
||||
// 删除回复
|
||||
CommentReply example = new CommentReply();
|
||||
example.setSenderId(user.getId());
|
||||
example.setReceiverId(user.getId());
|
||||
commentReplyMapper.deleteAllByExample(example, Logic.OR);
|
||||
}
|
||||
// 删除账号
|
||||
delete(user.getId());
|
||||
// 清除登录会话
|
||||
|
||||
Reference in New Issue
Block a user