<?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.tofly.feesapi.mxcx.mapper.YyBgLogMapper">

    <resultMap id="yyBgLogMap" type="com.tofly.feesapi.mxcx.entity.YyBgLog">
        <id property="id" column="ID"/>
        <result property="bgryid" column="BGRYID"/>
        <result property="bgryxm" column="BGRYXM"/>
        <result property="bgdate" column="BGDATE"/>
        <result property="bglx" column="BGLX"/>
        <result property="bglxid" column="BGLXID"/>
        <result property="bgqjson" column="BGQJSON"/>
        <result property="bghjson" column="BGHJSON"/>
        <result property="bgnr" column="BGNR"/>
        <result property="gdbh" column="GDBH"/>
    </resultMap>
    <select id="getPage" resultType="com.tofly.feesapi.mxcx.entity.vo.YyBgLogSelect">
        select
        id,
        bgryid,
        bgryxm,
        bgdate,
        (case
        when bglx = '1' then '欠费明细变更'
        when bglx = '2' then '费用调整'
        else '未知'
        end) bglx,
        bglxid,
        bgqjson,
        bghjson,
        bgnr,
        gdbh
        from YY_BG_LOG
        <where>
            <if test="filter.czry != null and filter.czry != ''">
                and BGRYID=#{filter.czry }
            </if>
            <if test="filter.czsjStart != null and filter.czsjEnd != null">
                and BGDATE between #{filter.czsjStart} and #{filter.czsjEnd}
            </if>
            <if test="filter.searchText != null and filter.searchText != ''">
                and (
                BGRYXM like '%${filter.searchText}%'
                or BGNR like '%${filter.searchText}%'
                )
            </if>
            <if test="filter.bglx != null and filter.bglx != ''">
                and BGLX = #{filter.bglx}
            </if>
        </where>
    </select>

</mapper>
