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.
 
 
 
 
 

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