選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

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