ArticleMapper.xml 14 KB

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