<?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.bjgl.mapper.YkHbLogMapper">

    <resultMap id="ykHbLogMap" type="com.tofly.feesapi.bjgl.entity.YkHbLog">
        <id property="id" column="ID"/>
        <result property="yhbh" column="YHBH"/>
        <result property="ykhbh" column="YKHBH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="cbkh" column="CBKH"/>
        <result property="cbkid" column="CBKID"/>
        <result property="oldSbcj" column="OLD_SBCJ"/>
        <result property="oldSbccrq" column="OLD_SBCCRQ"/>
        <result property="oldSbkj" column="OLD_SBKJ"/>
        <result property="oldSbxh" column="OLD_SBXH"/>
        <result property="oldSbbh" column="OLD_SBBH"/>
        <result property="oldIckid" column="OLD_ICKID"/>
        <result property="oldSbds" column="OLD_SBDS"/>
        <result property="oldIcbsysl" column="OLD_ICBSYSL"/>
        <result property="oldJxbysl" column="OLD_JXBYSL"/>
        <result property="newSbcj" column="NEW_SBCJ"/>
        <result property="newSbccrq" column="NEW_SBCCRQ"/>
        <result property="newSbkj" column="NEW_SBKJ"/>
        <result property="newSbxh" column="NEW_SBXH"/>
        <result property="newSbbh" column="NEW_SBBH"/>
        <result property="newIckid" column="NEW_ICKID"/>
        <result property="newSbds" column="NEW_SBDS"/>
        <result property="spry" column="SPRY"/>
        <result property="hbry" column="HBRY"/>
        <result property="hbrq" column="HBRQ"/>
        <result property="lrry" column="LRRY"/>
        <result property="lrrq" column="LRRQ"/>
        <result property="bz" column="BZ"/>
        <result property="oldSbqs" column="OLD_SBQS"/>
        <result property="newSbqs" column="NEW_SBQS"/>
        <result property="lrryxm" column="LRRYXM"/>
        <result property="oldSblb" column="OLD_SBLB"/>
        <result property="newSblb" column="NEW_SBLB"/>
        <result property="oldSblc" column="OLD_SBLC"/>
        <result property="newSblc" column="NEW_SBLC"/>
    </resultMap>

    <select id="getYkHbLogList" resultType="com.tofly.feesapi.bjgl.entity.vo.YhHbLogSelect">
        <include refid="querySql"/>
    </select>

    <select id="getYkHbLogPage" resultType="com.tofly.feesapi.bjgl.entity.vo.YhHbLogSelect">
        <include refid="querySql"/>
    </select>

    <sql id="querySql">
        SELECT
        a.ID,
        a.YHBH,
        a.YKHBH,
        a.YHXM,
        a.YHDZ,
        a.LXDH,
        (select name from bm_sblb where code= a.OLD_SBLB) oldSblb,
        (select name from bm_sbsccj where code= a.OLD_SBCJ) oldSbcj,
        a.OLD_SBKJ as oldSbkj,
        a.OLD_SBXH as oldSbxh,
        a.OLD_SBLC as oldSblc,
        a.OLD_SBBH as oldSbbh,
        a.OLD_SBQS as oldSbqs,
        a.OLD_SBDS as oldSbds,
        (select name from bm_sblb where code= a.NEW_SBLB) newSblb,
        (select name from bm_sbsccj where code= a.NEW_SBCJ) newSbcj,
        a.NEW_SBKJ as newSbkj,
        a.NEW_SBXH as newSbxh,
        a.NEW_SBLC as newSblc,
        a.NEW_SBBH as newSbbh,
        a.NEW_SBDS as newSbds,
        a.SPRY,
        a.HBRY,
        a.HBRQ,
        a.LRRYXM,
        a.Lrrq,
        a.BZ,
        a.gdbh,
        a.gdzt
        from YH_HB_LOG a,yh_khjbxx b
        where a.yhbh=b.yhbh
        <if test="filter.searchText != null and filter.searchText != ''">
            and (a.yhxm like '%${filter.searchText}%'
            or a.yhdz like '%${filter.searchText}%'
            or a.yhbh like '%${filter.searchText}%'
            )
        </if>
        <if test="filter.ssgs != null and filter.ssgs != ''">
            and b.ssgs=#{filter.ssgs}
        </if>
        <if test="filter.sscbpq != null and filter.sscbpq != ''">
            and b.sscbpq=#{filter.sscbpq}
        </if>
        <if test="filter.sscbb != null and filter.sscbb != ''">
            and b.sscbb=#{filter.sscbb}
        </if>
        <if test="filter.qyfzr!=null">
            and b.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>

        <if test="filter.ksrq!=null and filter.jsrq!=null">
            <![CDATA[ and a.hbrq >#{filter.ksrq}+0  and a.hbrq <= #{filter.jsrq}+0 ]]>
        </if>
        <if test="filter.gdzt!=null and filter.gdzt!=''">
            and a.gdzt=#{filter.gdzt}
        </if>
        <if test="filter.czry!=null and filter.czry!=''">
            and a.lrry=#{filter.czry}
        </if>
    </sql>
</mapper>
