You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

292 lines
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.WxBillDailyMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBillDaily">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  7. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  8. <result column="receive_date" jdbcType="TIMESTAMP" property="receiveDate" />
  9. <result column="pay_date" jdbcType="TIMESTAMP" property="payDate" />
  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="update_by" jdbcType="BIGINT" property="updateBy"/>
  14. <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/>
  15. <result column="expired_day" jdbcType="INTEGER" property="expiredDay" />
  16. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  17. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  18. <result column="status" jdbcType="INTEGER" property="status" />
  19. <result column="apply_status" jdbcType="INTEGER" property="applyStatus"/>
  20. <result column="apply_pay_img" jdbcType="INTEGER" property="applyPayImg"/>
  21. <result column="apply_update_time" jdbcType="INTEGER" property="applyUpdateTime"/>
  22. <result column="is_del" jdbcType="INTEGER" property="isDel" />
  23. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  24. <result column="user_id" jdbcType="BIGINT" property="userId" />
  25. <result column="shop_id" jdbcType="BIGINT" property="shopId" />
  26. <result column="shop_name" jdbcType="VARCHAR" property="shopName" />
  27. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime" />
  28. <result column="type" jdbcType="INTEGER" property="type" />
  29. <result column="rent_shop_type" jdbcType="INTEGER" property="rentShopType"/>
  30. <result column="pay_way" jdbcType="BIGINT" property="payWay"/>
  31. <result column="price_detail" jdbcType="VARCHAR" property="priceDetail"/>
  32. <result column="starttime" property="starttime"/>
  33. <result column="endtime" property="endtime"/>
  34. <result column="last_owe_call_time" jdbcType="TIMESTAMP" property="lastOweCallTime"/>
  35. <result column="last_owe_call_user" jdbcType="VARCHAR" property="lastOweCallUser"/>
  36. <result column="freeze" property="freeze"/>
  37. <result column="build_way" property="buildWay"/>
  38. <result column="service_charge_pay" property="serviceChargePay"/>
  39. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  40. <result column="energy_reading_calcuteId" jdbcType="BIGINT" property="energyReadingCalcuteId" />
  41. <result column="energy_reading_id" jdbcType="BIGINT" property="energyReadingId" />
  42. <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
  43. <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
  44. </resultMap>
  45. <sql id="allColumns">
  46. `id`,`receive_pay`,`pay`,`receive_date`,`pay_date`,`createtime`,`expired_day`,`apply_status`,`apply_pay_img`,`apply_update_time`,
  47. `tenant_id`,`parent_tenant_id`,`status`,`is_del`,`merchant_id`,`user_id`,`shop_id`,`shop_name`,`updatetime`,`type`,`last_owe_call_time`,
  48. `rent_shop_type`,`pay_way`,`price_detail`,`starttime`,`endtime`,freeze,build_way,service_charge_pay,`remark`,`last_owe_call_user`,
  49. `create_by`,`create_by_name`,`update_by`,`update_by_name`,`energy_reading_calcuteId`,`energy_reading_id`,`energy_fees_id`,`set_off`
  50. </sql>
  51. <sql id="dynamicWhereConditions">
  52. where 1 = 1
  53. <if test=" null != id "> and `id` = #{id} </if>
  54. <if test=" null != receivePay "> and `receive_pay` = #{receivePay} </if>
  55. <if test=" null != pay "> and `pay` = #{pay} </if>
  56. <if test=" null != receiveDate "> and `receive_date` = #{receiveDate} </if>
  57. <if test=" null != payDate "> and `pay_date` = #{payDate} </if>
  58. <if test=" null != createtime "> and `createtime` = #{createtime} </if>
  59. <if test=" null != expiredDay "> and `expired_day` = #{expiredDay} </if>
  60. <if test=" null != tenantId and '' != tenantId">
  61. and `tenant_id` = #{tenantId}
  62. </if>
  63. <if test=" null != parentTenantId and '' != parentTenantId">
  64. and `parent_tenant_id` = #{parentTenantId}
  65. </if>
  66. <if test=" null != status "> and `status` = #{status} </if>
  67. <if test=" null != applyStatus ">and `apply_status` = #{applyStatus}</if>
  68. <if test=" null != isDel "> and `is_del` = #{isDel} </if>
  69. <if test=" null != merchantId "> and `merchant_id` = #{merchantId} </if>
  70. <if test=" null != energyFeesId ">and `energy_fees_id` = #{energyFeesId}</if>
  71. <if test=" null != userId "> and `user_id` = #{userId} </if>
  72. <if test=" null != updatetime "> and `updatetime` = #{updatetime} </if>
  73. <if test=" null != type "> and `type` = #{type} </if>
  74. <if test=" null != rentShopType ">and `rent_shop_type` = #{rentShopType}</if>
  75. <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
  76. <if test=" null != buildWay ">and `build_way` = #{buildWay}</if>
  77. <if test=" null != energyReadingCalcuteId ">and `energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
  78. <if test=" null != energyReadingId ">and `energy_reading_id` = #{energyReadingId}</if>
  79. <if test=" 1 == notifyed ">and (`last_owe_call_time` is not null and `receive_pay` - `pay` - IFNULL(`set_off`,'0') &gt; 0 and status not in (3,6,7) )</if>
  80. <if test=" null != statusList ">
  81. and status in
  82. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  83. #{stItem}
  84. </foreach>
  85. </if>
  86. <if test=" null != ids ">
  87. and id in
  88. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  89. #{idItem}
  90. </foreach>
  91. </if>
  92. <if test=" null != notInIds ">
  93. and id not in
  94. <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
  95. #{nidItem}
  96. </foreach>
  97. </if>
  98. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  99. </sql>
  100. <select id="findList" parameterType="com.iformall.domain.po.WxBillDaily" resultMap="BaseResultMap">
  101. select <include refid="allColumns" /> from wx_bill_daily
  102. <include refid="dynamicWhereConditions" />
  103. </select>
  104. <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
  105. select <include refid="allColumns" /> from wx_bill_daily
  106. where id = #{id} and tenant_id = #{tenantId}
  107. </select>
  108. <sql id = "queryBillDailyListConditions" >
  109. <where>
  110. 1 = 1
  111. <if test=" null != id ">and br.`id` = #{id}</if>
  112. <if test=" null != tenantId and '' != tenantId"> and br.`tenant_id` = #{tenantId}</if>
  113. <if test=" null != parentTenantId and '' != parentTenantId">and br.`parent_tenant_id` = #{parentTenantId}</if>
  114. <if test=" null != freeze ">and br.`freeze` = #{freeze}</if>
  115. <if test=" null != id ">and br.`id` = #{id}</if>
  116. <if test=" null != merchantId ">and br.`merchant_id` = #{merchantId}</if>
  117. <if test=" null != energyFeesId ">and br.`energy_fees_id` = #{energyFeesId}</if>
  118. <if test=" null != status ">and br.`status` = #{status}</if>
  119. <if test=" null != applyStatus ">and br.`apply_status` = #{applyStatus}</if>
  120. <if test=" null != isDel ">and br.`is_del` = #{isDel}</if>
  121. <if test=" null != type ">and br.`type` = #{type}</if>
  122. <if test=" null != rentShopType ">and br.`rent_shop_type` = #{rentShopType}</if>
  123. <if test=" null != payWay ">and br.`pay_way` = #{payWay}</if>
  124. <if test=" null != starttime">and br.`starttime` &lt;= #{starttime}</if>
  125. <if test=" null != endtime">and br.`endtime` &gt;= #{endtime}</if>
  126. <if test=" null != month and '' != month">
  127. and date_format(br.starttime,'%Y-%m') &lt;= #{month} and date_format(br.endtime,'%Y-%m') &gt;= #{month}
  128. </if>
  129. <if test=" null == nearBillLastTime and null != oweBillLastTime">
  130. and (br.`starttime` &lt;= #{oweBillLastTime} and br.`receive_pay` - br.`pay` - IFNULL(br.`set_off`,'0') &gt; 0 and br.status not in (3,6,7))
  131. </if>
  132. <if test=" null != nearBillLastTime and null != oweBillLastTime">
  133. and (br.`starttime` &gt; #{oweBillLastTime} and br.`starttime` &lt;= #{nearBillLastTime} and br.`receive_pay` - br.`pay` - IFNULL(br.`set_off`,'0') &gt; 0 and br.status not in (3,6,7))
  134. </if>
  135. <if test=" null != needPayStartDay">
  136. and (br.`starttime` &lt;= #{needPayStartDay} and br.`receive_pay` - br.`pay` - IFNULL(br.`set_off`,'0') &gt; 0 and br.status not in (3,6,7))
  137. </if>
  138. <if test=" null != buildWay ">and br.`build_way` = #{buildWay}</if>
  139. <if test=" null != energyReadingCalcuteId ">and br.`energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
  140. <if test=" null != energyReadingId ">and br.`energy_reading_id` = #{energyReadingId}</if>
  141. <if test=" 1 == notifyed ">and (br.`last_owe_call_time` is not null and br.`receive_pay` - br.`pay` - IFNULL(br.`set_off`,'0') &gt; 0 and br.status not in (3,6,7) )</if>
  142. <if test=" null != merchantIds ">
  143. and br.`merchant_id` in
  144. <foreach collection="merchantIds" index="index" item="midItem" open="(" separator="," close=")">
  145. #{midItem}
  146. </foreach>
  147. </if>
  148. <if test=" null != notInIds ">
  149. and br.`id` not in
  150. <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
  151. #{nidItem}
  152. </foreach>
  153. </if>
  154. <if test=" null != statusList ">
  155. and br.status in
  156. <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
  157. #{stItem}
  158. </foreach>
  159. </if>
  160. </where>
  161. </sql>
  162. <select id="queryBillDailyList" parameterType="com.iformall.domain.po.WxBillDaily" resultMap="BaseResultMap">
  163. select br.`id`,br.`tenant_id`,br.`parent_tenant_id`,br.`receive_pay`,br.`pay`,br.`receive_date`,br.`pay_date`,br.`createtime`,br.`expired_day` ,
  164. br.`status`,br.`updatetime`,br.`merchant_id`,br.shop_id,br.`last_owe_call_time`,br.`last_owe_call_user`,br.`set_off`,
  165. br.shop_name,br.type,br.`rent_shop_type`,br.pay_way,br.price_detail,br.`starttime`,br.`endtime`,br.`build_way`,
  166. br.freeze,br.service_charge_pay,br.`apply_status`,br.`apply_pay_img`,br.`apply_update_time`,br.`remark`,br.`energy_fees_id`,
  167. br.`create_by`,br.`create_by_name`,br.`update_by`,br.`update_by_name`,br.`energy_reading_calcuteId`,br.`energy_reading_id`
  168. from wx_bill_daily br
  169. <include refid="queryBillDailyListConditions" />
  170. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  171. <if test=" null == sortColumns">order by id desc</if>
  172. </select>
  173. <resultMap id="SumBaseResultMap" type="com.iformall.domain.vo.WxBillSum">
  174. <result column="receive_pay" jdbcType="VARCHAR" property="needPay"/>
  175. <result column="paid" jdbcType="VARCHAR" property="paid" />
  176. <result column="min_date" jdbcType="TIMESTAMP" property="minDate" />
  177. <result column="max_date" jdbcType="TIMESTAMP" property="maxDate" />
  178. <result column="service_pay" jdbcType="VARCHAR" property="servicePay"/>
  179. <result column="late_pay" jdbcType="VARCHAR" property="latePay"/>
  180. <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
  181. </resultMap>
  182. <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxBillDaily" resultMap="SumBaseResultMap">
  183. select
  184. sum(CAST(br.receive_pay AS DECIMAL(20,2))) receive_pay ,
  185. sum(CAST(br.pay AS DECIMAL(20,2))) paid,
  186. min(starttime) min_date,
  187. max(endtime) max_date,
  188. sum(CAST(br.service_charge_pay AS DECIMAL(20,2))) service_pay ,
  189. '0' late_pay,
  190. '0' return_pay
  191. from wx_bill_daily br
  192. <include refid="queryBillDailyListConditions"/>
  193. </select>
  194. <select id="getMerchantIdList" parameterType="com.iformall.domain.po.WxBillDaily" resultType="Long">
  195. select distinct merchant_id from wx_bill_daily br
  196. <include refid="queryBillDailyListConditions"/>
  197. </select>
  198. <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
  199. <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
  200. <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
  201. <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
  202. </resultMap>
  203. <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxBillDaily" resultMap="HotNotifyBaseResultMap">
  204. select count(1) total_count , sum(CAST(br.`receive_pay` AS DECIMAL(20,2)) - CAST(br.`pay` AS DECIMAL(20,2)) - CAST(IFNULL(br.`set_off`,'0') AS DECIMAL(20,2))) total_money,MIN(br.starttime) min_begin_time from wx_bill_daily br
  205. <include refid="queryBillDailyListConditions"/>
  206. </select>
  207. <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
  208. <result column="bill_type" jdbcType="INTEGER" property="billType"/>
  209. <result column="bill_type_name" jdbcType="VARCHAR" property="billTypeName" />
  210. <result column="bill_id" jdbcType="BIGINT" property="billId" />
  211. <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
  212. <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
  213. <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
  214. <result column="pay" jdbcType="VARCHAR" property="pay"/>
  215. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  216. </resultMap>
  217. <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxBillDaily" resultMap="NotifyResultMap">
  218. select #{billType} bill_type,#{billTypeName} bill_type_name,br.id as bill_id, br.starttime,br.endtime,br.receive_pay,br.pay,br.merchant_id from wx_bill_daily br
  219. <include refid="queryBillDailyListConditions"/>
  220. </select>
  221. <update id="updateNotPaidStatus" parameterType="hashmap">
  222. update wx_bill_daily set status=#{notPaid},expired_day=DATEDIFF(now(),receive_date)
  223. where status!=#{paid}
  224. <if test=" null != tenantId and '' != tenantId">
  225. and `tenant_id` = #{tenantId}
  226. </if>
  227. <if test=" null != parentTenantId and '' != parentTenantId">
  228. and `parent_tenant_id` = #{parentTenantId}
  229. </if>
  230. and DATEDIFF(now(),receive_date)>0
  231. </update>
  232. <update id="updateWaitPayStatus" parameterType="hashmap">
  233. update wx_bill_daily set status=#{waitPay} where status!=#{paid}
  234. <if test=" null != tenantId and '' != tenantId">
  235. and `tenant_id` = #{tenantId}
  236. </if>
  237. <if test=" null != parentTenantId and '' != parentTenantId">
  238. and `parent_tenant_id` = #{parentTenantId}
  239. </if>
  240. and DATEDIFF(now(),receive_date) &lt;=0
  241. </update>
  242. <delete id = "deleteById" parameterType="HashMap">
  243. delete from wx_bill_daily where id = #{id} and tenant_id = #{tenantId}
  244. </delete>
  245. <insert id="insertBills" parameterType="HashMap">
  246. INSERT INTO wx_bill_daily (`id`,`tenant_id`,`parent_tenant_id`,`receive_pay`,`pay`,`receive_date`,`pay_date`,`createtime`,`expired_day`,`status`,`is_del`,
  247. `merchant_id`,`user_id`,`shop_id`,`shop_name`,`updatetime`,`type`,`rent_shop_type`,`apply_status`,`pay_way`,`price_detail`,
  248. `starttime`,`endtime`,`freeze`,`build_way`,`service_charge_pay`,`apply_pay_img`,`apply_update_time`,`remark`,`create_by`,`update_by`,
  249. `create_by_name`,`update_by_name`,`energy_reading_calcuteId`,`energy_reading_id`,`energy_fees_id`)
  250. VALUES
  251. <foreach collection="list" item="item" index="index" separator=",">
  252. (
  253. #{item.id},#{item.tenantId},#{item.parentTenantId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime},#{item.expiredDay},#{item.status},#{item.isDel},
  254. #{item.merchantId},#{item.userId},#{item.shopId},#{item.shopName},#{item.updatetime},#{item.type},#{item.rentShopType},#{item.applyStatus},#{item.payWay},#{item.priceDetail},
  255. #{item.starttime},#{item.endtime},#{item.freeze},#{item.buildWay},#{item.serviceChargePay},#{item.applyPayImg},#{item.applyUpdateTime},#{item.remark},#{item.createBy},#{item.updateBy},
  256. #{item.createByName},#{item.updateByName},#{item.energyReadingCalcuteId},#{item.energyReadingId},#{item.energyFeesId}
  257. )
  258. </foreach>
  259. </insert>
  260. <delete id = "deleteEnergyReadingBills" parameterType="HashMap">
  261. delete from wx_bill_daily where energy_reading_calcuteId = #{energyReadingCalcuteId} and tenant_id = #{tenantId} and status = 2 and pay &lt;= 0 and IFNULL(`set_off`,'0') &lt;= 0
  262. </delete>
  263. <delete id="deleteNoNeedPayBill" parameterType="com.iformall.domain.po.WxBillDaily">
  264. delete from wx_bill_daily where merchant_id = #{merchantId} and status = 2
  265. and starttime &gt; #{shopEndtime} and IFNULL(`pay`,'0') &lt;= 0 AND IFNULL(`set_off`,'0') &lt;= 0
  266. </delete>
  267. </mapper>