|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.iformall.mapper.WxBillSettleMapper">
- <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBillSettle">
- <id column="id" property="id"/>
- <result column="tenant_id" property="tenantId"/>
- <result column="parent_tenant_id" property="parentTenantId"/>
- <result column="settle_number" property="settleNumber"/>
- <result column="merchant_id" property="merchantId"/>
- <result column="status" property="status"/>
- <result column="apply_status" property="applyStatus"/>
- <result column="receiveMoney" property="receiveMoney"/>
- <result column="payMoney" property="payMoney"/>
- <result column="settletime" property="settletime"/>
- <result column="createtime" property="createtime"/>
- <result column="updatetime" property="updatetime"/>
- <result column="merchantName" property="merchantName"/>
- <result column="has_recorded" property="hasRecorded"/>
- </resultMap>
-
- <sql id="allColumns">
- `id`,`tenant_id`,`parent_tenant_id`,`settle_number`,`merchant_id`,`status`,`apply_status`,
- `receive_money`,`pay_money`,`settletime`,`createtime`,`updatetime`,`has_recorded`
- </sql>
-
- <sql id="dynamicWhereConditions">
- where 1=1
- <if test=" null != id ">and tt.`id` = #{id}</if>
- <if test=" null != tenantId and '' != tenantId">
- and tt.`tenant_id` = #{tenantId}
- </if>
- <if test=" null != parentTenantId and '' != parentTenantId">
- and tt.`parent_tenant_id` = #{parentTenantId}
- </if>
- <if test=" null != merchantName and merchantName !='' ">and tt.merchantName like concat('%', #{merchantName},'%')</if>
- <if test="starttime != null">
- and tt.createtime >= #{starttime}
- </if>
- <if test="endtime != null">
- and tt.createtime <= #{endtime}
- </if>
- <if test=" null != settleNumber and settleNumber !='' ">and tt.`settle_number` = #{settleNumber}</if>
- <if test=" null != status">and tt.`status` = #{status}</if>
- <if test=" null != applyStatus">and tt.`apply_status` = #{applyStatus}</if>
- <if test="0 == direction">
- and (tt.receiveMoney-tt.payMoney-
- (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = tt.id)
- ) >0
- </if>
- <if test="1 == direction">
- and (tt.receiveMoney-tt.payMoney-
- (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = tt.id)
- ) <0
- </if>
-
- <if test=" null != sortColumns">order by ${sortColumns}</if>
- </sql>
-
- <select id="findList" parameterType="com.iformall.domain.po.WxBillSettle" resultMap="BaseResultMap">
- select tt.*
- <if test="0 == filterSettleRecord">
- ,(tt.receiveMoney-tt.payMoney-
- (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = tt.id)
- ) balance
- </if>
- <if test="1 == filterSettleRecord">
- ,(tt.receiveMoney-tt.payMoney) balance
- </if>
- from (
- select s.*,m.name merchantName,
- (select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
- (select id,merchant_id,shop_id,tenant_id,parent_tenant_id,1 bill_type_value,'租金'
- bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_rent where is_preview = 0
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,2 bill_type_value,'租赁押金'
- bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
- wx_bill_rent_deposit
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,3 bill_type_value,'物业费'
- bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
- wx_bill_property where is_preview = 0
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,4 bill_type_value,'物业押金'
- bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
- wx_bill_property_deposit
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,5 bill_type_value,'水费' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
- type=1
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,6 bill_type_value,'电费' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
- type=2
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,9 bill_type_value,'空调费' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
- type=3
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
- ) bill
- on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=0
- ) receiveMoney,
-
- (select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
- (select id,merchant_id,shop_id,tenant_id,parent_tenant_id,1 bill_type_value,'租金'
- bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_rent where is_preview = 0
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,2 bill_type_value,'租赁押金'
- bill_type,need_pay,receive_pay,pay,receive_pay owe,receive_date,pay_date,expired_day,status,rent_shop_type from
- wx_bill_rent_deposit
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,3 bill_type_value,'物业费'
- bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
- wx_bill_property where is_preview = 0
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,4 bill_type_value,'物业押金'
- bill_type,need_pay,receive_pay,pay,receive_pay owe,receive_date,pay_date,expired_day,status,rent_shop_type from
- wx_bill_property_deposit
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,5 bill_type_value,'水费' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
- type=1
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,6 bill_type_value,'电费' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
- type=2
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,9 bill_type_value,'空调费' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
- type=3
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
- need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
- union all
- select id,merchant_id,shop_id,tenant_id,parent_tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
- need_pay,receive_pay,pay,receive_pay owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
- union all
- select id,id merchant_id,'' shop_id,tenant_id,parent_tenant_id,10 bill_type_value,'补贴' bill_type,0 as
- need_pay,subsidy receive_pay,0 pay,subsidy owe,'' receive_date,'' pay_date,'' expired_day,status,'' rent_shop_type from wx_merchant_subsidy
-
- ) bill
- on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=1
- ) payMoney
- from wx_bill_settle s left JOIN wx_merchant m on(s.merchant_id=m.id)
- ) tt
-
- <include refid="dynamicWhereConditions"/>
- <if test="null != limitStart and null != limitEnd">
- limit #{limitStart},#{limitEnd}
- </if>
- </select>
-
- <update id = "updateRecorded" parameterType = "hashmap">
- update wx_bill_settle set has_recorded = 1 where id = #{id}
- </update>
-
- </mapper>
-
|