|
- <?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.WxAllBillMapper">
- <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxAllBill">
- <id column="id" jdbcType="BIGINT" property="id"/>
- <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
- <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
- <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
- <result column="shop_number" jdbcType="VARCHAR" property="shopNumber"/>
- <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
- <result column="create_by" jdbcType="BIGINT" property="createBy"/>
- <result column="create_by_name" jdbcType="VARCHAR" property="createByName"/>
- <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
- <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
- <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/>
- <result column="price_detail" jdbcType="VARCHAR" property="priceDetail"/>
- <result column="need_pay" jdbcType="VARCHAR" property="needPay"/>
- <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
- <result column="pay" jdbcType="VARCHAR" property="pay"/>
- <result column="bill_type" jdbcType="INTEGER" property="billType"/>
- <result column="pay_way" jdbcType="BIGINT" property="payWay"/>
- <result column="pay_date" jdbcType="TIMESTAMP" property="payDate"/>
- <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
- <result column="use_money" jdbcType="VARCHAR" property="useMoney"/>
- <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
- <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
- <result column="receive_date" jdbcType="TIMESTAMP" property="receiveDate"/>
- <result column="period" jdbcType="VARCHAR" property="period"/>
- <result column="status" jdbcType="INTEGER" property="status"/>
- <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
- <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
- <result column="bill_remark" jdbcType="VARCHAR" property="billRemark"/>
- <result column="last_owe_call_time" jdbcType="TIMESTAMP" property="lastOweCallTime"/>
- <result column="last_owe_call_user" jdbcType="VARCHAR" property="lastOweCallUser"/>
-
- <result column="bussiness_manage_fee_need_pay" jdbcType="VARCHAR" property="bussinessManageFeeNeedPay"/>
- <result column="operating_manage_fee_need_pay" jdbcType="VARCHAR" property="operatingManageFeeNeedPay"/>
- <result column="is_preview" jdbcType="INTEGER" property="isPreview"/>
- <result column="shop_info" jdbcType="VARCHAR" property="shopInfo"/>
- <result column="rent_contract_id" jdbcType="BIGINT" property="rentContractId"/>
- <result column="rent_contract_agile_fees_type" jdbcType="INTEGER" property="rentContractAgileFeesType"/>
- <result column="property_contract_id" jdbcType="BIGINT" property="propertyContractId"/>
- <result column="parent_bill_id" jdbcType="BIGINT" property="parentBillId"/>
- <result column="energy_reading_calcuteId" jdbcType="BIGINT" property="energyReadingCalcuteId" />
- <result column="energy_reading_id" jdbcType="BIGINT" property="energyReadingId" />
- <result column="extra_create_from" jdbcType="INTEGER" property="extraCreateFrom" />
- <result column="rent_area" jdbcType="VARCHAR" property="rentArea" />
- <result column="can_edit" jdbcType="INTEGER" property="canEdit" />
- <result column="cus_name" jdbcType="VARCHAR" property="cusName" />
- </resultMap>
-
- <sql id="allColumns">
- `id`,`tenant_id`,`parent_tenant_id`,`createtime`,`create_by`,`create_by_name`,`updatetime`,`update_by`,`update_by_name`,
- `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`,
- `bill_remark`,`last_owe_call_time`,`last_owe_call_user`,`bussiness_manage_fee_need_pay`,`operating_manage_fee_need_pay`,`shop_id`,`shop_number`,`receive_date`,`period`,
- `is_preview`,`shop_info`,`rent_contract_id`,`rent_contract_agile_fees_type`,`property_contract_id`,`parent_bill_id`,`energy_reading_calcuteId`,`energy_reading_id`,`extra_create_from`,`rent_area`,
- `can_edit`,`cus_name`
- </sql>
-
- <sql id="dynamicWhereConditions">
- where `tenant_id` = #{tenantId}
- <if test=" null != id ">and `id` = #{id}</if>
- <if test=" null != parentTenantId and '' != parentTenantId"> and `parent_tenant_id` = #{parentTenantId}</if>
- <if test=" null != createBy ">and `create_by` = #{createBy}</if>
- <if test=" null != createByName and '' != createByName"> and `create_by_name` like concat('%',#{createByName},'%')</if>
- <if test=" null != billType ">and `bill_type` = #{billType}</if>
- <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
- <if test=" null != status ">and `status` = #{status}</if>
- <if test=" null != energyFeesId ">and `energy_fees_id` = #{energyFeesId}</if>
- <if test=" null != rentContractId ">and `rent_contract_id` = #{rentContractId}</if>
- <if test=" null != rentContractAgileFeesType ">and `rent_contract_agile_fees_type` = #{rentContractAgileFeesType}</if>
- <if test=" null != propertyContractId ">and `property_contract_id` = #{propertyContractId}</if>
- <if test=" null != parentBillId ">and `parent_bill_id` = #{parentBillId}</if>
- <if test=" null != isPreview ">and `is_preview` = #{isPreview}</if>
- <if test=" null != starttime">and `starttime` >= #{starttime}</if>
- <if test=" null != endtime">and `endtime` <= #{endtime}</if>
- <if test=" null != receiveDate">and `receive_date` <= #{receiveDate}</if>
- <if test=" null != starttimeEqual">and `starttime` = #{starttimeEqual}</if>
- <if test=" null != endtimeEqual">and `endtime` = #{endtimeEqual}</if>
- <if test=" null != extraCreateFrom">and `extra_create_from` = #{extraCreateFrom}</if>
- <if test=" null != noExtraCreateFrom">and `extra_create_from` is null</if>
- <if test=" null != advanceHasMoney">and bill_type = 6 and IFNULL(`pay`,'0') - IFNULL(`use_money`,'0') > 0</if>
- <if test=" null != canEdit">and `can_edit` = #{canEdit}</if>
- <if test=" null != shopNumber and '' != shopNumber"> and shop_number like concat('%',#{shopNumber},'%')</if>
- <if test=" null != queryShopNumber and '' != queryShopNumber"> and shop_number like concat('%,',#{shopNumber},',%')</if>
- <if test=" null != month and '' != month">
- and date_format(starttime,'%Y-%m') <= #{month} and date_format(endtime,'%Y-%m') >= #{month}
- </if>
- <if test=" null == nearBillLastTime and null != oweBillLastTime">
- and (
- (`receive_date` <= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and bill_type not in (13,21,5,7))
- or
- (`receive_date` <= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and bill_type in (13,21,5,7))
- )
- </if>
- <if test=" null != nearBillLastTime and null != oweBillLastTime">
- and (
- (`receive_date` > #{oweBillLastTime} and `receive_date` <= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and bill_type not in (13,21,5,7))
- or
- (`receive_date` > #{oweBillLastTime} and `receive_date` <= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and bill_type in (13,21,5,7))
- )
- </if>
- <if test=" null != needPayStartDay">
- and (
- (`receive_date` <= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and bill_type not in (13,21,5,7))
- or
- (`receive_date` <= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and bill_type in (13,21,5,7))
- )
- </if>
- <if test=" null != needPayNoDays">
- and (
- ( `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and bill_type not in (13,21,5,7))
- or
- ( `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and bill_type in (13,21,5,7))
- )
- </if>
- <if test=" null != toPayMerchant">
- and (
- ( `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') < 0 and bill_type not in (13,21,5,7))
- or
- ( `pay` - IFNULL(`return_pay`,'0') > 0 and bill_type in (13,21,5,7))
- )
- </if>
- <if test=" 1 == notifyed ">
- and (
- (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and bill_type not in (13,21,5,7))
- or
- (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') > 0 and bill_type in (13,21,5,7))
- )
- </if>
- <if test=" 1 == hasParentBillId ">and `parent_bill_id` is not null</if>
- <if test=" 0 == hasParentBillId ">and `parent_bill_id` is null</if>
- <if test=" null != energyReadingCalcuteId ">and `energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
- <if test=" null != energyReadingId ">and `energy_reading_id` = #{energyReadingId}</if>
- <if test=" null != energyFeesIds ">
- and `energy_fees_id` in
- <foreach collection="energyFeesIds" index="index" item="eidItem" open="(" separator="," close=")">
- #{eidItem}
- </foreach>
- </if>
- <if test=" null != rentContractIdList ">
- and `rent_contract_id` in
- <foreach collection="rentContractIdList" index="index" item="ridItem" open="(" separator="," close=")">
- #{ridItem}
- </foreach>
- </if>
- <if test=" null != propertyContractIds ">
- and property_contract_id in
- <foreach collection="propertyContractIds" index="index" item="pidItem" open="(" separator="," close=")">
- #{pidItem}
- </foreach>
- </if>
- <if test=" null != statusList ">
- and `status` in
- <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
- #{stItem}
- </foreach>
- </if>
- <if test=" null != notInIds ">
- and id not in
- <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
- #{nidItem}
- </foreach>
- </if>
- <if test=" null != ids ">
- and id in
- <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
- #{idItem}
- </foreach>
- </if>
- <if test=" null != sortColumns">order by ${sortColumns}</if>
- <if test="null != limitStart and null != limitEnd">
- limit #{limitStart},#{limitEnd}
- </if>
- </sql>
-
- <select id="findList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="BaseResultMap">
- select
- <include refid="allColumns"/>
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <select id="getShopIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
- select distinct shop_id
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
- select
- <include refid="allColumns"/>
- from wx_all_bill where id = #{id} and `tenant_id` = #{tenantId}
- </select>
-
- <select id="queryBillRentContractIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
- select distinct rent_contract_id from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <select id="getMerchantAdvanceGroupSumList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="BaseResultMap">
- select energy_fees_id, sum(CAST(pay AS DECIMAL(20,2))) pay , sum(CAST(ifnull(use_money,'0') AS DECIMAL(20,2))) use_money
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- group by energy_fees_id
- </select>
-
- <resultMap id="SumBaseResultMap" type="com.iformall.domain.vo.WxBillSum">
- <result column="cut_off_pay" jdbcType="VARCHAR" property="cutOffPay"/>
- <result column="receive_pay" jdbcType="VARCHAR" property="needPay"/>
- <result column="paid" jdbcType="VARCHAR" property="paid" />
- <result column="min_date" jdbcType="TIMESTAMP" property="minDate" />
- <result column="max_date" jdbcType="TIMESTAMP" property="maxDate" />
- <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
- <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
- <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
- </resultMap>
- <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
- select
- sum(CAST(need_pay AS DECIMAL(20,2))-CAST(receive_pay AS DECIMAL(20,2))) cut_off_pay ,
- sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
- sum(CAST(ifnull(pay,'0') AS DECIMAL(20,2))) paid,
- min(starttime) min_date,
- max(endtime) max_date,
- sum(CAST(ifnull(set_off,'0') AS DECIMAL(20,2))) set_off ,
- sum(CAST(ifnull(return_pay,'0') AS DECIMAL(20,2))) return_pay
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
- <select id="getFeesBillSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
- select
- energy_fees_id,
- sum(CAST(need_pay AS DECIMAL(20,2))-CAST(receive_pay AS DECIMAL(20,2))) cut_off_pay ,
- sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
- sum(CAST(ifnull(pay,'0') AS DECIMAL(20,2))) paid,
- min(starttime) min_date,
- max(endtime) max_date,
- sum(CAST(ifnull(set_off,'0') AS DECIMAL(20,2))) set_off ,
- sum(CAST(ifnull(return_pay,'0') AS DECIMAL(20,2))) return_pay
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- group by energy_fees_id
- </select>
-
- <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
- <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
- <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
- <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
- <result column="bill_type" jdbcType="INTEGER" property="billType"/>
- </resultMap>
- <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxAllBill" resultMap="HotNotifyBaseResultMap">
- select
- bill_type,
- count(1) total_count ,
- 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)) )
- 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)))
- end as total_money,
- MIN(starttime) min_begin_time from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- group by bill_type
- </select>
-
- <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
- <result column="bill_type" jdbcType="INTEGER" property="billType"/>
- <result column="bill_id" jdbcType="BIGINT" property="billId" />
- <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
- <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
- <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
- <result column="pay" jdbcType="VARCHAR" property="pay"/>
- <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
- </resultMap>
- <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="NotifyResultMap">
- select bill_type,br.id as bill_id, br.starttime,br.endtime,br.receive_pay,br.pay,br.shop_id from wx_all_bill br
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <delete id="deleteBillByContract" parameterType="com.iformall.domain.po.WxRentContract">
- delete from wx_all_bill where rent_contract_id = #{id}
- </delete>
-
- <delete id="deleteBillByPropertyContract" parameterType="com.iformall.domain.po.WxPropertyContract">
- delete from wx_all_bill where property_contract_id = #{id}
- </delete>
-
- <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxAllBill">
- delete from wx_all_bill where is_preview = 1
- <if test=" null != rentContractId">
- and rent_contract_id = #{rentContractId}
- </if>
- <if test=" null != propertyContractId">
- and property_contract_id = #{propertyContractId}
- </if>
- <if test=" null != rentContractAgileFeesType">
- and rent_contract_agile_fees_type = #{rentContractAgileFeesType}
- </if>
- <if test=" null != energyFeesId">
- and energy_fees_id = #{energyFeesId}
- </if>
- </delete>
-
- <delete id="deleteNoNeedPayBill" parameterType="com.iformall.domain.po.WxAllBill">
- delete from wx_all_bill where starttime >= #{shopEndtime} and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0
- and IFNULL(`return_pay`,'0') <= 0 and IFNULL(`use_money`,'0') <= 0
- <if test=" null != rentContractId">
- and rent_contract_id = #{rentContractId}
- </if>
- <if test=" null != propertyContractId">
- and property_contract_id = #{propertyContractId}
- </if>
- </delete>
-
- <delete id="deleteByRentHuiSuan" parameterType="com.iformall.domain.po.WxAllBill">
- delete from wx_all_bill where rent_contract_id = #{rentContractId}
- and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0 and IFNULL(`use_money`,'0') <= 0
- and extra_create_from = #{extraCreateFrom} and `starttime` = #{starttimeEqual}
- </delete>
-
- <select id="countValidBillCountByRentHuiSuan" parameterType="com.iformall.domain.po.WxAllBill" resultType="Integer">
- select count(1) from wx_all_bill where rent_contract_id = #{rentContractId}
- and (IFNULL(`pay`,'0') > 0 or IFNULL(`set_off`,'0') > 0 or IFNULL(`return_pay`,'0') > 0 or IFNULL(`use_money`,'0') > 0)
- and extra_create_from = #{extraCreateFrom} and `starttime` = #{starttimeEqual}
- </select>
-
- <delete id="deleteByRentReveneuSales" parameterType="com.iformall.domain.po.WxAllBill">
- delete from wx_all_bill where extra_create_from = #{extraCreateFrom}
- and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0 and IFNULL(`use_money`,'0') <= 0
- and `starttime` = #{starttimeEqual}
- <if test=" null != rentContractId">
- and rent_contract_id = #{rentContractId}
- </if>
- <if test=" null != propertyContractId">
- and property_contract_id = #{propertyContractId}
- </if>
- </delete>
-
- <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxAllBill">
- update wx_all_bill set is_preview = #{isPreview}
- <if test=" null != rentContractId">
- where rent_contract_id = #{rentContractId}
- </if>
- <if test=" null != propertyContractId">
- where property_contract_id = #{propertyContractId}
- </if>
- </update>
-
- <insert id="insertBills" parameterType="HashMap">
- INSERT INTO wx_all_bill (
- <include refid="allColumns"/>
- )
- VALUES
- <foreach collection="list" item="item" index="index" separator=",">
- (
- #{item.id},#{item.tenantId},#{item.parentTenantId},#{item.createtime},
- #{item.createBy},#{item.createByName},#{item.updatetime},#{item.updateBy},#{item.updateByName},#{item.priceDetail},
- #{item.needPay},#{item.receivePay},#{item.pay},#{item.billType},#{item.payWay},#{item.payDate},#{item.setOff},#{item.useMoney},
- #{item.starttime},#{item.endtime},#{item.status},#{item.energyFeesId},#{item.returnPay},#{item.billRemark},
- #{item.lastOweCallTime},#{item.lastOweCallUser},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},
- #{item.shopId},#{item.shopNumber},#{item.receiveDate},#{item.period},#{item.isPreview},#{item.shopInfo},#{item.rentContractId},#{item.rentContractAgileFeesType},#{item.propertyContractId},
- #{item.parentBillId},#{item.energyReadingCalcuteId},#{item.energyReadingId},#{item.extraCreateFrom},#{item.rentArea},#{item.canEdit},#{item.cusName}
- )
- </foreach>
- </insert>
-
- <delete id = "deleteById" parameterType="HashMap">
- delete from wx_all_bill where id = #{id} and tenant_id = #{tenantId}
- and pay <= 0 and IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0 and IFNULL(`use_money`,'0') <= 0
- </delete>
-
- <delete id = "deleteEnergyReadingBills" parameterType="HashMap">
- delete from wx_all_bill where energy_reading_calcuteId = #{energyReadingCalcuteId} and tenant_id = #{tenantId}
- and pay <= 0 and IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0 and IFNULL(`use_money`,'0') <= 0
- </delete>
-
- </mapper>
|