Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

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