Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

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