CommunityCollectionMapper.xml 3.2 KB

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