CommunityArticleCommentMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper">
  6. <select id="queryCommentCount" resultType="java.lang.Integer">
  7. select d.commentCount + d.replyCount
  8. from (select c.article_id,
  9. count(1) as commentCount,
  10. (select count(1) as replyCount
  11. from community_article_comment a
  12. left join community_comment_reply b on a.id = b.comment_id
  13. where a.article_id = #{articleId}
  14. and b.is_delete != 1) as replyCount from community_article_comment c
  15. where c.article_id = #{articleId} and c.is_delete != 1 ) as d
  16. </select>
  17. <select id="queryCommentReplyCount" resultType="java.lang.Integer">
  18. select d.commentCount + d.replyCount from (
  19. select
  20. count(1) as commentCount,
  21. (select
  22. count(*) count
  23. from
  24. community_article_comment a
  25. left join community_comment_reply b on a.id = b.comment_id
  26. <where>
  27. <if test=" articleIds != null and articleIds.size > 0">
  28. AND article_id in
  29. <foreach collection="articleIds" item="articleId" index="index" open="(" close=")" separator=",">
  30. #{articleId}
  31. </foreach>
  32. </if>
  33. and b.id is not null
  34. and (a.is_delete != 1 or a.is_delete is null)
  35. and (b.is_delete != 1 or b.is_delete is null)
  36. </where>
  37. ) as replyCount
  38. from community_article_comment c
  39. <where>
  40. <if test="articleIds != null and articleIds.size > 0">
  41. AND c.article_id in
  42. <foreach collection="articleIds" item="articleId" index="index" open="(" close=")" separator=",">
  43. #{articleId}
  44. </foreach>
  45. </if>
  46. and (c.is_delete != 1 or c.is_delete is null)
  47. </where>
  48. ) as d
  49. </select>
  50. <select id="queryCommentReplyCountPerson" resultType="java.lang.Integer">
  51. select count(1) count from (
  52. select
  53. f.user_id,sum(g.commentSum) sum
  54. from (
  55. select
  56. a.user_id,b.id as article_id
  57. from sys_user a
  58. left join community_article b on a.user_id = b. user_id
  59. where (a.status != 1 or a.status is null) and (b.is_delete != 1 or b.is_delete is null)
  60. and b.id is not null ) f
  61. left join (select
  62. d.article_id, d.commentCount + COALESCE(e.replyCount, 0) as commentSum
  63. from (
  64. select
  65. c.article_id,
  66. count(1) as commentCount
  67. from community_article_comment c
  68. where (c.is_delete != 1 or c.is_delete is null)
  69. group by c.article_id ) d
  70. left join (select
  71. a.article_id,count(1) replyCount
  72. from
  73. community_article_comment a
  74. left join community_comment_reply b on a.id = b.comment_id
  75. where b.id is not null
  76. and (a.is_delete != 1 or a.is_delete is null)
  77. and (b.is_delete != 1 or b.is_delete is null)
  78. group by a.article_id) e
  79. on d.article_id = e.article_id ) g
  80. on f.article_id = g.article_id
  81. group by f.user_id
  82. <if test="commentSum != null and commentSum > 0">
  83. HAVING sum &lt;= #{commentSum}
  84. </if>
  85. ) h
  86. </select>
  87. <select id="queryCommentReplyLikeCount" resultType="java.lang.Integer">
  88. select sum(count) sum
  89. from (
  90. select
  91. a.user_id, count (1) count
  92. from community_article a
  93. left join community_like b
  94. on a.id = b.article_id
  95. where (a.is_delete != 1 or a.is_delete is null)
  96. and b.id is not null
  97. and a.user_id = #{userId}
  98. GROUP BY a.user_id
  99. union ALL
  100. select
  101. a.user_id, count (1) count
  102. from
  103. community_article_comment a
  104. left join community_comment_like b
  105. on a.id = b.comment_id
  106. where (a.is_delete != 1 or a.is_delete is null)
  107. 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))
  108. and a.user_id = #{userId}
  109. group by a.user_id
  110. union all
  111. select
  112. b.user_id, count (1) count
  113. from
  114. community_article_comment a
  115. left join community_comment_reply b on a.id = b.comment_id
  116. left join community_comment_like c on b.id = c.reply_id
  117. where
  118. b.user_id = #{userId}
  119. and b.id is not null
  120. and c.id is not null
  121. and (a.is_delete != 1 or a.is_delete is null)
  122. and (b.is_delete != 1 or b.is_delete is null)
  123. 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))
  124. group by b.user_id ) AA
  125. group by user_id
  126. </select>
  127. <select id="queryCommentReplyLikeCountPerson" resultType="java.lang.Integer">
  128. select count(*) from (
  129. select user_id,sum(count) counts from (
  130. select
  131. a.user_id, count(1) count
  132. from community_article a
  133. left join community_like b
  134. on a.id = b.article_id
  135. where (a.is_delete != 1 or a.is_delete is null)
  136. and b.id is not null
  137. GROUP BY a.user_id
  138. union ALL
  139. select
  140. a.user_id,count(1) count
  141. from
  142. community_article_comment a
  143. left join community_comment_like b
  144. on a.id = b.comment_id
  145. where (a.is_delete != 1 or a.is_delete is null)
  146. 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))
  147. group by a.user_id
  148. union all
  149. select
  150. b.user_id,count(1) count
  151. from
  152. community_article_comment a
  153. left join community_comment_reply b on a.id = b.comment_id
  154. left join community_comment_like c on b.id = c.reply_id
  155. where
  156. b.id is not null
  157. and c.id is not null
  158. and (a.is_delete != 1 or a.is_delete is null)
  159. and (b.is_delete != 1 or b.is_delete is null)
  160. 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))
  161. group by b.user_id ) AA
  162. group by user_id
  163. <if test="likeSum != null and likeSum > 0">
  164. HAVING counts &lt;= #{likeSum}
  165. </if>
  166. ) BB
  167. </select>
  168. <select id="queryComment" resultType="com.ruoyi.generator.domain.Community.CommunityArticleComment">
  169. SELECT A.id,
  170. #{articleId} as articleId,
  171. A.content,
  172. A.user_id,
  173. A.image_url,
  174. A.create_time,
  175. A.create_by,
  176. A.update_time,
  177. A.update_by,
  178. A.address
  179. FROM (SELECT id,
  180. image_url,
  181. user_id,
  182. create_time,
  183. create_by,
  184. update_time,
  185. update_by,
  186. content,
  187. address
  188. FROM community_article_comment
  189. WHERE article_id = #{articleId}
  190. AND (is_delete != 1 OR is_delete IS NULL)
  191. UNION ALL
  192. SELECT id,
  193. image_url,
  194. user_id,
  195. create_time,
  196. create_by,
  197. update_time,
  198. update_by,
  199. content,
  200. address
  201. FROM community_comment_reply
  202. WHERE comment_id IN (SELECT id
  203. FROM community_article_comment
  204. WHERE article_id = #{articleId}
  205. AND (is_delete != 1 OR is_delete IS NULL))
  206. AND (is_delete != 1 OR is_delete IS NULL)) AS A
  207. WHERE A.content LIKE CONCAT('%', #{comment}, '%')
  208. limit #{offset}
  209. , #{limit};
  210. </select>
  211. <select id="getCommentListByUserId" resultType="com.ruoyi.generator.vo.CommentVo">
  212. SELECT
  213. c.id,
  214. c.article_id,
  215. c.user_id,
  216. c.image_url,
  217. c.type,
  218. c.avatar,
  219. c.nick_name,
  220. c.create_time,
  221. c.content,
  222. c.is_read
  223. FROM (
  224. SELECT
  225. cac.id,
  226. cac.article_id,
  227. (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,
  228. '8' AS type,
  229. su.avatar,
  230. su.nick_name,
  231. cac.user_id,
  232. cac.create_time,
  233. cac.content,
  234. cac.is_read
  235. FROM community_article ca
  236. LEFT JOIN community_article_comment cac ON ca.id = cac.article_id
  237. LEFT JOIN sys_user su ON cac.user_id = su.user_id
  238. WHERE ca.user_id = #{userId}
  239. AND cac.user_id != #{userId}
  240. AND cac.id IS NOT NULL
  241. AND (ca.is_delete IS NULL OR ca.is_delete != 1)
  242. AND (cac.is_delete IS NULL OR cac.is_delete != 1)
  243. AND (cac.is_notice != 1 or cac.is_notice is null)
  244. UNION ALL
  245. SELECT
  246. ccr.id,
  247. cac.article_id,
  248. (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,
  249. '9' AS type,
  250. su.avatar,
  251. su.nick_name,
  252. ccr.user_id,
  253. ccr.create_time,
  254. ccr.content,
  255. ccr.is_read
  256. FROM community_article_comment cac
  257. LEFT JOIN community_comment_reply ccr ON cac.id = ccr.comment_id
  258. LEFT JOIN sys_user su ON ccr.user_id = su.user_id
  259. WHERE cac.user_id = #{userId}
  260. AND ccr.user_id != #{userId}
  261. AND ccr.id IS NOT NULL
  262. AND (cac.is_delete IS NULL OR cac.is_delete != 1)
  263. AND (ccr.is_delete IS NULL OR ccr.is_delete != 1)
  264. AND (ccr.is_notice != 1 or ccr.is_notice is null)
  265. UNION ALL
  266. SELECT
  267. caa.id,
  268. caa.article_id,
  269. (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,
  270. '5' AS type,
  271. su.avatar,
  272. su.nick_name,
  273. caa.peer_id as user_id,
  274. caa.create_time,
  275. NULL AS content,
  276. caa.is_read
  277. FROM community_article_at caa
  278. LEFT JOIN sys_user su ON caa.user_id = su.user_id
  279. WHERE caa.type = 0
  280. AND caa.peer_id = #{userId}
  281. AND (caa.is_delete IS NULL OR caa.is_delete != 1)
  282. AND (caa.is_notice != 1 or caa.is_notice is null)
  283. UNION ALL
  284. SELECT
  285. caa.id,
  286. caa.article_id,
  287. (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,
  288. '6' AS type,
  289. su.avatar,
  290. su.nick_name,
  291. caa.peer_id as user_id,
  292. caa.create_time,
  293. cac.content,
  294. caa.is_read
  295. FROM community_article_at caa
  296. LEFT JOIN community_article_comment cac ON caa.comment_id = cac.id
  297. LEFT JOIN sys_user su ON caa.user_id = su.user_id
  298. WHERE caa.type = 1
  299. AND caa.peer_id = #{userId}
  300. AND (caa.is_delete IS NULL OR caa.is_delete != 1)
  301. AND (cac.is_delete IS NULL OR cac.is_delete != 1)
  302. AND (caa.is_notice != 1 or caa.is_notice is null)
  303. UNION ALL
  304. SELECT
  305. caa.id,
  306. caa.article_id,
  307. (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,
  308. '7' AS type,
  309. su.avatar,
  310. su.nick_name,
  311. caa.peer_id as user_id,
  312. caa.create_time,
  313. ccr.content,
  314. caa.is_read
  315. FROM community_article_at caa
  316. LEFT JOIN community_comment_reply ccr ON caa.reply_id = ccr.id
  317. LEFT JOIN sys_user su ON caa.user_id = su.user_id
  318. WHERE caa.type = 2
  319. AND caa.peer_id = #{userId}
  320. AND (caa.is_delete IS NULL OR caa.is_delete != 1)
  321. AND (ccr.is_delete IS NULL OR ccr.is_delete != 1)
  322. AND (caa.is_notice != 1 or caa.is_notice is null)
  323. ) c
  324. <if test="searchType == 1">
  325. order by c.create_time desc
  326. </if>
  327. <if test="searchType == 2">
  328. order by c.create_time asc
  329. </if>
  330. limit #{offset},#{limit}
  331. </select>
  332. </mapper>