RevenueMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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_water_property t2
  8. left join sms_month_sellwater t1 on t1.property_id=t2.id and t1.collect_date>=date_format(curdate(), '%Y-%m' )
  9. <if test="tenantId != null and tenantId != ''">
  10. and t1.tenant_id=#{tenantId}
  11. </if>
  12. <if test="companyOrgId != null and companyOrgId !=''">
  13. and t1.company_org_id=#{companyOrgId}
  14. </if>
  15. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  16. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  17. and t1.company_org_id in
  18. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  19. #{item.orgId}
  20. </foreach>
  21. </if>
  22. </if>
  23. inner join (
  24. select distinct property_id
  25. from sms_month_sellwater
  26. where 1=1
  27. <if test="tenantId != null and tenantId != ''">
  28. and tenant_id=#{tenantId}
  29. </if>
  30. <if test="companyOrgId != null and companyOrgId !=''">
  31. and company_org_id=#{companyOrgId}
  32. </if>
  33. )t3 on t2.id=t3.property_id
  34. group by t2.property_name
  35. order by water_usage desc,t2.property_name
  36. </select>
  37. <!--查询近6个月的售水量-->
  38. <select id="selectMonthSellTotal" resultType="com.huaxu.dto.MonthSellwaterDto">
  39. select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,sum(t1.water_usage) water_usage
  40. from sms_month_sellwater t1
  41. where t1.collect_date>=date_sub(date_format(curdate(), '%Y-%m-1' ), interval 5 month)
  42. <if test="tenantId != null and tenantId != ''">
  43. and t1.tenant_id=#{tenantId}
  44. </if>
  45. <if test="companyOrgId != null and companyOrgId !=''">
  46. and t1.company_org_id=#{companyOrgId}
  47. </if>
  48. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  49. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  50. and t1.company_org_id in
  51. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  52. #{item.orgId}
  53. </foreach>
  54. </if>
  55. </if>
  56. group by collect_date_string
  57. order by collect_date_string
  58. </select>
  59. <!--查询月营收情况-->
  60. <select id="selectMonthRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
  61. select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,sum(user_meter_count) user_meter_count,
  62. sum(receivable_total_amount) receivable_total_amount,sum(received_total_amount) received_total_amount,
  63. sum(general_user_usage) general_user_usage,sum(big_user_usage) big_user_usage,
  64. if(sum(receivable_total_amount)=0,null,sum(received_total_amount)/sum(receivable_total_amount)*100) water_fee_recovery_rate,
  65. if(sum(receivable_total_amount)=0,null,sum(general_user_usage)/sum(receivable_total_amount)*100) general_user_percent,
  66. if(sum(receivable_total_amount)=0,null,sum(big_user_usage)/sum(receivable_total_amount)*100) big_user_percent
  67. from sms_month_revenue t1
  68. where t1.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
  69. <if test="tenantId != null and tenantId != ''">
  70. and t1.tenant_id=#{tenantId}
  71. </if>
  72. <if test="companyOrgId != null and companyOrgId !=''">
  73. and t1.company_org_id=#{companyOrgId}
  74. </if>
  75. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  76. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  77. and t1.company_org_id in
  78. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  79. #{item.orgId}
  80. </foreach>
  81. </if>
  82. </if>
  83. group by collect_date_string
  84. order by collect_date_string
  85. </select>
  86. <!--查询本月各分公司的营收情况-->
  87. <select id="selectCompanyRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
  88. select company_org_id,sum(receivable_total_amount) receivable_total_amount,sum(received_total_amount) received_total_amount,
  89. if(sum(receivable_total_amount)=0,null,sum(received_total_amount)/sum(receivable_total_amount)*100) water_fee_recovery_rate
  90. from sms_month_revenue t1
  91. where t1.collect_date>=date_format(curdate(), '%y-%m-1' )
  92. <if test="tenantId != null and tenantId != ''">
  93. and t1.tenant_id=#{tenantId}
  94. </if>
  95. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  96. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  97. and t1.company_org_id in
  98. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  99. #{item.orgId}
  100. </foreach>
  101. </if>
  102. </if>
  103. group by company_org_id
  104. order by company_org_id
  105. </select>
  106. <!--App总览-生产-售水量(本月,本年)-->
  107. <select id="selectOverviewRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
  108. select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,
  109. sum(METER_READING_USAGE) meter_reading_usage,
  110. sum(RECEIVABLE_TOTAL_AMOUNT) receivable_total_amount,
  111. sum(RECEIVED_TOTAL_AMOUNT) received_total_amount,
  112. sum(GENERAL_USER_USAGE) general_user_usage,
  113. sum(BIG_USER_USAGE) big_user_usage
  114. from sms_month_revenue t1
  115. where t1.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
  116. <if test="tenantId != null and tenantId != ''">
  117. and t1.tenant_id=#{tenantId}
  118. </if>
  119. <if test="companyOrgId != null and companyOrgId !=''">
  120. and t1.company_org_id=#{companyOrgId}
  121. </if>
  122. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  123. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  124. and t1.company_org_id in
  125. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  126. #{item.orgId}
  127. </foreach>
  128. </if>
  129. </if>
  130. group by collect_date_string
  131. order by collect_date_string
  132. </select>
  133. <!--App总览-生产数据-按时间段查询(环比)-->
  134. <select id="selectRevenueByDate" resultType="com.huaxu.dto.MonthRevenueDto">
  135. select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,
  136. sum(METER_READING_USAGE) meter_reading_usage,
  137. sum(RECEIVABLE_TOTAL_AMOUNT) receivable_total_amount,
  138. sum(RECEIVED_TOTAL_AMOUNT) received_total_amount,
  139. sum(GENERAL_USER_USAGE) general_user_usage,
  140. sum(BIG_USER_USAGE) big_user_usage,
  141. from sms_month_revenue t1
  142. where t1.collect_date>=date_format(#{startDate}, '%y-%m-1' ) and t1.collect_date &lt;= date_format(#{endDate}, '%y-%m-1')
  143. <if test="tenantId != null and tenantId != ''">
  144. and t1.tenant_id=#{tenantId}
  145. </if>
  146. <if test="companyOrgId != null and companyOrgId !=''">
  147. and t1.company_org_id=#{companyOrgId}
  148. </if>
  149. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  150. <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
  151. and t1.company_org_id in
  152. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  153. #{item.orgId}
  154. </foreach>
  155. </if>
  156. </if>
  157. group by collect_date_string
  158. order by collect_date_string
  159. </select>
  160. <!--查询是否当月有营收数据-->
  161. <select id="isExistThisMonthRevenue" resultType="java.lang.Integer">
  162. select count(1)
  163. from sms_month_revenue t1
  164. where t1.collect_date>=date_format(curdate(), '%Y-%m' )
  165. <if test="tenantId != null and tenantId != ''">
  166. and t1.tenant_id=#{tenantId}
  167. </if>
  168. </select>
  169. <!-- 新增所有列 -->
  170. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  171. insert into sms_month_revenue(`tenant_id`, `company_org_id`, `collect_date`, `user_meter_count`, `user_meter_add_count`,
  172. `meter_reading_count`, `meter_reading_usage`, `charging_usage`, `meter_reading_finished_rate`, `meter_reading_arrival_rate`,
  173. `meter_reading_error_rate`, `receivable_total_amount`, `received_total_amount`, `invoiced_total_amount`,
  174. `arrears_total_amount`, `general_user_usage`, `big_user_usage`, `remark`, `date_create`, `create_by`, `date_update`, `update_by`)
  175. values (#{tenantId},#{companyOrgId},#{collectDate},#{userMeterCount},#{userMeterAddCount},#{meterReadingCount},
  176. #{meterReadingUsage},#{chargingUsage},#{meterReadingFinishedRate},#{meterReadingArrivalRate},#{meterReadingErrorRate},
  177. #{receivableTotalAmount},#{receivedTotalAmount},#{invoicedTotalAmount},#{arrearsTotalAmount},#{generalUserUsage},
  178. #{bigUserUsage},#{remark},now(),null,now(),null)
  179. </insert>
  180. <!-- 通过租户id修改当月数据 -->
  181. <update id="update">
  182. update sms_month_revenue
  183. <set>
  184. <if test="userMeterCount != null and userMeterCount != 0">
  185. user_meter_count = #{userMeterCount},
  186. </if>
  187. <if test="userMeterAddCount != null and userMeterAddCount != 0">
  188. user_meter_add_count = #{userMeterAddCount},
  189. </if>
  190. DATE_UPDATE = now()
  191. </set>
  192. where tenant_id = #{tenantId} and collect_date>=date_format(curdate(), '%Y-%m-1' )
  193. </update>
  194. <!--查询该租户一级公司id-->
  195. <select id="selectCompanyIdByTenant" resultType="java.lang.Integer">
  196. select id
  197. from uims.uims_org
  198. where parent_org_id=0 and tenant_id=#{tenantId}
  199. </select>
  200. </mapper>