后台服务
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

WxBillPropertyMapper.xml 19 KiB

hace 2 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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="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="BIGINT" 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="BIGINT" 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 != ids ">
  85. and id in
  86. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  87. #{idItem}
  88. </foreach>
  89. </if>
  90. <if test=" null != sortColumns">order by ${sortColumns}</if>
  91. </sql>
  92. <select id="findList" parameterType="com.iformall.domain.po.WxBillProperty" resultMap="BaseResultMap">
  93. select
  94. <include refid="allColumns"/>
  95. from wx_bill_property
  96. <include refid="dynamicWhereConditions"/>
  97. </select>
  98. <select id="queryBillPropertyList" parameterType="com.iformall.domain.po.WxBillProperty" resultMap="BaseResultMap">
  99. select br.`id`,br.`receive_pay`,br.`pay`,br.`receive_date`,br.`pay_date`,br.`createtime`,br.`expired_day`,
  100. case when br.status=1 then br.owe else 0 end owe,br.`status`,br.`need_pay`,m.`name`
  101. merchant_name,s.shop_number,br.`updatetime`,br.`merchant_id`,br.`rent_shop_type`,br.`period`,
  102. br.`revenue`,r.`late_pay_ratio`,br.`late_pay_time`,br.`property_contract_id`,d.receive_pay deposit,
  103. br.late_pay_price,d.`status`
  104. deposit_status,br.`shop_info`,br.pay_way,br.late_pay_status,
  105. br.`comments`,br.starttime,br.endtime,br.`apply_status`,br.`apply_pay_img`,br.`apply_update_time`,
  106. r.late_pay_day,r.late_pay_ratio,br.freeze,br.service_charge_pay
  107. from wx_bill_property br left join wx_merchant m on br.merchant_id=m.id
  108. left join wx_shop s on br.shop_id=s.id
  109. left join wx_property_contract r on br.property_contract_id=r.id
  110. left join wx_bill_property_deposit d on br.property_contract_id=d.property_contract_id
  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 != merchantName and ''!=merchantName ">and m.`name` like concat('%',#{merchantName},'%')</if>
  117. <if test=" null != status ">and br.`status` = #{status}</if>
  118. <if test=" null != applyStatus ">and br.`apply_status` = #{applyStatus}</if>
  119. <if test=" null != isDel ">and br.`is_del` = #{isDel}</if>
  120. <if test=" null != starttime and null!=endtime ">and br.`receive_date` between #{starttime} and #{endtime}</if>
  121. <if test=" null != rentShopType ">and br.`rent_shop_type` = #{rentShopType}</if>
  122. <if test=" null != propertyContractId ">and br.`property_contract_id` = #{propertyContractId}</if>
  123. <if test=" null != payWay ">and br.`pay_way` = #{payWay}</if>
  124. <if test=" null != latePayStatus ">and br.`late_pay_status` = #{latePayStatus}</if>
  125. <if test=" null != latePayStatus ">and br.`late_pay_status` = #{latePayStatus}</if>
  126. <if test=" null != depositStatus ">and d.`status` = #{depositStatus}</if>
  127. <if test=" null != building or null != floor">
  128. and br.merchant_id in(
  129. select ms.merchant_id from (select merchant_id,shop_id from wx_merchant_shop where is_del=0) ms
  130. inner join wx_merchant m on ms.merchant_id = m.id
  131. inner join wx_shop s on s.id=ms.shop_id
  132. where s.is_del=0
  133. <if test=" null != building ">
  134. and s.`building`= #{building}
  135. </if>
  136. <if test=" null != floor">
  137. and s.`floor` = #{floor}
  138. </if>
  139. )
  140. </if>
  141. </where>
  142. <if test=" null != sortColumns">order by ${sortColumns}</if>
  143. </select>
  144. <select id="queryPayInfo" resultType="hashmap" parameterType="hashmap">
  145. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_property
  146. where is_preview = 0 and status!=6
  147. <if test=" null != tenantId and '' != tenantId">
  148. and `tenant_id` = #{tenantId}
  149. </if>
  150. <if test=" null != parentTenantId and '' != parentTenantId">
  151. and `parent_tenant_id` = #{parentTenantId}
  152. </if>
  153. and receive_date between #{startdate} and #{enddate}
  154. group by tenant_id, parent_tenant_id
  155. </select>
  156. <select id="queryPayInfoTotal" resultType="hashmap" parameterType="hashmap">
  157. select IFNULL(sum(receive_pay),0) receivepay,IFNULL(sum(pay),0) pay,tenant_id from wx_bill_property
  158. where receive_date between #{startdate} and #{enddate}
  159. and is_preview = 0 and status!=6
  160. <if test=" null != tenantId and '' != tenantId">
  161. and `tenant_id` = #{tenantId}
  162. </if>
  163. <if test=" null != parentTenantId and '' != parentTenantId">
  164. and `parent_tenant_id` = #{parentTenantId}
  165. </if>
  166. </select>
  167. <select id="queryOweInfo" resultType="hashmap" parameterType="hashmap">
  168. select IFNULL(sum(owe),0) owe,tenant_id from wx_bill_property
  169. where status = 1
  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. and is_preview = 0
  178. </select>
  179. <update id="updateNotPaidStatus" parameterType="hashmap">
  180. update wx_bill_property b set b.status=#{notPaid},b.expired_day=
  181. DATEDIFF(now(), b.receive_date)
  182. where b.status!=#{paid} and b.status!=6
  183. and DATEDIFF(now(), b.receive_date) >0
  184. <if test=" null != tenantId and '' != tenantId">
  185. and b.`tenant_id` = #{tenantId}
  186. </if>
  187. <if test=" null != parentTenantId and '' != parentTenantId">
  188. and b.`parent_tenant_id` = #{parentTenantId}
  189. </if>
  190. </update>
  191. <update id="updateWaitPayStatus" parameterType="hashmap">
  192. update wx_bill_property set status=#{waitPay} where id in(
  193. select a.id from (
  194. select br.id,rc.receive_period,br.property_contract_id,br.receive_date
  195. from wx_bill_property br
  196. left join wx_property_contract rc on br.property_contract_id=rc.id
  197. where 1=1
  198. <if test=" null != tenantId and '' != tenantId">
  199. and br.`tenant_id` = #{tenantId}
  200. </if>
  201. <if test=" null != parentTenantId and '' != parentTenantId">
  202. and br.`parent_tenant_id` = #{parentTenantId}
  203. </if>
  204. and br.status!=#{paid} and br.status != 6 and now() &lt; br.receive_date
  205. and DATE_ADD(now(),INTERVAL 1 MONTH)>br.receive_date) a)
  206. </update>
  207. <update id="updateInvalidStatus" parameterType="com.iformall.domain.po.WxBillProperty">
  208. update wx_bill_property set status = 6 where property_contract_id = #{propertyContractId}
  209. and status in(4,2)
  210. </update>
  211. <update id="updateInvalidStatusByRent" parameterType="com.iformall.domain.po.WxRentContract">
  212. update wx_bill_property set status = 6 where property_contract_id in
  213. (select id from wx_property_contract where rent_contract_id = #{id})
  214. and status != 3
  215. </update>
  216. <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxPropertyContract">
  217. delete from wx_bill_property where property_contract_id = #{id}
  218. </delete>
  219. <update id="updateForReceivePay" parameterType="com.iformall.domain.po.WxBillProperty">
  220. update wx_bill_property set updatetime = now()
  221. <if test=" null != receivePay ">,receive_pay = #{receivePay},owe=#{receivePay}</if>
  222. <if test=" null != comments ">,comments = #{comments}</if>
  223. <if test=" null != receiveDate ">,receive_date = #{receiveDate}</if>
  224. <if test="0 == receivePay or 0l == receivePay">,status = 3,pay_date=now()</if>
  225. where id = #{id}
  226. </update>
  227. <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxBillProperty">
  228. update wx_bill_property set is_preview = #{isPreview},merchant_id = #{merchantId},need_pay = receive_pay,
  229. owe=receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
  230. where property_contract_id = #{propertyContractId}
  231. </update>
  232. <select id="oweBillCount" parameterType="java.lang.Long" resultType="java.lang.Long">
  233. select count(br.id) from wx_bill_property br,wx_property_contract c
  234. where c.id = br.property_contract_id and br.status = 1 and c.id = #{contractId}
  235. </select>
  236. <insert id="insertBills" parameterType="java.util.List">
  237. INSERT INTO wx_bill_property (id,property_contract_id, receive_pay, pay, receive_date, pay_date, createtime,
  238. expired_day,
  239. tenant_id, parent_tenant_id, owe, status, is_del, need_pay, merchant_id, user_id, shop_id, updatetime, starttime,
  240. endtime,
  241. rent_shop_type, revenue, late_pay_ratio, late_pay_time, late_pay_price, period, is_preview, shop_info,
  242. pay_way, late_pay_status, comments,service_charge_pay)
  243. VALUES
  244. <foreach collection="list" item="item" index="index" separator=",">
  245. (
  246. #{item.id},#{item.propertyContractId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime},
  247. #{item.expiredDay},#{item.tenantId},#{item.parentTenantId},
  248. #{item.owe},#{item.status},#{item.isDel},#{item.needPay},#{item.merchantId},
  249. #{item.userId},#{item.shopId},#{item.updatetime},#{item.starttime},#{item.endtime},#{item.rentShopType},#{item.revenue},
  250. #{item.latePayRatio},#{item.latePayTime},#{item.latePayPrice},#{item.period},#{item.isPreview},#{item.shopInfo},
  251. #{item.payWay},#{item.latePayStatus},#{item.comments},#{item.serviceChargePay}
  252. )
  253. </foreach>
  254. </insert>
  255. <update id="updateBills" parameterType="java.util.List">
  256. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  257. update wx_bill_property
  258. <set>
  259. <if test=" null != item.receivePay ">updatetime = now(),receive_pay = #{item.receivePay},</if>
  260. <if test=" null != item.comments ">comments = #{item.comments},</if>
  261. <if test=" null != item.receiveDate ">receive_date = #{item.receiveDate},</if>
  262. <if test="0 == item.receivePay or 0l == item.receivePay">status = 3,pay_date=now()</if>
  263. </set>
  264. where id = #{item.id}
  265. </foreach>
  266. </update>
  267. <select id="selectBillOne" parameterType="com.iformall.domain.po.WxBillProperty"
  268. resultType="com.iformall.domain.po.WxBillProperty">
  269. select * from wx_bill_property where merchant_id=#{merchantId}
  270. AND rent_shop_type = #{rentShopType} AND is_preview = #{isPreview}
  271. AND date_format(starttime,'%Y-%m-%d 00:00:00.0') = #{starttime} AND date_format(endtime,'%Y-%m-%d 00:00:00.0') = #{endtime}
  272. </select>
  273. <update id="insertBillAction">
  274. insert into wx_bill_action(id,user_name,`action`,bill_id,details,tenant_id,parent_tenant_id)
  275. select
  276. (select unix_timestamp(now()) + CEILING(RAND()*90000+10000) + CEILING(RAND()*90000+10000) + CEILING(RAND()*90000+10000)) id
  277. ,'系统端' user_name,7 `action`,b.id bill_id,
  278. CONCAT('系统计入',
  279. if(b.late_pay_price is null,
  280. round(
  281. b.owe * c.late_pay_ratio * DATEDIFF(now(), date_add(b.receive_date,interval(c.late_pay_day) day)) /10000
  282. ,2)
  283. ,
  284. round(
  285. b.owe * (c.late_pay_ratio) /10000
  286. ,2)
  287. )
  288. ,'元') details,b.tenant_id,b.parent_tenant_id
  289. from wx_bill_property b left join wx_property_contract c on(b.`property_contract_id`=c.id)
  290. where c.late_pay_ratio >0
  291. and DATEDIFF(now(), date_add(b.receive_date,interval(c.late_pay_day) day)) >0
  292. and b.status!=3 and b.status!=6
  293. </update>
  294. <update id="autoAddLatePayPrice">
  295. update wx_bill_property b set b.late_pay_price =
  296. if(b.late_pay_price is null,
  297. round(
  298. b.owe * (select late_pay_ratio from wx_property_contract where id = b.`property_contract_id`)
  299. * DATEDIFF(now(), date_add(b.receive_date,interval(select late_pay_day from wx_property_contract where id = b.`property_contract_id`) day)) /100
  300. ,2)
  301. ,
  302. b.late_pay_price +
  303. round(
  304. b.owe * (select late_pay_ratio from wx_property_contract where id = b.`property_contract_id`) /100
  305. ,2)
  306. )
  307. where b.status!=3 and b.status!=6
  308. and (select late_pay_ratio from wx_property_contract where id = b.`property_contract_id`) > 0
  309. 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;
  310. </update>
  311. <update id="updateServiceCharge" parameterType="com.iformall.domain.po.WxPayAccountBill">
  312. update wx_bill_property
  313. set service_charge_pay=round(receive_pay*#{serviceChargeRate}/10000),owe=receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
  314. where service_charge_pay=0 and status in(1,2,4)
  315. <if test=" null != tenantId and '' != tenantId">
  316. and `tenant_id` = #{tenantId}
  317. </if>
  318. <if test=" null != parentTenantId and '' != parentTenantId">
  319. and `parent_tenant_id` = #{parentTenantId}
  320. </if>
  321. </update>
  322. <update id="updateOwe">
  323. update wx_bill_property
  324. set owe = receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
  325. where status in (1,2,4)
  326. </update>
  327. </mapper>