123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper">
- <select id="queryCommentCount" resultType="java.lang.Integer">
- select d.commentCount + d.replyCount
- from (select c.article_id,
- count(1) as commentCount,
- (select count(1) as replyCount
- from community_article_comment a
- left join community_comment_reply b on a.id = b.comment_id
- where a.article_id = #{articleId}
- and b.is_delete != 1) as replyCount from community_article_comment c
- where c.article_id = #{articleId} and c.is_delete != 1 ) as d
- </select>
- <select id="queryCommentReplyCount" resultType="java.lang.Integer">
- select d.commentCount + d.replyCount from (
- select
- count(1) as commentCount,
- (select
- count(*) count
- from
- community_article_comment a
- left join community_comment_reply b on a.id = b.comment_id
- <where>
- <if test=" articleIds != null and articleIds.size > 0">
- AND article_id in
- <foreach collection="articleIds" item="articleId" index="index" open="(" close=")" separator=",">
- #{articleId}
- </foreach>
- </if>
- and b.id is not null
- and (a.is_delete != 1 or a.is_delete is null)
- and (b.is_delete != 1 or b.is_delete is null)
- </where>
- ) as replyCount
- from community_article_comment c
- <where>
- <if test="articleIds != null and articleIds.size > 0">
- AND c.article_id in
- <foreach collection="articleIds" item="articleId" index="index" open="(" close=")" separator=",">
- #{articleId}
- </foreach>
- </if>
- and (c.is_delete != 1 or c.is_delete is null)
- </where>
- ) as d
- </select>
- <select id="queryCommentReplyCountPerson" resultType="java.lang.Integer">
- select count(1) count from (
- select
- f.user_id,sum(g.commentSum) sum
- from (
- select
- a.user_id,b.id as article_id
- from sys_user a
- left join community_article b on a.user_id = b. user_id
- where (a.status != 1 or a.status is null) and (b.is_delete != 1 or b.is_delete is null)
- and b.id is not null ) f
- left join (select
- d.article_id, d.commentCount + COALESCE(e.replyCount, 0) as commentSum
- from (
- select
- c.article_id,
- count(1) as commentCount
- from community_article_comment c
- where (c.is_delete != 1 or c.is_delete is null)
- group by c.article_id ) d
- left join (select
- a.article_id,count(1) replyCount
- from
- community_article_comment a
- left join community_comment_reply b on a.id = b.comment_id
- where b.id is not null
- and (a.is_delete != 1 or a.is_delete is null)
- and (b.is_delete != 1 or b.is_delete is null)
- group by a.article_id) e
- on d.article_id = e.article_id ) g
- on f.article_id = g.article_id
- group by f.user_id
- <if test="commentSum != null and commentSum > 0">
- HAVING sum <= #{commentSum}
- </if>
- ) h
- </select>
- <select id="queryCommentReplyLikeCount" resultType="java.lang.Integer">
- select sum(count) sum
- from (
- select
- a.user_id, COUNT(1) AS count
- from community_article a
- left join community_like b
- on a.id = b.article_id
- where (a.is_delete != 1 or a.is_delete is null)
- and b.id is not null
- and a.user_id = #{userId}
- GROUP BY a.user_id
- union ALL
- select
- a.user_id, COUNT(1) AS count
- from
- community_article_comment a
- left join community_comment_like b
- on a.id = b.comment_id
- where (a.is_delete != 1 or a.is_delete is null)
- and b.id is not null and EXISTS (select distinct id from community_article z where a.article_id = z.id and (z.is_delete != 1 or z.is_delete is null))
- and a.user_id = #{userId}
- group by a.user_id
- union all
- select
- b.user_id, COUNT(1) AS count
- from
- community_article_comment a
- left join community_comment_reply b on a.id = b.comment_id
- left join community_comment_like c on b.id = c.reply_id
- where
- b.user_id = #{userId}
- and b.id is not null
- and c.id is not null
- and (a.is_delete != 1 or a.is_delete is null)
- and (b.is_delete != 1 or b.is_delete is null)
- and EXISTS (select distinct id from community_article z where a.article_id = z.id and (z.is_delete != 1 or z.is_delete is null))
- group by b.user_id ) AA
- group by user_id
- </select>
- <select id="queryCommentReplyLikeCountPerson" resultType="java.lang.Integer">
- select count(*) from (
- select user_id,sum(count) counts from (
- select
- a.user_id, count(1) count
- from community_article a
- left join community_like b
- on a.id = b.article_id
- where (a.is_delete != 1 or a.is_delete is null)
- and b.id is not null
- GROUP BY a.user_id
- union ALL
- select
- a.user_id,count(1) count
- from
- community_article_comment a
- left join community_comment_like b
- on a.id = b.comment_id
- where (a.is_delete != 1 or a.is_delete is null)
- and b.id is not null and EXISTS (select distinct id from community_article z where a.article_id = z.id and (z.is_delete != 1 or z.is_delete is null))
- group by a.user_id
- union all
- select
- b.user_id,count(1) count
- from
- community_article_comment a
- left join community_comment_reply b on a.id = b.comment_id
- left join community_comment_like c on b.id = c.reply_id
- where
- b.id is not null
- and c.id is not null
- and (a.is_delete != 1 or a.is_delete is null)
- and (b.is_delete != 1 or b.is_delete is null)
- and EXISTS (select distinct id from community_article z where a.article_id = z.id and (z.is_delete != 1 or z.is_delete is null))
- group by b.user_id ) AA
- group by user_id
- <if test="likeSum != null and likeSum > 0">
- HAVING counts <= #{likeSum}
- </if>
- ) BB
- </select>
- <select id="queryComment" resultType="com.ruoyi.generator.domain.Community.CommunityArticleComment">
- SELECT A.id,
- #{articleId} as articleId,
- A.content,
- A.user_id,
- A.image_url,
- A.create_time,
- A.create_by,
- A.update_time,
- A.update_by,
- A.address
- FROM (SELECT id,
- image_url,
- user_id,
- create_time,
- create_by,
- update_time,
- update_by,
- content,
- address
- FROM community_article_comment
- WHERE article_id = #{articleId}
- AND (is_delete != 1 OR is_delete IS NULL)
- UNION ALL
- SELECT id,
- image_url,
- user_id,
- create_time,
- create_by,
- update_time,
- update_by,
- content,
- address
- FROM community_comment_reply
- WHERE comment_id IN (SELECT id
- FROM community_article_comment
- WHERE article_id = #{articleId}
- AND (is_delete != 1 OR is_delete IS NULL))
- AND (is_delete != 1 OR is_delete IS NULL)) AS A
- WHERE A.content LIKE CONCAT('%', #{comment}, '%')
- limit #{offset}
- , #{limit};
- </select>
- <select id="getCommentListByUserId" resultType="com.ruoyi.generator.vo.CommentVo">
- SELECT
- c.id,
- c.joinId,
- c.parentReplyId,
- c.article_id,
- c.user_id,
- c.image_url,
- c.type,
- c.avatar,
- c.nick_name,
- c.create_time,
- c.content,
- c.is_read,
- c.isLike
- FROM (
- SELECT
- cac.id,
- cac.id as joinId,
- cac.id as parentReplyId,
- cac.article_id,
- (SELECT cai.image_url FROM community_article_images cai WHERE cac.article_id = cai.article_id AND (cai.is_delete IS NULL OR cai.is_delete != 1) ORDER BY cai.create_time DESC LIMIT 1) AS image_url,
- '8' AS type,
- su.avatar,
- su.nick_name,
- cac.user_id,
- cac.create_time,
- cac.content,
- cac.is_read,
- CASE WHEN EXISTS (SELECT 1 FROM community_comment_like cck WHERE cck.comment_id = cac.id AND cck.user_id = #{userId} ) THEN TRUE ELSE FALSE END AS isLike
- FROM community_article ca
- LEFT JOIN community_article_comment cac ON ca.id = cac.article_id
- LEFT JOIN sys_user su ON cac.user_id = su.user_id
- WHERE ca.user_id = #{userId}
- AND cac.user_id != #{userId}
- AND cac.id IS NOT NULL
- AND (ca.is_delete IS NULL OR ca.is_delete != 1)
- AND (cac.is_delete IS NULL OR cac.is_delete != 1)
- AND (cac.is_notice != 1 or cac.is_notice is null)
- AND cac.ID not in ( select comment_id from community_article_at caa where peer_id = #{userId})
- UNION ALL
- SELECT
- ccr.id,
- ccr.comment_id as joinId,
- ccr.parent_reply_id as parentReplyId,
- cac.article_id,
- (SELECT cai.image_url FROM community_article_images cai WHERE cac.article_id = cai.article_id AND (cai.is_delete IS NULL OR cai.is_delete != 1) ORDER BY cai.create_time DESC LIMIT 1) AS image_url,
- '9' AS type,
- su.avatar,
- su.nick_name,
- ccr.user_id,
- ccr.create_time,
- ccr.content,
- ccr.is_read,
- CASE WHEN EXISTS (SELECT 1 FROM community_comment_like cck WHERE cck.reply_id = ccr.id AND cck.user_id = #{userId} ) THEN TRUE ELSE FALSE END AS isLike
- FROM community_article_comment cac
- LEFT JOIN community_comment_reply ccr ON cac.id = ccr.comment_id
- LEFT JOIN sys_user su ON ccr.user_id = su.user_id
- WHERE cac.user_id = #{userId}
- AND ccr.user_id != #{userId}
- AND ccr.id IS NOT NULL
- AND (cac.is_delete IS NULL OR cac.is_delete != 1)
- AND (ccr.is_delete IS NULL OR ccr.is_delete != 1)
- AND (ccr.is_notice != 1 or ccr.is_notice is null)
- UNION ALL
- SELECT
- caa.id,
- caa.article_id as joinId,
- null as parentReplyId,
- caa.article_id,
- (SELECT cai.image_url FROM community_article_images cai WHERE caa.article_id = cai.article_id AND (cai.is_delete IS NULL OR cai.is_delete != 1) ORDER BY cai.create_time DESC LIMIT 1) AS image_url,
- '5' AS type,
- su.avatar,
- su.nick_name,
- caa.peer_id as user_id,
- caa.create_time,
- NULL AS content,
- caa.is_read,
- CASE WHEN EXISTS (SELECT 1 FROM community_like cl WHERE cl.article_id = caa.article_id AND cl.user_id = #{userId}) THEN TRUE ELSE FALSE END AS isLike
- FROM community_article_at caa
- LEFT JOIN sys_user su ON caa.user_id = su.user_id
- WHERE caa.type = 0
- AND caa.peer_id = #{userId}
- AND (caa.is_delete IS NULL OR caa.is_delete != 1)
- AND (caa.is_notice != 1 or caa.is_notice is null)
- UNION ALL
- SELECT
- caa.id,
- cac.id as joinId,
- cac.id as parentReplyId,
- caa.article_id,
- (SELECT cai.image_url FROM community_article_images cai WHERE caa.article_id = cai.article_id AND (cai.is_delete IS NULL OR cai.is_delete != 1) ORDER BY cai.create_time DESC LIMIT 1) AS image_url,
- '6' AS type,
- su.avatar,
- su.nick_name,
- caa.peer_id as user_id,
- caa.create_time,
- cac.content,
- caa.is_read,
- CASE WHEN EXISTS (SELECT 1 FROM community_comment_like cck WHERE cck.comment_id = cac.id AND cck.user_id = #{userId}) THEN TRUE ELSE FALSE END AS isLike
- FROM community_article_at caa
- LEFT JOIN community_article_comment cac ON caa.comment_id = cac.id
- LEFT JOIN sys_user su ON caa.user_id = su.user_id
- WHERE caa.type = 1
- AND caa.peer_id = #{userId}
- AND (caa.is_delete IS NULL OR caa.is_delete != 1)
- AND (cac.is_delete IS NULL OR cac.is_delete != 1)
- AND (caa.is_notice != 1 or caa.is_notice is null)
- UNION ALL
- SELECT
- caa.id,
- ccr.comment_id as joinId,
- ccr.parent_reply_id as parentReplyId,
- caa.article_id,
- (SELECT cai.image_url FROM community_article_images cai WHERE caa.article_id = cai.article_id AND (cai.is_delete IS NULL OR cai.is_delete != 1) ORDER BY cai.create_time DESC LIMIT 1) AS image_url,
- '7' AS type,
- su.avatar,
- su.nick_name,
- caa.peer_id as user_id,
- caa.create_time,
- ccr.content,
- caa.is_read,
- CASE WHEN EXISTS (SELECT 1 FROM community_comment_like cck WHERE cck.reply_id = ccr.id AND cck.user_id = #{userId}) THEN TRUE ELSE FALSE END AS isLike
- FROM community_article_at caa
- LEFT JOIN community_comment_reply ccr ON caa.reply_id = ccr.id
- LEFT JOIN sys_user su ON caa.user_id = su.user_id
- WHERE caa.type = 2
- AND caa.peer_id = #{userId}
- AND (caa.is_delete IS NULL OR caa.is_delete != 1)
- AND (ccr.is_delete IS NULL OR ccr.is_delete != 1)
- AND (caa.is_notice != 1 or caa.is_notice is null)
- ) c
- <if test="searchType == 1">
- order by c.create_time desc
- </if>
- <if test="searchType == 2">
- order by c.create_time asc
- </if>
- limit #{offset},#{limit}
- </select>
- </mapper>
|