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.
 
 
 
 
 

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