CommunityCollectionMapper.xml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.CommunityCollectionMapper">
  6. <select id="selectUserCollection" resultType="com.ruoyi.generator.vo.CommunityCollectionVo">
  7. select id,user_id,collection_name,collection_profile,images,is_delete,articleCount,pageViews,create_by,update_by,create_time,update_time,isFollow from (
  8. SELECT a.id,
  9. a.user_id,
  10. a.collection_name,
  11. a.collection_profile,
  12. a.images,
  13. a.is_delete,
  14. COUNT(b.article_id) AS articleCount,
  15. SUM(c.page_views) AS pageViews,
  16. a.create_by,
  17. a.update_by,
  18. a.create_time,
  19. a.update_time,
  20. '0' as isFollow
  21. FROM community_collection a
  22. LEFT JOIN community_collection_article b ON a.id = b.collection_id
  23. LEFT JOIN community_article c ON b.article_id = c.id
  24. WHERE a.user_id = #{userId}
  25. AND (a.is_delete != '1' OR a.is_delete IS NULL)
  26. <if test="articleId != null and articleId != ''">
  27. AND b.article_id = #{articleId}
  28. </if>
  29. GROUP BY a.id,
  30. a.user_id,
  31. a.collection_name,
  32. a.collection_profile,
  33. a.images,
  34. a.is_delete,
  35. a.create_by,
  36. a.update_by,
  37. a.create_time,
  38. a.update_time
  39. union all
  40. SELECT a.id,
  41. a.user_id,
  42. a.collection_name,
  43. a.collection_profile,
  44. a.images,
  45. a.is_delete,
  46. COUNT(b.article_id) AS articleCount,
  47. SUM(c.page_views) AS pageViews,
  48. a.create_by,
  49. a.update_by,
  50. a.create_time,
  51. a.update_time,
  52. '1' as isFollow
  53. FROM community_collection a
  54. LEFT JOIN community_collection_article b ON a.id = b.collection_id
  55. LEFT JOIN community_article c ON b.article_id = c.id
  56. LEFT JOIN community_collection_user d ON d.collection_id = a.id
  57. WHERE d.user_id = #{userId} AND d.id is not null
  58. AND (a.is_delete != '1' OR a.is_delete IS NULL)
  59. <if test="articleId != null and articleId != ''">
  60. AND b.article_id = #{articleId}
  61. </if>
  62. GROUP BY a.id,
  63. a.user_id,
  64. a.collection_name,
  65. a.collection_profile,
  66. a.images,
  67. a.is_delete,
  68. a.create_by,
  69. a.update_by,
  70. a.create_time,
  71. a.update_time
  72. ) A
  73. <if test="searchType == 1">
  74. order by a.create_time desc
  75. </if>
  76. <if test="searchType == 2">
  77. order by a.page_views desc
  78. </if>
  79. limit #{offset},#{limit}
  80. </select>
  81. <select id="selectCollectById" resultType="com.ruoyi.generator.vo.CommunityCollectionVo">
  82. select a.id,a.collection_name,a.collection_profile,a.images
  83. from `ruoyi-community`.community_collection a
  84. left join `ruoyi-community`.community_collection_article b on a.id = b.collection_id
  85. where b.article_id = #{articleId} and (b.is_delete is null or b.is_delete != '1')
  86. </select>
  87. </mapper>