完成笔记点赞收藏优化

This commit is contained in:
wangxulei 2024-12-26 11:04:27 +08:00
parent 7f80c71c5a
commit 599696d68c
9 changed files with 79 additions and 32 deletions

View File

@ -217,7 +217,7 @@ public class AuthApi {
Author follow = authorService.getById(followId); Author follow = authorService.getById(followId);
Boolean isUp = Boolean.FALSE; Boolean isUp = Boolean.FALSE;
//查看在不在点赞列表 //查看在不在点赞列表
UpNotes upNotes = upNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId); UpNotes upNotes = upNotesService.selectOneByFollowId(noteDto.getNoteId(), followId);
//不在证明是点赞 //不在证明是点赞
if(upNotes==null){ if(upNotes==null){
upNotes = new UpNotes(); upNotes = new UpNotes();
@ -245,7 +245,7 @@ public class AuthApi {
Author follow = authorService.getById(followId); Author follow = authorService.getById(followId);
Boolean isStar = Boolean.FALSE; Boolean isStar = Boolean.FALSE;
//查看在不在点赞列表 //查看在不在点赞列表
StarNotes starNotes = starNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId); StarNotes starNotes = starNotesService.selectOneByFollowId(noteDto.getNoteId(), followId);
//不在证明是点赞 //不在证明是点赞
if(starNotes==null){ if(starNotes==null){
starNotes = new StarNotes(); starNotes = new StarNotes();
@ -440,7 +440,7 @@ public class AuthApi {
Author follow = authorService.getById(followId); Author follow = authorService.getById(followId);
Boolean isUp = Boolean.FALSE; Boolean isUp = Boolean.FALSE;
//查看在不在点赞列表 //查看在不在点赞列表
UpReplys upReplys = upReplysService.selectOneByFollowId(replyDto.getReplyId(),replyDto.getAuthorId(), followId); UpReplys upReplys = upReplysService.selectOneByFollowId(replyDto.getReplyId(), followId);
//不在证明是点赞 //不在证明是点赞
if(upReplys==null){ if(upReplys==null){
upReplys = new UpReplys(); upReplys = new UpReplys();

View File

@ -32,8 +32,25 @@
<select id="selectNotePage" resultType="com.dd.admin.business.note.domain.NoteVo"> <select id="selectNotePage" resultType="com.dd.admin.business.note.domain.NoteVo">
SELECT SELECT
a.*, a.*,
COALESCE(COUNT(b.note_id), 0) AS starCount, (SELECT
COALESCE(COUNT(c.note_id), 0) AS upCount COALESCE (COUNT(e.note_id), 0)
FROM
business_star_notes e
WHERE
e.note_id = a.note_id
GROUP BY
e.note_id
) AS starCount,
(
SELECT
COALESCE (COUNT(d.note_id), 0)
FROM
business_up_notes d
WHERE
d.note_id = a.note_id
GROUP BY
d.note_id
) AS upCount
<if test="noteDto.followId!= null and noteDto.followId!= ''"> <if test="noteDto.followId!= null and noteDto.followId!= ''">
,CASE WHEN EXISTS ( ,CASE WHEN EXISTS (
SELECT 1 SELECT 1
@ -53,26 +70,40 @@
LEFT JOIN LEFT JOIN
business_star_notes b ON a.note_id = b.note_id business_star_notes b ON a.note_id = b.note_id
LEFT JOIN LEFT JOIN
business_up_notes c ON a.note_id = c.note_id where a.deleted = 0 business_up_notes c ON a.note_id = c.note_id
WHERE
a.deleted = 0
<if test="noteDto.authorId!= null and noteDto.authorId!= ''"> <if test="noteDto.authorId!= null and noteDto.authorId!= ''">
and a.AUTHOR_ID = #{noteDto.authorId} AND a.AUTHOR_ID = #{noteDto.authorId}
</if> </if>
<if test="noteDto.authorIds!= null and noteDto.authorIds!= ''"> <if test="noteDto.authorIds!= null and noteDto.authorIds!= ''">
and a.AUTHOR_ID in ${noteDto.authorIds} AND a.AUTHOR_ID IN ${noteDto.authorIds}
</if> </if>
<if test="noteDto.ipRealAddress!= null and noteDto.ipRealAddress!= ''"> <if test="noteDto.ipRealAddress!= null and noteDto.ipRealAddress!= ''">
and a.IP_REAL_ADDRESS = #{noteDto.ipRealAddress} AND a.IP_REAL_ADDRESS = #{noteDto.ipRealAddress}
</if> </if>
<if test="noteDto.myStarById!= null and noteDto.myStarById!= ''"> <if test="noteDto.myStarById!= null and noteDto.myStarById!= ''">
and b.follow_id = #{noteDto.myStarById} AND b.follow_id = #{noteDto.myStarById}
</if> </if>
<if test="noteDto.myUpById!= null and noteDto.myUpById!= ''"> <if test="noteDto.myUpById!= null and noteDto.myUpById!= ''">
and c.follow_id = #{noteDto.myUpById} AND c.follow_id = #{noteDto.myUpById}
</if> </if>
GROUP BY GROUP BY
a.note_id a.note_id
<choose>
<when test="noteDto.myUpById!= null and noteDto.myUpById!= ''">
ORDER BY
c.create_time DESC
</when>
<when test="noteDto.myStarById!= null and noteDto.myStarById!= ''">
ORDER BY
b.create_time DESC
</when>
<otherwise>
ORDER BY ORDER BY
a.create_time DESC a.create_time DESC
</otherwise>
</choose>
</select> </select>
<select id="selectNoteList" resultType="com.dd.admin.business.note.domain.NoteVo"> <select id="selectNoteList" resultType="com.dd.admin.business.note.domain.NoteVo">
@ -96,8 +127,25 @@
parameterType="java.lang.String"> parameterType="java.lang.String">
SELECT SELECT
a.*, a.*,
COALESCE(COUNT(b.note_id), 0) AS starCount, (SELECT
COALESCE(COUNT(c.note_id), 0) AS upCount COALESCE (COUNT(e.note_id), 0)
FROM
business_star_notes e
WHERE
e.note_id = a.note_id
GROUP BY
e.note_id
) AS starCount,
(
SELECT
COALESCE (COUNT(d.note_id), 0)
FROM
business_up_notes d
WHERE
d.note_id = a.note_id
GROUP BY
d.note_id
) AS upCount
-- 使用 CASE WHEN 语句判断是否存在当前用户(通过传入的 followId对笔记的收藏记录有则为 true否则为 false -- 使用 CASE WHEN 语句判断是否存在当前用户(通过传入的 followId对笔记的收藏记录有则为 true否则为 false
<if test="noteDto.followId != null and noteDto.followId != ''"> <if test="noteDto.followId != null and noteDto.followId != ''">
,CASE WHEN EXISTS ( ,CASE WHEN EXISTS (
@ -134,6 +182,8 @@
GROUP BY GROUP BY
a.note_id a.note_id
ORDER BY ORDER BY
a.create_time DESC limit 1 a.create_time DESC
limit 1
</select> </select>
</mapper> </mapper>

View File

@ -39,7 +39,7 @@ public class Reply implements Serializable {
private String noteId; private String noteId;
@ApiModelProperty(value = "笔记标题") @ApiModelProperty(value = "笔记标题")
@TableField("NOTE_TITILE") @TableField("NOTE_TITLE")
private String noteTitle; private String noteTitle;
@ApiModelProperty(value = "作者id") @ApiModelProperty(value = "作者id")

View File

@ -27,7 +27,7 @@ public interface StarNotesService extends IService<StarNotes> {
//收藏笔记列表-列表 //收藏笔记列表-列表
List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto); List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto);
StarNotes selectOneByFollowId(String noteId, String authorId, String followId); StarNotes selectOneByFollowId(String noteId, String followId);
} }

View File

@ -37,10 +37,9 @@ public class StarNotesServiceImpl extends ServiceImpl<StarNotesMapper, StarNotes
} }
@Override @Override
public StarNotes selectOneByFollowId(String noteId, String authorId, String followId) { public StarNotes selectOneByFollowId(String noteId, String followId) {
LambdaQueryWrapper<StarNotes> queryWrapper = new LambdaQueryWrapper(); LambdaQueryWrapper<StarNotes> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(StarNotes::getNoteId,noteId); queryWrapper.eq(StarNotes::getNoteId,noteId);
queryWrapper.eq(StarNotes::getAuthorId,authorId);
queryWrapper.eq(StarNotes::getFollowId,followId); queryWrapper.eq(StarNotes::getFollowId,followId);
return this.getOne(queryWrapper); return this.getOne(queryWrapper);
} }

View File

@ -25,6 +25,6 @@ public interface UpNotesService extends IService<UpNotes> {
List<UpNotesVo> selectAllUpCount(); List<UpNotesVo> selectAllUpCount();
UpNotes selectOneByFollowId(String noteId,String authorId,String followId); UpNotes selectOneByFollowId(String noteId ,String followId);
} }

View File

@ -41,10 +41,9 @@ public class UpNotesServiceImpl extends ServiceImpl<UpNotesMapper, UpNotes> impl
} }
@Override @Override
public UpNotes selectOneByFollowId(String noteId,String authorId, String followId) { public UpNotes selectOneByFollowId(String noteId, String followId) {
LambdaQueryWrapper<UpNotes> queryWrapper = new LambdaQueryWrapper(); LambdaQueryWrapper<UpNotes> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(UpNotes::getNoteId,noteId); queryWrapper.eq(UpNotes::getNoteId,noteId);
queryWrapper.eq(UpNotes::getAuthorId,authorId);
queryWrapper.eq(UpNotes::getFollowId,followId); queryWrapper.eq(UpNotes::getFollowId,followId);
return this.getOne(queryWrapper); return this.getOne(queryWrapper);
} }

View File

@ -23,6 +23,6 @@ public interface UpReplysService extends IService<UpReplys> {
//笔记点赞表-列表 //笔记点赞表-列表
List<UpReplysVo> selectUpReplysList(UpReplysDto upReplysDto); List<UpReplysVo> selectUpReplysList(UpReplysDto upReplysDto);
UpReplys selectOneByFollowId(String replyId,String authorId,String followId); UpReplys selectOneByFollowId(String replyId,String followId);
} }

View File

@ -37,10 +37,9 @@ public class UpReplysServiceImpl extends ServiceImpl<UpReplysMapper, UpReplys> i
} }
@Override @Override
public UpReplys selectOneByFollowId(String replyId, String authorId, String followId) { public UpReplys selectOneByFollowId(String replyId, String followId) {
LambdaQueryWrapper<UpReplys> queryWrapper = new LambdaQueryWrapper(); LambdaQueryWrapper<UpReplys> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(UpReplys::getReplyId,replyId); queryWrapper.eq(UpReplys::getReplyId,replyId);
queryWrapper.eq(UpReplys::getAuthorId,authorId);
queryWrapper.eq(UpReplys::getFollowId,followId); queryWrapper.eq(UpReplys::getFollowId,followId);
return this.getOne(queryWrapper); return this.getOne(queryWrapper);
} }