CommunityArticleCommentMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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) AS 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) AS 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) AS 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.joinId,
  215. c.parentReplyId,
  216. c.article_id,
  217. c.user_id,
  218. c.image_url,
  219. c.type,
  220. c.avatar,
  221. c.nick_name,
  222. c.create_time,
  223. c.content,
  224. c.is_read,
  225. c.isLike
  226. FROM (
  227. SELECT
  228. cac.id,
  229. cac.id as joinId,
  230. cac.id as parentReplyId,
  231. cac.article_id,
  232. (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,
  233. '8' AS type,
  234. su.avatar,
  235. su.nick_name,
  236. cac.user_id,
  237. cac.create_time,
  238. cac.content,
  239. cac.is_read,
  240. 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
  241. FROM community_article ca
  242. LEFT JOIN community_article_comment cac ON ca.id = cac.article_id
  243. LEFT JOIN sys_user su ON cac.user_id = su.user_id
  244. WHERE ca.user_id = #{userId}
  245. AND cac.user_id != #{userId}
  246. AND cac.id IS NOT NULL
  247. AND (ca.is_delete IS NULL OR ca.is_delete != 1)
  248. AND (cac.is_delete IS NULL OR cac.is_delete != 1)
  249. AND (cac.is_notice != 1 or cac.is_notice is null)
  250. AND cac.ID not in ( select comment_id from community_article_at caa where peer_id = #{userId})
  251. UNION ALL
  252. SELECT
  253. ccr.id,
  254. ccr.comment_id as joinId,
  255. ccr.parent_reply_id as parentReplyId,
  256. cac.article_id,
  257. (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,
  258. '9' AS type,
  259. su.avatar,
  260. su.nick_name,
  261. ccr.user_id,
  262. ccr.create_time,
  263. ccr.content,
  264. ccr.is_read,
  265. 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
  266. FROM community_article_comment cac
  267. LEFT JOIN community_comment_reply ccr ON cac.id = ccr.comment_id
  268. LEFT JOIN sys_user su ON ccr.user_id = su.user_id
  269. WHERE cac.user_id = #{userId}
  270. AND ccr.user_id != #{userId}
  271. AND ccr.id IS NOT NULL
  272. AND (cac.is_delete IS NULL OR cac.is_delete != 1)
  273. AND (ccr.is_delete IS NULL OR ccr.is_delete != 1)
  274. AND (ccr.is_notice != 1 or ccr.is_notice is null)
  275. UNION ALL
  276. SELECT
  277. caa.id,
  278. caa.article_id as joinId,
  279. null as parentReplyId,
  280. caa.article_id,
  281. (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,
  282. '5' AS type,
  283. su.avatar,
  284. su.nick_name,
  285. caa.peer_id as user_id,
  286. caa.create_time,
  287. NULL AS content,
  288. caa.is_read,
  289. 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
  290. FROM community_article_at caa
  291. LEFT JOIN sys_user su ON caa.user_id = su.user_id
  292. WHERE caa.type = 0
  293. AND caa.peer_id = #{userId}
  294. AND (caa.is_delete IS NULL OR caa.is_delete != 1)
  295. AND (caa.is_notice != 1 or caa.is_notice is null)
  296. UNION ALL
  297. SELECT
  298. caa.id,
  299. cac.id as joinId,
  300. cac.id as parentReplyId,
  301. caa.article_id,
  302. (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,
  303. '6' AS type,
  304. su.avatar,
  305. su.nick_name,
  306. caa.peer_id as user_id,
  307. caa.create_time,
  308. cac.content,
  309. caa.is_read,
  310. 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
  311. FROM community_article_at caa
  312. LEFT JOIN community_article_comment cac ON caa.comment_id = cac.id
  313. LEFT JOIN sys_user su ON caa.user_id = su.user_id
  314. WHERE caa.type = 1
  315. AND caa.peer_id = #{userId}
  316. AND (caa.is_delete IS NULL OR caa.is_delete != 1)
  317. AND (cac.is_delete IS NULL OR cac.is_delete != 1)
  318. AND (caa.is_notice != 1 or caa.is_notice is null)
  319. UNION ALL
  320. SELECT
  321. caa.id,
  322. ccr.comment_id as joinId,
  323. ccr.parent_reply_id as parentReplyId,
  324. caa.article_id,
  325. (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,
  326. '7' AS type,
  327. su.avatar,
  328. su.nick_name,
  329. caa.peer_id as user_id,
  330. caa.create_time,
  331. ccr.content,
  332. caa.is_read,
  333. 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
  334. FROM community_article_at caa
  335. LEFT JOIN community_comment_reply ccr ON caa.reply_id = ccr.id
  336. LEFT JOIN sys_user su ON caa.user_id = su.user_id
  337. WHERE caa.type = 2
  338. AND caa.peer_id = #{userId}
  339. AND (caa.is_delete IS NULL OR caa.is_delete != 1)
  340. AND (ccr.is_delete IS NULL OR ccr.is_delete != 1)
  341. AND (caa.is_notice != 1 or caa.is_notice is null)
  342. ) c
  343. <if test="searchType == 1">
  344. order by c.create_time desc
  345. </if>
  346. <if test="searchType == 2">
  347. order by c.create_time asc
  348. </if>
  349. limit #{offset},#{limit}
  350. </select>
  351. </mapper>