RevenueMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.huaxu.dao.RevenueMapper">
  4. <!--查询本月售水信息-->
  5. <select id="selectMonthSell" resultType="com.huaxu.dto.MonthSellwaterDto">
  6. select t2.property_name ,sum(t1.water_usage) water_usage
  7. from sms_month_sellwater t1
  8. inner join sms_water_property t2 on t1.property_id=t2.id
  9. where t1.collect_date>=date_format(curdate(), '%Y-%m' )
  10. <if test="tenantId != null and tenantId != ''">
  11. and t1.tenant_id=#{tenantId}
  12. </if>
  13. <if test="companyOrgId != null and companyOrgId !=''">
  14. and t1.company_org_id=#{companyOrgId}
  15. </if>
  16. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  17. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  18. and t1.company_org_id in
  19. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  20. #{item.orgId}
  21. </foreach>
  22. </if>
  23. </if>
  24. group by t2.property_name
  25. order by water_usage desc
  26. </select>
  27. <!--查询近6个月的售水量-->
  28. <select id="selectMonthSellTotal" resultType="com.huaxu.dto.MonthSellwaterDto">
  29. select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,sum(t1.water_usage) water_usage
  30. from sms_month_sellwater t1
  31. where t1.collect_date>=date_sub(date_format(curdate(), '%Y-%m-1' ), interval 5 month)
  32. <if test="tenantId != null and tenantId != ''">
  33. and t1.tenant_id=#{tenantId}
  34. </if>
  35. <if test="companyOrgId != null and companyOrgId !=''">
  36. and t1.company_org_id=#{companyOrgId}
  37. </if>
  38. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  39. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  40. and t1.company_org_id in
  41. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  42. #{item.orgId}
  43. </foreach>
  44. </if>
  45. </if>
  46. group by collect_date_string
  47. order by collect_date_string
  48. </select>
  49. <!--查询月营收情况-->
  50. <select id="selectMonthRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
  51. select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,
  52. sum(receivable_total_amount) receivable_total_amount,sum(received_total_amount) received_total_amount,
  53. sum(general_user_usage) general_user_usage,sum(big_user_usage) big_user_usage,
  54. if(sum(receivable_total_amount)=0,null,sum(received_total_amount)/sum(receivable_total_amount)*100) water_fee_recovery_rate,
  55. if(sum(receivable_total_amount)=0,null,sum(general_user_usage)/sum(receivable_total_amount)*100) general_user_percent,
  56. if(sum(receivable_total_amount)=0,null,sum(big_user_usage)/sum(receivable_total_amount)*100) big_user_percent
  57. from sms_month_revenue t1
  58. where t1.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
  59. <if test="tenantId != null and tenantId != ''">
  60. and t1.tenant_id=#{tenantId}
  61. </if>
  62. <if test="companyOrgId != null and companyOrgId !=''">
  63. and t1.company_org_id=#{companyOrgId}
  64. </if>
  65. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  66. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  67. and t1.company_org_id in
  68. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  69. #{item.orgId}
  70. </foreach>
  71. </if>
  72. </if>
  73. group by collect_date_string
  74. order by collect_date_string
  75. </select>
  76. <!--查询本月各分公司的营收情况-->
  77. <select id="selectCompanyRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
  78. select company_org_id,sum(receivable_total_amount) receivable_total_amount,sum(received_total_amount) received_total_amount,
  79. if(sum(receivable_total_amount)=0,null,sum(received_total_amount)/sum(receivable_total_amount)*100) water_fee_recovery_rate
  80. from sms_month_revenue t1
  81. where t1.collect_date>=date_format(curdate(), '%y-%m-1' )
  82. <if test="tenantId != null and tenantId != ''">
  83. and t1.tenant_id=#{tenantId}
  84. </if>
  85. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  86. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  87. and t1.company_org_id in
  88. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  89. #{item.orgId}
  90. </foreach>
  91. </if>
  92. </if>
  93. group by company_org_id
  94. order by company_org_id
  95. </select>
  96. </mapper>