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.
 
 
 
 
 

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