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.
 
 
 
 
 

279 linhas
14 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.WxAllBillMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxAllBill">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  8. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  9. <result column="rent_shop_type" jdbcType="INTEGER" property="rentShopType"/>
  10. <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
  11. <result column="create_by" jdbcType="BIGINT" property="createBy"/>
  12. <result column="create_by_name" jdbcType="VARCHAR" property="createByName"/>
  13. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
  14. <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
  15. <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/>
  16. <result column="price_detail" jdbcType="VARCHAR" property="priceDetail"/>
  17. <result column="need_pay" jdbcType="VARCHAR" property="needPay"/>
  18. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  19. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  20. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  21. <result column="pay_way" jdbcType="BIGINT" property="payWay"/>
  22. <result column="pay_date" jdbcType="TIMESTAMP" property="payDate"/>
  23. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  24. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  25. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  26. <result column="status" jdbcType="INTEGER" property="status"/>
  27. <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
  28. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  29. <result column="bill_remark" jdbcType="VARCHAR" property="billRemark"/>
  30. <result column="last_owe_call_time" jdbcType="TIMESTAMP" property="lastOweCallTime"/>
  31. <result column="last_owe_call_user" jdbcType="VARCHAR" property="lastOweCallUser"/>
  32. <result column="bussiness_manage_fee_need_pay" jdbcType="VARCHAR" property="bussinessManageFeeNeedPay"/>
  33. <result column="operating_manage_fee_need_pay" jdbcType="VARCHAR" property="operatingManageFeeNeedPay"/>
  34. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  35. <result column="shop_number" jdbcType="VARCHAR" property="shopNumber"/>
  36. <result column="is_preview" jdbcType="INTEGER" property="isPreview"/>
  37. <result column="shop_info" jdbcType="VARCHAR" property="shopInfo"/>
  38. <result column="rent_contract_id" jdbcType="BIGINT" property="rentContractId"/>
  39. <result column="property_contract_id" jdbcType="BIGINT" property="propertyContractId"/>
  40. <result column="parent_bill_id" jdbcType="BIGINT" property="parentBillId"/>
  41. <result column="energy_reading_calcuteId" jdbcType="BIGINT" property="energyReadingCalcuteId" />
  42. <result column="energy_reading_id" jdbcType="BIGINT" property="energyReadingId" />
  43. </resultMap>
  44. <sql id="allColumns">
  45. `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`rent_shop_type`,`createtime`,`create_by`,`create_by_name`,`updatetime`,`update_by`,`update_by_name`,
  46. `price_detail`,`need_pay`,`receive_pay`,`pay`,`bill_type`,`pay_way`,`pay_date`,`set_off`,`starttime`,`endtime`,`status`,`energy_fees_id`,`return_pay`,
  47. `bill_remark`,`last_owe_call_time`,`last_owe_call_user`,`bussiness_manage_fee_need_pay`,`operating_manage_fee_need_pay`,`shop_id`,`shop_number`,
  48. `is_preview`,`shop_info`,`rent_contract_id`,`property_contract_id`,`parent_bill_id`,`energy_reading_calcuteId`,`energy_reading_id`
  49. </sql>
  50. <sql id="dynamicWhereConditions">
  51. where `tenant_id` = #{tenantId}
  52. <if test=" null != id ">and `id` = #{id}</if>
  53. <if test=" null != parentTenantId and '' != parentTenantId"> and `parent_tenant_id` = #{parentTenantId}</if>
  54. <if test=" null != merchantId ">and `merchant_id` = #{merchantId}</if>
  55. <if test=" null != rentShopType ">and `rent_shop_type` = #{rentShopType}</if>
  56. <if test=" null != createBy ">and `create_by` = #{createBy}</if>
  57. <if test=" null != createByName and '' != createByName"> and `create_by_name` like concat('%',#{createByName},'%')</if>
  58. <if test=" null != billType ">and `bill_type` = #{billType}</if>
  59. <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
  60. <if test=" null != status ">and `status` = #{status}</if>
  61. <if test=" null != energyFeesId ">and `energy_fees_id` = #{energyFeesId}</if>
  62. <if test=" null != rentContractId ">and `rent_contract_id` = #{rentContractId}</if>
  63. <if test=" null != propertyContractId ">and `property_contract_id` = #{propertyContractId}</if>
  64. <if test=" null != parentBillId ">and `parent_bill_id` = #{parentBillId}</if>
  65. <if test=" null != isPreview ">and `is_preview` = #{isPreview}</if>
  66. <if test=" null != starttime">and `starttime` &gt;= #{starttime}</if>
  67. <if test=" null != endtime">and `endtime` &lt;= #{endtime}</if>
  68. <if test=" null != month and '' != month">
  69. and date_format(starttime,'%Y-%m') &lt;= #{month} and date_format(endtime,'%Y-%m') &gt;= #{month}
  70. </if>
  71. <if test=" null == nearBillLastTime and null != oweBillLastTime">
  72. and (`starttime` &lt;= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7))
  73. </if>
  74. <if test=" null != nearBillLastTime and null != oweBillLastTime">
  75. and (`starttime` &gt; #{oweBillLastTime} and `starttime` &lt;= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7))
  76. </if>
  77. <if test=" null != needPayStartDay">
  78. and (`starttime` &lt;= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7))
  79. </if>
  80. <if test=" null != toPayMerchant">
  81. and ( `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &lt; 0 or status in (8,9))
  82. </if>
  83. <if test=" 1 == notifyed ">and (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7) )</if>
  84. <if test=" null != hasMerchant ">and `merchant_id` is not null</if>
  85. <if test=" 1 == hasParentBillId ">and `parent_bill_id` is not null</if>
  86. <if test=" 0 == hasParentBillId ">and `parent_bill_id` is null</if>
  87. <if test=" null != energyReadingCalcuteId ">and `energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
  88. <if test=" null != energyReadingId ">and `energy_reading_id` = #{energyReadingId}</if>
  89. <if test=" null != rentContractIdList ">
  90. and `rent_contract_id` in
  91. <foreach collection="rentContractIdList" index="index" item="ridItem" open="(" separator="," close=")">
  92. #{ridItem}
  93. </foreach>
  94. </if>
  95. <if test=" null != propertyContractIds ">
  96. and property_contract_id in
  97. <foreach collection="propertyContractIds" index="index" item="pidItem" open="(" separator="," close=")">
  98. #{pidItem}
  99. </foreach>
  100. </if>
  101. <if test=" null != merchantIdList ">
  102. and `merchant_id` in
  103. <foreach collection="merchantIdList" index="index" item="midItem" open="(" separator="," close=")">
  104. #{midItem}
  105. </foreach>
  106. </if>
  107. <if test=" null != statusList ">
  108. and `status` in
  109. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  110. #{stItem}
  111. </foreach>
  112. </if>
  113. <if test=" null != notInIds ">
  114. and id not in
  115. <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
  116. #{nidItem}
  117. </foreach>
  118. </if>
  119. <if test=" null != sortColumns">order by ${sortColumns}</if>
  120. <if test="null != limitStart and null != limitEnd">
  121. limit #{limitStart},#{limitEnd}
  122. </if>
  123. </sql>
  124. <select id="findList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="BaseResultMap">
  125. select
  126. <include refid="allColumns"/>
  127. from wx_all_bill
  128. <include refid="dynamicWhereConditions"/>
  129. </select>
  130. <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
  131. select
  132. <include refid="allColumns"/>
  133. from wx_all_bill where id = #{id} and `tenant_id` = #{tenantId}
  134. </select>
  135. <select id="queryBillRentContractIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
  136. select distinct rent_contract_id from wx_all_bill
  137. <include refid="dynamicWhereConditions"/>
  138. </select>
  139. <resultMap id="SumBaseResultMap" type="com.iformall.domain.vo.WxBillSum">
  140. <result column="receive_pay" jdbcType="VARCHAR" property="needPay"/>
  141. <result column="paid" jdbcType="VARCHAR" property="paid" />
  142. <result column="min_date" jdbcType="TIMESTAMP" property="minDate" />
  143. <result column="max_date" jdbcType="TIMESTAMP" property="maxDate" />
  144. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  145. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  146. </resultMap>
  147. <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
  148. select
  149. sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
  150. sum(CAST(pay AS DECIMAL(20,2))) paid,
  151. min(starttime) min_date,
  152. max(endtime) max_date,
  153. sum(CAST(set_off AS DECIMAL(20,2))) set_off ,
  154. sum(CAST(return_pay AS DECIMAL(20,2))) return_pay
  155. from wx_all_bill
  156. <include refid="dynamicWhereConditions"/>
  157. </select>
  158. <select id="getMerchantIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
  159. select distinct merchant_id from wx_all_bill
  160. <include refid="dynamicWhereConditions"/>
  161. </select>
  162. <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
  163. <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
  164. <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
  165. <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
  166. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  167. </resultMap>
  168. <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxAllBill" resultMap="HotNotifyBaseResultMap">
  169. select
  170. bill_type,
  171. count(1) total_count ,
  172. sum(CAST(`receive_pay` AS DECIMAL(20,2)) - CAST(`pay` AS DECIMAL(20,2)) - CAST(IFNULL(`set_off`,'0') AS DECIMAL(20,2)) + CAST(IFNULL(`return_pay`,'0') AS DECIMAL(20,2))) total_money,
  173. MIN(starttime) min_begin_time from wx_all_bill
  174. <include refid="dynamicWhereConditions"/>
  175. group by bill_type
  176. </select>
  177. <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
  178. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  179. <result column="bill_id" jdbcType="BIGINT" property="billId" />
  180. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  181. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  182. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  183. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  184. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  185. </resultMap>
  186. <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="NotifyResultMap">
  187. select bill_type,br.id as bill_id, br.starttime,br.endtime,br.receive_pay,br.pay,br.merchant_id from wx_all_bill br
  188. <include refid="dynamicWhereConditions"/>
  189. </select>
  190. <delete id="deleteBillByContract" parameterType="com.iformall.domain.po.WxRentContract">
  191. delete from wx_all_bill where rent_contract_id = #{id}
  192. </delete>
  193. <delete id="deleteBillByPropertyContract" parameterType="com.iformall.domain.po.WxPropertyContract">
  194. delete from wx_all_bill where property_contract_id = #{id}
  195. </delete>
  196. <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxAllBill">
  197. delete from wx_all_bill where is_preview = 1
  198. <if test=" null != rentContractId">
  199. and rent_contract_id = #{rentContractId}
  200. </if>
  201. <if test=" null != propertyContractId">
  202. and property_contract_id = #{propertyContractId}
  203. </if>
  204. </delete>
  205. <delete id="deleteNoNeedPayBill" parameterType="com.iformall.domain.po.WxAllBill">
  206. delete from wx_all_bill where status = 2
  207. and starttime &gt;= #{shopEndtime} and IFNULL(`pay`,'0') &lt;= 0 AND IFNULL(`set_off`,'0') &lt;= 0 and IFNULL(`return_pay`,'0') &lt;= 0
  208. <if test=" null != rentContractId">
  209. and rent_contract_id = #{rentContractId}
  210. </if>
  211. <if test=" null != propertyContractId">
  212. and property_contract_id = #{propertyContractId}
  213. </if>
  214. <if test=" null != merchantId">
  215. and merchant_id = #{merchantId}
  216. </if>
  217. </delete>
  218. <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxAllBill">
  219. update wx_all_bill set is_preview = #{isPreview}
  220. <if test=" null != rentContractId">
  221. where rent_contract_id = #{rentContractId}
  222. </if>
  223. <if test=" null != propertyContractId">
  224. where property_contract_id = #{propertyContractId}
  225. </if>
  226. </update>
  227. <insert id="insertBills" parameterType="HashMap">
  228. INSERT INTO wx_all_bill (
  229. <include refid="allColumns"/>
  230. )
  231. VALUES
  232. <foreach collection="list" item="item" index="index" separator=",">
  233. (
  234. #{item.id},#{item.tenantId},#{item.parentTenantId},#{item.merchantId},#{item.rentShopType},#{item.createtime},
  235. #{item.createBy},#{item.createByName},#{item.updatetime},#{item.updateBy},#{item.updateByName},#{item.priceDetail},
  236. #{item.needPay},#{item.receivePay},#{item.pay},#{item.billType},#{item.payWay},#{item.payDate},#{item.setOff},
  237. #{item.starttime},#{item.endtime},#{item.status},#{item.energyFeesId},#{item.returnPay},#{item.billRemark},
  238. #{item.lastOweCallTime},#{item.lastOweCallUser},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},
  239. #{item.shopId},#{item.shopNumber},#{item.isPreview},#{item.shopInfo},#{item.rentContractId},#{item.propertyContractId},
  240. #{item.parentBillId},#{item.energyReadingCalcuteId},#{item.energyReadingId}
  241. )
  242. </foreach>
  243. </insert>
  244. <delete id = "deleteById" parameterType="HashMap">
  245. delete from wx_all_bill where id = #{id} and tenant_id = #{tenantId}
  246. </delete>
  247. <delete id = "deleteEnergyReadingBills" parameterType="HashMap">
  248. delete from wx_all_bill where energy_reading_calcuteId = #{energyReadingCalcuteId} and tenant_id = #{tenantId} and status = 2 and pay &lt;= 0 and IFNULL(`set_off`,'0') &lt;= 0 and IFNULL(`return_pay`,'0') &lt;= 0
  249. </delete>
  250. <update id="updatePropertyBillInvalidStatusByRent" parameterType="com.iformall.domain.po.WxRentContract">
  251. update wx_all_bill set status = 6 where property_contract_id in
  252. (select id from wx_property_contract where rent_contract_id = #{id})
  253. and status != 3
  254. </update>
  255. </mapper>