ArticleMapper.xml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.caimei.www.mapper.ArticleDao">
  4. <select id="getArticleTypes" resultType="com.caimei.www.pojo.page.BaseLink">
  5. select a.id,
  6. a.name,
  7. a.sort
  8. from info_type a
  9. where a.enabledStatus = 1
  10. order by a.sort desc
  11. </select>
  12. <select id="getTopClickRate" resultType="java.lang.Integer">
  13. select IFNULL(clickRate, 1)
  14. from info_label
  15. where hotLabelStatus = 1
  16. order by clickRate desc
  17. limit 1
  18. </select>
  19. <select id="getArticleLabels" resultType="com.caimei.www.pojo.page.BaseLink">
  20. select id,name,clickRate as sort,link,jumpStatus as typeId
  21. from info_label
  22. where hotLabelStatus = 1
  23. order by recommendLabelStatus desc, hotLabelStatus desc, createDate desc
  24. limit 30
  25. </select>
  26. <select id="getArticleRecommended" resultType="com.caimei.www.pojo.page.ImageLink">
  27. select a.id,
  28. a.title,
  29. a.guidanceImage as image
  30. from info a
  31. where a.recommendStatus = 1
  32. and a.enabledStatus = 1
  33. and NOW() >= a.pubdate
  34. <if test="typeId != null and typeId != ''">
  35. and a.typeId = #{typeId}
  36. </if>
  37. order by a.pubdate desc
  38. </select>
  39. <select id="getArticleRelated" resultType="com.caimei.www.pojo.page.Article">
  40. select
  41. a.id as id,
  42. a.title as title,
  43. a.guidanceImage as image,
  44. a.publisher as publisher,
  45. a.pubdate as publish_date,
  46. a.recommendContent as intro,
  47. a.infoContent as content,
  48. (IFNULL(c.pv, 0) + IFNULL(a.basePv, 0) + IFNULL((c.num + a.basePraise), 0)) as pv,
  49. a.label as label,
  50. a.typeId as typeId
  51. from info as a
  52. left join info_praise c on a.id = c.infoId
  53. <where>
  54. <if test="labels != null and labels != ''">
  55. <foreach collection="labels" item="label" open="(" close=")" index="index" separator="OR">
  56. a.label like CONCAT(CONCAT('%', #{label}), '%')
  57. </foreach>
  58. </if>
  59. <if test="id != null and id != ''">
  60. and a.id != #{id}
  61. </if>
  62. and NOW() >= a.pubdate
  63. and a.enabledStatus = 1
  64. </where>
  65. order by a.pubdate desc
  66. </select>
  67. <select id="getLastestInfoADs" resultType="com.caimei.www.pojo.page.ImageLink">
  68. select a.id, a.serviceObject as title, a.guidanceImage as image, a.link
  69. from info_ad a
  70. where a.location = 2
  71. and a.enabledStatus = 1
  72. order by a.createDate desc
  73. limit 3
  74. </select>
  75. <update id="clickArticleAd">
  76. update info_ad
  77. set clickRate = IFNULL(clickRate, 0) + 1,
  78. updateDate = NOW()
  79. where id = #{id}
  80. </update>
  81. <update id="clickArticleLabel">
  82. update info_label
  83. set clickRate = IFNULL(clickRate, 0) + 1,
  84. updateDate = NOW()
  85. where id = #{id}
  86. </update>
  87. <update id="articleLike">
  88. UPDATE info_praise
  89. SET num = num+1
  90. WHERE infoId = #{infoId}
  91. </update>
  92. <update id="articlePv">
  93. UPDATE info_praise
  94. SET pv = pv+1
  95. WHERE infoId = #{infoId}
  96. </update>
  97. <select id="getArticleInfo" resultType="com.caimei.www.pojo.page.Article">
  98. SELECT
  99. a.id AS id,
  100. a.title AS title,
  101. a.guidanceImage AS image,
  102. a.publisher AS publisher,
  103. a.pubdate AS publish_date,
  104. a.recommendContent AS intro,
  105. a.infoContent AS content,
  106. (
  107. IFNULL(c.pv, 0) + IFNULL(a.basePv, 0) + IFNULL(
  108. (c.num + a.basePraise),
  109. 0
  110. )
  111. ) AS pv,
  112. a.label AS label,
  113. a.typeId AS typeId,
  114. a.keyword AS keyword,
  115. a.recommendContent AS recommendContent,
  116. a.source AS source,
  117. IFNULL((c.num + a.basePraise), 0) AS likes
  118. FROM
  119. info AS a
  120. LEFT JOIN info_praise c ON a.id = c.infoId
  121. WHERE
  122. a.id = #{id}
  123. AND a.enabledStatus = 1
  124. </select>
  125. <select id="findLabelIdsByName" resultType="java.lang.Integer">
  126. select id
  127. from info_label
  128. where infoLabelStatus = 1
  129. and name in
  130. <foreach collection="labelTexts" item="label" open="(" close=")" index="index" separator=",">
  131. #{label}
  132. </foreach>
  133. group by name
  134. order by clickRate desc
  135. </select>
  136. </mapper>