后台服务
Não pode escolher mais do que 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.

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