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

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Cur">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="cod" column="cod" jdbcType="VARCHAR"/>
        <result property="newcur" column="newcur" jdbcType="VARCHAR"/>
        <result property="altcod" column="altcod" jdbcType="VARCHAR"/>
        <result property="dec" column="decnum" jdbcType="INTEGER"/>
        <result property="seq" column="seq" jdbcType="INTEGER"/>
        <result property="acc1" column="acc1" jdbcType="VARCHAR"/>
        <result property="acc2" column="acc2" jdbcType="VARCHAR"/>
        <result property="bsrmar" column="bsrmar" jdbcType="DECIMAL"/>
        <result property="sqrmar" column="sqrmar" jdbcType="DECIMAL"/>
        <result property="glbrat" column="glbrat" jdbcType="DECIMAL"/>
        <result property="dif" column="dif" jdbcType="DECIMAL"/>
        <result property="bas" column="bas" jdbcType="INTEGER"/>
        <result property="rndunt" column="rndunt" jdbcType="DECIMAL"/>
        <result property="begdat" column="begdat" jdbcType="DATE"/>
        <result property="enddat" column="enddat" jdbcType="DATE"/>
        <result property="odrintday" column="odrintday" jdbcType="INTEGER"/>
        <result property="dbtday" column="dbtday" jdbcType="INTEGER"/>
        <result property="cdtday" column="cdtday" jdbcType="INTEGER"/>
        <result property="maxcur" column="maxcur" jdbcType="VARCHAR"/>
        <result property="maxamt" column="maxamt" jdbcType="DECIMAL"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="etgextkey" column="etgextkey" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,cod,newcur,altcod,decnum,seq,acc1,acc2,bsrmar,sqrmar,glbrat,dif,bas,rndunt,begdat,enddat,odrintday,dbtday,cdtday,maxcur,maxamt,ver,etgextkey
    </sql>

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

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

    <insert id="insert">
        insert into cur (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{cod,jdbcType=VARCHAR},
            #{newcur,jdbcType=VARCHAR},
            #{altcod,jdbcType=VARCHAR},
            #{dec,jdbcType=INTEGER},
            #{seq,jdbcType=INTEGER},
            #{acc1,jdbcType=VARCHAR},
            #{acc2,jdbcType=VARCHAR},
            #{bsrmar,jdbcType=DECIMAL},
            #{sqrmar,jdbcType=DECIMAL},
            #{glbrat,jdbcType=DECIMAL},
            #{dif,jdbcType=DECIMAL},
            #{bas,jdbcType=INTEGER},
            #{rndunt,jdbcType=DECIMAL},
            #{begdat,jdbcType=DATE},
            #{enddat,jdbcType=DATE},
            #{odrintday,jdbcType=INTEGER},
            #{dbtday,jdbcType=INTEGER},
            #{cdtday,jdbcType=INTEGER},
            #{maxcur,jdbcType=VARCHAR},
            #{maxamt,jdbcType=DECIMAL},
            #{ver,jdbcType=VARCHAR},
            'CEBGRP',
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into cur
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="cod != null">cod,</if>
            <if test="newcur != null">newcur,</if>
            <if test="altcod != null">altcod,</if>
            <if test="dec != null">decnum,</if>
            <if test="seq != null">seq,</if>
            <if test="acc1 != null">acc1,</if>
            <if test="acc2 != null">acc2,</if>
            <if test="bsrmar != null">bsrmar,</if>
            <if test="sqrmar != null">sqrmar,</if>
            <if test="glbrat != null">glbrat,</if>
            <if test="dif != null">dif,</if>
            <if test="bas != null">bas,</if>
            <if test="rndunt != null">rndunt,</if>
            <if test="begdat != null">begdat,</if>
            <if test="enddat != null">enddat,</if>
            <if test="odrintday != null">odrintday,</if>
            <if test="dbtday != null">dbtday,</if>
            <if test="cdtday != null">cdtday,</if>
            <if test="maxcur != null">maxcur,</if>
            <if test="maxamt != null">maxamt,</if>
            <if test="ver != null">ver,</if>
            etgextkey,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="cod != null">#{cod,jdbcType=VARCHAR}, </if>
            <if test="newcur != null">#{newcur,jdbcType=VARCHAR}, </if>
            <if test="altcod != null">#{altcod,jdbcType=VARCHAR}, </if>
            <if test="dec != null">#{dec,jdbcType=INTEGER}, </if>
            <if test="seq != null">#{seq,jdbcType=INTEGER}, </if>
            <if test="acc1 != null">#{acc1,jdbcType=VARCHAR}, </if>
            <if test="acc2 != null">#{acc2,jdbcType=VARCHAR}, </if>
            <if test="bsrmar != null">#{bsrmar,jdbcType=DECIMAL}, </if>
            <if test="sqrmar != null">#{sqrmar,jdbcType=DECIMAL}, </if>
            <if test="glbrat != null">#{glbrat,jdbcType=DECIMAL}, </if>
            <if test="dif != null">#{dif,jdbcType=DECIMAL}, </if>
            <if test="bas != null">#{bas,jdbcType=INTEGER}, </if>
            <if test="rndunt != null">#{rndunt,jdbcType=DECIMAL}, </if>
            <if test="begdat != null">#{begdat,jdbcType=DATE}, </if>
            <if test="enddat != null">#{enddat,jdbcType=DATE}, </if>
            <if test="odrintday != null">#{odrintday,jdbcType=INTEGER}, </if>
            <if test="dbtday != null">#{dbtday,jdbcType=INTEGER}, </if>
            <if test="cdtday != null">#{cdtday,jdbcType=INTEGER}, </if>
            <if test="maxcur != null">#{maxcur,jdbcType=VARCHAR}, </if>
            <if test="maxamt != null">#{maxamt,jdbcType=DECIMAL}, </if>
            <if test="ver != null">#{ver,jdbcType=VARCHAR}, </if>
            'CEBGRP',
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update cur
        <set>
            <if test="cod != null">cod = #{cod,jdbcType=VARCHAR},</if>
            <if test="newcur != null">newcur = #{newcur,jdbcType=VARCHAR},</if>
            <if test="altcod != null">altcod = #{altcod,jdbcType=VARCHAR},</if>
            <if test="dec != null">decnum = #{dec,jdbcType=INTEGER},</if>
            <if test="seq != null">seq = #{seq,jdbcType=INTEGER},</if>
            <if test="acc1 != null">acc1 = #{acc1,jdbcType=VARCHAR},</if>
            <if test="acc2 != null">acc2 = #{acc2,jdbcType=VARCHAR},</if>
            <if test="bsrmar != null">bsrmar = #{bsrmar,jdbcType=DECIMAL},</if>
            <if test="sqrmar != null">sqrmar = #{sqrmar,jdbcType=DECIMAL},</if>
            <if test="glbrat != null">glbrat = #{glbrat,jdbcType=DECIMAL},</if>
            <if test="dif != null">dif = #{dif,jdbcType=DECIMAL},</if>
            <if test="bas != null">bas = #{bas,jdbcType=INTEGER},</if>
            <if test="rndunt != null">rndunt = #{rndunt,jdbcType=DECIMAL},</if>
            <if test="begdat != null">begdat = #{begdat,jdbcType=DATE},</if>
            <if test="enddat != null">enddat = #{enddat,jdbcType=DATE},</if>
            <if test="odrintday != null">odrintday = #{odrintday,jdbcType=INTEGER},</if>
            <if test="dbtday != null">dbtday = #{dbtday,jdbcType=INTEGER},</if>
            <if test="cdtday != null">cdtday = #{cdtday,jdbcType=INTEGER},</if>
            <if test="maxcur != null">maxcur = #{maxcur,jdbcType=VARCHAR},</if>
            <if test="maxamt != null">maxamt = #{maxamt,jdbcType=DECIMAL},</if>
            <if test="ver != null">ver = #{ver,jdbcType=VARCHAR},</if>
            etgextkey = 'CEBGRP',
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update cur
        <set>
            cod = #{cod,jdbcType=VARCHAR},
            newcur = #{newcur,jdbcType=VARCHAR},
            altcod = #{altcod,jdbcType=VARCHAR},
            decnum = #{dec,jdbcType=INTEGER},
            seq = #{seq,jdbcType=INTEGER},
            acc1 = #{acc1,jdbcType=VARCHAR},
            acc2 = #{acc2,jdbcType=VARCHAR},
            bsrmar = #{bsrmar,jdbcType=DECIMAL},
            sqrmar = #{sqrmar,jdbcType=DECIMAL},
            glbrat = #{glbrat,jdbcType=DECIMAL},
            dif = #{dif,jdbcType=DECIMAL},
            bas = #{bas,jdbcType=INTEGER},
            rndunt = #{rndunt,jdbcType=DECIMAL},
            begdat = #{begdat,jdbcType=DATE},
            enddat = #{enddat,jdbcType=DATE},
            odrintday = #{odrintday,jdbcType=INTEGER},
            dbtday = #{dbtday,jdbcType=INTEGER},
            cdtday = #{cdtday,jdbcType=INTEGER},
            maxcur = #{maxcur,jdbcType=VARCHAR},
            maxamt = #{maxamt,jdbcType=DECIMAL},
            ver = #{ver,jdbcType=VARCHAR},
            etgextkey = 'CEBGRP',
        </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 cur
        <set>
            <if test="module.cod != null">cod = #{module.cod,jdbcType=VARCHAR},</if>
            <if test="module.newcur != null">newcur = #{module.newcur,jdbcType=VARCHAR},</if>
            <if test="module.altcod != null">altcod = #{module.altcod,jdbcType=VARCHAR},</if>
            <if test="module.dec != null">decnum = #{module.dec,jdbcType=INTEGER},</if>
            <if test="module.seq != null">seq = #{module.seq,jdbcType=INTEGER},</if>
            <if test="module.acc1 != null">acc1 = #{module.acc1,jdbcType=VARCHAR},</if>
            <if test="module.acc2 != null">acc2 = #{module.acc2,jdbcType=VARCHAR},</if>
            <if test="module.bsrmar != null">bsrmar = #{module.bsrmar,jdbcType=DECIMAL},</if>
            <if test="module.sqrmar != null">sqrmar = #{module.sqrmar,jdbcType=DECIMAL},</if>
            <if test="module.glbrat != null">glbrat = #{module.glbrat,jdbcType=DECIMAL},</if>
            <if test="module.dif != null">dif = #{module.dif,jdbcType=DECIMAL},</if>
            <if test="module.bas != null">bas = #{module.bas,jdbcType=INTEGER},</if>
            <if test="module.rndunt != null">rndunt = #{module.rndunt,jdbcType=DECIMAL},</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.odrintday != null">odrintday = #{module.odrintday,jdbcType=INTEGER},</if>
            <if test="module.dbtday != null">dbtday = #{module.dbtday,jdbcType=INTEGER},</if>
            <if test="module.cdtday != null">cdtday = #{module.cdtday,jdbcType=INTEGER},</if>
            <if test="module.maxcur != null">maxcur = #{module.maxcur,jdbcType=VARCHAR},</if>
            <if test="module.maxamt != null">maxamt = #{module.maxamt,jdbcType=DECIMAL},</if>
            <if test="module.ver != null">ver = #{module.ver,jdbcType=VARCHAR},</if>
            etgextkey = 'CEBGRP',
        </set>
        ${conditions}
    </update>

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

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

    <select id="getCurByCodeAndEty" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from cur ${argSql}
    </select>


    <select id="queryById" resultMap="BaseResultMap">
        select INR,
               COD,
               NEWCUR,
               ALTCOD, DECNUM, SEQ, ACC1, ACC2, BSRMAR, SQRMAR, GLBRAT, DIF, BAS, RNDUNT, BEGDAT, ENDDAT, ODRINTDAY, DBTDAY, CDTDAY, MAXCUR, MAXAMT, VER, ETGEXTKEY
        from CUR
        where INR = #{inr}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseResultMap">
        select
        INR, COD, NEWCUR, ALTCOD, SEQ, ACC1, ACC2, BSRMAR, SQRMAR, GLBRAT, DIF, BAS, RNDUNT, BEGDAT, ENDDAT,
        ODRINTDAY, DBTDAY, CDTDAY, MAXCUR, MAXAMT, VER, ETGEXTKEY
        from CUR
        <where>
            <if test="cod != null and cod != ''">
                COD like concat(concat('%', #{cod}), '%')
            </if>
        </where>
        order by length(INR) desc, INR desc
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from CUR
        <where>
            <if test="inr != null and inr != ''">
                and INR = #{inr}
            </if>
            <if test="cod != null and cod != ''">
                and COD = #{cod}
            </if>
            <if test="newcur != null and newcur != ''">
                and NEWCUR = #{newcur}
            </if>
            <if test="altcod != null and altcod != ''">
                and ALTCOD = #{altcod}
            </if>
            <if test="dec != null">
                and DECNUM = #{dec}
            </if>
            <if test="seq != null">
                and SEQ = #{seq}
            </if>
            <if test="acc1 != null and acc1 != ''">
                and ACC1 = #{acc1}
            </if>
            <if test="acc2 != null and acc2 != ''">
                and ACC2 = #{acc2}
            </if>
            <if test="bsrmar != null">
                and BSRMAR = #{bsrmar}
            </if>
            <if test="sqrmar != null">
                and SQRMAR = #{sqrmar}
            </if>
            <if test="glbrat != null">
                and GLBRAT = #{glbrat}
            </if>
            <if test="dif != null">
                and DIF = #{dif}
            </if>
            <if test="bas != null">
                and BAS = #{bas}
            </if>
            <if test="rndunt != null">
                and RNDUNT = #{rndunt}
            </if>
            <if test="begdat != null">
                and BEGDAT = #{begdat}
            </if>
            <if test="enddat != null">
                and ENDDAT = #{enddat}
            </if>
            <if test="odrintday != null">
                and ODRINTDAY = #{odrintday}
            </if>
            <if test="dbtday != null">
                and DBTDAY = #{dbtday}
            </if>
            <if test="cdtday != null">
                and CDTDAY = #{cdtday}
            </if>
            <if test="maxcur != null and maxcur != ''">
                and MAXCUR = #{maxcur}
            </if>
            <if test="maxamt != null">
                and MAXAMT = #{maxamt}
            </if>
            <if test="ver != null and ver != ''">
                and VER = #{ver}
            </if>
            <if test="etgextkey != null and etgextkey != ''">
                and ETGEXTKEY = 'CEBGRP'
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insertCur">
        insert into CUR(INR, COD, NEWCUR, ALTCOD, DECNUM, SEQ, ACC1, ACC2, BSRMAR, SQRMAR, GLBRAT, DIF, BAS, RNDUNT,
        BEGDAT, ENDDAT, ODRINTDAY, DBTDAY, CDTDAY, MAXCUR, MAXAMT, VER, ETGEXTKEY)
        values (#{inr}, #{cod,jdbcType=VARCHAR}, #{newcur,jdbcType=VARCHAR}, #{altcod,jdbcType=VARCHAR}, #{dec,jdbcType=VARCHAR}, #{seq,jdbcType=VARCHAR}, #{acc1,jdbcType=VARCHAR}, #{acc2,jdbcType=VARCHAR}, #{bsrmar,jdbcType=VARCHAR}, #{sqrmar,jdbcType=VARCHAR}, #{glbrat,jdbcType=VARCHAR},
        #{dif,jdbcType=VARCHAR}, #{bas,jdbcType=VARCHAR}, #{rndunt,jdbcType=VARCHAR}, #{begdat,jdbcType=VARCHAR}, #{enddat,jdbcType=VARCHAR}, #{odrintday,jdbcType=VARCHAR}, #{dbtday,jdbcType=VARCHAR}, #{cdtday,jdbcType=VARCHAR}, #{maxcur,jdbcType=VARCHAR},
        #{maxamt}, '0000', 'CEBGRP')
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update CUR
        <set>
            <if test="cod != null and cod != ''">
                COD = #{cod},
            </if>
            <if test="newcur != null and newcur != ''">
                NEWCUR = #{newcur},
            </if>
            <if test="altcod != null and altcod != ''">
                ALTCOD = #{altcod},
            </if>
            <if test="dec != null">
                DECNUM = #{dec},
            </if>
            <if test="seq != null">
                SEQ = #{seq},
            </if>
            <if test="acc1 != null and acc1 != ''">
                ACC1 = #{acc1},
            </if>
            <if test="acc2 != null and acc2 != ''">
                ACC2 = #{acc2},
            </if>
            <if test="bsrmar != null">
                BSRMAR = #{bsrmar},
            </if>
            <if test="sqrmar != null">
                SQRMAR = #{sqrmar},
            </if>
            <if test="glbrat != null">
                GLBRAT = #{glbrat},
            </if>
            <if test="dif != null">
                DIF = #{dif},
            </if>
            <if test="bas != null">
                BAS = #{bas},
            </if>
            <if test="rndunt != null">
                RNDUNT = #{rndunt},
            </if>
            <if test="begdat != null">
                BEGDAT = #{begdat},
            </if>
            <if test="enddat != null">
                ENDDAT = #{enddat},
            </if>
            <if test="odrintday != null">
                ODRINTDAY = #{odrintday},
            </if>
            <if test="dbtday != null">
                DBTDAY = #{dbtday},
            </if>
            <if test="cdtday != null">
                CDTDAY = #{cdtday},
            </if>
            <if test="maxcur != null and maxcur != ''">
                MAXCUR = #{maxcur},
            </if>
            <if test="maxamt != null">
                MAXAMT = #{maxamt},
            </if>
            <if test="ver != null and ver != ''">
                VER = #{ver},
            </if>
                ETGEXTKEY = 'CEBGRP',
        </set>
        where INR = #{inr}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from CUR
        where INR = #{inr}
    </delete>

    <select id="getVersionByInr" resultType="String">
        select VER from CUR where INR = #{inr}
    </select>

    <select id="queryCod" resultType="java.lang.Integer">
        select count(*) from cur where rtrim(cod) = #{cod}
    </select>

    <select id="queryByIdSum" resultType="java.lang.Integer">
        select count(*) from cur where rtrim(inr) = #{inr}
    </select>

    <select id="selectByCod" resultMap="BaseResultMap">
        select INR,
               COD,
               NEWCUR,
               ALTCOD, DECNUM, SEQ, ACC1, ACC2, BSRMAR, SQRMAR, GLBRAT, DIF, BAS, RNDUNT, BEGDAT, ENDDAT, ODRINTDAY, DBTDAY, CDTDAY, MAXCUR, MAXAMT, VER, ETGEXTKEY
        from CUR
        where COD = #{cod}
    </select>


    <select id="getValidCurrenciesList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from cur
        <where>
            <if test="etgextkey != null and etgextkey != ''">
                etgextkey = #{etgextkey}
            </if>
            <if test="begdat != null ">
                and  (begdat is NULL or BEGDAT <![CDATA[ <= ]]> #{begdat} )
            </if>
            <if test="enddat != null">
                and  (enddat is NULL or ENDDAT <![CDATA[ > ]]> #{enddat} )
            </if>
        </where>
    </select>

</mapper>