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.
 
 
 
 
 

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