<?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.brilliance.isc.mda.dao.DbbMapper">

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.bopdecbo.Dbb">
        <result property="inr" column="inr" jdbcType="VARCHAR" />
        <result property="tmpref" column="tmpref" jdbcType="VARCHAR" />
        <result property="ownextkey" column="ownextkey" jdbcType="VARCHAR" />
        <result property="actiontype" column="actiontype" jdbcType="VARCHAR" />
        <result property="actiondesc" column="actiondesc" jdbcType="VARCHAR" />
        <result property="rptno" column="rptno" jdbcType="VARCHAR" />
        <result property="custype" column="custype" jdbcType="VARCHAR" />
        <result property="idcode" column="idcode" jdbcType="VARCHAR" />
        <result property="custcod" column="custcod" jdbcType="VARCHAR" />
        <result property="custnm" column="custnm" jdbcType="VARCHAR" />
        <result property="oppuser" column="oppuser" jdbcType="VARCHAR" />
        <result property="txccy" column="txccy" jdbcType="VARCHAR" />
        <result property="txamt" column="txamt" jdbcType="DECIMAL" />
        <result property="exrate" column="exrate" jdbcType="DECIMAL" />
        <result property="lcyamt" column="lcyamt" jdbcType="DECIMAL" />
        <result property="lcyacc" column="lcyacc" jdbcType="VARCHAR" />
        <result property="fcyamt" column="fcyamt" jdbcType="DECIMAL" />
        <result property="fcyacc" column="fcyacc" jdbcType="VARCHAR" />
        <result property="othamt" column="othamt" jdbcType="DECIMAL" />
        <result property="othacc" column="othacc" jdbcType="VARCHAR" />
        <result property="method" column="method" jdbcType="VARCHAR" />
        <result property="buscode" column="buscode" jdbcType="VARCHAR" />
    </resultMap>

    <resultMap id="BaseResultMap2" type="com.brilliance.isc.bo.bopdecbo.Dbb">
        <result property="inr" column="inr" jdbcType="VARCHAR" />
        <result property="tmpref" column="tmpref" jdbcType="VARCHAR" />
        <result property="ownextkey" column="ownextkey" jdbcType="VARCHAR" />
        <result property="actiontype" column="actiontype" jdbcType="VARCHAR" />
        <result property="actiondesc" column="actiondesc" jdbcType="VARCHAR" />
        <result property="rptno" column="rptno" jdbcType="VARCHAR" />
        <result property="custype" column="custype" jdbcType="VARCHAR" />
        <result property="idcode" column="idcode" jdbcType="VARCHAR" />
        <result property="custcod" column="custcod" jdbcType="VARCHAR" />
        <result property="custnm" column="custnm" jdbcType="VARCHAR" />
        <result property="oppuser" column="oppuser" jdbcType="VARCHAR" />
        <result property="txccy" column="txccy" jdbcType="VARCHAR" />
        <result property="txamt" column="txamt" jdbcType="DECIMAL" />
        <result property="exrate" column="exrate" jdbcType="DECIMAL" />
        <result property="lcyamt" column="lcyamt" jdbcType="DECIMAL" />
        <result property="lcyacc" column="lcyacc" jdbcType="VARCHAR" />
        <result property="fcyamt" column="fcyamt" jdbcType="DECIMAL" />
        <result property="fcyacc" column="fcyacc" jdbcType="VARCHAR" />
        <result property="othamt" column="othamt" jdbcType="DECIMAL" />
        <result property="othacc" column="othacc" jdbcType="VARCHAR" />
        <result property="method" column="method" jdbcType="VARCHAR" />
        <result property="buscode" column="buscode" jdbcType="VARCHAR" />
        <result property="objtyp" column="objtyp" jdbcType="VARCHAR"/>
        <result property="sndflg" column="sndflg" jdbcType="VARCHAR"/>
        <result property="bassta" column="bassta" jdbcType="VARCHAR"/>
        <result property="dclsta" column="dclsta" jdbcType="VARCHAR"/>
        <result property="vrfsta" column="vrfsta" jdbcType="VARCHAR"/>
        <result property="bchnam" column="bchnam" jdbcType="VARCHAR"/>
        <result property="credat" column="credat" jdbcType="DATE"/>
        <result property="sfhdat" column="sfhdat" jdbcType="DATE"/>
        <result property="ownusr" column="ownusr" jdbcType="VARCHAR"/>
        <result property="datsrc" column="datsrc" jdbcType="VARCHAR"/>
        <result property="extinf" column="extinf" jdbcType="VARCHAR"/>
        <result property="exmandapp" column="exmandapp" jdbcType="VARCHAR"/>
    </resultMap>

    <resultMap id="BaseResultMap3" type="com.brilliance.isc.vo.bop.DbbResultVo">
        <result property="rptno" column="rptno" jdbcType="VARCHAR" />
        <result property="sndflg" column="sndflg" jdbcType="VARCHAR"/>
        <result property="bassta" column="bassta" jdbcType="VARCHAR"/>
        <result property="dclsta" column="dclsta" jdbcType="VARCHAR"/>
        <result property="vrfsta" column="vrfsta" jdbcType="VARCHAR"/>
        <result property="bchnam" column="bchnam" jdbcType="VARCHAR"/>
        <result property="credat" column="credat" jdbcType="DATE"/>
        <result property="actiontype" column="actiontype" jdbcType="VARCHAR" />
        <result property="actiondesc" column="actiondesc" jdbcType="VARCHAR" />
        <result property="custype" column="custype" jdbcType="VARCHAR" />
        <result property="idcode" column="idcode" jdbcType="VARCHAR" />
        <result property="custcod" column="custcod" jdbcType="VARCHAR" />
        <result property="custnm" column="custnm" jdbcType="VARCHAR" />
        <result property="oppuser" column="oppuser" jdbcType="VARCHAR" />
        <result property="txccy" column="txccy" jdbcType="VARCHAR" />
        <result property="txamt" column="txamt" jdbcType="DECIMAL" />
        <result property="exrate" column="exrate" jdbcType="DECIMAL" />
        <result property="lcyamt" column="lcyamt" jdbcType="DECIMAL" />
        <result property="lcyacc" column="lcyacc" jdbcType="VARCHAR" />
        <result property="fcyamt" column="fcyamt" jdbcType="DECIMAL" />
        <result property="fcyacc" column="fcyacc" jdbcType="VARCHAR" />
        <result property="othamt" column="othamt" jdbcType="DECIMAL" />
        <result property="othacc" column="othacc" jdbcType="VARCHAR" />
        <result property="method" column="method" jdbcType="VARCHAR" />
        <result property="buscode" column="buscode" jdbcType="VARCHAR" />
        <result property="dclActiontype" column="dclActiontype" jdbcType="VARCHAR" />
        <result property="dclActiondesc" column="dclActiondesc" jdbcType="VARCHAR" />
        <result property="country" column="country" jdbcType="VARCHAR" />
        <result property="paytype" column="paytype" jdbcType="VARCHAR" />
        <result property="txcode" column="txcode" jdbcType="VARCHAR" />
        <result property="tc1amt" column="tc1amt" jdbcType="DECIMAL" />
        <result property="txrem" column="txrem" jdbcType="VARCHAR" />
        <result property="txcode2" column="txcode2" jdbcType="VARCHAR" />
        <result property="tc2amt" column="tc2amt" jdbcType="DECIMAL" />
        <result property="tx2rem" column="tx2rem" jdbcType="VARCHAR" />
        <result property="isref" column="isref" jdbcType="VARCHAR" />
        <result property="crtuser" column="crtuser" jdbcType="VARCHAR" />
        <result property="inptelc" column="inptelc" jdbcType="VARCHAR" />
        <result property="rptdate" column="rptdate" jdbcType="DATE" />
        <result property="regno" column="regno" jdbcType="VARCHAR" />
        <result property="vrfActiontype" column="vrfActiontype" jdbcType="VARCHAR" />
        <result property="vrfActiondesc" column="vrfActiondesc" jdbcType="VARCHAR" />
        <result property="contrno" column="contrno" jdbcType="VARCHAR" />
        <result property="invoino" column="invoino" jdbcType="VARCHAR" />
        <result property="vrfCrtuser" column="vrfCrtuser" jdbcType="VARCHAR" />
        <result property="vrfInptelc" column="vrfInptelc" jdbcType="VARCHAR" />
        <result property="vrfRptdate" column="vrfRptdate" jdbcType="DATE" />
    </resultMap>

    <sql id="Base_Column_List">
        inr,tmpref,ownextkey,actiontype,actiondesc,rptno,custype,idcode,custcod,custnm,oppuser,txccy,txamt,exrate,lcyamt,lcyacc,fcyamt,fcyacc,othamt,othacc,method,buscode
    </sql>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from dbb
        where inr = #{inr,jdbcType=VARCHAR}
    </select>

    <select id="selectByBuscode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from dbb
        where buscode = #{buscode,jdbcType=VARCHAR}
    </select>

    <select id="selectByCountryAndOppuser" resultType="com.brilliance.isc.vo.bop.BopdecSelectVo">
        select b.rptno,b.oppuser,h.country
        from dbl l,dbb b
        left join dbh h on h.tmpref = b.inr
        left join dbn n on b.inr = n.tmpref
        where
        b.inr = l.objinr
        and l.curflg = "*"
        and l.objtyp = "dbb"
        and h.country is not null
        and h.country != #{country}
        and upper(trim(b.oppuser)) = #{oppuser}
        and l.credat > curdate()-interval '1' year
        order by l.credat DESC
    </select>

    <delete id="deleteByPrimaryKey">
        delete from dbb
        where inr = #{inr,jdbcType=VARCHAR}
    </delete>

    <insert id="insert">
        insert into dbb (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{tmpref,jdbcType=VARCHAR},
            #{ownextkey,jdbcType=VARCHAR},
            #{actiontype,jdbcType=VARCHAR},
            #{actiondesc,jdbcType=VARCHAR},
            #{rptno,jdbcType=VARCHAR},
            #{custype,jdbcType=VARCHAR},
            #{idcode,jdbcType=VARCHAR},
            #{custcod,jdbcType=VARCHAR},
            #{custnm,jdbcType=VARCHAR},
            #{oppuser,jdbcType=VARCHAR},
            #{txccy,jdbcType=VARCHAR},
            #{txamt,jdbcType=DECIMAL},
            #{exrate,jdbcType=DECIMAL},
            #{lcyamt,jdbcType=DECIMAL},
            #{lcyacc,jdbcType=VARCHAR},
            #{fcyamt,jdbcType=DECIMAL},
            #{fcyacc,jdbcType=VARCHAR},
            #{othamt,jdbcType=DECIMAL},
            #{othacc,jdbcType=VARCHAR},
            #{method,jdbcType=VARCHAR},
            #{buscode,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into dbb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="tmpref != null">tmpref,</if>
            <if test="ownextkey != null">ownextkey,</if>
            <if test="actiontype != null">actiontype,</if>
            <if test="actiondesc != null">actiondesc,</if>
            <if test="rptno != null">rptno,</if>
            <if test="custype != null">custype,</if>
            <if test="idcode != null">idcode,</if>
            <if test="custcod != null">custcod,</if>
            <if test="custnm != null">custnm,</if>
            <if test="oppuser != null">oppuser,</if>
            <if test="txccy != null">txccy,</if>
            <if test="txamt != null">txamt,</if>
            <if test="exrate != null">exrate,</if>
            <if test="lcyamt != null">lcyamt,</if>
            <if test="lcyacc != null">lcyacc,</if>
            <if test="fcyamt != null">fcyamt,</if>
            <if test="fcyacc != null">fcyacc,</if>
            <if test="othamt != null">othamt,</if>
            <if test="othacc != null">othacc,</if>
            <if test="method != null">method,</if>
            <if test="buscode != null">buscode,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="tmpref != null">#{tmpref,jdbcType=VARCHAR}, </if>
            <if test="ownextkey != null">#{ownextkey,jdbcType=VARCHAR}, </if>
            <if test="actiontype != null">#{actiontype,jdbcType=VARCHAR}, </if>
            <if test="actiondesc != null">#{actiondesc,jdbcType=VARCHAR}, </if>
            <if test="rptno != null">#{rptno,jdbcType=VARCHAR}, </if>
            <if test="custype != null">#{custype,jdbcType=VARCHAR}, </if>
            <if test="idcode != null">#{idcode,jdbcType=VARCHAR}, </if>
            <if test="custcod != null">#{custcod,jdbcType=VARCHAR}, </if>
            <if test="custnm != null">#{custnm,jdbcType=VARCHAR}, </if>
            <if test="oppuser != null">#{oppuser,jdbcType=VARCHAR}, </if>
            <if test="txccy != null">#{txccy,jdbcType=VARCHAR}, </if>
            <if test="txamt != null">#{txamt,jdbcType=DECIMAL}, </if>
            <if test="exrate != null">#{exrate,jdbcType=DECIMAL}, </if>
            <if test="lcyamt != null">#{lcyamt,jdbcType=DECIMAL}, </if>
            <if test="lcyacc != null">#{lcyacc,jdbcType=VARCHAR}, </if>
            <if test="fcyamt != null">#{fcyamt,jdbcType=DECIMAL}, </if>
            <if test="fcyacc != null">#{fcyacc,jdbcType=VARCHAR}, </if>
            <if test="othamt != null">#{othamt,jdbcType=DECIMAL}, </if>
            <if test="othacc != null">#{othacc,jdbcType=VARCHAR}, </if>
            <if test="method != null">#{method,jdbcType=VARCHAR}, </if>
            <if test="buscode != null">#{buscode,jdbcType=VARCHAR}, </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update dbb
        <set>
            <if test="tmpref != null">tmpref = #{tmpref,jdbcType=VARCHAR},</if>
            <if test="ownextkey != null">ownextkey = #{ownextkey,jdbcType=VARCHAR},</if>
            <if test="actiontype != null">actiontype = #{actiontype,jdbcType=VARCHAR},</if>
            <if test="actiondesc != null">actiondesc = #{actiondesc,jdbcType=VARCHAR},</if>
            <if test="rptno != null">rptno = #{rptno,jdbcType=VARCHAR},</if>
            <if test="custype != null">custype = #{custype,jdbcType=VARCHAR},</if>
            <if test="idcode != null">idcode = #{idcode,jdbcType=VARCHAR},</if>
            <if test="custcod != null">custcod = #{custcod,jdbcType=VARCHAR},</if>
            <if test="custnm != null">custnm = #{custnm,jdbcType=VARCHAR},</if>
            <if test="oppuser != null">oppuser = #{oppuser,jdbcType=VARCHAR},</if>
            <if test="txccy != null">txccy = #{txccy,jdbcType=VARCHAR},</if>
            <if test="txamt != null">txamt = #{txamt,jdbcType=DECIMAL},</if>
            <if test="exrate != null">exrate = #{exrate,jdbcType=DECIMAL},</if>
            <if test="lcyamt != null">lcyamt = #{lcyamt,jdbcType=DECIMAL},</if>
            <if test="lcyacc != null">lcyacc = #{lcyacc,jdbcType=VARCHAR},</if>
            <if test="fcyamt != null">fcyamt = #{fcyamt,jdbcType=DECIMAL},</if>
            <if test="fcyacc != null">fcyacc = #{fcyacc,jdbcType=VARCHAR},</if>
            <if test="othamt != null">othamt = #{othamt,jdbcType=DECIMAL},</if>
            <if test="othacc != null">othacc = #{othacc,jdbcType=VARCHAR},</if>
            <if test="method != null">method = #{method,jdbcType=VARCHAR},</if>
            <if test="buscode != null">buscode = #{buscode,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update dbb
        <set>
            tmpref = #{tmpref,jdbcType=VARCHAR},
            ownextkey = #{ownextkey,jdbcType=VARCHAR},
            actiontype = #{actiontype,jdbcType=VARCHAR},
            actiondesc = #{actiondesc,jdbcType=VARCHAR},
            rptno = #{rptno,jdbcType=VARCHAR},
            custype = #{custype,jdbcType=VARCHAR},
            idcode = #{idcode,jdbcType=VARCHAR},
            custcod = #{custcod,jdbcType=VARCHAR},
            custnm = #{custnm,jdbcType=VARCHAR},
            oppuser = #{oppuser,jdbcType=VARCHAR},
            txccy = #{txccy,jdbcType=VARCHAR},
            txamt = #{txamt,jdbcType=DECIMAL},
            exrate = #{exrate,jdbcType=DECIMAL},
            lcyamt = #{lcyamt,jdbcType=DECIMAL},
            lcyacc = #{lcyacc,jdbcType=VARCHAR},
            fcyamt = #{fcyamt,jdbcType=DECIMAL},
            fcyacc = #{fcyacc,jdbcType=VARCHAR},
            othamt = #{othamt,jdbcType=DECIMAL},
            othacc = #{othacc,jdbcType=VARCHAR},
            method = #{method,jdbcType=VARCHAR},
            buscode = #{buscode,jdbcType=VARCHAR},
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <delete id="deleteByIds">
        delete from act where inr in
        <foreach item="item" index="index" collection="collection" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <delete id="dyncDelete">
        ${sql}
    </delete>

    <select id="dyncRead" resultMap="BaseResultMap">
        ${sql}
    </select>

    <select id="selectByArgmodVo" resultMap="BaseResultMap2">
        select
        m2.inr,m2.tmpref,m2.ownextkey,m2.actiontype,m2.actiondesc,m2.rptno,m2.custype,m2.idcode,m2.custcod,m2.custnm,m2.oppuser,m2.txccy,m2.txamt,m2.exrate,m2.lcyamt,m2.lcyacc,m2.fcyamt,m2.fcyacc,m2.othamt,m2.othacc,m2.method,m2.buscode
        ,
        m1.objtyp,m1.sndflg,m1.bassta,m1.dclsta,m1.vrfsta,concat(m3.branch,m3.bchname) as bchnam,m1.reldat as credat,m1.sfhdat,m1.ownusr,m1.datsrc,m1.extinf,m1.exmandapp
        from dbl m1,dbb m2,bch m3 WHERE m1.objtyp='DBB' and m1.objinr=m2.inr and m1.ownextkey=m3.branch and (m1.trninr is null or m1.trninr = '')
        <!--只查询出最新数据 -->
        and m1.curflg='*'

        <!--申报主体名称 -->
        <if test="custnm != null and custnm != ''">
            and  m2.custnm LIKE concat('%', #{custnm}, '%')
        </if>
        <!--业务号码 -->
        <if test="extinfbop != null and extinfbop != ''">
            and  m2.buscode LIKE concat('%', #{extinfbop}, '%')
        </if>
        <!--账号 -->
        <if test="rptno != null and rptno != ''">
            and  m2.rptno LIKE concat('%', #{rptno}, '%')
        </if>

        <if test="branchInrs != null and branchInrs.size() >0 ">
            and (
            m1.ownextkey in
            <foreach item="branchinr" collection="branchInrs" open="(" separator="," close=")">
                #{branchinr}
            </foreach>
            or m1.ownextkey is null
            )
        </if>

        <if test="selectdat == 'B'.toString() ">
            <!--经办起始时间 -->
            <if test="ywcredat != null" >
                and  m1.reldat >=  #{ywcredat}
            </if>
            <if test="ywtildat != null" >
                and  m1.reldat &lt;=  #{ywtildat}
            </if>
        </if>


        <if test="selectdat == 'A'.toString() ">
            <!--业务起始时间 -->
            <if test="ywcredat != null" >
                and  m1.sfhdat >=  #{ywcredat}
            </if>
            <if test="ywtildat != null" >
                and  m1.sfhdat &lt;=  #{ywtildat}
            </if>
        </if>

        <!--数据来源 -->
        <if test="datsrc != null and datsrc != ''">
            and  m1.datsrc = #{datsrc}
        </if>
        <!--数据状态查询条件 -->
        <if test="selsta != null and selsta != ''">
            <choose>
                <!--如果是待确认,则查找待确认数据 -->
                <when test="selsta == 'Q'.toString()">
                    and m1.sndflg = 'W'
                </when>
                <!--如果是D,基础操作类型为删除 -->
                <when test="selsta == 'D'.toString()">
                    and m2.actiontype = 'D'
                </when>
                <otherwise>
                    and (
                    <!--基础状态 -->
                    m1.bassta = #{selsta}
                    or
                    <!--申报状态 -->
                    m1.dclsta = #{selsta}
                    or
                    <!--管理状态 -->
                    m1.vrfsta = #{selsta}
                    )
                </otherwise>
            </choose>
        </if>
        <!--收入款币种 -->
        <if test="txccy != null and txccy != ''">
            and m2.txccy=#{txccy}
        </if>

        <!--收入款币种 -->
        <if test="usr != null and usr != ''">
            and m1.ownusr LIKE  concat('%', #{usr}, '%')
        </if>
        <!--机构号 -->
        <if test="branch != null and branch != ''">
            and m3.branch LIKE  concat('%', #{branch}, '%')
        </if>
        <!--组织机构代码 -->
        <if test="custcod != null and custcod != ''">
            and m2.custcod LIKE  concat('%', #{custcod}, '%')
        </if>
        <!--金融机构标识号 -->
        <if test="bchcod != null and bchcod != ''">
            and m3.decnum LIKE  concat('%', #{bchcod}, '%')
        </if>
        union select
        m2.inr,m2.tmpref,m2.ownextkey,m2.actiontype,m2.actiondesc,m2.rptno,m2.custype,m2.idcode,m2.custcod,m2.custnm,m2.oppuser,m2.txccy,m2.txamt,m2.exrate,m2.lcyamt,m2.lcyacc,m2.fcyamt,m2.fcyacc,m2.othamt,m2.othacc,m2.method,m2.buscode
        ,
        m1.objtyp,m1.sndflg,m1.bassta,m1.dclsta,m1.vrfsta,concat(m3.branch,m3.bchname) as bchnam,m1.reldat as credat,m1.sfhdat,m1.ownusr,m1.datsrc,m1.extinf,m1.exmandapp
        from dbl m1,dbb m2,bch m3,trn m4 WHERE m1.objtyp='dbb' and m1.objinr=m2.inr and m1.ownextkey=m3.branch and m1.trninr = m4.inr and m4.relflg = 'R'
        <!--只查询出最新数据 -->
        and m1.curflg='*'

        <!--申报主体名称 -->
        <if test="custnm != null and custnm != ''">
            and  m2.custnm LIKE concat('%', #{custnm}, '%')
        </if>
        <!--业务号码 -->
        <if test="extinfbop != null and extinfbop != ''">
            and  m2.buscode LIKE concat('%', #{extinfbop}, '%')
        </if>
        <!--账号 -->
        <if test="rptno != null and rptno != ''">
            and  m2.rptno LIKE concat('%', #{rptno}, '%')
        </if>

        <if test="branchInrs != null and branchInrs.size() >0 ">
            and (
            m1.ownextkey in
            <foreach item="branchinr" collection="branchInrs" open="(" separator="," close=")">
                #{branchinr}
            </foreach>
            or m1.ownextkey is null
            )
        </if>

        <if test="selectdat == 'B'.toString() ">
            <!--经办起始时间 -->
            <if test="ywcredat != null" >
                and  m1.reldat >=  #{ywcredat}
            </if>
            <if test="ywtildat != null" >
                and  m1.reldat &lt;=  #{ywtildat}
            </if>
        </if>


        <if test="selectdat == 'A'.toString() ">
            <!--业务起始时间 -->
            <if test="ywcredat != null" >
                and  m1.sfhdat >=  #{ywcredat}
            </if>
            <if test="ywtildat != null" >
                and  m1.sfhdat &lt;=  #{ywtildat}
            </if>
        </if>

        <!--数据来源 -->
        <if test="datsrc != null and datsrc != ''">
            and  m1.datsrc = #{datsrc}
        </if>
        <!--数据状态查询条件 -->
        <if test="selsta != null and selsta != ''">
            <choose>
                <!--如果是待确认,则查找待确认数据 -->
                <when test="selsta == 'Q'.toString()">
                    and m1.sndflg = 'W'
                </when>
                <!--如果是D,基础操作类型为删除 -->
                <when test="selsta == 'D'.toString()">
                    and m2.actiontype = 'D'
                </when>
                <otherwise>
                    and (
                    <!--基础状态 -->
                    m1.bassta = #{selsta}
                    or
                    <!--申报状态 -->
                    m1.dclsta = #{selsta}
                    or
                    <!--管理状态 -->
                    m1.vrfsta = #{selsta}
                    )
                </otherwise>
            </choose>
        </if>
        <!--收入款币种 -->
        <if test="txccy != null and txccy != ''">
            and m2.txccy=#{txccy}
        </if>

        <!--收入款币种 -->
        <if test="usr != null and usr != ''">
            and m1.ownusr LIKE  concat('%', #{usr}, '%')
        </if>
        <!--机构号 -->
        <if test="branch != null and branch != ''">
            and m3.branch LIKE  concat('%', #{branch}, '%')
        </if>
        <!--组织机构代码 -->
        <if test="custcod != null and custcod != ''">
            and m2.custcod LIKE  concat('%', #{custcod}, '%')
        </if>
        <!--金融机构标识号 -->
        <if test="bchcod != null and bchcod != ''">
            and m3.decnum LIKE  concat('%', #{bchcod}, '%')
        </if>
        order by sfhdat DESC, credat DESC
    </select>

    <select id="selectByBasInrs" resultMap="BaseResultMap3">
        select m2.rptno,m1.sndflg,m1.bassta,m1.dclsta,m1.vrfsta,concat(m5.branch,m5.bchname) as bchnam,m1.reldat as credat,
        m2.actiontype,m2.actiondesc,m2.custype,m2.idcode,m2.custcod,m2.custnm,m2.oppuser,m2.txccy,m2.txamt,m2.exrate,m2.lcyamt,m2.lcyacc,m2.fcyamt,m2.fcyacc,m2.othamt,m2.othacc,m2.method,m2.buscode,
        m3.actiontype as dclActiontype,m3.actiondesc as dclActiondesc, m3.country,m3.paytype,m3.txcode,m3.tc1amt,m3.txrem,m3.txcode2,m3.tc2amt,m3.tx2rem,m3.isref,m3.crtuser,m3.inptelc,m3.rptdate,m3.regno,
        m4.actiontype as vrfActiontype,m4.actiondesc as vrfActiondesc,m4.contrno,m4.invoino,m4.crtuser as vrfCrtuser,m4.inptelc as vrfInptelc,m4.rptdate as vrfRptdate
        from dbl m1,bch m5, dbb m2
        left join dbh m3 on m2.inr=m3.TMPREF and m2.RPTNO =m3.RPTNO
        left join dbn m4 on m2.inr=m4.TMPREF and m2.RPTNO =m4.RPTNO
        where m1.OBJTYP ='dbb' and m1.OBJINR =m2.inr and m1.ownextkey=m5.branch and m1.bassta != 'G' and m1.curflg='*'
        <if test="basInrs != null and basInrs.size() >0 ">
            and (
            m2.inr in
            <foreach item="basInr" collection="basInrs" open="(" separator="," close=")">
                #{basInr}
            </foreach>
            )
        </if>
        order by m1.sfhdat DESC, credat DESC
    </select>

</mapper>