Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

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