TaPostMapper.xml 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.yunzhi.demo.mapper.TaPostMapper">
  4. <select id="getPostStatis" resultType="com.yunzhi.demo.vo.StatisPost">
  5. SELECT
  6. *
  7. FROM
  8. (
  9. SELECT
  10. t.*,
  11. sum( IF ( s.serial_no IS NULL, 0, 1 ) ) AS p_v,
  12. count( DISTINCT s.person_id ) AS u_v,
  13. sum( IF ( m.serial_no IS NULL, 0, 1 ) ) AS saved_num
  14. FROM
  15. ta_post t
  16. LEFT JOIN ta_read_log s ON t.post_id = s.post_id
  17. LEFT JOIN ta_post_save m ON t.post_id = m.post_id
  18. AND m.`status` > - 1
  19. WHERE
  20. 1 = 1
  21. <if test="startDate != null and startDate != ''">
  22. AND s.create_date &gt;= DATE_FORMAT( #{startDate}, '%Y-%m-%d' )
  23. AND m.create_date &gt;= DATE_FORMAT( #{startDate}, '%Y-%m-%d' )
  24. </if>
  25. <if test="startDate != null and startDate != ''">
  26. AND s.create_date &lt;= DATE_FORMAT( #{endDate}, '%Y-%m-%d' )
  27. AND m.create_date &lt;= DATE_FORMAT( #{endDate}, '%Y-%m-%d' )
  28. </if>
  29. <if test="typeId != null and typeId != ''">
  30. AND t.type_id = #{typeId}
  31. </if>
  32. <if test="name != null and name != ''">
  33. AND t.name LIKE CONCAT('%', #{name}, '%')
  34. </if>
  35. GROUP BY
  36. t.post_id
  37. ) a
  38. ORDER BY
  39. <if test="asc != null and asc != ''">
  40. ${asc} ASC
  41. </if>
  42. <if test="desc != null and desc != ''">
  43. ${desc} DESC
  44. </if>
  45. </select>
  46. </mapper>