25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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