ArticleMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.CommunityArticleMapper">
  6. <resultMap type="com.ruoyi.generator.vo.CommunityArticleVo" id="CommunityArticleVoResult">
  7. <id property="id" column="article_id"/>
  8. <result property="userId" column="article_user_id"/>
  9. <result property="title" column="article_title"/>
  10. <result property="content" column="article_content"/>
  11. <result property="createBy" column="article_create_by"/>
  12. <result property="createTime" column="article_create_time"/>
  13. <result property="updateBy" column="article_update_by"/>
  14. <result property="updateTime" column="article_update_time"/>
  15. <result property="remark" column="remark"/>
  16. <result property="userName" column="user_name"/>
  17. <result property="nickName" column="nick_name"/>
  18. <result property="comment" column=" is_comment"/>
  19. <result property="raffle" column="is_raffle"/>
  20. <result property="draft" column="is_draft"/>
  21. <result property="download" column="is_download"/>
  22. <result property="email" column="email"/>
  23. <result property="avatar" column="avatar"/>
  24. <result property="pageViews" column="pageViews"/>
  25. <result column="images" property="imageList" javaType="java.util.List" typeHandler="com.ruoyi.common.utils.bean.JSONTypeHandler"/>
  26. <result column="comments" property="comments" typeHandler="com.ruoyi.common.utils.bean.JSONTypeHandler"/>
  27. </resultMap>
  28. <resultMap type="CommunityArticleImages" id="CommunityArticleImagesResult">
  29. <id property="id" column="image_id"/>
  30. <result property="articleId" column="images_article_id"/>
  31. <result property="imageUrl" column="image_url"/>
  32. <result property="createBy" column="images_create_by"/>
  33. <result property="createTime" column="images_create_time"/>
  34. <result property="updateBy" column="images_update_by"/>
  35. <result property="updateTime" column="images_update_time"/>
  36. </resultMap>
  37. <resultMap type="SysUser" id="SysUserResult">
  38. <id property="userId" column="user_id"/>
  39. <result property="deptId" column="dept_id"/>
  40. <result property="phonenumber" column="phonenumber"/>
  41. <result property="sex" column="sex"/>
  42. <result property="password" column="password"/>
  43. <result property="userName" column="user_name"/>
  44. <result property="nickName" column="nick_name"/>
  45. <result property="email" column="email"/>
  46. <result property="avatar" column="avatar"/>
  47. <result property="status" column="status"/>
  48. <result property="createBy" column="create_by"/>
  49. <result property="createTime" column="create_time"/>
  50. <result property="updateBy" column="update_by"/>
  51. <result property="updateTime" column="update_time"/>
  52. <result property="remark" column="remark"/>
  53. </resultMap>
  54. <resultMap type="com.ruoyi.generator.vo.CommunityArticleCommentVo" id="CommunityCommentsResult">
  55. <id property="id" column="comment_id"/>
  56. <result property="articleId" column="comment_article_id"/>
  57. <result property="userId" column="comment_user_id"/>
  58. <result property="content" column="comment_content"/>
  59. <result property="createBy" column="comment_create_by"/>
  60. <result property="createTime" column="comment_create_time"/>
  61. <result property="updateBy" column="comment_update_by"/>
  62. <result property="updateTime" column="comment_update_time"/>
  63. <result property="remark" column="comment_remark"/>
  64. </resultMap>
  65. <resultMap id="CommunityCollectResult" type="CommunityArticleCollect">
  66. <id property="id" column="collect_id"/>
  67. <result property="articleId" column="article_id"/>
  68. <result property="userId" column="user_id"/>
  69. <result property="createBy" column="create_by"/>
  70. <result property="createTime" column="create_time"/>
  71. <result property="updateBy" column="update_by"/>
  72. <result property="updateTime" column="update_time"/>
  73. </resultMap>
  74. <resultMap id="CommunityLikeResult" type="CommunityLike">
  75. <id property="id" column="like_id"/>
  76. <result property="articleId" column="article_id"/>
  77. <result property="userId" column="user_id"/>
  78. <result property="createBy" column="create_by"/>
  79. <result property="createTime" column="create_time"/>
  80. <result property="updateBy" column="update_by"/>
  81. <result property="updateTime" column="update_time"/>
  82. </resultMap>
  83. <sql id="selectCommunityArticleVo">
  84. select id as article_id,
  85. user_id,
  86. title,
  87. content,
  88. create_by,
  89. create_time,
  90. update_by,
  91. update_time,
  92. remark
  93. from community_article
  94. </sql>
  95. <select id="selectCommunityArticleList" parameterType="CommunityArticle" resultMap="CommunityArticleVoResult">
  96. select
  97. a.id as article_id,
  98. a.user_id as article_user_id,
  99. a.title as article_title,
  100. a.is_comment as article_is_comment,
  101. a.content as article_content,
  102. a.page_views as pageViews,
  103. a.create_by as article_create_by,
  104. a.create_time as article_create_time,
  105. a.update_by as article_update_by,
  106. a.update_time as article_update_time,
  107. IFNULL(a.address, '未知') as address,
  108. a.is_comment,
  109. a.is_raffle,
  110. a.is_download,
  111. a.article_type,
  112. COALESCE((
  113. SELECT
  114. JSON_ARRAYAGG(
  115. CASE
  116. WHEN b.id IS NOT NULL THEN
  117. JSON_OBJECT(
  118. 'id', IFNULL(b.id,''),
  119. 'articleId', IFNULL(b.article_id,''),
  120. 'imageUrl', IFNULL(b.image_url,''),
  121. 'compressUrl', IFNULL(b.compress_url,''),
  122. 'createBy', IFNULL(b.create_by,''),
  123. 'createTime', IFNULL(DATE_FORMAT(b.create_time,'%Y-%m-%d %H:%i:%s'),''),
  124. 'updateBy', IFNULL(b.update_by,''),
  125. 'updateTime', IFNULL(DATE_FORMAT(b.update_time,'%Y-%m-%d %H:%i:%s'),'')
  126. )
  127. ELSE NULL
  128. END
  129. )
  130. FROM
  131. community_article_images b
  132. WHERE
  133. b.article_id = a.id
  134. and (b.is_delete != 1 or b.is_delete is null)
  135. ), '[]') AS images,
  136. c.user_name as user_name,
  137. c.nick_name as nick_name,
  138. c.email as email,
  139. c.avatar as avatar
  140. # COALESCE((
  141. # SELECT
  142. # JSON_ARRAYAGG(
  143. # CASE
  144. # WHEN d.id IS NOT NULL THEN
  145. # JSON_OBJECT(
  146. # 'id', IFNULL(d.id,''),
  147. # 'articleId', IFNULL(d.article_id,''),
  148. # 'userId', IFNULL(d.user_id,''),
  149. # 'content', IFNULL(d.content,''),
  150. # 'createBy', IFNULL(d.create_by,''),
  151. # 'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
  152. # 'updateBy', IFNULL(d.update_by,''),
  153. # 'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
  154. # )
  155. # ELSE NULL
  156. # END
  157. # )
  158. # FROM
  159. # community_article_comment d
  160. # WHERE
  161. # d.article_id = a.id and d.is_delete != 1 order by d.create_time desc
  162. # ), '[]') AS comments
  163. from
  164. community_article a
  165. left join sys_user c on a.user_id = c.user_id
  166. left join community_article_class e on e.article_id = a.id
  167. left join community_article_tag f on f.article_id = a.id
  168. <where>
  169. <if test="communityArticle.id != null and communityArticle.id != ''">
  170. AND a.id = #{communityArticle.id}
  171. </if>
  172. <if test="communityArticle.title != null and communityArticle.title != ''">
  173. AND a.title like concat('%', #{communityArticle.title}, '%')
  174. </if>
  175. <if test="classIds != null and classIds.size() > 0">
  176. and e.class_id IN
  177. <foreach collection="classIds" item="classId" index="index" open="(" close=")" separator=",">
  178. #{classId}
  179. </foreach>
  180. </if>
  181. <if test="communityArticle.userId != null and communityArticle.userId != ''">
  182. AND a.user_id = #{communityArticle.userId}
  183. </if>
  184. <if test="communityArticle.userIds != null and communityArticle.userIds.size > 0">
  185. AND a.user_id in
  186. <foreach collection="communityArticle.userIds" item="userId" index="index" open="(" close=")" separator=",">
  187. #{userId}
  188. </foreach>
  189. </if>
  190. <if test="communityArticle.tags != null and communityArticle.tags.size > 0">
  191. AND f.tag_id in
  192. <foreach collection="communityArticle.tags" item="tags" index="index" open="(" close=")" separator=",">
  193. ( select distinct id from community_tag where tag_name = #{tags} )
  194. </foreach>
  195. </if>
  196. <if test="communityArticle.articleIds != null and communityArticle.articleIds.size > 0">
  197. AND a.id in
  198. <foreach collection="communityArticle.articleIds" item="articleId" index="index" open="(" close=")" separator=",">
  199. #{articleId}
  200. </foreach>
  201. </if>
  202. <if test="communityArticle.isDraft != null and communityArticle.isDraft != '' ">
  203. AND IFNULL(a.is_Draft,0) = #{communityArticle.isDraft}
  204. </if>
  205. and (a.is_delete != 1 or a.is_delete is null)
  206. and (f.is_delete != 1 or f.is_delete is null)
  207. and a.user_id not in (select distinct peer_id from community_user_block where user_id = #{loginId} and is_block = 1 )
  208. </where>
  209. group by a.id,a.create_time
  210. <if test="searchType == 1">
  211. order by a.create_time desc
  212. </if>
  213. <if test="searchType == 2">
  214. order by a.page_views desc
  215. </if>
  216. <if test="searchType == 3">
  217. order by RAND()
  218. </if>
  219. limit #{offset},#{limit}
  220. </select>
  221. <select id="selectCommunityArticleCount" parameterType="CommunityArticle" resultType="int">
  222. SELECT COUNT(DISTINCT a.id)
  223. FROM community_article a
  224. LEFT JOIN sys_user c ON a.user_id = c.user_id
  225. LEFT JOIN community_article_class e ON e.article_id = a.id
  226. LEFT JOIN community_article_tag f ON f.article_id = a.id
  227. <where>
  228. <if test="communityArticle.id != null and communityArticle.id != ''">
  229. AND a.id = #{communityArticle.id}
  230. </if>
  231. <if test="communityArticle.title != null and communityArticle.title != ''">
  232. AND a.title LIKE CONCAT('%', #{communityArticle.title}, '%')
  233. </if>
  234. <if test="classIds != null and classIds.size() > 0">
  235. AND e.class_id IN
  236. <foreach collection="classIds" item="classId" open="(" close=")" separator=",">
  237. #{classId}
  238. </foreach>
  239. </if>
  240. <if test="communityArticle.userId != null and communityArticle.userId != ''">
  241. AND a.user_id = #{communityArticle.userId}
  242. </if>
  243. <if test="communityArticle.userIds != null and communityArticle.userIds.size > 0">
  244. AND a.user_id IN
  245. <foreach collection="communityArticle.userIds" item="userId" open="(" close=")" separator=",">
  246. #{userId}
  247. </foreach>
  248. </if>
  249. AND (a.is_delete != 1 OR a.is_delete IS NULL)
  250. AND (f.is_delete != 1 OR f.is_delete is null)
  251. </where>
  252. </select>
  253. <select id="selectCommunityArticleCollectById" resultMap="CommunityCollectResult">
  254. select collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
  255. community_article_collect
  256. <where>
  257. <if test="userId != null and userId != ''">
  258. user_id = #{userId}
  259. </if>
  260. <if test="articleId != null and articleId != ''">
  261. and article_id = #{articleId}
  262. </if>
  263. </where>
  264. </select>
  265. <!--点赞-->
  266. <select id="selectCommunityArticleLikeById" resultMap="CommunityLikeResult">
  267. select id as like_id, article_id, user_id, create_by, create_time, update_by, update_time from
  268. community_like
  269. <where>
  270. <if test="userId != null and userId != ''">
  271. user_id = #{userId}
  272. </if>
  273. <if test="articleId != null and articleId != ''">
  274. and article_id = #{articleId}
  275. </if>
  276. </where>
  277. </select>
  278. <insert id="insertCommunityLikeById" parameterType="communityLike">
  279. insert into community_like (article_id, user_id, create_by, create_time, update_by, update_time)
  280. values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
  281. </insert>
  282. <delete id="deleteCommunityLikeById" parameterType="communityLike">
  283. delete
  284. from community_like
  285. where user_id = #{userId}
  286. and article_id = #{articleId};
  287. </delete>
  288. <!--收藏-->
  289. <select id="selectCommunityCollectById" resultMap="CommunityCollectResult" parameterType="communityArticleCollect">
  290. select id as collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
  291. community_article_collect
  292. <where>
  293. <if test="userId != null and userId != ''">
  294. user_id = #{userId}
  295. </if>
  296. <if test="articleId != null and articleId != ''">
  297. and article_id = #{articleId}
  298. </if>
  299. </where>
  300. </select>
  301. <insert id="insertCommunityCollectById" parameterType="communityArticleCollect">
  302. insert into community_article_collect (article_id, user_id, create_by, create_time, update_by, update_time)
  303. values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
  304. </insert>
  305. <delete id="deleteCommunityCollectById" parameterType="communityArticleCollect">
  306. delete
  307. from community_article_collect
  308. where user_id = #{userId}
  309. and article_id = #{articleId};
  310. </delete>
  311. <select id="selectTrendingTopByContent" resultType="com.ruoyi.generator.domain.Community.TrendingTop">
  312. SELECT
  313. distinct type,id,content
  314. FROM (
  315. SELECT
  316. 'article' as type, id,title as content
  317. FROM community_article
  318. WHERE title LIKE CONCAT( #{content}, '%') AND is_delete != '1'
  319. UNION ALL
  320. SELECT
  321. 'tag' as type, id,tag_name
  322. FROM community_tag
  323. WHERE tag_name LIKE CONCAT( #{content}, '%') AND is_delete != '1'
  324. UNION ALL
  325. SELECT
  326. 'user' as type, user_id,nick_name
  327. FROM sys_user
  328. WHERE nick_name LIKE CONCAT( #{content}, '%') AND status = '0'
  329. ) AS A
  330. </select>
  331. <select id="selectUserNoCoArticles" resultMap="CommunityArticleVoResult">
  332. SELECT
  333. a.id as article_id,
  334. a.user_id as article_user_id,
  335. a.title as article_title,
  336. a.is_comment as article_is_comment, -- 去重
  337. a.content as article_content,
  338. a.page_views as pageViews,
  339. a.create_by as article_create_by,
  340. a.create_time as article_create_time,
  341. a.update_by as article_update_by,
  342. a.update_time as article_update_time,
  343. a.address as address,
  344. a.is_raffle,
  345. COALESCE(
  346. (SELECT JSON_ARRAYAGG(JSON_OBJECT('imageUrl', IFNULL(b.image_url,'')))
  347. FROM community_article_images b
  348. WHERE b.article_id = a.id
  349. AND IFNULL(b.is_delete, 0) != 1),
  350. '[]'
  351. ) AS images,
  352. a.is_download
  353. FROM community_article a
  354. WHERE a.create_by = #{userId}
  355. AND NOT EXISTS (
  356. SELECT 1
  357. FROM community_collection_article c
  358. WHERE c.article_id = a.id
  359. AND IFNULL(c.is_delete, 0) != 1
  360. )
  361. AND IFNULL(a.is_delete, 0) != 1 -- 统一过滤条件
  362. </select>
  363. </mapper>