ArticleMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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="email" column="email"/>
  19. <result property="avatar" column="avatar"/>
  20. <result property="pageViews" column="pageViews"/>
  21. <result column="images" property="imageList" javaType="java.util.List" typeHandler="com.ruoyi.common.utils.bean.JSONTypeHandler"/>
  22. <result column="comments" property="comments" typeHandler="com.ruoyi.common.utils.bean.JSONTypeHandler"/>
  23. </resultMap>
  24. <resultMap type="CommunityArticleImages" id="CommunityArticleImagesResult">
  25. <id property="id" column="image_id"/>
  26. <result property="articleId" column="images_article_id"/>
  27. <result property="imageUrl" column="image_url"/>
  28. <result property="createBy" column="images_create_by"/>
  29. <result property="createTime" column="images_create_time"/>
  30. <result property="updateBy" column="images_update_by"/>
  31. <result property="updateTime" column="images_update_time"/>
  32. </resultMap>
  33. <resultMap type="SysUser" id="SysUserResult">
  34. <id property="userId" column="user_id"/>
  35. <result property="deptId" column="dept_id"/>
  36. <result property="phonenumber" column="phonenumber"/>
  37. <result property="sex" column="sex"/>
  38. <result property="password" column="password"/>
  39. <result property="userName" column="user_name"/>
  40. <result property="nickName" column="nick_name"/>
  41. <result property="email" column="email"/>
  42. <result property="avatar" column="avatar"/>
  43. <result property="status" column="status"/>
  44. <result property="createBy" column="create_by"/>
  45. <result property="createTime" column="create_time"/>
  46. <result property="updateBy" column="update_by"/>
  47. <result property="updateTime" column="update_time"/>
  48. <result property="remark" column="remark"/>
  49. </resultMap>
  50. <resultMap type="com.ruoyi.generator.vo.CommunityArticleCommentVo" id="CommunityCommentsResult">
  51. <id property="id" column="comment_id"/>
  52. <result property="articleId" column="comment_article_id"/>
  53. <result property="userId" column="comment_user_id"/>
  54. <result property="content" column="comment_content"/>
  55. <result property="createBy" column="comment_create_by"/>
  56. <result property="createTime" column="comment_create_time"/>
  57. <result property="updateBy" column="comment_update_by"/>
  58. <result property="updateTime" column="comment_update_time"/>
  59. <result property="remark" column="comment_remark"/>
  60. </resultMap>
  61. <resultMap id="CommunityCollectResult" type="CommunityArticleCollect">
  62. <id property="id" column="collect_id"/>
  63. <result property="articleId" column="article_id"/>
  64. <result property="userId" column="user_id"/>
  65. <result property="createBy" column="create_by"/>
  66. <result property="createTime" column="create_time"/>
  67. <result property="updateBy" column="update_by"/>
  68. <result property="updateTime" column="update_time"/>
  69. </resultMap>
  70. <resultMap id="CommunityLikeResult" type="CommunityLike">
  71. <id property="id" column="like_id"/>
  72. <result property="articleId" column="article_id"/>
  73. <result property="userId" column="user_id"/>
  74. <result property="createBy" column="create_by"/>
  75. <result property="createTime" column="create_time"/>
  76. <result property="updateBy" column="update_by"/>
  77. <result property="updateTime" column="update_time"/>
  78. </resultMap>
  79. <sql id="selectCommunityArticleVo">
  80. select id as article_id,
  81. user_id,
  82. title,
  83. content,
  84. create_by,
  85. create_time,
  86. update_by,
  87. update_time,
  88. remark
  89. from community_article
  90. </sql>
  91. <select id="selectCommunityArticleList" parameterType="CommunityArticle" resultMap="CommunityArticleVoResult">
  92. select
  93. a.id as article_id,
  94. a.user_id as article_user_id,
  95. a.title as article_title,
  96. a.is_comment as article_is_comment,
  97. a.content as article_content,
  98. a.page_views as pageViews,
  99. a.create_by as article_create_by,
  100. a.create_time as article_create_time,
  101. a.update_by as article_update_by,
  102. a.update_time as article_update_time,
  103. COALESCE((
  104. SELECT
  105. JSON_ARRAYAGG(
  106. CASE
  107. WHEN b.id IS NOT NULL THEN
  108. JSON_OBJECT(
  109. 'id', IFNULL(b.id,''),
  110. 'articleId', IFNULL(b.article_id,''),
  111. 'imageUrl', IFNULL(b.image_url,''),
  112. 'createBy', IFNULL(b.create_by,''),
  113. 'createTime', IFNULL(DATE_FORMAT(b.create_time,'%Y-%m-%d %H:%i:%s'),''),
  114. 'updateBy', IFNULL(b.update_by,''),
  115. 'updateTime', IFNULL(DATE_FORMAT(b.update_time,'%Y-%m-%d %H:%i:%s'),'')
  116. )
  117. ELSE NULL
  118. END
  119. )
  120. FROM
  121. community_article_images b
  122. WHERE
  123. b.article_id = a.id
  124. ), '[]') AS images,
  125. c.user_name as user_name,
  126. c.nick_name as nick_name,
  127. c.email as email,
  128. c.avatar as avatar,
  129. COALESCE((
  130. SELECT
  131. JSON_ARRAYAGG(
  132. CASE
  133. WHEN d.id IS NOT NULL THEN
  134. JSON_OBJECT(
  135. 'id', IFNULL(d.id,''),
  136. 'articleId', IFNULL(d.article_id,''),
  137. 'userId', IFNULL(d.user_id,''),
  138. 'content', IFNULL(d.content,''),
  139. 'createBy', IFNULL(d.create_by,''),
  140. 'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
  141. 'updateBy', IFNULL(d.update_by,''),
  142. 'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
  143. )
  144. ELSE NULL
  145. END
  146. )
  147. FROM
  148. community_article_comment d
  149. WHERE
  150. d.article_id = a.id
  151. ), '[]') AS comments
  152. from
  153. community_article a
  154. left join sys_user c on a.user_id = c.user_id
  155. left join community_article_circle e on e.article_id = a.id
  156. left join community_article_tag f on f.article_id = a.id
  157. <where>
  158. <if test="communityArticle.id != null and communityArticle.id != ''">
  159. AND a.id = #{communityArticle.id}
  160. </if>
  161. <if test="communityArticle.title != null and communityArticle.title != ''">
  162. AND a.title like concat('%', #{communityArticle.title}, '%')
  163. </if>
  164. <if test="circleIds != null and circleIds.size() > 0">
  165. and e.circle_id IN
  166. <foreach collection="circleIds" item="circleId" index="index" open="(" close=")" separator=",">
  167. #{circleId}
  168. </foreach>
  169. </if>
  170. <if test="communityArticle.userId != null and communityArticle.userId != ''">
  171. AND a.user_id = #{communityArticle.userId}
  172. </if>
  173. </where>
  174. group by a.id,a.create_time
  175. <if test="searchType == 1">
  176. order by a.create_time desc
  177. </if>
  178. <if test="searchType == 2">
  179. order by a.page_views desc
  180. </if>
  181. limit #{offset},#{limit}
  182. </select>
  183. <select id="selectCommunityArticleCollectById" resultMap="CommunityCollectResult">
  184. select collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
  185. community_article_collect
  186. <where>
  187. <if test="userId != null and userId != ''">
  188. user_id = #{userId}
  189. </if>
  190. <if test="articleId != null and articleId != ''">
  191. and article_id = #{articleId}
  192. </if>
  193. </where>
  194. </select>
  195. <!--点赞-->
  196. <select id="selectCommunityArticleLikeById" resultMap="CommunityLikeResult">
  197. select id as like_id, article_id, user_id, create_by, create_time, update_by, update_time from
  198. community_like
  199. <where>
  200. <if test="userId != null and userId != ''">
  201. user_id = #{userId}
  202. </if>
  203. <if test="articleId != null and articleId != ''">
  204. and article_id = #{articleId}
  205. </if>
  206. </where>
  207. </select>
  208. <insert id="insertCommunityLikeById" parameterType="communityLike">
  209. insert into community_like (article_id, user_id, create_by, create_time, update_by, update_time)
  210. values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
  211. </insert>
  212. <delete id="deleteCommunityLikeById" parameterType="communityLike">
  213. delete
  214. from community_like
  215. where user_id = #{userId}
  216. and article_id = #{articleId};
  217. </delete>
  218. <!--收藏-->
  219. <select id="selectCommunityCollectById" resultMap="CommunityCollectResult" parameterType="communityArticleCollect">
  220. select id as collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
  221. community_article_collect
  222. <where>
  223. <if test="userId != null and userId != ''">
  224. user_id = #{userId}
  225. </if>
  226. <if test="articleId != null and articleId != ''">
  227. and article_id = #{articleId}
  228. </if>
  229. </where>
  230. </select>
  231. <insert id="insertCommunityCollectById" parameterType="communityArticleCollect">
  232. insert into community_article_collect (article_id, user_id, create_by, create_time, update_by, update_time)
  233. values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
  234. </insert>
  235. <delete id="deleteCommunityCollectById" parameterType="communityArticleCollect">
  236. delete
  237. from community_article_collect
  238. where user_id = #{userId}
  239. and article_id = #{articleId};
  240. </delete>
  241. </mapper>