MarketStatMapper.xml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ( 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">
  9. and user_id in
  10. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  11. #{userId}
  12. </foreach>
  13. </if> </where>) AS yearSaleTarget,
  14. ( SELECT sum(ifnull(payment_target,0)) FROM user_target
  15. <where>
  16. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  17. and user_id in
  18. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  19. #{userId}
  20. </foreach>
  21. </if> </where>) AS yearPaymentTarget,
  22. ( SELECT count(*) FROM business_opportunity WHERE state = '跟进中' AND deleted = 0
  23. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  24. and user_id in
  25. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  26. #{userId}
  27. </foreach>
  28. </if>
  29. ) AS businessNum,
  30. ( SELECT
  31. ifnull(sum(amount ),0)
  32. FROM
  33. item
  34. WHERE
  35. deleted = 0
  36. AND sign_date &gt;= DATE_SUB( CURDATE(), INTERVAL dayofyear( now())- 1 DAY )
  37. AND sign_date &lt;= concat( YEAR ( now()), '-12-31' )
  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 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;= DATE_SUB( CURDATE(), INTERVAL dayofyear( now())- 1 DAY )
  46. AND pc.payment_date &lt;= concat( YEAR ( now()), '-12-31' )
  47. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  48. and i.user_id in
  49. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  50. #{userId}
  51. </foreach>
  52. </if>
  53. ) AS yearPaymentDone,
  54. ( 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}
  55. AND pc.payment_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  56. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  57. and i.user_id in
  58. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  59. #{userId}
  60. </foreach>
  61. </if>
  62. ) AS monthPaymentDone
  63. </select>
  64. </mapper>