Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

278 рядки
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` &lt;= #{starttime}</if>
  67. <if test=" null != endtime">and `endtime` &gt;= #{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=" 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>
  81. <if test=" null != hasMerchant ">and `merchant_id` is not null</if>
  82. <if test=" 1 == hasParentBillId ">and `parent_bill_id` is not null</if>
  83. <if test=" 0 == hasParentBillId ">and `parent_bill_id` is null</if>
  84. <if test=" 1 == hasFeesStardarsId ">and `energy_fees_id` is not null</if>
  85. <if test=" 0 == hasFeesStardarsId ">and `energy_fees_id` is null</if>
  86. <if test=" null != energyReadingCalcuteId ">and `energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
  87. <if test=" null != energyReadingId ">and `energy_reading_id` = #{energyReadingId}</if>
  88. <if test=" null != rentContractIdList ">
  89. and `rent_contract_id` in
  90. <foreach collection="rentContractIdList" index="index" item="ridItem" open="(" separator="," close=")">
  91. #{ridItem}
  92. </foreach>
  93. </if>
  94. <if test=" null != propertyContractIds ">
  95. and property_contract_id in
  96. <foreach collection="propertyContractIds" index="index" item="pidItem" open="(" separator="," close=")">
  97. #{pidItem}
  98. </foreach>
  99. </if>
  100. <if test=" null != merchantIdList ">
  101. and `merchant_id` in
  102. <foreach collection="merchantIdList" index="index" item="midItem" open="(" separator="," close=")">
  103. #{midItem}
  104. </foreach>
  105. </if>
  106. <if test=" null != statusList ">
  107. and `status` in
  108. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  109. #{stItem}
  110. </foreach>
  111. </if>
  112. <if test=" null != notInIds ">
  113. and id not in
  114. <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
  115. #{nidItem}
  116. </foreach>
  117. </if>
  118. <if test=" null != sortColumns">order by ${sortColumns}</if>
  119. <if test="null != limitStart and null != limitEnd">
  120. limit #{limitStart},#{limitEnd}
  121. </if>
  122. </sql>
  123. <select id="findList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="BaseResultMap">
  124. select
  125. <include refid="allColumns"/>
  126. from wx_all_bill
  127. <include refid="dynamicWhereConditions"/>
  128. </select>
  129. <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
  130. select
  131. <include refid="allColumns"/>
  132. from wx_all_bill where id = #{id} and `tenant_id` = #{tenantId}
  133. </select>
  134. <select id="queryBillRentContractIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
  135. select distinct rent_contract_id from wx_all_bill
  136. <include refid="dynamicWhereConditions"/>
  137. </select>
  138. <resultMap id="SumBaseResultMap" type="com.iformall.domain.vo.WxBillSum">
  139. <result column="receive_pay" jdbcType="VARCHAR" property="needPay"/>
  140. <result column="paid" jdbcType="VARCHAR" property="paid" />
  141. <result column="min_date" jdbcType="TIMESTAMP" property="minDate" />
  142. <result column="max_date" jdbcType="TIMESTAMP" property="maxDate" />
  143. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  144. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  145. </resultMap>
  146. <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
  147. select
  148. sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
  149. sum(CAST(pay AS DECIMAL(20,2))) paid,
  150. min(starttime) min_date,
  151. max(endtime) max_date,
  152. sum(CAST(set_off AS DECIMAL(20,2))) set_off ,
  153. sum(CAST(return_pay AS DECIMAL(20,2))) return_pay
  154. from wx_all_bill
  155. <include refid="dynamicWhereConditions"/>
  156. </select>
  157. <select id="getMerchantIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
  158. select distinct merchant_id from wx_all_bill
  159. <include refid="dynamicWhereConditions"/>
  160. </select>
  161. <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
  162. <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
  163. <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
  164. <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
  165. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  166. </resultMap>
  167. <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxAllBill" resultMap="HotNotifyBaseResultMap">
  168. select
  169. bill_type,
  170. count(1) total_count ,
  171. 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,
  172. MIN(br.starttime) min_begin_time from wx_all_bill
  173. <include refid="dynamicWhereConditions"/>
  174. group by bill_type
  175. </select>
  176. <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
  177. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  178. <result column="bill_id" jdbcType="BIGINT" property="billId" />
  179. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  180. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  181. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  182. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  183. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  184. </resultMap>
  185. <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="NotifyResultMap">
  186. 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
  187. <include refid="dynamicWhereConditions"/>
  188. </select>
  189. <delete id="deleteBillByContract" parameterType="com.iformall.domain.po.WxRentContract">
  190. delete from wx_all_bill where rent_contract_id = #{id}
  191. </delete>
  192. <delete id="deleteBillByPropertyContract" parameterType="com.iformall.domain.po.WxPropertyContract">
  193. delete from wx_all_bill where property_contract_id = #{id}
  194. </delete>
  195. <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxAllBill">
  196. delete from wx_all_bill where is_preview = 1
  197. <if test=" null != rentContractId">
  198. and rent_contract_id = #{rentContractId}
  199. </if>
  200. <if test=" null != propertyContractId">
  201. and property_contract_id = #{propertyContractId}
  202. </if>
  203. </delete>
  204. <delete id="deleteNoNeedPayBill" parameterType="com.iformall.domain.po.WxAllBill">
  205. delete from wx_all_bill where rent_contract_id = #{rentContractId} and is_preview = 0 and status = 2
  206. and starttime &gt; #{shopEndtime} and IFNULL(`pay`,'0') &lt;= 0 AND IFNULL(`set_off`,'0') &lt;= 0 and IFNULL(`return_pay`,'0') &lt;= 0
  207. <if test=" null != rentContractId">
  208. and rent_contract_id = #{rentContractId}
  209. </if>
  210. <if test=" null != propertyContractId">
  211. and property_contract_id = #{propertyContractId}
  212. </if>
  213. <if test=" null != merchantId">
  214. and merchant_id = #{merchantId}
  215. </if>
  216. </delete>
  217. <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxAllBill">
  218. update wx_all_bill set is_preview = #{isPreview},merchant_id = #{merchantId},need_pay = receive_pay
  219. <if test=" null != rentContractId">
  220. where rent_contract_id = #{rentContractId}
  221. </if>
  222. <if test=" null != propertyContractId">
  223. where property_contract_id = #{propertyContractId}
  224. </if>
  225. </update>
  226. <insert id="insertBills" parameterType="HashMap">
  227. INSERT INTO wx_all_bill (
  228. <include refid="allColumns"/>
  229. )
  230. VALUES
  231. <foreach collection="list" item="item" index="index" separator=",">
  232. (
  233. #{item.id},#{item.tenantId},#{item.parentTenantId},#{item.merchantId},#{item.rentShopType},#{item.createtime},
  234. #{item.createBy},#{item.createByName},#{item.updatetime},#{item.updateBy},#{item.updateByName},#{item.priceDetail},
  235. #{item.needPay},#{item.receivePay},#{item.pay},#{item.billType},#{item.payWay},#{item.payDate},#{item.setOff},
  236. #{item.starttime},#{item.endtime},#{item.status},#{item.energyFeesId},#{item.returnPay},#{item.billRemark},
  237. #{item.lastOweCallTime},#{item.lastOweCallUser},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},
  238. #{item.shopId},#{item.shopNumber},#{item.isPreview},#{item.shopInfo},#{item.rentContractId},#{item.propertyContractId},
  239. #{item.parentBillId},#{item.energyReadingCalcuteId},#{item.energyReadingId}
  240. )
  241. </foreach>
  242. </insert>
  243. <delete id = "deleteById" parameterType="HashMap">
  244. delete from wx_all_bill where id = #{id} and tenant_id = #{tenantId}
  245. </delete>
  246. <delete id = "deleteEnergyReadingBills" parameterType="HashMap">
  247. 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
  248. </delete>
  249. <update id="updatePropertyBillInvalidStatusByRent" parameterType="com.iformall.domain.po.WxRentContract">
  250. update wx_all_bill set status = 6 where property_contract_id in
  251. (select id from wx_property_contract where rent_contract_id = #{id})
  252. and status != 3
  253. </update>
  254. </mapper>