Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

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