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

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Ecb">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="actiontype" column="actiontype" jdbcType="VARCHAR"/>
        <result property="actiondesc" column="actiondesc" jdbcType="VARCHAR"/>
        <result property="dofoexlocode" column="dofoexlocode" jdbcType="VARCHAR"/>
        <result property="buscode" column="buscode" jdbcType="VARCHAR"/>
        <result property="changeno" column="changeno" jdbcType="VARCHAR"/>
        <result property="loanopenbalan" column="loanopenbalan" jdbcType="DECIMAL"/>
        <result property="changedate" column="changedate" jdbcType="DATE"/>
        <result property="withcurrence" column="withcurrence" jdbcType="VARCHAR"/>
        <result property="withamount" column="withamount" jdbcType="DECIMAL"/>
        <result property="settamount" column="settamount" jdbcType="DECIMAL"/>
        <result property="useofunds" column="useofunds" jdbcType="VARCHAR"/>
        <result property="princurr" column="princurr" jdbcType="VARCHAR"/>
        <result property="repayamount" column="repayamount" jdbcType="DECIMAL"/>
        <result property="prepayamount" column="prepayamount" jdbcType="DECIMAL"/>
        <result property="inpaycurr" column="inpaycurr" jdbcType="VARCHAR"/>
        <result property="inpayamount" column="inpayamount" jdbcType="DECIMAL"/>
        <result property="pinpayamount" column="pinpayamount" jdbcType="DECIMAL"/>
        <result property="endbalan" column="endbalan" jdbcType="DECIMAL"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
        <result property="sta" column="sta" jdbcType="VARCHAR"/>
        <result property="eblinr" column="eblinr" jdbcType="VARCHAR"/>
        <result property="fincod" column="fincod" jdbcType="VARCHAR"/>
        <result property="objtyp" column="objtyp" jdbcType="VARCHAR"/>
        <result property="objinr" column="objinr" jdbcType="VARCHAR"/>
        <result property="credat" column="credat" jdbcType="DATE"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,ver,actiontype,actiondesc,dofoexlocode,buscode,changeno,loanopenbalan,changedate,withcurrence,withamount,settamount,useofunds,princurr,repayamount,prepayamount,inpaycurr,inpayamount,pinpayamount,endbalan,remark,sta,eblinr,fincod,objtyp,objinr,credat
    </sql>

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

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

    <insert id="insert">
        insert into ecb (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{ver,jdbcType=VARCHAR},
            #{actiontype,jdbcType=VARCHAR},
            #{actiondesc,jdbcType=VARCHAR},
            #{dofoexlocode,jdbcType=VARCHAR},
            #{buscode,jdbcType=VARCHAR},
            #{changeno,jdbcType=VARCHAR},
            #{loanopenbalan,jdbcType=DECIMAL},
            #{changedate,jdbcType=DATE},
            #{withcurrence,jdbcType=VARCHAR},
            #{withamount,jdbcType=DECIMAL},
            #{settamount,jdbcType=DECIMAL},
            #{useofunds,jdbcType=VARCHAR},
            #{princurr,jdbcType=VARCHAR},
            #{repayamount,jdbcType=DECIMAL},
            #{prepayamount,jdbcType=DECIMAL},
            #{inpaycurr,jdbcType=VARCHAR},
            #{inpayamount,jdbcType=DECIMAL},
            #{pinpayamount,jdbcType=DECIMAL},
            #{endbalan,jdbcType=DECIMAL},
            #{remark,jdbcType=VARCHAR},
            #{sta,jdbcType=VARCHAR},
            #{eblinr,jdbcType=VARCHAR},
            #{fincod,jdbcType=VARCHAR},
            #{objtyp,jdbcType=VARCHAR},
            #{objinr,jdbcType=VARCHAR},
            #{credat,jdbcType=DATE},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into ecb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="ver != null">ver,</if>
            <if test="actiontype != null">actiontype,</if>
            <if test="actiondesc != null">actiondesc,</if>
            <if test="dofoexlocode != null">dofoexlocode,</if>
            <if test="buscode != null">buscode,</if>
            <if test="changeno != null">changeno,</if>
            <if test="loanopenbalan != null">loanopenbalan,</if>
            <if test="changedate != null">changedate,</if>
            <if test="withcurrence != null">withcurrence,</if>
            <if test="withamount != null">withamount,</if>
            <if test="settamount != null">settamount,</if>
            <if test="useofunds != null">useofunds,</if>
            <if test="princurr != null">princurr,</if>
            <if test="repayamount != null">repayamount,</if>
            <if test="prepayamount != null">prepayamount,</if>
            <if test="inpaycurr != null">inpaycurr,</if>
            <if test="inpayamount != null">inpayamount,</if>
            <if test="pinpayamount != null">pinpayamount,</if>
            <if test="endbalan != null">endbalan,</if>
            <if test="remark != null">remark,</if>
            <if test="sta != null">sta,</if>
            <if test="eblinr != null">eblinr,</if>
            <if test="fincod != null">fincod,</if>
            <if test="objtyp != null">objtyp,</if>
            <if test="objinr != null">objinr,</if>
            <if test="credat != null">credat,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="ver != null">#{ver,jdbcType=VARCHAR}, </if>
            <if test="actiontype != null">#{actiontype,jdbcType=VARCHAR}, </if>
            <if test="actiondesc != null">#{actiondesc,jdbcType=VARCHAR}, </if>
            <if test="dofoexlocode != null">#{dofoexlocode,jdbcType=VARCHAR}, </if>
            <if test="buscode != null">#{buscode,jdbcType=VARCHAR}, </if>
            <if test="changeno != null">#{changeno,jdbcType=VARCHAR}, </if>
            <if test="loanopenbalan != null">#{loanopenbalan,jdbcType=DECIMAL}, </if>
            <if test="changedate != null">#{changedate,jdbcType=DATE}, </if>
            <if test="withcurrence != null">#{withcurrence,jdbcType=VARCHAR}, </if>
            <if test="withamount != null">#{withamount,jdbcType=DECIMAL}, </if>
            <if test="settamount != null">#{settamount,jdbcType=DECIMAL}, </if>
            <if test="useofunds != null">#{useofunds,jdbcType=VARCHAR}, </if>
            <if test="princurr != null">#{princurr,jdbcType=VARCHAR}, </if>
            <if test="repayamount != null">#{repayamount,jdbcType=DECIMAL}, </if>
            <if test="prepayamount != null">#{prepayamount,jdbcType=DECIMAL}, </if>
            <if test="inpaycurr != null">#{inpaycurr,jdbcType=VARCHAR}, </if>
            <if test="inpayamount != null">#{inpayamount,jdbcType=DECIMAL}, </if>
            <if test="pinpayamount != null">#{pinpayamount,jdbcType=DECIMAL}, </if>
            <if test="endbalan != null">#{endbalan,jdbcType=DECIMAL}, </if>
            <if test="remark != null">#{remark,jdbcType=VARCHAR}, </if>
            <if test="sta != null">#{sta,jdbcType=VARCHAR}, </if>
            <if test="eblinr != null">#{eblinr,jdbcType=VARCHAR}, </if>
            <if test="fincod != null">#{fincod,jdbcType=VARCHAR}, </if>
            <if test="objtyp != null">#{objtyp,jdbcType=VARCHAR}, </if>
            <if test="objinr != null">#{objinr,jdbcType=VARCHAR}, </if>
            <if test="credat != null">#{credat,jdbcType=DATE}, </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update ecb
        <set>
            <if test="ver != null">ver = #{ver,jdbcType=VARCHAR},</if>
            <if test="actiontype != null">actiontype = #{actiontype,jdbcType=VARCHAR},</if>
            <if test="actiondesc != null">actiondesc = #{actiondesc,jdbcType=VARCHAR},</if>
            <if test="dofoexlocode != null">dofoexlocode = #{dofoexlocode,jdbcType=VARCHAR},</if>
            <if test="buscode != null">buscode = #{buscode,jdbcType=VARCHAR},</if>
            <if test="changeno != null">changeno = #{changeno,jdbcType=VARCHAR},</if>
            <if test="loanopenbalan != null">loanopenbalan = #{loanopenbalan,jdbcType=DECIMAL},</if>
            <if test="changedate != null">changedate = #{changedate,jdbcType=DATE},</if>
            <if test="withcurrence != null">withcurrence = #{withcurrence,jdbcType=VARCHAR},</if>
            <if test="withamount != null">withamount = #{withamount,jdbcType=DECIMAL},</if>
            <if test="settamount != null">settamount = #{settamount,jdbcType=DECIMAL},</if>
            <if test="useofunds != null">useofunds = #{useofunds,jdbcType=VARCHAR},</if>
            <if test="princurr != null">princurr = #{princurr,jdbcType=VARCHAR},</if>
            <if test="repayamount != null">repayamount = #{repayamount,jdbcType=DECIMAL},</if>
            <if test="prepayamount != null">prepayamount = #{prepayamount,jdbcType=DECIMAL},</if>
            <if test="inpaycurr != null">inpaycurr = #{inpaycurr,jdbcType=VARCHAR},</if>
            <if test="inpayamount != null">inpayamount = #{inpayamount,jdbcType=DECIMAL},</if>
            <if test="pinpayamount != null">pinpayamount = #{pinpayamount,jdbcType=DECIMAL},</if>
            <if test="endbalan != null">endbalan = #{endbalan,jdbcType=DECIMAL},</if>
            <if test="remark != null">remark = #{remark,jdbcType=VARCHAR},</if>
            <if test="sta != null">sta = #{sta,jdbcType=VARCHAR},</if>
            <if test="eblinr != null">eblinr = #{eblinr,jdbcType=VARCHAR},</if>
            <if test="fincod != null">fincod = #{fincod,jdbcType=VARCHAR},</if>
            <if test="objtyp != null">objtyp = #{objtyp,jdbcType=VARCHAR},</if>
            <if test="objinr != null">objinr = #{objinr,jdbcType=VARCHAR},</if>
            <if test="credat != null">credat = #{credat,jdbcType=DATE},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update ecb
        <set>
            ver = #{ver,jdbcType=VARCHAR},
            actiontype = #{actiontype,jdbcType=VARCHAR},
            actiondesc = #{actiondesc,jdbcType=VARCHAR},
            dofoexlocode = #{dofoexlocode,jdbcType=VARCHAR},
            buscode = #{buscode,jdbcType=VARCHAR},
            changeno = #{changeno,jdbcType=VARCHAR},
            loanopenbalan = #{loanopenbalan,jdbcType=DECIMAL},
            changedate = #{changedate,jdbcType=DATE},
            withcurrence = #{withcurrence,jdbcType=VARCHAR},
            withamount = #{withamount,jdbcType=DECIMAL},
            settamount = #{settamount,jdbcType=DECIMAL},
            useofunds = #{useofunds,jdbcType=VARCHAR},
            princurr = #{princurr,jdbcType=VARCHAR},
            repayamount = #{repayamount,jdbcType=DECIMAL},
            prepayamount = #{prepayamount,jdbcType=DECIMAL},
            inpaycurr = #{inpaycurr,jdbcType=VARCHAR},
            inpayamount = #{inpayamount,jdbcType=DECIMAL},
            pinpayamount = #{pinpayamount,jdbcType=DECIMAL},
            endbalan = #{endbalan,jdbcType=DECIMAL},
            remark = #{remark,jdbcType=VARCHAR},
            sta = #{sta,jdbcType=VARCHAR},
            eblinr = #{eblinr,jdbcType=VARCHAR},
            fincod = #{fincod,jdbcType=VARCHAR},
            objtyp = #{objtyp,jdbcType=VARCHAR},
            objinr = #{objinr,jdbcType=VARCHAR},
            credat = #{credat,jdbcType=DATE},
        </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 ecb
        <set>
            <if test="module.ver != null">ver = #{module.ver,jdbcType=VARCHAR},</if>
            <if test="module.actiontype != null">actiontype = #{module.actiontype,jdbcType=VARCHAR},</if>
            <if test="module.actiondesc != null">actiondesc = #{module.actiondesc,jdbcType=VARCHAR},</if>
            <if test="module.dofoexlocode != null">dofoexlocode = #{module.dofoexlocode,jdbcType=VARCHAR},</if>
            <if test="module.buscode != null">buscode = #{module.buscode,jdbcType=VARCHAR},</if>
            <if test="module.changeno != null">changeno = #{module.changeno,jdbcType=VARCHAR},</if>
            <if test="module.loanopenbalan != null">loanopenbalan = #{module.loanopenbalan,jdbcType=DECIMAL},</if>
            <if test="module.changedate != null">changedate = #{module.changedate,jdbcType=DATE},</if>
            <if test="module.withcurrence != null">withcurrence = #{module.withcurrence,jdbcType=VARCHAR},</if>
            <if test="module.withamount != null">withamount = #{module.withamount,jdbcType=DECIMAL},</if>
            <if test="module.settamount != null">settamount = #{module.settamount,jdbcType=DECIMAL},</if>
            <if test="module.useofunds != null">useofunds = #{module.useofunds,jdbcType=VARCHAR},</if>
            <if test="module.princurr != null">princurr = #{module.princurr,jdbcType=VARCHAR},</if>
            <if test="module.repayamount != null">repayamount = #{module.repayamount,jdbcType=DECIMAL},</if>
            <if test="module.prepayamount != null">prepayamount = #{module.prepayamount,jdbcType=DECIMAL},</if>
            <if test="module.inpaycurr != null">inpaycurr = #{module.inpaycurr,jdbcType=VARCHAR},</if>
            <if test="module.inpayamount != null">inpayamount = #{module.inpayamount,jdbcType=DECIMAL},</if>
            <if test="module.pinpayamount != null">pinpayamount = #{module.pinpayamount,jdbcType=DECIMAL},</if>
            <if test="module.endbalan != null">endbalan = #{module.endbalan,jdbcType=DECIMAL},</if>
            <if test="module.remark != null">remark = #{module.remark,jdbcType=VARCHAR},</if>
            <if test="module.sta != null">sta = #{module.sta,jdbcType=VARCHAR},</if>
            <if test="module.eblinr != null">eblinr = #{module.eblinr,jdbcType=VARCHAR},</if>
            <if test="module.fincod != null">fincod = #{module.fincod,jdbcType=VARCHAR},</if>
            <if test="module.objtyp != null">objtyp = #{module.objtyp,jdbcType=VARCHAR},</if>
            <if test="module.objinr != null">objinr = #{module.objinr,jdbcType=VARCHAR},</if>
            <if test="module.credat != null">credat = #{module.credat,jdbcType=DATE},</if>
        </set>
        ${conditions}
    </update>

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

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

    <select id="selectLastEndbalan" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from ecb
        where DOFOEXLOCODE = #{dofoexlocode,jdbcType=VARCHAR}
        AND CHANGENO = (SELECT MAX(CHANGENO) FROM ECB WHERE DOFOEXLOCODE = #{dofoexlocode,jdbcType=VARCHAR}
        AND STA IN ('W','S') AND ACTIONTYPE != 'D')
    </select>

    <select id="selectByEblinr" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from ecb
        where
        eblinr = #{eblinr,jdbcType=VARCHAR} limit 1;
    </select>

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

    <select id="selectByObjinrAndTrn" resultMap="BaseResultMap">
        select
        ecb.*
        from ecb , ebl, trn
        where 1=1
        AND ecb.objinr = #{objinr,jdbcType=VARCHAR}
        AND ecb.objtyp = #{objtyp,jdbcType=VARCHAR}
        and ebl.inr = ecb.eblinr
        and ebl.trninr = trn.inr
        and trn.relflg='R'
    </select>

    <select id="selectByObjinr" resultMap="BaseResultMap">
        select
        ecb.*
        from ecb , ebl
        where ecb.objtyp = 'ECA'
        AND ecb.objinr = #{objinr,jdbcType=VARCHAR}
        and ebl.inr = ecb.eblinr
        and (ebl.trninr = '' or ebl.trninr is null)

    </select>

    <update id="updateStaByRptno">
        update ecb
        <set>
            sta = #{sta,jdbcType=VARCHAR},
        </set>
        where dofoexlocode = #{dofoexlocode,jdbcType=VARCHAR}
    </update>



</mapper>