MarketStatMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.dayou.mapper.MarketStatMapper">
  4. <select id="marketStat" resultType="com.dayou.vo.MarketStatVO" parameterType="com.dayou.dto.MarketStatDTO">
  5. SELECT
  6. ifnull(( SELECT sum(ifnull(sale_target,0)) FROM user_target
  7. <where>
  8. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">and user_id in
  9. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  10. #{userId}
  11. </foreach>
  12. </if> </where> ),0) AS yearSaleTarget,
  13. ifnull(( SELECT sum(ifnull(payment_target,0)) FROM user_target
  14. <where>
  15. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  16. and user_id in
  17. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  18. #{userId}
  19. </foreach>
  20. </if> </where>),0) AS yearPaymentTarget,
  21. ( SELECT count(*) FROM business_opportunity WHERE state = '跟进中' AND deleted = 0
  22. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  23. and user_id in
  24. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  25. #{userId}
  26. </foreach>
  27. </if>
  28. ) AS businessNum,
  29. ( SELECT
  30. ifnull(sum(amount ),0)
  31. FROM
  32. item
  33. WHERE
  34. deleted = 0
  35. AND upload_date is not null
  36. AND upload_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  37. AND upload_date &lt;= concat( YEAR ( now()), '-12-22' )
  38. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  39. and user_id in
  40. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  41. #{userId}
  42. </foreach>
  43. </if>
  44. ) AS yearSaleDone,
  45. ( SELECT
  46. ifnull( sum( pc.amount ), 0 )
  47. FROM
  48. payment_collection pc
  49. LEFT JOIN item i ON i.id = pc.item_id
  50. WHERE
  51. pc.deleted = 0
  52. AND pc.payment_date &gt;= concat(
  53. YEAR (
  54. now())-1,
  55. '-12-23'
  56. )
  57. AND pc.payment_date &lt;= concat(
  58. YEAR (
  59. now()),
  60. '-12-22'
  61. )
  62. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  63. and i.user_id in
  64. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  65. #{userId}
  66. </foreach>
  67. </if>
  68. ) AS yearPaymentDone,
  69. ( SELECT ifnull(sum( pc.amount ),0) FROM payment_collection pc left join item i on i.id = pc.item_id WHERE pc.deleted = 0 AND pc.payment_date &gt;= #{lastMonth23}
  70. AND pc.payment_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  71. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  72. and i.user_id in
  73. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  74. #{userId}
  75. </foreach>
  76. </if>
  77. ) AS monthPaymentDone,
  78. ifnull(( select sum(estimate_amount) from business_opportunity where deleted = 0 and state = '跟进中'
  79. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  80. and user_id in
  81. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  82. #{userId}
  83. </foreach>
  84. </if>
  85. ),0) AS estimateAmount
  86. </select>
  87. <select id="currentMonthPayment" resultType="java.math.BigDecimal">
  88. SELECT ifnull(sum( pc.amount ),0) FROM payment_collection pc left join item i on i.id = pc.item_id WHERE pc.deleted = 0 AND pc.payment_date >= #{lastMonth23}
  89. AND pc.payment_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' ) and i.user_id = #{userId}
  90. </select>
  91. <select id="currentYearPayment" resultType="java.math.BigDecimal">
  92. SELECT
  93. ifnull( sum( pc.amount ), 0 )
  94. FROM
  95. payment_collection pc
  96. LEFT JOIN item i ON i.id = pc.item_id
  97. WHERE
  98. pc.deleted = 0
  99. AND pc.payment_date &gt;= concat(
  100. YEAR (
  101. now())-1,
  102. '-12-23'
  103. )
  104. AND pc.payment_date &lt;= concat(
  105. YEAR (
  106. now()),
  107. '-12-22'
  108. )
  109. and i.user_id = #{userId}
  110. </select>
  111. <select id="currentYearTeamPayment" parameterType="java.util.Set" resultType="java.math.BigDecimal">
  112. SELECT
  113. ifnull( sum( pc.amount ), 0 )
  114. FROM
  115. payment_collection pc
  116. LEFT JOIN item i ON i.id = pc.item_id
  117. WHERE
  118. pc.deleted = 0
  119. AND pc.payment_date &gt;= concat(
  120. YEAR (
  121. now())-1,
  122. '-12-23'
  123. )
  124. AND pc.payment_date &lt;= concat(
  125. YEAR (
  126. now()),
  127. '-12-22'
  128. )
  129. and i.user_id in (
  130. <foreach collection="userIds" item="item" index="index" separator=",">
  131. #{item}
  132. </foreach>
  133. )
  134. </select>
  135. </mapper>