ArticleMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 and d.is_delete != 1 order by d.create_time desc
  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_class 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="classIds != null and classIds.size() > 0">
  165. and e.class_id IN
  166. <foreach collection="classIds" item="classId" index="index" open="(" close=")" separator=",">
  167. #{classId}
  168. </foreach>
  169. </if>
  170. <if test="communityArticle.userId != null and communityArticle.userId != ''">
  171. AND a.user_id = #{communityArticle.userId}
  172. </if>
  173. <if test="communityArticle.userIds != null and communityArticle.userIds.size > 0">
  174. AND a.user_id in
  175. <foreach collection="communityArticle.userIds" item="userId" index="index" open="(" close=")" separator=",">
  176. #{userId}
  177. </foreach>
  178. </if>
  179. <if test="communityArticle.tags != null and communityArticle.tags.size > 0">
  180. AND f.tag_id in
  181. <foreach collection="communityArticle.tags" item="tags" index="index" open="(" close=")" separator=",">
  182. ( select distinct id from community_tag where tag_name = #{tags} )
  183. </foreach>
  184. </if>
  185. and (is_delete != 1 or is_delete is null)
  186. </where>
  187. group by a.id,a.create_time
  188. <if test="searchType == 1">
  189. order by a.create_time desc
  190. </if>
  191. <if test="searchType == 2">
  192. order by a.page_views desc
  193. </if>
  194. limit #{offset},#{limit}
  195. </select>
  196. <select id="selectCommunityArticleCount" parameterType="CommunityArticle" resultType="int">
  197. SELECT COUNT(DISTINCT a.id)
  198. FROM community_article a
  199. LEFT JOIN sys_user c ON a.user_id = c.user_id
  200. LEFT JOIN community_article_class e ON e.article_id = a.id
  201. LEFT JOIN community_article_tag f ON f.article_id = a.id
  202. <where>
  203. <if test="communityArticle.id != null and communityArticle.id != ''">
  204. AND a.id = #{communityArticle.id}
  205. </if>
  206. <if test="communityArticle.title != null and communityArticle.title != ''">
  207. AND a.title LIKE CONCAT('%', #{communityArticle.title}, '%')
  208. </if>
  209. <if test="classIds != null and classIds.size() > 0">
  210. AND e.class_id IN
  211. <foreach collection="classIds" item="classId" open="(" close=")" separator=",">
  212. #{classId}
  213. </foreach>
  214. </if>
  215. <if test="communityArticle.userId != null and communityArticle.userId != ''">
  216. AND a.user_id = #{communityArticle.userId}
  217. </if>
  218. <if test="communityArticle.userIds != null and communityArticle.userIds.size > 0">
  219. AND a.user_id IN
  220. <foreach collection="communityArticle.userIds" item="userId" open="(" close=")" separator=",">
  221. #{userId}
  222. </foreach>
  223. </if>
  224. AND (a.is_delete != 1 OR a.is_delete IS NULL)
  225. </where>
  226. </select>
  227. <select id="selectCommunityArticleCollectById" resultMap="CommunityCollectResult">
  228. select collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
  229. community_article_collect
  230. <where>
  231. <if test="userId != null and userId != ''">
  232. user_id = #{userId}
  233. </if>
  234. <if test="articleId != null and articleId != ''">
  235. and article_id = #{articleId}
  236. </if>
  237. </where>
  238. </select>
  239. <!--点赞-->
  240. <select id="selectCommunityArticleLikeById" resultMap="CommunityLikeResult">
  241. select id as like_id, article_id, user_id, create_by, create_time, update_by, update_time from
  242. community_like
  243. <where>
  244. <if test="userId != null and userId != ''">
  245. user_id = #{userId}
  246. </if>
  247. <if test="articleId != null and articleId != ''">
  248. and article_id = #{articleId}
  249. </if>
  250. </where>
  251. </select>
  252. <insert id="insertCommunityLikeById" parameterType="communityLike">
  253. insert into community_like (article_id, user_id, create_by, create_time, update_by, update_time)
  254. values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
  255. </insert>
  256. <delete id="deleteCommunityLikeById" parameterType="communityLike">
  257. delete
  258. from community_like
  259. where user_id = #{userId}
  260. and article_id = #{articleId};
  261. </delete>
  262. <!--收藏-->
  263. <select id="selectCommunityCollectById" resultMap="CommunityCollectResult" parameterType="communityArticleCollect">
  264. select id as collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
  265. community_article_collect
  266. <where>
  267. <if test="userId != null and userId != ''">
  268. user_id = #{userId}
  269. </if>
  270. <if test="articleId != null and articleId != ''">
  271. and article_id = #{articleId}
  272. </if>
  273. </where>
  274. </select>
  275. <insert id="insertCommunityCollectById" parameterType="communityArticleCollect">
  276. insert into community_article_collect (article_id, user_id, create_by, create_time, update_by, update_time)
  277. values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
  278. </insert>
  279. <delete id="deleteCommunityCollectById" parameterType="communityArticleCollect">
  280. delete
  281. from community_article_collect
  282. where user_id = #{userId}
  283. and article_id = #{articleId};
  284. </delete>
  285. </mapper>