完成笔记点赞收藏优化
This commit is contained in:
parent
7f80c71c5a
commit
599696d68c
@ -217,7 +217,7 @@ public class AuthApi {
|
||||
Author follow = authorService.getById(followId);
|
||||
Boolean isUp = Boolean.FALSE;
|
||||
//查看在不在点赞列表
|
||||
UpNotes upNotes = upNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId);
|
||||
UpNotes upNotes = upNotesService.selectOneByFollowId(noteDto.getNoteId(), followId);
|
||||
//不在证明是点赞
|
||||
if(upNotes==null){
|
||||
upNotes = new UpNotes();
|
||||
@ -245,7 +245,7 @@ public class AuthApi {
|
||||
Author follow = authorService.getById(followId);
|
||||
Boolean isStar = Boolean.FALSE;
|
||||
//查看在不在点赞列表
|
||||
StarNotes starNotes = starNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId);
|
||||
StarNotes starNotes = starNotesService.selectOneByFollowId(noteDto.getNoteId(), followId);
|
||||
//不在证明是点赞
|
||||
if(starNotes==null){
|
||||
starNotes = new StarNotes();
|
||||
@ -440,7 +440,7 @@ public class AuthApi {
|
||||
Author follow = authorService.getById(followId);
|
||||
Boolean isUp = Boolean.FALSE;
|
||||
//查看在不在点赞列表
|
||||
UpReplys upReplys = upReplysService.selectOneByFollowId(replyDto.getReplyId(),replyDto.getAuthorId(), followId);
|
||||
UpReplys upReplys = upReplysService.selectOneByFollowId(replyDto.getReplyId(), followId);
|
||||
//不在证明是点赞
|
||||
if(upReplys==null){
|
||||
upReplys = new UpReplys();
|
||||
|
@ -32,9 +32,26 @@
|
||||
<select id="selectNotePage" resultType="com.dd.admin.business.note.domain.NoteVo">
|
||||
SELECT
|
||||
a.*,
|
||||
COALESCE(COUNT(b.note_id), 0) AS starCount,
|
||||
COALESCE(COUNT(c.note_id), 0) AS upCount
|
||||
<if test="noteDto.followId != null and noteDto.followId != ''">
|
||||
(SELECT
|
||||
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!= ''">
|
||||
,CASE WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM business_star_notes sub_b
|
||||
@ -53,26 +70,40 @@
|
||||
LEFT JOIN
|
||||
business_star_notes b ON a.note_id = b.note_id
|
||||
LEFT JOIN
|
||||
business_up_notes c ON a.note_id = c.note_id where a.deleted = 0
|
||||
<if test="noteDto.authorId != null and noteDto.authorId != ''">
|
||||
and a.AUTHOR_ID = #{noteDto.authorId}
|
||||
business_up_notes c ON a.note_id = c.note_id
|
||||
WHERE
|
||||
a.deleted = 0
|
||||
<if test="noteDto.authorId!= null and noteDto.authorId!= ''">
|
||||
AND a.AUTHOR_ID = #{noteDto.authorId}
|
||||
</if>
|
||||
<if test="noteDto.authorIds != null and noteDto.authorIds != ''">
|
||||
and a.AUTHOR_ID in ${noteDto.authorIds}
|
||||
<if test="noteDto.authorIds!= null and noteDto.authorIds!= ''">
|
||||
AND a.AUTHOR_ID IN ${noteDto.authorIds}
|
||||
</if>
|
||||
<if test="noteDto.ipRealAddress != null and noteDto.ipRealAddress != ''">
|
||||
and a.IP_REAL_ADDRESS = #{noteDto.ipRealAddress}
|
||||
<if test="noteDto.ipRealAddress!= null and noteDto.ipRealAddress!= ''">
|
||||
AND a.IP_REAL_ADDRESS = #{noteDto.ipRealAddress}
|
||||
</if>
|
||||
<if test="noteDto.myStarById != null and noteDto.myStarById != ''">
|
||||
and b.follow_id = #{noteDto.myStarById}
|
||||
<if test="noteDto.myStarById!= null and noteDto.myStarById!= ''">
|
||||
AND b.follow_id = #{noteDto.myStarById}
|
||||
</if>
|
||||
<if test="noteDto.myUpById != null and noteDto.myUpById != ''">
|
||||
and c.follow_id = #{noteDto.myUpById}
|
||||
<if test="noteDto.myUpById!= null and noteDto.myUpById!= ''">
|
||||
AND c.follow_id = #{noteDto.myUpById}
|
||||
</if>
|
||||
GROUP BY
|
||||
a.note_id
|
||||
ORDER BY
|
||||
a.create_time DESC
|
||||
<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
|
||||
a.create_time DESC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="selectNoteList" resultType="com.dd.admin.business.note.domain.NoteVo">
|
||||
@ -96,8 +127,25 @@
|
||||
parameterType="java.lang.String">
|
||||
SELECT
|
||||
a.*,
|
||||
COALESCE(COUNT(b.note_id), 0) AS starCount,
|
||||
COALESCE(COUNT(c.note_id), 0) AS upCount
|
||||
(SELECT
|
||||
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
|
||||
<if test="noteDto.followId != null and noteDto.followId != ''">
|
||||
,CASE WHEN EXISTS (
|
||||
@ -134,6 +182,8 @@
|
||||
GROUP BY
|
||||
a.note_id
|
||||
ORDER BY
|
||||
a.create_time DESC limit 1
|
||||
a.create_time DESC
|
||||
|
||||
limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -39,7 +39,7 @@ public class Reply implements Serializable {
|
||||
private String noteId;
|
||||
|
||||
@ApiModelProperty(value = "笔记标题")
|
||||
@TableField("NOTE_TITILE")
|
||||
@TableField("NOTE_TITLE")
|
||||
private String noteTitle;
|
||||
|
||||
@ApiModelProperty(value = "作者id")
|
||||
|
@ -27,7 +27,7 @@ public interface StarNotesService extends IService<StarNotes> {
|
||||
//收藏笔记列表-列表
|
||||
List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto);
|
||||
|
||||
StarNotes selectOneByFollowId(String noteId, String authorId, String followId);
|
||||
StarNotes selectOneByFollowId(String noteId, String followId);
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ public class StarNotesServiceImpl extends ServiceImpl<StarNotesMapper, StarNotes
|
||||
}
|
||||
|
||||
@Override
|
||||
public StarNotes selectOneByFollowId(String noteId, String authorId, String followId) {
|
||||
public StarNotes selectOneByFollowId(String noteId, String followId) {
|
||||
LambdaQueryWrapper<StarNotes> queryWrapper = new LambdaQueryWrapper();
|
||||
queryWrapper.eq(StarNotes::getNoteId,noteId);
|
||||
queryWrapper.eq(StarNotes::getAuthorId,authorId);
|
||||
queryWrapper.eq(StarNotes::getFollowId,followId);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ public interface UpNotesService extends IService<UpNotes> {
|
||||
|
||||
List<UpNotesVo> selectAllUpCount();
|
||||
|
||||
UpNotes selectOneByFollowId(String noteId,String authorId,String followId);
|
||||
UpNotes selectOneByFollowId(String noteId ,String followId);
|
||||
|
||||
}
|
||||
|
@ -41,10 +41,9 @@ public class UpNotesServiceImpl extends ServiceImpl<UpNotesMapper, UpNotes> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpNotes selectOneByFollowId(String noteId,String authorId, String followId) {
|
||||
public UpNotes selectOneByFollowId(String noteId, String followId) {
|
||||
LambdaQueryWrapper<UpNotes> queryWrapper = new LambdaQueryWrapper();
|
||||
queryWrapper.eq(UpNotes::getNoteId,noteId);
|
||||
queryWrapper.eq(UpNotes::getAuthorId,authorId);
|
||||
queryWrapper.eq(UpNotes::getFollowId,followId);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ public interface UpReplysService extends IService<UpReplys> {
|
||||
//笔记点赞表-列表
|
||||
List<UpReplysVo> selectUpReplysList(UpReplysDto upReplysDto);
|
||||
|
||||
UpReplys selectOneByFollowId(String replyId,String authorId,String followId);
|
||||
UpReplys selectOneByFollowId(String replyId,String followId);
|
||||
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ public class UpReplysServiceImpl extends ServiceImpl<UpReplysMapper, UpReplys> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpReplys selectOneByFollowId(String replyId, String authorId, String followId) {
|
||||
public UpReplys selectOneByFollowId(String replyId, String followId) {
|
||||
LambdaQueryWrapper<UpReplys> queryWrapper = new LambdaQueryWrapper();
|
||||
queryWrapper.eq(UpReplys::getReplyId,replyId);
|
||||
queryWrapper.eq(UpReplys::getAuthorId,authorId);
|
||||
queryWrapper.eq(UpReplys::getFollowId,followId);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user