You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

387 lines
20 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.WxBillDepositMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBillDeposit">
  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="rent_contract_id" jdbcType="BIGINT" property="rentContractId" />
  9. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  10. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  11. <result column="receive_date" jdbcType="TIMESTAMP" property="receiveDate" />
  12. <result column="pay_date" jdbcType="TIMESTAMP" property="payDate" />
  13. <result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
  14. <result column="create_by" jdbcType="BIGINT" property="createBy"/>
  15. <result column="create_by_name" jdbcType="VARCHAR" property="createByName"/>
  16. <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
  17. <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/>
  18. <result column="expired_day" jdbcType="BIGINT" property="expiredDay" />
  19. <result column="status" jdbcType="INTEGER" property="status" />
  20. <result column="apply_status" jdbcType="INTEGER" property="applyStatus"/>
  21. <result column="apply_pay_img" jdbcType="INTEGER" property="applyPayImg"/>
  22. <result column="apply_update_time" jdbcType="INTEGER" property="applyUpdateTime"/>
  23. <result column="is_del" jdbcType="INTEGER" property="isDel" />
  24. <result column="need_pay" jdbcType="VARCHAR" property="needPay"/>
  25. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  26. <result column="user_id" jdbcType="BIGINT" property="userId" />
  27. <result column="shop_id" jdbcType="BIGINT" property="shopId" />
  28. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime" />
  29. <result column="rent_shop_type" jdbcType="INTEGER" property="rentShopType"/>
  30. <result column="return_price" jdbcType="VARCHAR" property="returnPrice"/>
  31. <result column="pay_way" jdbcType="BIGINT" property="payWay"/>
  32. <result column="service_charge_pay" property="serviceChargePay"/>
  33. <result column="shop_info" property="shopInfo"/>
  34. <result column="freeze" property="freeze"/>
  35. <result column="merchant_name" property="merchantName"/>
  36. <result column="shop_number" property="shopNumber"/>
  37. <result column="contract_depoist_detail" property="contractDepoistDetail"/>
  38. <result column="last_owe_call_time" jdbcType="TIMESTAMP" property="lastOweCallTime"/>
  39. <result column="last_owe_call_user" jdbcType="VARCHAR" property="lastOweCallUser"/>
  40. <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
  41. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  42. </resultMap>
  43. <sql id="allColumns">
  44. `id`,`tenant_id`,`parent_tenant_id`,`rent_contract_id`,`receive_pay`,`pay`,`receive_date`,`pay_date`,`createtime`,`last_owe_call_time`,`set_off`,
  45. `expired_day`,`status`,`is_del`,`need_pay`,`merchant_id`,`user_id`,`shop_id`,`updatetime`,`apply_status`,`apply_pay_img`,`apply_update_time`,`energy_fees_id`,
  46. `last_owe_call_user`,`rent_shop_type`,`return_price`,`pay_way`,service_charge_pay,contract_depoist_detail,`create_by`,`create_by_name`,`update_by`,`update_by_name`
  47. </sql>
  48. <sql id="dynamicWhereConditions">
  49. where 1 = 1
  50. <if test=" null != id "> and `id` = #{id} </if>
  51. <if test=" null != tenantId and '' != tenantId">
  52. and `tenant_id` = #{tenantId}
  53. </if>
  54. <if test=" null != parentTenantId and '' != parentTenantId">
  55. and `parent_tenant_id` = #{parentTenantId}
  56. </if>
  57. <if test=" null != rentContractId "> and `rent_contract_id` = #{rentContractId} </if>
  58. <if test=" null != energyFeesId ">and `energy_fees_id` = #{energyFeesId}</if>
  59. <if test=" null != receivePay "> and `receive_pay` = #{receivePay} </if>
  60. <if test=" null != pay "> and `pay` = #{pay} </if>
  61. <if test=" null != receiveDate "> and `receive_date` = #{receiveDate} </if>
  62. <if test=" null != payDate "> and `pay_date` = #{payDate} </if>
  63. <if test=" null != createtime "> and `createtime` = #{createtime} </if>
  64. <if test=" null != expiredDay "> and `expired_day` = #{expiredDay} </if>
  65. <if test=" null != status "> and `status` = #{status} </if>
  66. <if test=" null != applyStatus ">and `apply_status` = #{applyStatus}</if>
  67. <if test=" null != isDel "> and `is_del` = #{isDel} </if>
  68. <if test=" null != needPay "> and `need_pay` = #{needPay} </if>
  69. <if test=" null != merchantId "> and `merchant_id` = #{merchantId} </if>
  70. <if test=" null != userId "> and `user_id` = #{userId} </if>
  71. <if test=" null != shopId "> and `shop_id` = #{shopId} </if>
  72. <if test=" null != updatetime ">and `updatetime` = #{updatetime}</if>
  73. <if test=" null != rentShopType ">and `rent_shop_type` = #{rentShopType}</if>
  74. <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
  75. <if test=" null != contractDepoistDetail and '' != contractDepoistDetail">
  76. and `contract_depoist_detail` like concat('%', #{contractDepoistDetail},'%')
  77. </if>
  78. <if test=" null != starttime">and `starttime` &lt;= #{starttime}</if>
  79. <if test=" null != endtime">and `endtime` &gt;= #{endtime}</if>
  80. <if test=" null != month and '' != month">
  81. and date_format(starttime,'%Y-%m') &lt;= #{month} and date_format(endtime,'%Y-%m') &gt;= #{month}
  82. </if>
  83. <if test=" null == nearBillLastTime and null != oweBillLastTime">
  84. and (`starttime` &lt;= #{oweBillLastTime} and `receive_pay` - `pay` - `set_off` &gt; 0 and status not in (3,6,7))
  85. </if>
  86. <if test=" null != nearBillLastTime and null != oweBillLastTime">
  87. and (`starttime` &gt; #{oweBillLastTime} and `starttime` &lt;= #{nearBillLastTime} and `receive_pay` - `pay` - `set_off` &gt; 0 and status not in (3,6,7))
  88. </if>
  89. <if test=" 1 == notifyed ">and (`last_owe_call_time` is not null and `receive_pay` - `pay` - `set_off` &gt; 0 and status not in (3,6,7) )</if>
  90. <if test=" null != merchantIds ">
  91. and `merchant_id` in
  92. <foreach collection="merchantIds" index="index" item="midItem" open="(" separator="," close=")">
  93. #{midItem}
  94. </foreach>
  95. </if>
  96. <if test=" null != rentContractIdList ">
  97. and rent_contract_id in
  98. <foreach collection="rentContractIdList" index="index" item="rdItem" open="(" separator="," close=")">
  99. #{rdItem}
  100. </foreach>
  101. </if>
  102. <if test=" null != statusList ">
  103. and status in
  104. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  105. #{stItem}
  106. </foreach>
  107. </if>
  108. <if test=" null != ids ">
  109. and id in
  110. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  111. #{idItem}
  112. </foreach>
  113. </if>
  114. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  115. </sql>
  116. <select id="findList" parameterType="com.iformall.domain.po.WxBillDeposit" resultMap="BaseResultMap">
  117. select <include refid="allColumns" /> from wx_bill_rent_deposit
  118. <include refid="dynamicWhereConditions" />
  119. </select>
  120. <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
  121. select <include refid="allColumns" /> from wx_bill_rent_deposit
  122. where id = #{id} and tenant_id = #{tenantId}
  123. </select>
  124. <select id="findRentContractIds" parameterType="com.iformall.domain.po.WxBillDeposit" resultType="Long">
  125. select distinct rent_contract_id from wx_bill_rent_deposit
  126. <include refid="dynamicWhereConditions" />
  127. </select>
  128. <select id="queryBillDepositList" parameterType="com.iformall.domain.po.WxBillDeposit" resultMap="BaseResultMap">
  129. select br.`id`,br.`tenant_id`,br.`parent_tenant_id`,br.`rent_contract_id`,br.`receive_pay`,br.`pay`,br.`receive_date`,br.`pay_date`,br.`createtime`,br.`expired_day`,br.`last_owe_call_time`,
  130. br.`status`,br.`need_pay`,br.`updatetime`,br.`merchant_id`,br.`apply_status`,br.`apply_pay_img`,br.`apply_update_time`,br.`contract_depoist_detail`,br.`last_owe_call_user`,br.`set_off`,
  131. br.`rent_shop_type`,br.`return_price`, br.pay_way,br.shop_info ,br.freeze,br.service_charge_pay,br.`create_by`,br.`create_by_name`,br.`update_by`,br.`update_by_name`,br.`energy_fees_id`
  132. from wx_bill_rent_deposit br
  133. <include refid="queryBillRentListCondition"/>
  134. order by br.id desc
  135. </select>
  136. <sql id="queryBillRentListCondition">
  137. <where>
  138. 1 = 1
  139. <if test=" null != id ">and br.`id` = #{id}</if>
  140. <if test=" null != merchantId ">and br.`merchant_id` = #{merchantId}</if>
  141. <if test=" null != tenantId and '' != tenantId">
  142. and br.`tenant_id` = #{tenantId}
  143. </if>
  144. <if test=" null != parentTenantId and '' != parentTenantId">
  145. and br.`parent_tenant_id` = #{parentTenantId}
  146. </if>
  147. <if test=" null != status ">and br.`status` = #{status}</if>
  148. <if test=" null != applyStatus ">and br.`apply_status` = #{applyStatus}</if>
  149. <if test=" null != isDel ">and br.`is_del` = #{isDel}</if>
  150. <if test=" null != rentShopType ">and br.`rent_shop_type` = #{rentShopType}</if>
  151. <if test=" null != rentContractId ">and br.`rent_contract_id` = #{rentContractId}</if>
  152. <if test=" null != energyFeesId ">and br.`energy_fees_id` = #{energyFeesId}</if>
  153. <if test=" null != payWay ">and br.`pay_way` = #{payWay}</if>
  154. <if test=" null != contractDepoistDetail and '' != contractDepoistDetail">
  155. and br.`contract_depoist_detail` like concat('%', #{contractDepoistDetail},'%')
  156. </if>
  157. <if test=" null != starttime">and br.`starttime` &lt;= #{starttime}</if>
  158. <if test=" null != endtime">and br.`endtime` &gt;= #{endtime}</if>
  159. <if test=" null != month and '' != month">
  160. and date_format(br.starttime,'%Y-%m') &lt;= #{month} and date_format(br.endtime,'%Y-%m') &gt;= #{month}
  161. </if>
  162. <if test=" null == nearBillLastTime and null != oweBillLastTime">
  163. and (br.`starttime` &lt;= #{oweBillLastTime} and br.`receive_pay` - br.`pay` - br.`set_off` &gt; 0 and br.status not in (3,6,7))
  164. </if>
  165. <if test=" null != nearBillLastTime and null != oweBillLastTime">
  166. and (br.`starttime` &gt; #{oweBillLastTime} and br.`starttime` &lt;= #{nearBillLastTime} and br.`receive_pay` - br.`pay` - br.`set_off` &gt; 0 and br.status not in (3,6,7))
  167. </if>
  168. <if test=" null != needPayStartDay">
  169. and (br.`starttime` &lt;= #{needPayStartDay} and br.`receive_pay` - br.`pay` - br.`set_off` &gt; 0 and br.status not in (3,6,7))
  170. </if>
  171. <if test=" 1 == notifyed ">and (br.`last_owe_call_time` is not null and br.`receive_pay` - br.`pay` - br.`set_off` &gt; 0 and br.status not in (3,6,7) )</if>
  172. <if test=" null != merchantIds ">
  173. and br.`merchant_id` in
  174. <foreach collection="merchantIds" index="index" item="midItem" open="(" separator="," close=")">
  175. #{midItem}
  176. </foreach>
  177. </if>
  178. <if test=" null != statusList ">
  179. and br.status in
  180. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  181. #{stItem}
  182. </foreach>
  183. </if>
  184. </where>
  185. </sql>
  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="service_pay" jdbcType="VARCHAR" property="servicePay"/>
  192. <result column="late_pay" jdbcType="VARCHAR" property="latePay"/>
  193. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  194. </resultMap>
  195. <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxBillDeposit" resultMap="SumBaseResultMap">
  196. select
  197. sum(CAST(br.receive_pay AS DECIMAL(20,2))) receive_pay ,
  198. sum(CAST(br.pay AS DECIMAL(20,2))) paid,
  199. min(starttime) min_date,
  200. max(endtime) max_date,
  201. sum(CAST(br.service_charge_pay AS DECIMAL(20,2))) service_pay ,
  202. '0' late_pay,
  203. sum(CAST(br.return_price AS DECIMAL(20,2))) as return_pay
  204. from wx_bill_rent_deposit br
  205. <include refid="queryBillRentListCondition"/>
  206. </select>
  207. <select id="getMerchantIdList" parameterType="com.iformall.domain.po.WxBillDeposit" resultType="Long">
  208. select distinct merchant_id from wx_bill_rent_deposit br
  209. <include refid="queryBillRentListCondition"/>
  210. </select>
  211. <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
  212. <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
  213. <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
  214. <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
  215. </resultMap>
  216. <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxBillDeposit" resultMap="HotNotifyBaseResultMap">
  217. select count(1) total_count , sum(CAST(br.`receive_pay` AS DECIMAL(20,2)) - CAST(br.`pay` AS DECIMAL(20,2)) - CAST(IFNULL(br.`set_off`,"0") AS DECIMAL(20,2))) total_money,MIN(br.starttime) min_begin_time from wx_bill_rent_deposit br
  218. <include refid="queryBillRentListCondition"/>
  219. </select>
  220. <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
  221. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  222. <result column="bill_type_name" jdbcType="VARCHAR" property="billTypeName" />
  223. <result column="bill_id" jdbcType="BIGINT" property="billId" />
  224. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  225. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  226. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  227. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  228. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  229. </resultMap>
  230. <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxBillDeposit" resultMap="NotifyResultMap">
  231. select #{billType} bill_type,#{billTypeName} bill_type_name,br.id as bill_id, br.starttime,br.endtime,br.receive_pay,br.pay,br.merchant_id from wx_bill_rent_deposit br
  232. <include refid="queryBillRentListCondition"/>
  233. </select>
  234. <select id="queryPayInfo" resultType="hashmap" parameterType="hashmap">
  235. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id,parent_tenant_id from wx_bill_rent_deposit
  236. where 1=1
  237. <if test=" null != tenantId and '' != tenantId">
  238. and `tenant_id` = #{tenantId}
  239. </if>
  240. <if test=" null != parentTenantId and '' != parentTenantId">
  241. and `parent_tenant_id` = #{parentTenantId}
  242. </if>
  243. and date_format(receive_date,'%Y-%m')=#{receiveDate}
  244. group by tenant_id,parent_tenant_id
  245. </select>
  246. <select id="queryPayInfoAllTotal" resultType="hashmap" parameterType="hashmap">
  247. select round(sum(res.receivepay)/100,2) receivepay,round(sum(res.pay)/100,2) pay,res.tenant_id from
  248. (
  249. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_rent_deposit
  250. where 1=1
  251. <if test=" null != tenantId and '' != tenantId">
  252. and `tenant_id` = #{tenantId}
  253. </if>
  254. <if test=" null != parentTenantId and '' != parentTenantId">
  255. and `parent_tenant_id` = #{parentTenantId}
  256. </if>
  257. and receive_date between #{startdate} and #{enddate}
  258. union all
  259. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_property_deposit
  260. where 1=1
  261. <if test=" null != tenantId and '' != tenantId">
  262. and `tenant_id` = #{tenantId}
  263. </if>
  264. <if test=" null != parentTenantId and '' != parentTenantId">
  265. and `parent_tenant_id` = #{parentTenantId}
  266. </if>
  267. and receive_date between #{startdate} and #{enddate}
  268. union all
  269. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_other_deposit
  270. where 1=1
  271. <if test=" null != tenantId and '' != tenantId">
  272. and `tenant_id` = #{tenantId}
  273. </if>
  274. <if test=" null != parentTenantId and '' != parentTenantId">
  275. and `parent_tenant_id` = #{parentTenantId}
  276. </if>
  277. and receive_date between #{startdate} and #{enddate}
  278. ) res
  279. </select>
  280. <select id="queryOweInfoAll" resultType="hashmap" parameterType="hashmap">
  281. select IFNULL(round(sum(res.owe)/100,2),0) owe,res.tenant_id from
  282. (
  283. select IFNULL(sum(receive_pay - pay),0) owe,tenant_id from wx_bill_rent_deposit
  284. where status = 1
  285. <if test=" null != tenantId and '' != tenantId">
  286. and `tenant_id` = #{tenantId}
  287. </if>
  288. <if test=" null != parentTenantId and '' != parentTenantId">
  289. and `parent_tenant_id` = #{parentTenantId}
  290. </if>
  291. and receive_date between #{startdate} and #{enddate}
  292. union all
  293. select IFNULL(sum(receive_pay - pay),0) owe,tenant_id from wx_bill_property_deposit
  294. where status = 1
  295. <if test=" null != tenantId and '' != tenantId">
  296. and `tenant_id` = #{tenantId}
  297. </if>
  298. <if test=" null != parentTenantId and '' != parentTenantId">
  299. and `parent_tenant_id` = #{parentTenantId}
  300. </if>
  301. and receive_date between #{startdate} and #{enddate}
  302. union all
  303. select IFNULL(sum(receive_pay - pay),0) owe,tenant_id from wx_bill_other_deposit
  304. where status = 1
  305. <if test=" null != tenantId and '' != tenantId">
  306. and `tenant_id` = #{tenantId}
  307. </if>
  308. <if test=" null != parentTenantId and '' != parentTenantId">
  309. and `parent_tenant_id` = #{parentTenantId}
  310. </if>
  311. and receive_date between #{startdate} and #{enddate}
  312. ) res
  313. </select>
  314. <update id="updateNotPaidStatus" parameterType="hashmap">
  315. update wx_bill_rent_deposit set status=#{notPaid},expired_day=DATEDIFF(now(),receive_date)
  316. where status!=#{paid}
  317. <if test=" null != tenantId and '' != tenantId">
  318. and `tenant_id` = #{tenantId}
  319. </if>
  320. <if test=" null != parentTenantId and '' != parentTenantId">
  321. and `parent_tenant_id` = #{parentTenantId}
  322. </if>
  323. and status!=5 and DATEDIFF(now(),receive_date)>0
  324. </update>
  325. <update id="updateWaitPayStatus" parameterType="hashmap">
  326. update wx_bill_rent_deposit set status=#{waitPay} where id in(
  327. select a.id from (select br.id,rc.receive_period,br.rent_contract_id,br.receive_date from wx_bill_rent_deposit br
  328. left join wx_rent_contract rc on br.rent_contract_id=rc.id
  329. where br.status!=#{paid}
  330. <if test=" null != tenantId and '' != tenantId">
  331. and br.`tenant_id` = #{tenantId}
  332. </if>
  333. <if test=" null != parentTenantId and '' != parentTenantId">
  334. and br.`parent_tenant_id` = #{parentTenantId}
  335. </if>
  336. and br.status!=5 and now() &lt; br.receive_date
  337. and DATE_ADD(now(),INTERVAL 1 MONTH)>br.receive_date) a)
  338. </update>
  339. <select id="queryOweCount" parameterType="com.iformall.domain.po.WxRentContract" resultType="Long">
  340. select count(*) c from wx_rent_contract r,wx_bill_rent_deposit b
  341. where b.rent_contract_id = r.id and b.status = 1 and r.id = #{id}
  342. </select>
  343. <delete id = "deleteById" parameterType="HashMap">
  344. delete from wx_bill_rent_deposit where id = #{id} and tenant_id = #{tenantId}
  345. </delete>
  346. <insert id="insertBills" parameterType="hashmap">
  347. INSERT INTO wx_bill_rent_deposit (id,rent_contract_id, receive_pay, pay, receive_date, pay_date, createtime,
  348. expired_day,tenant_id, parent_tenant_id,status,is_del,need_pay, merchant_id, user_id, shop_id, updatetime, starttime,
  349. endtime,rent_shop_type,return_price,shop_info,pay_way,freeze,service_charge_pay,
  350. contract_depoist_detail,create_by,create_by_name,update_by,update_by_name,energy_fees_id
  351. )
  352. VALUES
  353. <foreach collection="list" item="item" index="index" separator=",">
  354. (
  355. #{item.id},#{item.rentContractId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime},
  356. #{item.expiredDay},#{item.tenantId},#{item.parentTenantId},#{item.status},#{item.isDel},#{item.needPay},
  357. #{item.merchantId},#{item.userId},#{item.shopId},#{item.updatetime},#{item.starttime},
  358. #{item.endtime},#{item.rentShopType},#{item.returnPrice},#{item.shopInfo},#{item.payWay},#{item.freeze},#{item.serviceChargePay},
  359. #{item.contractDepoistDetail},#{item.createBy},#{item.createByName},#{item.updateBy},#{item.updateByName},#{item.energyFeesId}
  360. )
  361. </foreach>
  362. </insert>
  363. </mapper>