后台服务
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

163 linhas
7.9 KiB

  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.iformall.mapper.WxBillSettleMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBillSettle">
  5. <id column="id" property="id"/>
  6. <result column="tenant_id" property="tenantId"/>
  7. <result column="parent_tenant_id" property="parentTenantId"/>
  8. <result column="settle_number" property="settleNumber"/>
  9. <result column="merchant_id" property="merchantId"/>
  10. <result column="status" property="status"/>
  11. <result column="apply_status" property="applyStatus"/>
  12. <result column="receiveMoney" property="receiveMoney"/>
  13. <result column="payMoney" property="payMoney"/>
  14. <result column="settletime" property="settletime"/>
  15. <result column="createtime" property="createtime"/>
  16. <result column="updatetime" property="updatetime"/>
  17. <result column="merchantName" property="merchantName"/>
  18. <result column="has_recorded" property="hasRecorded"/>
  19. </resultMap>
  20. <sql id="allColumns">
  21. `id`,`tenant_id`,`parent_tenant_id`,`settle_number`,`merchant_id`,`status`,`apply_status`,
  22. `receive_money`,`pay_money`,`settletime`,`createtime`,`updatetime`,`has_recorded`
  23. </sql>
  24. <sql id="dynamicWhereConditions">
  25. where 1=1
  26. <if test=" null != id ">and tt.`id` = #{id}</if>
  27. <if test=" null != tenantId and '' != tenantId">
  28. and tt.`tenant_id` = #{tenantId}
  29. </if>
  30. <if test=" null != parentTenantId and '' != parentTenantId">
  31. and tt.`parent_tenant_id` = #{parentTenantId}
  32. </if>
  33. <if test=" null != merchantName and merchantName !='' ">and tt.merchantName like concat('%', #{merchantName},'%')</if>
  34. <if test="starttime != null">
  35. and tt.createtime &gt;= #{starttime}
  36. </if>
  37. <if test="endtime != null">
  38. and tt.createtime &lt;= #{endtime}
  39. </if>
  40. <if test=" null != settleNumber and settleNumber !='' ">and tt.`settle_number` = #{settleNumber}</if>
  41. <if test=" null != status">and tt.`status` = #{status}</if>
  42. <if test=" null != applyStatus">and tt.`apply_status` = #{applyStatus}</if>
  43. <if test="0 == direction">
  44. and (tt.receiveMoney-tt.payMoney-
  45. (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = tt.id)
  46. ) >0
  47. </if>
  48. <if test="1 == direction">
  49. and (tt.receiveMoney-tt.payMoney-
  50. (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = tt.id)
  51. ) &lt;0
  52. </if>
  53. <if test=" null != sortColumns">order by ${sortColumns}</if>
  54. </sql>
  55. <select id="findList" parameterType="com.iformall.domain.po.WxBillSettle" resultMap="BaseResultMap">
  56. select tt.*
  57. <if test="0 == filterSettleRecord">
  58. ,(tt.receiveMoney-tt.payMoney-
  59. (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = tt.id)
  60. ) balance
  61. </if>
  62. <if test="1 == filterSettleRecord">
  63. ,(tt.receiveMoney-tt.payMoney) balance
  64. </if>
  65. from (
  66. select s.*,m.name merchantName,
  67. (select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
  68. (select id,merchant_id,shop_id,tenant_id,parent_tenant_id,1 bill_type_value,'租金'
  69. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_rent where is_preview = 0
  70. union all
  71. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,2 bill_type_value,'租赁押金'
  72. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  73. wx_bill_rent_deposit
  74. union all
  75. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,3 bill_type_value,'物业费'
  76. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  77. wx_bill_property where is_preview = 0
  78. union all
  79. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,4 bill_type_value,'物业押金'
  80. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  81. wx_bill_property_deposit
  82. union all
  83. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,5 bill_type_value,'水费' bill_type,0 as
  84. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  85. type=1
  86. union all
  87. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,6 bill_type_value,'电费' bill_type,0 as
  88. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  89. type=2
  90. union all
  91. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  92. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  93. type=3
  94. union all
  95. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  96. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  97. union all
  98. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  99. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  100. ) bill
  101. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=0
  102. ) receiveMoney,
  103. (select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
  104. (select id,merchant_id,shop_id,tenant_id,parent_tenant_id,1 bill_type_value,'租金'
  105. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_rent where is_preview = 0
  106. union all
  107. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,2 bill_type_value,'租赁押金'
  108. bill_type,need_pay,receive_pay,pay,receive_pay owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  109. wx_bill_rent_deposit
  110. union all
  111. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,3 bill_type_value,'物业费'
  112. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  113. wx_bill_property where is_preview = 0
  114. union all
  115. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,4 bill_type_value,'物业押金'
  116. bill_type,need_pay,receive_pay,pay,receive_pay owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  117. wx_bill_property_deposit
  118. union all
  119. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,5 bill_type_value,'水费' bill_type,0 as
  120. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  121. type=1
  122. union all
  123. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,6 bill_type_value,'电费' bill_type,0 as
  124. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  125. type=2
  126. union all
  127. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  128. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  129. type=3
  130. union all
  131. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  132. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  133. union all
  134. select id,merchant_id,shop_id,tenant_id,parent_tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  135. need_pay,receive_pay,pay,receive_pay owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  136. union all
  137. select id,id merchant_id,'' shop_id,tenant_id,parent_tenant_id,10 bill_type_value,'补贴' bill_type,0 as
  138. need_pay,subsidy receive_pay,0 pay,subsidy owe,'' receive_date,'' pay_date,'' expired_day,status,'' rent_shop_type from wx_merchant_subsidy
  139. ) bill
  140. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=1
  141. ) payMoney
  142. from wx_bill_settle s left JOIN wx_merchant m on(s.merchant_id=m.id)
  143. ) tt
  144. <include refid="dynamicWhereConditions"/>
  145. <if test="null != limitStart and null != limitEnd">
  146. limit #{limitStart},#{limitEnd}
  147. </if>
  148. </select>
  149. <update id = "updateRecorded" parameterType = "hashmap">
  150. update wx_bill_settle set has_recorded = 1 where id = #{id}
  151. </update>
  152. </mapper>