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.
 
 
 
 
 

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