Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

318 строки
16 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.WxAllBillMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxAllBill">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  8. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  9. <result column="rent_shop_type" jdbcType="INTEGER" property="rentShopType"/>
  10. <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
  11. <result column="create_by" jdbcType="BIGINT" property="createBy"/>
  12. <result column="create_by_name" jdbcType="VARCHAR" property="createByName"/>
  13. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
  14. <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
  15. <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/>
  16. <result column="price_detail" jdbcType="VARCHAR" property="priceDetail"/>
  17. <result column="need_pay" jdbcType="VARCHAR" property="needPay"/>
  18. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  19. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  20. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  21. <result column="pay_way" jdbcType="BIGINT" property="payWay"/>
  22. <result column="pay_date" jdbcType="TIMESTAMP" property="payDate"/>
  23. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  24. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  25. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  26. <result column="status" jdbcType="INTEGER" property="status"/>
  27. <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
  28. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  29. <result column="bill_remark" jdbcType="VARCHAR" property="billRemark"/>
  30. <result column="last_owe_call_time" jdbcType="TIMESTAMP" property="lastOweCallTime"/>
  31. <result column="last_owe_call_user" jdbcType="VARCHAR" property="lastOweCallUser"/>
  32. <result column="bussiness_manage_fee_need_pay" jdbcType="VARCHAR" property="bussinessManageFeeNeedPay"/>
  33. <result column="operating_manage_fee_need_pay" jdbcType="VARCHAR" property="operatingManageFeeNeedPay"/>
  34. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  35. <result column="shop_number" jdbcType="VARCHAR" property="shopNumber"/>
  36. <result column="is_preview" jdbcType="INTEGER" property="isPreview"/>
  37. <result column="shop_info" jdbcType="VARCHAR" property="shopInfo"/>
  38. <result column="rent_contract_id" jdbcType="BIGINT" property="rentContractId"/>
  39. <result column="property_contract_id" jdbcType="BIGINT" property="propertyContractId"/>
  40. <result column="parent_bill_id" jdbcType="BIGINT" property="parentBillId"/>
  41. <result column="energy_reading_calcuteId" jdbcType="BIGINT" property="energyReadingCalcuteId" />
  42. <result column="energy_reading_id" jdbcType="BIGINT" property="energyReadingId" />
  43. </resultMap>
  44. <sql id="allColumns">
  45. `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`rent_shop_type`,`createtime`,`create_by`,`create_by_name`,`updatetime`,`update_by`,`update_by_name`,
  46. `price_detail`,`need_pay`,`receive_pay`,`pay`,`bill_type`,`pay_way`,`pay_date`,`set_off`,`starttime`,`endtime`,`status`,`energy_fees_id`,`return_pay`,
  47. `bill_remark`,`last_owe_call_time`,`last_owe_call_user`,`bussiness_manage_fee_need_pay`,`operating_manage_fee_need_pay`,`shop_id`,`shop_number`,
  48. `is_preview`,`shop_info`,`rent_contract_id`,`property_contract_id`,`parent_bill_id`,`energy_reading_calcuteId`,`energy_reading_id`
  49. </sql>
  50. <sql id="dynamicWhereConditions">
  51. where `tenant_id` = #{tenantId}
  52. <if test=" null != id ">and `id` = #{id}</if>
  53. <if test=" null != parentTenantId and '' != parentTenantId"> and `parent_tenant_id` = #{parentTenantId}</if>
  54. <if test=" null != merchantId ">and `merchant_id` = #{merchantId}</if>
  55. <if test=" null != rentShopType ">and `rent_shop_type` = #{rentShopType}</if>
  56. <if test=" null != createBy ">and `create_by` = #{createBy}</if>
  57. <if test=" null != createByName and '' != createByName"> and `create_by_name` like concat('%',#{createByName},'%')</if>
  58. <if test=" null != billType ">and `bill_type` = #{billType}</if>
  59. <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
  60. <if test=" null != status ">and `status` = #{status}</if>
  61. <if test=" null != energyFeesId ">and `energy_fees_id` = #{energyFeesId}</if>
  62. <if test=" null != rentContractId ">and `rent_contract_id` = #{rentContractId}</if>
  63. <if test=" null != propertyContractId ">and `property_contract_id` = #{propertyContractId}</if>
  64. <if test=" null != parentBillId ">and `parent_bill_id` = #{parentBillId}</if>
  65. <if test=" null != isPreview ">and `is_preview` = #{isPreview}</if>
  66. <if test=" null != starttime">and `starttime` &gt;= #{starttime}</if>
  67. <if test=" null != endtime">and `endtime` &lt;= #{endtime}</if>
  68. <if test=" null != month and '' != month">
  69. and date_format(starttime,'%Y-%m') &lt;= #{month} and date_format(endtime,'%Y-%m') &gt;= #{month}
  70. </if>
  71. <if test=" null == nearBillLastTime and null != oweBillLastTime">
  72. and (
  73. (`starttime` &lt;= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7) and bill_type not in (13,21,5))
  74. or
  75. (`starttime` &lt;= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') &gt; 0 and status not in (3,6,7) and bill_type in (13,21,5))
  76. )
  77. </if>
  78. <if test=" null != nearBillLastTime and null != oweBillLastTime">
  79. and (
  80. (`starttime` &gt; #{oweBillLastTime} and `starttime` &lt;= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7) and bill_type not in (13,21,5))
  81. or
  82. (`starttime` &gt; #{oweBillLastTime} and `starttime` &lt;= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') &gt; 0 and status not in (3,6,7) and bill_type in (13,21,5))
  83. )
  84. </if>
  85. <if test=" null != needPayStartDay">
  86. and (
  87. (`starttime` &lt;= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7) and bill_type not in (13,21,5))
  88. or
  89. (`starttime` &lt;= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') &gt; 0 and status not in (3,6,7) and bill_type in (13,21,5))
  90. )
  91. </if>
  92. <if test=" null != toPayMerchant">
  93. and (
  94. ( `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &lt; 0 and bill_type not in (13,21,5))
  95. or
  96. ( `receive_pay` - `pay` - IFNULL(`set_off`,'0') &lt; 0 and bill_type in (13,21,5))
  97. or status in (8,9)
  98. )
  99. </if>
  100. <if test=" 1 == notifyed ">
  101. and (
  102. (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') &gt; 0 and status not in (3,6,7) and bill_type not in (13,21,5))
  103. or
  104. (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') &gt; 0 and status not in (3,6,7) and bill_type in (13,21,5))
  105. )
  106. </if>
  107. <if test=" null != hasMerchant ">and `merchant_id` is not null</if>
  108. <if test=" 1 == hasParentBillId ">and `parent_bill_id` is not null</if>
  109. <if test=" 0 == hasParentBillId ">and `parent_bill_id` is null</if>
  110. <if test=" null != energyReadingCalcuteId ">and `energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
  111. <if test=" null != energyReadingId ">and `energy_reading_id` = #{energyReadingId}</if>
  112. <if test=" null != rentContractIdList ">
  113. and `rent_contract_id` in
  114. <foreach collection="rentContractIdList" index="index" item="ridItem" open="(" separator="," close=")">
  115. #{ridItem}
  116. </foreach>
  117. </if>
  118. <if test=" null != propertyContractIds ">
  119. and property_contract_id in
  120. <foreach collection="propertyContractIds" index="index" item="pidItem" open="(" separator="," close=")">
  121. #{pidItem}
  122. </foreach>
  123. </if>
  124. <if test=" null != merchantIdList ">
  125. and `merchant_id` in
  126. <foreach collection="merchantIdList" index="index" item="midItem" open="(" separator="," close=")">
  127. #{midItem}
  128. </foreach>
  129. </if>
  130. <if test=" null != statusList ">
  131. and `status` in
  132. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  133. #{stItem}
  134. </foreach>
  135. </if>
  136. <if test=" null != notInIds ">
  137. and id not in
  138. <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
  139. #{nidItem}
  140. </foreach>
  141. </if>
  142. <if test=" null != sortColumns">order by ${sortColumns}</if>
  143. <if test="null != limitStart and null != limitEnd">
  144. limit #{limitStart},#{limitEnd}
  145. </if>
  146. </sql>
  147. <select id="findList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="BaseResultMap">
  148. select
  149. <include refid="allColumns"/>
  150. from wx_all_bill
  151. <include refid="dynamicWhereConditions"/>
  152. </select>
  153. <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
  154. select
  155. <include refid="allColumns"/>
  156. from wx_all_bill where id = #{id} and `tenant_id` = #{tenantId}
  157. </select>
  158. <select id="queryBillRentContractIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
  159. select distinct rent_contract_id from wx_all_bill
  160. <include refid="dynamicWhereConditions"/>
  161. </select>
  162. <resultMap id="SumBaseResultMap" type="com.iformall.domain.vo.WxBillSum">
  163. <result column="receive_pay" jdbcType="VARCHAR" property="needPay"/>
  164. <result column="paid" jdbcType="VARCHAR" property="paid" />
  165. <result column="min_date" jdbcType="TIMESTAMP" property="minDate" />
  166. <result column="max_date" jdbcType="TIMESTAMP" property="maxDate" />
  167. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  168. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  169. <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
  170. </resultMap>
  171. <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
  172. select
  173. sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
  174. sum(CAST(pay AS DECIMAL(20,2))) paid,
  175. min(starttime) min_date,
  176. max(endtime) max_date,
  177. sum(CAST(set_off AS DECIMAL(20,2))) set_off ,
  178. sum(CAST(return_pay AS DECIMAL(20,2))) return_pay
  179. from wx_all_bill
  180. <include refid="dynamicWhereConditions"/>
  181. </select>
  182. <select id="getFeesBillSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
  183. select
  184. energy_fees_id,
  185. sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
  186. sum(CAST(pay AS DECIMAL(20,2))) paid,
  187. min(starttime) min_date,
  188. max(endtime) max_date,
  189. sum(CAST(set_off AS DECIMAL(20,2))) set_off ,
  190. sum(CAST(return_pay AS DECIMAL(20,2))) return_pay
  191. from wx_all_bill
  192. <include refid="dynamicWhereConditions"/>
  193. group by energy_fees_id
  194. </select>
  195. <select id="getMerchantIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
  196. select distinct merchant_id from wx_all_bill
  197. <include refid="dynamicWhereConditions"/>
  198. </select>
  199. <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
  200. <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
  201. <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
  202. <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
  203. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  204. </resultMap>
  205. <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxAllBill" resultMap="HotNotifyBaseResultMap">
  206. select
  207. bill_type,
  208. count(1) total_count ,
  209. case when bill_type in (13,21,5) then sum(CAST(`receive_pay` AS DECIMAL(20,2)) - CAST(`pay` AS DECIMAL(20,2)) - CAST(IFNULL(`set_off`,'0') AS DECIMAL(20,2)) )
  210. else sum(CAST(`receive_pay` AS DECIMAL(20,2)) - CAST(`pay` AS DECIMAL(20,2)) - CAST(IFNULL(`set_off`,'0') AS DECIMAL(20,2)) + CAST(IFNULL(`return_pay`,'0') AS DECIMAL(20,2)))
  211. end as total_money,
  212. MIN(starttime) min_begin_time from wx_all_bill
  213. <include refid="dynamicWhereConditions"/>
  214. group by bill_type
  215. </select>
  216. <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
  217. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  218. <result column="bill_id" jdbcType="BIGINT" property="billId" />
  219. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  220. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  221. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  222. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  223. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  224. </resultMap>
  225. <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="NotifyResultMap">
  226. select bill_type,br.id as bill_id, br.starttime,br.endtime,br.receive_pay,br.pay,br.merchant_id from wx_all_bill br
  227. <include refid="dynamicWhereConditions"/>
  228. </select>
  229. <delete id="deleteBillByContract" parameterType="com.iformall.domain.po.WxRentContract">
  230. delete from wx_all_bill where rent_contract_id = #{id}
  231. </delete>
  232. <delete id="deleteBillByPropertyContract" parameterType="com.iformall.domain.po.WxPropertyContract">
  233. delete from wx_all_bill where property_contract_id = #{id}
  234. </delete>
  235. <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxAllBill">
  236. delete from wx_all_bill where is_preview = 1
  237. <if test=" null != rentContractId">
  238. and rent_contract_id = #{rentContractId}
  239. </if>
  240. <if test=" null != propertyContractId">
  241. and property_contract_id = #{propertyContractId}
  242. </if>
  243. </delete>
  244. <delete id="deleteNoNeedPayBill" parameterType="com.iformall.domain.po.WxAllBill">
  245. delete from wx_all_bill where status = 2
  246. and starttime &gt;= #{shopEndtime} and IFNULL(`pay`,'0') &lt;= 0 AND IFNULL(`set_off`,'0') &lt;= 0 and IFNULL(`return_pay`,'0') &lt;= 0
  247. <if test=" null != rentContractId">
  248. and rent_contract_id = #{rentContractId}
  249. </if>
  250. <if test=" null != propertyContractId">
  251. and property_contract_id = #{propertyContractId}
  252. </if>
  253. <if test=" null != merchantId">
  254. and merchant_id = #{merchantId}
  255. </if>
  256. </delete>
  257. <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxAllBill">
  258. update wx_all_bill set is_preview = #{isPreview}
  259. <if test=" null != rentContractId">
  260. where rent_contract_id = #{rentContractId}
  261. </if>
  262. <if test=" null != propertyContractId">
  263. where property_contract_id = #{propertyContractId}
  264. </if>
  265. </update>
  266. <insert id="insertBills" parameterType="HashMap">
  267. INSERT INTO wx_all_bill (
  268. <include refid="allColumns"/>
  269. )
  270. VALUES
  271. <foreach collection="list" item="item" index="index" separator=",">
  272. (
  273. #{item.id},#{item.tenantId},#{item.parentTenantId},#{item.merchantId},#{item.rentShopType},#{item.createtime},
  274. #{item.createBy},#{item.createByName},#{item.updatetime},#{item.updateBy},#{item.updateByName},#{item.priceDetail},
  275. #{item.needPay},#{item.receivePay},#{item.pay},#{item.billType},#{item.payWay},#{item.payDate},#{item.setOff},
  276. #{item.starttime},#{item.endtime},#{item.status},#{item.energyFeesId},#{item.returnPay},#{item.billRemark},
  277. #{item.lastOweCallTime},#{item.lastOweCallUser},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},
  278. #{item.shopId},#{item.shopNumber},#{item.isPreview},#{item.shopInfo},#{item.rentContractId},#{item.propertyContractId},
  279. #{item.parentBillId},#{item.energyReadingCalcuteId},#{item.energyReadingId}
  280. )
  281. </foreach>
  282. </insert>
  283. <delete id = "deleteById" parameterType="HashMap">
  284. delete from wx_all_bill where id = #{id} and tenant_id = #{tenantId}
  285. </delete>
  286. <delete id = "deleteEnergyReadingBills" parameterType="HashMap">
  287. delete from wx_all_bill where energy_reading_calcuteId = #{energyReadingCalcuteId} and tenant_id = #{tenantId} and status = 2 and pay &lt;= 0 and IFNULL(`set_off`,'0') &lt;= 0 and IFNULL(`return_pay`,'0') &lt;= 0
  288. </delete>
  289. <update id="updatePropertyBillInvalidStatusByRent" parameterType="com.iformall.domain.po.WxRentContract">
  290. update wx_all_bill set status = 6 where property_contract_id in
  291. (select id from wx_property_contract where rent_contract_id = #{id})
  292. and status != 3
  293. </update>
  294. </mapper>