fix comment page
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package com.imyeyu.api.modules.blog.entity;
|
||||
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyView;
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||
import com.imyeyu.spring.annotation.table.Id;
|
||||
import lombok.Data;
|
||||
@ -32,5 +32,5 @@ public class CommentRemindQueue {
|
||||
|
||||
private Long replyId;
|
||||
|
||||
private CommentReplyView reply;
|
||||
private CommentReply reply;
|
||||
}
|
||||
|
||||
@ -37,12 +37,16 @@ public class CommentRemindQueueServiceImplement extends AbstractEntityService<Co
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void destroyByUserId(Long userId) {
|
||||
mapper.destroyByUserId(userId);
|
||||
CommentRemindQueue example = new CommentRemindQueue();
|
||||
example.setUserId(userId);
|
||||
mapper.deleteAllByExample(example);
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void destroyByReplyId(Long replyId) {
|
||||
mapper.destroyByReplyId(replyId);
|
||||
CommentRemindQueue example = new CommentRemindQueue();
|
||||
example.setReplyId(replyId);
|
||||
mapper.destroyAllByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,13 +8,10 @@ import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
import com.imyeyu.api.modules.common.service.CommentReplyService;
|
||||
import com.imyeyu.api.modules.common.service.CommentService;
|
||||
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.vo.issue.CommentPage;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import com.imyeyu.spring.bean.CaptchaData;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -51,8 +48,8 @@ public class CommentController {
|
||||
|
||||
@RequestRateLimit
|
||||
@PostMapping("/list")
|
||||
public PageResult<CommentView> list(@Valid @RequestBody CommentPage commentPage) {
|
||||
return service.pageByBizId(commentPage);
|
||||
public PageResult<Comment> list(@Valid @RequestBody Page<Comment> page) {
|
||||
return service.page(page);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,9 +74,14 @@ public class CommentController {
|
||||
*/
|
||||
@RequestRateLimit
|
||||
@RequestMapping("/reply/list")
|
||||
public PageResult<CommentReplyView> pageCommentReplies(@Valid @RequestBody CommentReplyPage page) {
|
||||
public PageResult<CommentReply> pageReplies(@Valid @RequestBody Page<CommentReply> page) {
|
||||
// 通用接口,只允许查询评论的回复
|
||||
page.setBizType(CommentReplyPage.BizType.COMMENT);
|
||||
return replyService.pageByBizType(page);
|
||||
CommentReply example = new CommentReply();
|
||||
if (page.getEqualsExample() != null) {
|
||||
example.setCommentId(page.getEqualsExample().getCommentId());
|
||||
}
|
||||
page.setEqualsExample(example);
|
||||
page.setLikesExample(null);
|
||||
return replyService.page(page);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,12 +11,14 @@ import com.imyeyu.api.modules.common.entity.Task;
|
||||
import com.imyeyu.api.modules.common.entity.Template;
|
||||
import com.imyeyu.api.modules.common.entity.Version;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.common.service.ClipboardService;
|
||||
import com.imyeyu.api.modules.common.service.FeedbackService;
|
||||
import com.imyeyu.api.modules.common.service.SettingService;
|
||||
import com.imyeyu.api.modules.common.service.TaskService;
|
||||
import com.imyeyu.api.modules.common.service.TempFileService;
|
||||
import com.imyeyu.api.modules.common.service.TemplateService;
|
||||
import com.imyeyu.api.modules.common.service.VersionService;
|
||||
import com.imyeyu.api.modules.common.vo.ClipboardRequest;
|
||||
import com.imyeyu.api.modules.common.vo.FeedbackRequest;
|
||||
import com.imyeyu.api.modules.common.vo.TempFileResponse;
|
||||
import com.imyeyu.api.modules.system.util.ResourceHandler;
|
||||
@ -45,6 +47,7 @@ import lombok.Cleanup;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tika.Tika;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsResource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -55,6 +58,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@ -89,6 +93,7 @@ public class CommonController {
|
||||
private final TemplateService templateService;
|
||||
private final TempFileService tempFileService;
|
||||
private final AttachmentService attachmentService;
|
||||
private final ClipboardService clipboardService;
|
||||
|
||||
private final Gson gson;
|
||||
private final Yaml yaml;
|
||||
@ -102,6 +107,45 @@ public class CommonController {
|
||||
return "IT WORKING! " + TimiSpring.getRequestIP();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取共享剪切板内容
|
||||
*
|
||||
* @param id 会话 ID
|
||||
* @return 剪切板内容
|
||||
*/
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@GetMapping("/clipboard/{id}")
|
||||
public String clipboardGet(@Valid @NotBlank @PathVariable("id") String id) {
|
||||
return clipboardService.getContent(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置共享剪切板内容
|
||||
*
|
||||
* @param id 会话 ID
|
||||
* @param request 请求内容
|
||||
*/
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@PostMapping("/clipboard/{id}")
|
||||
public void clipboardSet(@Valid @NotBlank @PathVariable("id") String id, @Valid @RequestBody ClipboardRequest request) {
|
||||
clipboardService.setContent(id, request.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅共享剪切板实时更新
|
||||
*
|
||||
* @param id 会话 ID
|
||||
* @return SSE 发射器
|
||||
*/
|
||||
@AOPLog
|
||||
@IgnoreGlobalReturn
|
||||
@GetMapping(value = "/clipboard/stream/{id}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter clipboardStream(@Valid @NotBlank @PathVariable("id") String id) {
|
||||
return clipboardService.subscribe(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.controller;
|
||||
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.api.annotation.CaptchaValid;
|
||||
import com.imyeyu.api.annotation.EnableSetting;
|
||||
import com.imyeyu.api.bean.CaptchaFrom;
|
||||
import com.imyeyu.api.modules.common.bean.SettingKey;
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
import com.imyeyu.api.modules.common.entity.UserConfig;
|
||||
import com.imyeyu.api.modules.common.entity.UserPrivacy;
|
||||
@ -15,10 +14,6 @@ import com.imyeyu.api.modules.common.service.UserConfigService;
|
||||
import com.imyeyu.api.modules.common.service.UserPrivacyService;
|
||||
import com.imyeyu.api.modules.common.service.UserProfileService;
|
||||
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.common.vo.comment.UserCommentPage;
|
||||
import com.imyeyu.api.modules.common.vo.user.EmailVerifyCallbackRequest;
|
||||
import com.imyeyu.api.modules.common.vo.user.LoginRequest;
|
||||
import com.imyeyu.api.modules.common.vo.user.LoginResponse;
|
||||
@ -27,11 +22,14 @@ import com.imyeyu.api.modules.common.vo.user.UpdatePasswordByKeyRequest;
|
||||
import com.imyeyu.api.modules.common.vo.user.UpdatePasswordRequest;
|
||||
import com.imyeyu.api.modules.common.vo.user.UserRequest;
|
||||
import com.imyeyu.api.modules.common.vo.user.UserView;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import com.imyeyu.spring.annotation.RequestSingleParam;
|
||||
import com.imyeyu.spring.annotation.RequiredToken;
|
||||
import com.imyeyu.spring.bean.CaptchaData;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.utils.Time;
|
||||
import jakarta.validation.Valid;
|
||||
@ -266,9 +264,11 @@ public class UserController implements TimiJava {
|
||||
@RequiredToken
|
||||
@RequestRateLimit
|
||||
@PostMapping("/comment/list")
|
||||
public PageResult<CommentView> listComment(@Valid @RequestBody UserCommentPage page) {
|
||||
page.setUserId(service.getLoginUser().getId());
|
||||
return commentService.pageByUserId(page);
|
||||
public PageResult<Comment> listComment(@Valid @RequestBody Page<Comment> page) {
|
||||
Comment example = new Comment();
|
||||
example.setUserId(service.getLoginUser().getId());
|
||||
page.setEqualsExample(example);
|
||||
return commentService.page(page);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@ -287,9 +287,11 @@ public class UserController implements TimiJava {
|
||||
@RequiredToken
|
||||
@RequestRateLimit
|
||||
@PostMapping("/comment/reply/list")
|
||||
public PageResult<CommentReplyView> listCommentReply(@Valid @RequestBody CommentReplyPage page) {
|
||||
page.setBizId(service.getLoginUser().getId());
|
||||
return commentReplyService.pageByBizType(page);
|
||||
public PageResult<CommentReply> listCommentReply(@Valid @RequestBody Page<CommentReply> page) {
|
||||
CommentReply example = new CommentReply();
|
||||
example.setReceiverId(service.getLoginUser().getId());
|
||||
page.setEqualsExample(example);
|
||||
return commentReplyService.page(page);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
|
||||
@ -1,5 +1,14 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.api.modules.blog.entity.Article;
|
||||
import com.imyeyu.api.modules.blog.service.implement.ArticleServiceImplement;
|
||||
import com.imyeyu.api.modules.common.bean.CommentSupport;
|
||||
import com.imyeyu.api.modules.common.vo.user.UserView;
|
||||
import com.imyeyu.api.modules.git.bean.gitea.Repository;
|
||||
import com.imyeyu.api.modules.git.service.implement.IssueServiceImplement;
|
||||
import com.imyeyu.api.modules.git.service.implement.MergeServiceImplement;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.Entity;
|
||||
import com.imyeyu.spring.service.GettableService;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -7,11 +16,8 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import com.imyeyu.api.modules.blog.service.implement.ArticleServiceImplement;
|
||||
import com.imyeyu.api.modules.common.bean.CommentSupport;
|
||||
import com.imyeyu.api.modules.git.service.implement.IssueServiceImplement;
|
||||
import com.imyeyu.api.modules.git.service.implement.MergeServiceImplement;
|
||||
import com.imyeyu.spring.entity.Entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论
|
||||
@ -64,4 +70,24 @@ public class Comment extends Entity {
|
||||
|
||||
/** 发送用户 IP */
|
||||
private String ip;
|
||||
|
||||
/** 回复数量 */
|
||||
@Transient
|
||||
private long repliesLength;
|
||||
|
||||
/** 发送用户 */
|
||||
@Transient
|
||||
private UserView user;
|
||||
|
||||
/** 关联文章 */
|
||||
@Transient
|
||||
private Article article;
|
||||
|
||||
/** 关联仓库 */
|
||||
@Transient
|
||||
private Repository repository;
|
||||
|
||||
/** 回复列表 */
|
||||
@Transient
|
||||
private List<CommentReply> replies;
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.api.modules.common.vo.user.UserView;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.Entity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import com.imyeyu.spring.entity.Entity;
|
||||
|
||||
/**
|
||||
* 评论回复
|
||||
@ -42,4 +44,16 @@ public class CommentReply extends Entity {
|
||||
|
||||
/** 被回复用户忽略该回复的时间 */
|
||||
private Long ignoredAt;
|
||||
|
||||
/** 所属评论 */
|
||||
@Transient
|
||||
private Comment comment;
|
||||
|
||||
/** 发送用户 */
|
||||
@Transient
|
||||
private UserView sender;
|
||||
|
||||
/** 回复用户 */
|
||||
@Transient
|
||||
private UserView receiver;
|
||||
}
|
||||
|
||||
@ -1,15 +1,9 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentView;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论
|
||||
*
|
||||
@ -18,30 +12,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface CommentMapper extends BaseMapper<Comment, Long> {
|
||||
|
||||
@Override
|
||||
long countByPage(Page page);
|
||||
|
||||
@Override
|
||||
List<Comment> selectByPage(Page page);
|
||||
|
||||
@Select("SELECT * FROM comment WHERE id = #{id}" + NOT_DELETE)
|
||||
Comment select(Long id);
|
||||
|
||||
@Update("UPDATE comment SET deleted_at = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000) WHERE id = #{id}")
|
||||
@Override
|
||||
void delete(Long id);
|
||||
|
||||
@Select("SELECT COUNT(1) FROM comment WHERE biz_type = #{bizType} AND biz_id = #{bizId}" + NOT_DELETE)
|
||||
long count(Comment.BizType bizType, Long bizId);
|
||||
|
||||
long countAll(Comment.BizType bizType, Long bizId);
|
||||
|
||||
List<CommentView> list(Comment.BizType bizType, Long bizId, Long offset, long limit, LinkedHashMap<String, OrderType> orderMap);
|
||||
|
||||
long countByUserId(Long userId);
|
||||
|
||||
List<CommentView> listByUserId(Long userId, Long offset, long limit, LinkedHashMap<String, OrderType> orderMap);
|
||||
|
||||
@Update("UPDATE comment SET deleted_at = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000) WHERE user_id = #{userId} ")
|
||||
void deleteByUserId(Long userId);
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.blog.entity.CommentRemindQueue;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,10 +16,4 @@ public interface CommentRemindQueueMapper extends BaseMapper<CommentRemindQueue,
|
||||
|
||||
@Select("SELECT * FROM comment_remind_queue WHERE user_id = #{userId}")
|
||||
List<CommentRemindQueue> listByUserId(Long userId);
|
||||
|
||||
@Delete("DELETE FROM comment_remind_queue WHERE user_id = #{userId}")
|
||||
void destroyByUserId(Long userId);
|
||||
|
||||
@Delete("DELETE FROM comment_remind_queue WHERE reply_id = #{replyId}")
|
||||
void destroyByReplyId(Long replyId);
|
||||
}
|
||||
|
||||
@ -2,13 +2,7 @@ package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
|
||||
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.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论回复
|
||||
@ -17,19 +11,4 @@ import java.util.List;
|
||||
* @since 2021-08-24 10:36
|
||||
*/
|
||||
public interface CommentReplyMapper extends BaseMapper<CommentReply, Long> {
|
||||
|
||||
@Select("SELECT * FROM comment_reply WHERE sender_id = #{senderId}" + NOT_DELETE)
|
||||
List<CommentReply> listAllBySenderId(Long senderId);
|
||||
|
||||
@Select("SELECT COUNT(1) FROM comment_reply WHERE ${bizType.column} = #{bizId}" + NOT_DELETE)
|
||||
long countByBizType(CommentReplyPage.BizType bizType, Long bizId);
|
||||
|
||||
@Select("SELECT * FROM comment_reply WHERE ${bizType.column} = #{bizId} AND ignored_at IS NULL" + NOT_DELETE + PAGE)
|
||||
List<CommentReplyView> listByBizType(CommentReplyPage.BizType bizType, Long bizId, Long offset, long limit);
|
||||
|
||||
@Update("UPDATE comment_reply SET deleted_at = " + UNIX_TIME + " WHERE sender_id = #{userId} OR receiver_id = #{userId}")
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
@Update("UPDATE comment_reply SET deleted_at = " + UNIX_TIME + " WHERE comment_id = #{commentId}")
|
||||
void deleteByCommentId(Long commentId);
|
||||
}
|
||||
|
||||
@ -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> {
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
// 清除登录会话
|
||||
|
||||
@ -17,7 +17,6 @@ import com.imyeyu.api.modules.common.entity.User;
|
||||
import com.imyeyu.api.modules.common.service.CommentReplyService;
|
||||
import com.imyeyu.api.modules.common.service.EmailQueueService;
|
||||
import com.imyeyu.api.modules.common.service.UserService;
|
||||
import com.imyeyu.api.modules.common.vo.comment.CommentReplyView;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
import com.imyeyu.utils.Text;
|
||||
import com.imyeyu.utils.Time;
|
||||
@ -175,9 +174,7 @@ public class EmailTask implements TimiJava {
|
||||
for (CommentRemindQueue remind : reminds) {
|
||||
// 回复
|
||||
CommentReply reply = commentReplyService.get(remind.getReplyId());
|
||||
CommentReplyView replyView = new CommentReplyView();
|
||||
BeanUtils.copyProperties(reply, replyView);
|
||||
remind.setReply(replyView);
|
||||
remind.setReply(reply);
|
||||
if (TimiJava.isNotEmpty(remind.getReply().getSenderId())) {
|
||||
// 发送者
|
||||
remind.getReply().setSender(userService.view(remind.getReply().getSenderId()));
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
package com.imyeyu.api.modules.common.vo.comment;
|
||||
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2023-07-15 09:03
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommentReplyPage extends Page {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2025-04-17 23:29
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BizType {
|
||||
|
||||
COMMENT("comment_id"),
|
||||
|
||||
SENDER("sender_id"),
|
||||
|
||||
RECEIVER("receiver_id");
|
||||
|
||||
final String column;
|
||||
}
|
||||
|
||||
private BizType bizType;
|
||||
|
||||
@Min(1)
|
||||
private Long bizId;
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package com.imyeyu.api.modules.common.vo.comment;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.CommentReply;
|
||||
import com.imyeyu.api.modules.common.vo.user.UserView;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2024-03-05 17:48
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommentReplyView extends CommentReply {
|
||||
|
||||
/** 所属评论 */
|
||||
@Transient
|
||||
private CommentView comment;
|
||||
|
||||
/** 发送用户 */
|
||||
@Transient
|
||||
private UserView sender;
|
||||
|
||||
/** 回复用户 */
|
||||
@Transient
|
||||
private UserView receiver;
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package com.imyeyu.api.modules.common.vo.comment;
|
||||
|
||||
import com.imyeyu.api.modules.blog.entity.Article;
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.api.modules.common.vo.user.UserView;
|
||||
import com.imyeyu.api.modules.git.bean.gitea.Repository;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2024-02-29 16:37
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommentView extends Comment {
|
||||
|
||||
/** 回复数量 */
|
||||
private int repliesLength;
|
||||
|
||||
/** 发送用户 */
|
||||
private UserView user;
|
||||
|
||||
/** 关联文章 */
|
||||
private Article article;
|
||||
|
||||
/** 关联仓库 */
|
||||
private Repository repository;
|
||||
|
||||
/** 回复列表 */
|
||||
private List<CommentReplyView> replies;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package com.imyeyu.api.modules.common.vo.comment;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2023-07-15 14:13
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UserCommentPage extends Page {
|
||||
|
||||
@Min(1)
|
||||
private Long userId;
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package com.imyeyu.api.modules.git.vo.issue;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Comment;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2024-02-28 14:27
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommentPage extends Page<Comment> {
|
||||
|
||||
private Comment.BizType bizType;
|
||||
|
||||
private long bizId;
|
||||
}
|
||||
@ -2,101 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.imyeyu.api.modules.common.mapper.CommentMapper">
|
||||
<sql id="table">comment</sql>
|
||||
<!-- 主评论 -->
|
||||
<select id="selectByPage" resultMap="selectResult">
|
||||
SELECT
|
||||
-- 主评论
|
||||
comment.id,
|
||||
comment.biz_type,
|
||||
comment.biz_id,
|
||||
comment.user_id,
|
||||
comment.nick,
|
||||
comment.content,
|
||||
comment.created_at,
|
||||
|
||||
-- 回复数量
|
||||
reply_count.reply_length,
|
||||
|
||||
-- 回复
|
||||
reply.id AS reply_id,
|
||||
reply.comment_id,
|
||||
reply.sender_id,
|
||||
reply.sender_nick,
|
||||
reply.receiver_id,
|
||||
reply.receiver_nick,
|
||||
reply.content AS reply_content,
|
||||
reply.created_at AS reply_created_at
|
||||
FROM (
|
||||
-- 查询主评论
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
<include refid="table" />
|
||||
WHERE
|
||||
biz_type = #{bizType}
|
||||
AND biz_id = #{bizId}
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY
|
||||
created_at ${orderMap.createdAt}
|
||||
LIMIT
|
||||
#{offset}, #{limit}
|
||||
) AS comment
|
||||
LEFT JOIN (
|
||||
-- 查询前 6 条回复(时间升序)
|
||||
SELECT
|
||||
*
|
||||
FROM (
|
||||
SELECT
|
||||
comment_reply.*,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY comment_id
|
||||
ORDER BY created_at ASC
|
||||
) AS seq
|
||||
FROM
|
||||
comment_reply
|
||||
WHERE
|
||||
deleted_at IS NULL
|
||||
) AS reply
|
||||
WHERE
|
||||
seq < 7
|
||||
) AS reply
|
||||
ON
|
||||
reply.comment_id = comment.id
|
||||
LEFT JOIN(
|
||||
-- 统计回复总数
|
||||
SELECT
|
||||
comment_id AS id,
|
||||
COUNT(*) AS reply_length
|
||||
FROM
|
||||
comment_reply
|
||||
WHERE
|
||||
deleted_at IS NULL
|
||||
GROUP BY
|
||||
comment_id
|
||||
) AS reply_count
|
||||
ON
|
||||
reply_count.id = comment.id
|
||||
</select>
|
||||
<resultMap id="selectResult" type="com.imyeyu.api.modules.common.vo.comment.CommentView">
|
||||
<id property="id" column="id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="nick" column="nick" />
|
||||
<result property="content" column="content" />
|
||||
<result property="repliesLength" column="reply_length" />
|
||||
<result property="createdAt" column="created_at" />
|
||||
<!-- 关联回复 -->
|
||||
<collection property="replies" ofType="com.imyeyu.api.modules.common.vo.comment.CommentReplyView">
|
||||
<id property="id" column="reply_id" />
|
||||
<result property="commentId" column="comment_id" />
|
||||
<result property="senderId" column="sender_id" />
|
||||
<result property="senderNick" column="sender_nick" />
|
||||
<result property="receiverId" column="receiver_id" />
|
||||
<result property="receiverNick" column="receiver_nick" />
|
||||
<result property="content" column="reply_content" />
|
||||
<result property="createdAt" column="reply_created_at" />
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="countByPage" resultType="long">
|
||||
<select id="countAll" resultType="long">
|
||||
SELECT
|
||||
SUM(result.total_comment + result.total_reply)
|
||||
FROM (
|
||||
@ -116,28 +22,4 @@
|
||||
AND comment_reply.deleted_at IS NULL
|
||||
) AS result
|
||||
</select>
|
||||
|
||||
<sql id="byUserIdCondition">
|
||||
FROM
|
||||
<include refid="table" />
|
||||
WHERE
|
||||
user_id = #{userId}
|
||||
AND deleted_at IS NULL
|
||||
</sql>
|
||||
<select id="countByUserId" resultType="long">
|
||||
SELECT COUNT(1) <include refid="byUserIdCondition" />
|
||||
</select>
|
||||
<select id="listByUserId" resultType="com.imyeyu.api.modules.common.vo.comment.CommentView">
|
||||
SELECT
|
||||
id,
|
||||
biz_type,
|
||||
biz_id,
|
||||
content,
|
||||
created_at
|
||||
<include refid="byUserIdCondition" />
|
||||
ORDER BY
|
||||
created_at ${orderMap.createdAt}
|
||||
LIMIT
|
||||
#{offset}, #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user