Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

366 wiersze
17 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.WxBillRentMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBillRent">
  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="BIGINT" property="receivePay"/>
  10. <result column="pay" jdbcType="BIGINT" 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="expired_day" jdbcType="INTEGER" property="expiredDay"/>
  15. <result column="owe" jdbcType="BIGINT" property="owe"/>
  16. <result column="status" jdbcType="INTEGER" property="status"/>
  17. <result column="is_del" jdbcType="INTEGER" property="isDel"/>
  18. <result column="contract_need_pay" jdbcType="BIGINT" property="contractNeedPay"/>
  19. <result column="rent_price_info" jdbcType="VARCHAR" property="rentPriceInfo"/>
  20. <result column="need_pay" jdbcType="BIGINT" property="needPay"/>
  21. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  22. <result column="user_id" jdbcType="BIGINT" property="userId"/>
  23. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  24. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
  25. <result column="rent_shop_type" jdbcType="INTEGER" property="rentShopType"/>
  26. <result column="revenue" jdbcType="INTEGER" property="revenue"/>
  27. <result column="late_pay_ratio" jdbcType="INTEGER" property="latePayRatio"/>
  28. <result column="late_pay_time" jdbcType="TIMESTAMP" property="latePayTime"/>
  29. <result column="late_pay_price" jdbcType="BIGINT" property="latePayPrice"/>
  30. <result column="period" jdbcType="INTEGER" property="period"/>
  31. <result column="is_preview" property="isPreview"/>
  32. <result column="shop_info" jdbcType="VARCHAR" property="shopInfo"/>
  33. <result column="pay_way" jdbcType="INTEGER" property="payWay"/>
  34. <result column="late_pay_status" jdbcType="INTEGER" property="latePayStatus"/>
  35. <result column="comments" jdbcType="VARCHAR" property="comments"/>
  36. <result column="starttime" property="starttime"/>
  37. <result column="endtime" property="endtime"/>
  38. <result column="merchant_name" property="merchantName"/>
  39. <result column="deposit" property="deposit"/>
  40. <result column="deposit_status" property="depositStatus"/>
  41. <result column="rent_type" property="rentType"/>
  42. <result column="all_period" property="allPeriod"/>
  43. <result column="pay_ratio" property="payRatio"/>
  44. <result column="bus_discount_ratio" property="busDiscountRatio"/>
  45. <result column="late_pay_day" property="latePayDay"/>
  46. <result column="late_pay_ratio" property="latePayRatio"/>
  47. <result column="freeze" property="freeze"/>
  48. <result column="bus_discount_ratio" property="busDiscountRatio"/>
  49. <result column="join_rent_price" property="joinRentPrice"/>
  50. <result column="service_charge_pay" property="serviceChargePay"/>
  51. </resultMap>
  52. <sql id="allColumns">
  53. `id`,`tenant_id`,`parent_tenant_id`,`rent_contract_id`,`receive_pay`,`pay`,`receive_date`,`pay_date`,
  54. `createtime`,`expired_day`,`owe`,`status`,`is_del`,`contract_need_pay`,`rent_price_info`,`need_pay`,
  55. `merchant_id`,`user_id`,`shop_id`,`updatetime`,`rent_shop_type`,
  56. `revenue`,`late_pay_ratio`,`late_pay_time`,`late_pay_price`,`period`,`is_preview`,`shop_info`,
  57. `pay_way`,`late_pay_status`,`comments`,starttime,endtime,bus_discount_ratio,freeze,join_rent_price,service_charge_pay
  58. </sql>
  59. <sql id="dynamicWhereConditions">
  60. where 1=1
  61. <if test=" null != id ">and `id` = #{id}</if>
  62. <if test=" null != tenantId and '' != tenantId">
  63. and `tenant_id` = #{tenantId}
  64. </if>
  65. <if test=" null != parentTenantId and '' != parentTenantId">
  66. and `parent_tenant_id` = #{parentTenantId}
  67. </if>
  68. <if test=" null != rentContractId ">and `rent_contract_id` = #{rentContractId}</if>
  69. <if test=" null != receivePay ">and `receive_pay` = #{receivePay}</if>
  70. <if test=" null != pay ">and `pay` = #{pay}</if>
  71. <if test=" null != receiveDate ">and `receive_date` = #{receiveDate}</if>
  72. <if test=" null != payDate ">and `pay_date` = #{payDate}</if>
  73. <if test=" null != createtime ">and `createtime` = #{createtime}</if>
  74. <if test=" null != expiredDay ">and `expired_day` = #{expiredDay}</if>
  75. <if test=" null != owe ">and `owe` = #{owe}</if>
  76. <if test=" null != status ">and `status` = #{status}</if>
  77. <if test=" null != isDel ">and `is_del` = #{isDel}</if>
  78. <if test=" null != needPay ">and `need_pay` = #{needPay}</if>
  79. <if test=" null != merchantId ">and `merchant_id` = #{merchantId}</if>
  80. <if test=" null != userId ">and `user_id` = #{userId}</if>
  81. <if test=" null != shopId ">and `shop_id` = #{shopId}</if>
  82. <if test=" null != updatetime ">and `updatetime` = #{updatetime}</if>
  83. <if test=" null != rentShopType ">and `rent_shop_type` = #{rentShopType}</if>
  84. <if test=" null != isPreview ">and is_preview = #{isPreview}</if>
  85. <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
  86. <if test=" null != latePayStatus ">and `late_pay_status` = #{latePayStatus}</if>
  87. <if test=" null != ids ">
  88. and id in
  89. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  90. #{idItem}
  91. </foreach>
  92. </if>
  93. <if test=" null != sortColumns">order by ${sortColumns}</if>
  94. </sql>
  95. <select id="findList" parameterType="com.iformall.domain.po.WxBillRent" resultMap="BaseResultMap">
  96. select
  97. <include refid="allColumns"/>
  98. from wx_bill_rent
  99. <include refid="dynamicWhereConditions"/>
  100. </select>
  101. <select id="queryBillRentList" parameterType="com.iformall.domain.po.WxBillRent" resultMap="BaseResultMap">
  102. select br.`id`,br.`receive_pay`,br.`pay`,br.`receive_date`,br.`pay_date`,br.`createtime`,br.`expired_day`,
  103. case when br.status=1 then br.owe else 0 end owe,br.`status`,br.`contract_need_pay`,br.`rent_price_info`,br.`need_pay`,r.merchant_name,
  104. br.`updatetime`,br.`merchant_id`,br.`rent_shop_type`,r.type as rent_type,
  105. r.pay_ratio,br.`revenue`,r.`late_pay_ratio`,br.`late_pay_time`,br.`period`,br.`rent_contract_id`,
  106. d.receive_pay deposit,d.`status`
  107. deposit_status,br.late_pay_price,br.shop_info,br.pay_way,br.late_pay_status,br.`comments`,br.starttime,br.endtime,
  108. r.late_pay_day,r.late_pay_ratio,br.bus_discount_ratio,br.freeze,br.join_rent_price,br.service_charge_pay
  109. from wx_bill_rent br
  110. left join wx_rent_contract r on br.rent_contract_id=r.id
  111. left join wx_bill_rent_deposit d on br.rent_contract_id=d.rent_contract_id and br.merchant_id=d.merchant_id
  112. <where>
  113. br.is_preview = 0
  114. <if test=" null != freeze ">and br.`freeze` = #{freeze}</if>
  115. <if test=" null != rentShopType ">and br.`rent_shop_type` = #{rentShopType}</if>
  116. <if test=" null != status ">and br.`status` = #{status}</if>
  117. <if test=" null != depositStatus ">and d.`status` = #{depositStatus}</if>
  118. <if test=" null != id ">and br.`id` = #{id}</if>
  119. <if test=" null != merchantId ">and br.`merchant_id` = #{merchantId}</if>
  120. <if test=" null != merchantName and ''!=merchantName ">and r.merchant_name like
  121. concat('%',#{merchantName},'%')
  122. </if>
  123. <if test=" null != isDel ">and br.`is_del` = #{isDel}</if>
  124. <if test=" null != rentContractId ">and br.`rent_contract_id` = #{rentContractId}</if>
  125. <if test=" null != payWay ">and br.`pay_way` = #{payWay}</if>
  126. <if test=" null != latePayStatus ">and br.`late_pay_status` = #{latePayStatus}</if>
  127. <if test=" null != starttime and null!=endtime ">and br.`receive_date` between #{starttime} and #{endtime}
  128. </if>
  129. <if test=" null != building or null != floor">
  130. and br.`merchant_id` in(
  131. select ms.merchant_id from (select merchant_id,shop_id from wx_merchant_shop where is_del=0) ms
  132. inner join wx_merchant m on ms.merchant_id = m.id
  133. inner join wx_shop s on s.id=ms.shop_id
  134. where s.is_del=0
  135. <if test=" null != building ">
  136. and s.`building`= #{building}
  137. </if>
  138. <if test=" null != floor">
  139. and s.`floor` = #{floor}
  140. </if>
  141. )
  142. </if>
  143. </where>
  144. <if test=" null != sortColumns">order by ${sortColumns}</if>
  145. <if test="null != limitStart and null != limitEnd">
  146. limit #{limitStart},#{limitEnd}
  147. </if>
  148. </select>
  149. <select id="queryPayInfo" resultType="hashmap" parameterType="hashmap">
  150. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_rent
  151. where is_preview = 0
  152. and status!=6
  153. <if test=" null != tenantId and '' != tenantId">
  154. and `tenant_id` = #{tenantId}
  155. </if>
  156. <if test=" null != parentTenantId and '' != parentTenantId">
  157. and `parent_tenant_id` = #{parentTenantId}
  158. </if>
  159. <if test=" null != startTime ">
  160. and receive_date &gt;= #{startdate}
  161. </if>
  162. <if test=" null != endTime">
  163. and receive_date &lt; #{enddate}
  164. </if>
  165. </select>
  166. <select id="queryPayInfoTotal" resultType="hashmap" parameterType="hashmap">
  167. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_rent
  168. where is_preview = 0 and status!=6
  169. <if test=" null != tenantId and '' != tenantId">
  170. and `tenant_id` = #{tenantId}
  171. </if>
  172. <if test=" null != parentTenantId and '' != parentTenantId">
  173. and `parent_tenant_id` = #{parentTenantId}
  174. </if>
  175. <if test=" null != startTime ">
  176. and receive_date &gt;= #{startdate}
  177. </if>
  178. <if test=" null != endTime">
  179. and receive_date &lt; #{enddate}
  180. </if>
  181. </select>
  182. <select id="queryOweInfo" resultType="hashmap" parameterType="hashmap">
  183. select IFNULL(sum(owe),0) owe,tenant_id from wx_bill_rent
  184. where status = 1
  185. <if test=" null != tenantId and '' != tenantId">
  186. and `tenant_id` = #{tenantId}
  187. </if>
  188. <if test=" null != parentTenantId and '' != parentTenantId">
  189. and `parent_tenant_id` = #{parentTenantId}
  190. </if>
  191. and receive_date between #{startdate} and #{enddate} and is_preview = 0
  192. </select>
  193. <update id="updateNotPaidStatus" parameterType="hashmap">
  194. update wx_bill_rent b set b.status=#{notPaid},b.expired_day=
  195. DATEDIFF(now(), b.receive_date)
  196. where b.status!=#{paid} and b.status!=6 and
  197. DATEDIFF(now(), b.receive_date) >0
  198. <if test=" null != tenantId and '' != tenantId">
  199. and b.`tenant_id` = #{tenantId}
  200. </if>
  201. <if test=" null != parentTenantId and '' != parentTenantId">
  202. and b.`parent_tenant_id` = #{parentTenantId}
  203. </if>
  204. </update>
  205. <update id="updateWaitPayStatus" parameterType="hashmap">
  206. update wx_bill_rent set status=#{waitPay} where id in(
  207. select a.id from (select br.id,rc.receive_period,br.rent_contract_id,br.receive_date from wx_bill_rent br
  208. left join wx_rent_contract rc on br.rent_contract_id=rc.id
  209. where br.status!=#{paid}
  210. <if test=" null != tenantId and '' != tenantId">
  211. and br.`tenant_id` = #{tenantId}
  212. </if>
  213. <if test=" null != parentTenantId and '' != parentTenantId">
  214. and br.`parent_tenant_id` = #{parentTenantId}
  215. </if>
  216. and br.status!=6 and now() &lt; br.receive_date
  217. and DATE_ADD(now(),INTERVAL 1 MONTH)>br.receive_date) a)
  218. </update>
  219. <update id="updateInvalidStatus" parameterType="com.iformall.domain.po.WxBillRent">
  220. update wx_bill_rent set status = 6 where rent_contract_id = #{rentContractId}
  221. and status != 3
  222. </update>
  223. <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxRentContract">
  224. delete from wx_bill_rent where rent_contract_id = #{id}
  225. </delete>
  226. <update id="updateForReceiverPay" parameterType="com.iformall.domain.po.WxBillRent">
  227. update wx_bill_rent set updatetime = now()
  228. <if test=" null != receivePay ">,receive_pay = #{receivePay}</if>
  229. <if test=" null != comments ">,comments = #{comments}</if>
  230. <if test=" null != receiveDate ">,receive_date = #{receiveDate}</if>
  231. <if test="0 == receivePay or 0l == receivePay">,status = 3,pay_date=now()</if>
  232. where id = #{id}
  233. </update>
  234. <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxBillRent">
  235. update wx_bill_rent set is_preview = #{isPreview},merchant_id = #{merchantId},need_pay = receive_pay,
  236. owe=receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
  237. where rent_contract_id = #{rentContractId}
  238. </update>
  239. <select id="oweBillCount" parameterType="java.lang.Long" resultType="java.lang.Long">
  240. select count(br.id) from wx_bill_rent br,wx_rent_contract c where c.id = br.rent_contract_id
  241. and br.status = 1 and c.id = #{contractId}
  242. </select>
  243. <insert id="insertBills" parameterType="java.util.List">
  244. INSERT INTO wx_bill_rent (id,tenant_id,parent_tenant_id,
  245. rent_contract_id, receive_pay, pay, receive_date, pay_date, createtime, expired_day,
  246. owe, status, is_del, contract_need_pay,rent_price_info,need_pay, merchant_id, user_id, shop_id, updatetime, starttime, endtime,
  247. rent_shop_type, revenue, late_pay_ratio, late_pay_time, late_pay_price, period, is_preview, shop_info,
  248. pay_way, late_pay_status, comments,service_charge_pay)
  249. VALUES
  250. <foreach collection="list" item="item" index="index" separator=",">
  251. (
  252. #{item.id},#{item.tenantId},#{item.parentTenantId},
  253. #{item.rentContractId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime},
  254. #{item.expiredDay},#{item.owe},#{item.status},#{item.isDel},#{item.contractNeedPay},#{item.rentPriceInfo},#{item.needPay},#{item.merchantId},
  255. #{item.userId},#{item.shopId},#{item.updatetime},#{item.starttime},#{item.endtime},#{item.rentShopType},#{item.revenue},
  256. #{item.latePayRatio},#{item.latePayTime},#{item.latePayPrice},#{item.period},#{item.isPreview},#{item.shopInfo},
  257. #{item.payWay},#{item.latePayStatus},#{item.comments},#{item.serviceChargePay}
  258. )
  259. </foreach>
  260. </insert>
  261. <update id="updateBills" parameterType="java.util.List">
  262. <foreach collection="bills" item="item" index="index" open="" close="" separator=";">
  263. update wx_bill_rent
  264. <set>
  265. <if test=" null != item.receivePay ">updatetime = now(),receive_pay = #{item.receivePay},</if>
  266. <if test=" null != item.comments ">comments = #{item.comments},</if>
  267. <if test=" null != item.receiveDate ">receive_date = #{item.receiveDate},</if>
  268. <if test="0 == item.receivePay or 0l == item.receivePay">status = 3,pay_date=now()</if>
  269. </set>
  270. where id = #{item.id}
  271. </foreach>
  272. </update>
  273. <select id="selectBillOne" parameterType="com.iformall.domain.po.WxBillRent"
  274. resultType="com.iformall.domain.po.WxBillRent">
  275. select * from wx_bill_rent where merchant_id=#{merchantId}
  276. AND rent_shop_type = #{rentShopType} AND is_preview = #{isPreview}
  277. AND date_format(starttime,'%Y-%m-%d 00:00:00.0') = #{starttime} AND date_format(endtime,'%Y-%m-%d 00:00:00.0') = #{endtime}
  278. </select>
  279. <update id="insertBillAction">
  280. insert into wx_bill_action(id,user_name,`action`,bill_id,details,tenant_id,parent_tenant_id)
  281. select
  282. (select unix_timestamp(now()) + CEILING(RAND()*90000+10000) + CEILING(RAND()*90000+10000)+ CEILING(RAND()*90000+10000) ) id
  283. ,'系统端' user_name,7 `action`,b.id bill_id,
  284. CONCAT('系统计入',
  285. if(b.late_pay_price is null,
  286. round(
  287. b.owe * c.late_pay_ratio * DATEDIFF(now(), date_add(b.receive_date,interval(c.late_pay_day) day)) /10000
  288. ,2)
  289. ,
  290. round(
  291. b.owe * (c.late_pay_ratio) /10000
  292. ,2)
  293. )
  294. ,'元') details,b.tenant_id,b.parent_tenant_id
  295. from wx_bill_rent b left join wx_rent_contract c on(b.rent_contract_id=c.id)
  296. where c.late_pay_ratio >0
  297. and DATEDIFF(now(), date_add(b.receive_date,interval(c.late_pay_day) day)) >0
  298. and b.status!=3 and b.status!=6
  299. </update>
  300. <update id="autoAddLatePayPrice">
  301. update wx_bill_rent b set b.late_pay_price =
  302. if(b.late_pay_price is null,
  303. round(
  304. b.owe * (select late_pay_ratio from wx_rent_contract where id = b.`rent_contract_id`)
  305. * DATEDIFF(now(), date_add(b.receive_date,interval(select late_pay_day from wx_rent_contract where id = b.`rent_contract_id`) day)) /100
  306. ,2)
  307. ,
  308. b.late_pay_price +
  309. round(
  310. b.owe * (select late_pay_ratio from wx_rent_contract where id = b.`rent_contract_id`) /100
  311. ,2)
  312. )
  313. where b.status!=3 and b.status!=6
  314. and (select late_pay_ratio from wx_rent_contract where id = b.`rent_contract_id`) > 0
  315. and DATEDIFF(now(), date_add(b.receive_date,interval(select late_pay_day from wx_rent_contract where id = b.`rent_contract_id`) day)) >0;
  316. </update>
  317. <update id="updateServiceCharge" parameterType="com.iformall.domain.po.WxPayAccountBill">
  318. update wx_bill_rent set service_charge_pay=round(receive_pay*#{serviceChargeRate}/10000),owe=receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
  319. where service_charge_pay=0
  320. <if test=" null != tenantId and '' != tenantId">
  321. and `tenant_id` = #{tenantId}
  322. </if>
  323. <if test=" null != parentTenantId and '' != parentTenantId">
  324. and `parent_tenant_id` = #{parentTenantId}
  325. </if>
  326. and status in(1,2,4)
  327. </update>
  328. <update id="updateOwe">
  329. update wx_bill_rent set owe = receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay where status in (1,2,4)
  330. </update>
  331. </mapper>