Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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