<?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.XrtMapper">

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Xrt">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="cur" column="cur" jdbcType="VARCHAR"/>
        <result property="begdat" column="begdat" jdbcType="DATE"/>
        <result property="enddat" column="enddat" jdbcType="DATE"/>
        <result property="buyrat" column="buyrat" jdbcType="DECIMAL"/>
        <result property="midrat" column="midrat" jdbcType="DECIMAL"/>
        <result property="selrat" column="selrat" jdbcType="DECIMAL"/>
        <result property="ttrrat" column="ttrrat" jdbcType="DECIMAL"/>
        <result property="odrrat" column="odrrat" jdbcType="DECIMAL"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="resrat" column="resrat" jdbcType="DECIMAL"/>
        <result property="rebrat" column="rebrat" jdbcType="DECIMAL"/>
        <result property="ibrrat" column="ibrrat" jdbcType="DECIMAL"/>
        <result property="sel1rat" column="sel1rat" jdbcType="DECIMAL"/>
        <result property="buy1rat" column="buy1rat" jdbcType="DECIMAL"/>
        <result property="etgextkey" column="etgextkey" jdbcType="VARCHAR"/>
        <result property="xrttim" column="xrttim" jdbcType="VARCHAR"/>
    </resultMap>

    <resultMap id="ResultMapVo" type="com.brilliance.isc.vo.manager.XrtVo">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="cur" column="cur" jdbcType="VARCHAR"/>
        <result property="curnam" column="curnam" jdbcType="VARCHAR"/>
        <result property="begdat" column="begdat" jdbcType="DATE"/>
        <result property="enddat" column="enddat" jdbcType="DATE"/>
        <result property="buyrat" column="buyrat" jdbcType="DECIMAL"/>
        <result property="midrat" column="midrat" jdbcType="DECIMAL"/>
        <result property="selrat" column="selrat" jdbcType="DECIMAL"/>
        <result property="ttrrat" column="ttrrat" jdbcType="DECIMAL"/>
        <result property="odrrat" column="odrrat" jdbcType="DECIMAL"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="resrat" column="resrat" jdbcType="DECIMAL"/>
        <result property="rebrat" column="rebrat" jdbcType="DECIMAL"/>
        <result property="ibrrat" column="ibrrat" jdbcType="DECIMAL"/>
        <result property="sel1rat" column="sel1rat" jdbcType="DECIMAL"/>
        <result property="buy1rat" column="buy1rat" jdbcType="DECIMAL"/>
        <result property="etgextkey" column="etgextkey" jdbcType="VARCHAR"/>
        <result property="xrttim" column="xrttim" jdbcType="VARCHAR"/>
        <result property="uil" column="uil" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,cur,begdat,enddat,buyrat,midrat,selrat,ttrrat,odrrat,ver,resrat,rebrat,ibrrat,sel1rat,buy1rat,etgextkey,xrttim
    </sql>

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

    <select id="selectByCurWithDatRng" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xrt
        where cur = #{cur,jdbcType=VARCHAR}
        <![CDATA[and begdat<= #{curDat,jdbcType=DATE} and enddat > #{curDat,jdbcType=DATE}]]>
    </select>

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

    <insert id="insert">
        insert into xrt (<include refid="Base_Column_List"/>)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{cur,jdbcType=VARCHAR},
            #{begdat,jdbcType=DATE},
            #{enddat,jdbcType=DATE},
            #{buyrat,jdbcType=DECIMAL},
            #{midrat,jdbcType=DECIMAL},
            #{selrat,jdbcType=DECIMAL},
            #{ttrrat,jdbcType=DECIMAL},
            #{odrrat,jdbcType=DECIMAL},
            #{ver,jdbcType=VARCHAR},
            #{resrat,jdbcType=DECIMAL},
            #{rebrat,jdbcType=DECIMAL},
            #{ibrrat,jdbcType=DECIMAL},
            #{sel1rat,jdbcType=DECIMAL},
            #{buy1rat,jdbcType=DECIMAL},
            'CEBGRP',
            #{xrttim,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into xrt
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="cur != null">cur,</if>
            <if test="begdat != null">begdat,</if>
            <if test="enddat != null">enddat,</if>
            <if test="buyrat != null">buyrat,</if>
            <if test="midrat != null">midrat,</if>
            <if test="selrat != null">selrat,</if>
            <if test="ttrrat != null">ttrrat,</if>
            <if test="odrrat != null">odrrat,</if>
            <if test="ver != null">ver,</if>
            <if test="resrat != null">resrat,</if>
            <if test="rebrat != null">rebrat,</if>
            <if test="ibrrat != null">ibrrat,</if>
            <if test="sel1rat != null">sel1rat,</if>
            <if test="buy1rat != null">buy1rat,</if>
            etgextkey,
            <if test="xrttim != null">xrttim,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR},</if>
            <if test="cur != null">#{cur,jdbcType=VARCHAR},</if>
            <if test="begdat != null">#{begdat,jdbcType=DATE},</if>
            <if test="enddat != null">#{enddat,jdbcType=DATE},</if>
            <if test="buyrat != null">#{buyrat,jdbcType=DECIMAL},</if>
            <if test="midrat != null">#{midrat,jdbcType=DECIMAL},</if>
            <if test="selrat != null">#{selrat,jdbcType=DECIMAL},</if>
            <if test="ttrrat != null">#{ttrrat,jdbcType=DECIMAL},</if>
            <if test="odrrat != null">#{odrrat,jdbcType=DECIMAL},</if>
            <if test="ver != null">#{ver,jdbcType=VARCHAR},</if>
            <if test="resrat != null">#{resrat,jdbcType=DECIMAL},</if>
            <if test="rebrat != null">#{rebrat,jdbcType=DECIMAL},</if>
            <if test="ibrrat != null">#{ibrrat,jdbcType=DECIMAL},</if>
            <if test="sel1rat != null">#{sel1rat,jdbcType=DECIMAL},</if>
            <if test="buy1rat != null">#{buy1rat,jdbcType=DECIMAL},</if>
            'CEBGRP',
            <if test="xrttim != null">#{xrttim,jdbcType=VARCHAR},</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update xrt
        <set>
            <if test="cur != null">cur = #{cur,jdbcType=VARCHAR},</if>
            <if test="begdat != null">begdat = #{begdat,jdbcType=DATE},</if>
            <if test="enddat != null">enddat = #{enddat,jdbcType=DATE},</if>
            <if test="buyrat != null">buyrat = #{buyrat,jdbcType=DECIMAL},</if>
            <if test="midrat != null">midrat = #{midrat,jdbcType=DECIMAL},</if>
            <if test="selrat != null">selrat = #{selrat,jdbcType=DECIMAL},</if>
            <if test="ttrrat != null">ttrrat = #{ttrrat,jdbcType=DECIMAL},</if>
            <if test="odrrat != null">odrrat = #{odrrat,jdbcType=DECIMAL},</if>
            <if test="ver != null">ver = #{ver,jdbcType=VARCHAR},</if>
            <if test="resrat != null">resrat = #{resrat,jdbcType=DECIMAL},</if>
            <if test="rebrat != null">rebrat = #{rebrat,jdbcType=DECIMAL},</if>
            <if test="ibrrat != null">ibrrat = #{ibrrat,jdbcType=DECIMAL},</if>
            <if test="sel1rat != null">sel1rat = #{sel1rat,jdbcType=DECIMAL},</if>
            <if test="buy1rat != null">buy1rat = #{buy1rat,jdbcType=DECIMAL},</if>
            etgextkey = 'CEBGRP',
            <if test="xrttim != null">xrttim = #{xrttim,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update xrt
        <set>
            cur = #{cur,jdbcType=VARCHAR},
            begdat = #{begdat,jdbcType=DATE},
            enddat = #{enddat,jdbcType=DATE},
            buyrat = #{buyrat,jdbcType=DECIMAL},
            midrat = #{midrat,jdbcType=DECIMAL},
            selrat = #{selrat,jdbcType=DECIMAL},
            ttrrat = #{ttrrat,jdbcType=DECIMAL},
            odrrat = #{odrrat,jdbcType=DECIMAL},
            ver = #{ver,jdbcType=VARCHAR},
            resrat = #{resrat,jdbcType=DECIMAL},
            rebrat = #{rebrat,jdbcType=DECIMAL},
            ibrrat = #{ibrrat,jdbcType=DECIMAL},
            sel1rat = #{sel1rat,jdbcType=DECIMAL},
            buy1rat = #{buy1rat,jdbcType=DECIMAL},
            etgextkey = 'CEBGRP',
            xrttim = #{xrttim,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>

    <update id="dyncUpdate">
        update xrt
        <set>
            <if test="module.cur != null">cur = #{module.cur,jdbcType=VARCHAR},</if>
            <if test="module.begdat != null">begdat = #{module.begdat,jdbcType=DATE},</if>
            <if test="module.enddat != null">enddat = #{module.enddat,jdbcType=DATE},</if>
            <if test="module.buyrat != null">buyrat = #{module.buyrat,jdbcType=DECIMAL},</if>
            <if test="module.midrat != null">midrat = #{module.midrat,jdbcType=DECIMAL},</if>
            <if test="module.selrat != null">selrat = #{module.selrat,jdbcType=DECIMAL},</if>
            <if test="module.ttrrat != null">ttrrat = #{module.ttrrat,jdbcType=DECIMAL},</if>
            <if test="module.odrrat != null">odrrat = #{module.odrrat,jdbcType=DECIMAL},</if>
            <if test="module.ver != null">ver = #{module.ver,jdbcType=VARCHAR},</if>
            <if test="module.resrat != null">resrat = #{module.resrat,jdbcType=DECIMAL},</if>
            <if test="module.rebrat != null">rebrat = #{module.rebrat,jdbcType=DECIMAL},</if>
            <if test="module.ibrrat != null">ibrrat = #{module.ibrrat,jdbcType=DECIMAL},</if>
            <if test="module.sel1rat != null">sel1rat = #{module.sel1rat,jdbcType=DECIMAL},</if>
            <if test="module.buy1rat != null">buy1rat = #{module.buy1rat,jdbcType=DECIMAL},</if>
            etgextkey = 'CEBGRP',
            <if test="module.xrttim != null">xrttim = #{module.xrttim,jdbcType=VARCHAR},</if>
        </set>
        ${conditions}
    </update>

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

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

    <select id="getMaxXrtInr" resultType="java.lang.String">
        SELECT MAX(INR) FROM XRT WHERE CUR= #{argCur} AND SUBSTR(XRTTIM,1,16) &lt;= #{dateString}
    </select>

    <select id="getXrtByConditionSql" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xrt
        ${conditionSql}
    </select>

    <!--查询单个-->
    <select id="queryById" resultMap="BaseResultMap">
        select
          INR, CUR, BEGDAT, ENDDAT, BUYRAT, MIDRAT, SELRAT, TTRRAT, ODRRAT, VER, RESRAT, REBRAT, IBRRAT, SEL1RAT, BUY1RAT, ETGEXTKEY, XRTTIM
        from XRT
        where trim(INR) = trim(#{inr})
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseResultMap">
        select
        INR, CUR, BEGDAT, ENDDAT, BUYRAT, MIDRAT, SELRAT, TTRRAT, ODRRAT, VER, RESRAT, REBRAT, IBRRAT, SEL1RAT, BUY1RAT,
        ETGEXTKEY, XRTTIM
        from XRT
        <where>
            <if test=" inr != null and inr != ''">
                and INR like concat(concat ('%',#{inr}),'%')
            </if>
            <if test="cur != null and cur != ''">
                and CUR like concat(concat ('%',#{cur}),'%')
            </if>
            <if test="etgextkey != null and etgextkey != ''">
                and ETGEXTKEY like concat(concat ('%','CEBGRP'),'%')
            </if>
            <if test="begdat != null">
                and XRTTIM <![CDATA[>=]]> #{begdat,jdbcType=DATE}
            </if>
            <if test="enddat != null">
                and XRTTIM <![CDATA[<=]]> #{enddat,jdbcType=DATE}
            </if>
        </where>
        order by
        <if test='columnStr != null and columnStr!="" '>
            ${columnStr} ${orderStr}
        </if>
        <if test='columnStr == null or columnStr=="" '>
            XRTTIM desc
        </if>
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit1" resultMap="ResultMapVo">
        select
        INR, CUR ,stb.txt CURNAM, BEGDAT, ENDDAT, BUYRAT, MIDRAT, SELRAT, TTRRAT, ODRRAT, VER, RESRAT, REBRAT, IBRRAT, SEL1RAT, BUY1RAT,
        ETGEXTKEY, XRTTIM
        from XRT left join stb on stb.tbl='CURTXT' and xrt.cur=stb.cod  and stb.uil='EN'
        <where>
            <if test=" inr != null and inr != ''">
                and INR like concat(concat ('%',#{inr}),'%')
            </if>
            <if test="cur != null and cur != ''">
                and CUR like concat(concat ('%',#{cur}),'%')
            </if>
            <if test="etgextkey != null and etgextkey != ''">
                and ETGEXTKEY like concat(concat ('%','CEBGRP'),'%')
            </if>
            <if test="begdat != null and begdat != ''">
                and XRTTIM <![CDATA[>=]]> #{begdat,jdbcType=DATE}
            </if>
            <if test="enddat != null and enddat != ''">
                and XRTTIM <![CDATA[<=]]> #{enddat,jdbcType=DATE}
            </if>
        </where>
        order by
        <if test='columnStr != null and columnStr!="" '>
            ${columnStr} ${orderStr}
        </if>
        <if test='columnStr == null or columnStr=="" '>
            XRTTIM desc
        </if>
    </select>
    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from XRT
        <where>
            <if test="inr != null and inr != ''">
                and trim(INR) = trim(#{inr})
            </if>
            <if test="cur != null and cur != ''">
                and CUR = #{cur}
            </if>
            <if test="begdat != null">
                and BEGDAT = #{begdat}
            </if>
            <if test="enddat != null">
                and ENDDAT = #{enddat}
            </if>
            <if test="buyrat != null">
                and BUYRAT = #{buyrat}
            </if>
            <if test="midrat != null">
                and MIDRAT = #{midrat}
            </if>
            <if test="selrat != null">
                and SELRAT = #{selrat}
            </if>
            <if test="ttrrat != null">
                and TTRRAT = #{ttrrat}
            </if>
            <if test="odrrat != null">
                and ODRRAT = #{odrrat}
            </if>
            <if test="ver != null and ver != ''">
                and VER = #{ver}
            </if>
            <if test="resrat != null">
                and RESRAT = #{resrat}
            </if>
            <if test="rebrat != null">
                and REBRAT = #{rebrat}
            </if>
            <if test="ibrrat != null">
                and IBRRAT = #{ibrrat}
            </if>
            <if test="sel1rat != null">
                and SEL1RAT = #{sel1rat}
            </if>
            <if test="buy1rat != null">
                and BUY1RAT = #{buy1rat}
            </if>
            <if test="etgextkey != null and etgextkey != ''">
                and ETGEXTKEY = 'CEBGRP'
            </if>
            <if test="xrttim != null and xrttim != ''">
                and XRTTIM = #{xrttim}
            </if>
        </where>
    </select>

    <!--通过主键修改数据-->
    <update id="update">
        update XRT
        <set>
            <if test="inr != null and inr != ''">
                INR = #{inr},
            </if>
            <if test="cur != null and cur != ''">
                CUR = #{cur},
            </if>
            <if test="begdat != null">
                BEGDAT = #{begdat},
            </if>
            <if test="enddat != null">
                ENDDAT = #{enddat},
            </if>
            <if test="buyrat != null">
                BUYRAT = #{buyrat},
            </if>
            <if test="midrat != null">
                MIDRAT = #{midrat},
            </if>
            <if test="selrat != null">
                SELRAT = #{selrat},
            </if>
            <if test="ttrrat != null">
                TTRRAT = #{ttrrat},
            </if>
            <if test="odrrat != null">
                ODRRAT = #{odrrat},
            </if>
            <if test="ver != null and ver != ''">
                VER = #{ver},
            </if>
            <if test="resrat != null">
                RESRAT = #{resrat},
            </if>
            <if test="rebrat != null">
                REBRAT = #{rebrat},
            </if>
            <if test="ibrrat != null">
                IBRRAT = #{ibrrat},
            </if>
            <if test="sel1rat != null">
                SEL1RAT = #{sel1rat},
            </if>
            <if test="buy1rat != null">
                BUY1RAT = #{buy1rat},
            </if>
                ETGEXTKEY = 'CEBGRP',
            XRTTIM = #{xrttim},
        </set>
        where trim(INR) = trim(#{inr})
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from XRT where replace(INR,' ','')= #{inr}
    </delete>

    <select id="queryFXRateList" resultMap="ResultMapVo">
        select a.INR inr, a.CUR cur, a.BEGDAT begdat, a.ENDDAT enddat, a.BUYRAT buyrat, a.MIDRAT midrat, a.SELRAT selrat, a.TTRRAT ttrrat,
        a.ODRRAT odrrat, a.VER ver, a.RESRAT resrat, a.REBRAT rebrat, a.IBRRAT ibrrat, a.SEL1RAT sel1rat, a.BUY1RAT buy1rat, a.ETGEXTKEY etgextkey, a.XRTTIM xrttim, b.txt curnam
        from xrt a left join stb b on b.TBL = 'CURTXT' and UIL = #{uil} and a.cur = b.COD
        where a.ENDDAT = '2299-12-31'
        order by b.SRT ASC
    </select>

    <select id="selectRepeat" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from xrt
        where cur = #{cur,jdbcType=VARCHAR} <![CDATA[and enddat > #{begdat, jdbcType=DATE} and enddat != #{enddat, jdbcType=DATE}]]>
    </select>

    <update id="setHistoryAvailableDat">
        update XRT
        <set>
            <if test="enddat != null">
                ENDDAT = #{begdat, jdbcType=DATE}
            </if>
        </set>
        where cur = #{cur, jdbcType=VARCHAR} <![CDATA[and enddat = #{enddat, jdbcType=DATE}]]>
    </update>

    <select id="selectAvailable" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from xrt
        where cur = #{cur, jdbcType=VARCHAR} <![CDATA[and enddat = #{enddat, jdbcType=DATE}]]>
    </select>

    <select id="selectInfoByTimeAndCur" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from xrt
        WHERE
        BEGDAT &lt;= date_format(curdate() ,'%Y%m%d') and enddat > date_format(curdate(),'%Y%m%d')
        <if test="cur != null and cur != ''">
            and cur = #{cur,jdbcType=VARCHAR}
        </if>
        order by inr DESC
    </select>
</mapper>