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.
 
 
 
 
 

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