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.
 
 
 
 
 

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