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

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Imfinv">
        <result column="INR" property="inr" jdbcType="VARCHAR"/>
        <result column="bustyp" property="bustyp" jdbcType="VARCHAR"/>
        <result column="busdcr" property="busdcr" jdbcType="VARCHAR"/>
        <result column="antnum" property="antnum" jdbcType="VARCHAR"/>
        <result column="antnam" property="antnam" jdbcType="VARCHAR"/>
        <result column="antdat" property="antdat" jdbcType="DATE"/>
        <result column="antdtl" property="antdtl" jdbcType="VARCHAR"/>
        <result column="smhinr" property="smhinr" jdbcType="VARCHAR"/>
        <result column="regsmhinr" property="regsmhinr" jdbcType="VARCHAR"/>
        <result column="selreg" property="selreg" jdbcType="VARCHAR"/>
        <result column="regsta" property="regsta" jdbcType="VARCHAR"/>
        <result column="prebnkdat" property="prebnkdat" jdbcType="DATE"/>
        <result column="optusr" property="optusr" jdbcType="VARCHAR"/>
        <result column="optbranch" property="optbranch" jdbcType="VARCHAR"/>
        <result column="invtyp" property="invtyp" jdbcType="VARCHAR"/>
        <result column="invnum" property="invnum" jdbcType="VARCHAR"/>
        <result column="invcod" property="invcod" jdbcType="VARCHAR"/>
        <result column="invamt" property="invamt" jdbcType="VARCHAR"/>
        <result column="opndat" property="opndat" jdbcType="DATE"/>
        <result column="vrfcod" property="vrfcod" jdbcType="VARCHAR"/>
        <result column="imgcod" property="imgcod" jdbcType="VARCHAR"/>
        <result column="isfnc" property="isfnc" jdbcType="VARCHAR"/>
        <result column="valflg" property="valflg" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,bustyp,busdcr,antnum,antnam,antdat,antdtl,smhinr,regsmhinr,selreg,regsta,prebnkdat,optusr,optbranch,invtyp,invnum,invcod,invamt,opndat,vrfcod,imgcod,isfnc,valflg
    </sql>

    <select id="selectByInvcodInvnumRegsta" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from imfinv
        where invcod = #{invcod} and invnum = #{invnum} and regsta = #{regsta} and optbranch = #{optbranch}
    </select>

    <select id="selectByInvcodInvnum" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from imfinv
        where invcod = #{invcod} and invnum = #{invnum} and optbranch = #{optbranch}
    </select>

    <select id="getInvRegList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from imfinv
        where selreg = 'R'
        <if test="invcod != null and invcod !='' and invcod !='null' ">
            and invcod like concat('%', #{invcod}, '%')
        </if>
        <if test="invnum != null and invnum !='' and invnum !='null'">
            and invnum like concat('%', #{invnum}, '%')
        </if>
        <if test="bustyp != null and bustyp !='' and bustyp !='null' ">
            and bustyp = #{bustyp}
        </if>
        <if test="antnum != null and antnum !='' and antnum !='null'">
            and antnum like concat('%', #{antnum}, '%')
        </if>
        <if test="prebnkdat != null">
            and prebnkdat &gt;= #{prebnkdat}
        </if>
        <if test="prebnkdat2 != null">
            and prebnkdat &lt;= #{prebnkdat2}
        </if>
        <if test="opndat != null">
            and opndat between #{opndat} and #{opndat}+1
        </if>
        <if test="optbranch != null and optbranch !='' and optbranch !='null' and optbranch != '1000'">
            and optbranch = #{optbranch}
        </if>
        order by inr desc
    </select>

    <select id="getInvList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from imfinv
        where 1=1 and optbranch like concat('%', #{optbranch}, '%')
        <if test="invcod != null and invcod !='' and invcod !='null' ">
            and invcod like concat('%', #{invcod}, '%')
        </if>
        <if test="invnum != null and invnum !='' and invnum !='null'">
            and invnum like concat('%', #{invnum}, '%')
        </if>
        <if test="prebnkdat != null">
            and prebnkdat &gt;= #{prebnkdat}
        </if>
        <if test="prebnkdat2 != null">
            and prebnkdat &lt;= #{prebnkdat2}
        </if>
        order by inr desc
    </select>


    <select id="selectByRegsmhinr" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from imfinv
        where regsmhinr = #{regsmhinr}
    </select>

    <update id="updateByPrimaryKey">
        update imfinv
        <set>
            bustyp = #{bustyp,jdbcType=VARCHAR},
            busdcr = #{busdcr,jdbcType=VARCHAR},
            antnum = #{antnum,jdbcType=VARCHAR},
            antnam = #{antnam,jdbcType=VARCHAR},
            antdat = #{antdat,jdbcType=DATE},
            antdtl = #{antdtl,jdbcType=VARCHAR},
            smhinr = #{smhinr,jdbcType=VARCHAR},
            regsmhinr = #{regsmhinr,jdbcType=VARCHAR},
            selreg = #{selreg,jdbcType=VARCHAR},
            regsta = #{regsta,jdbcType=VARCHAR},
            prebnkdat = #{prebnkdat,jdbcType=DATE},
            optusr = #{optusr,jdbcType=VARCHAR},
            optbranch = #{optbranch,jdbcType=VARCHAR},
            invtyp = #{invtyp,jdbcType=VARCHAR},
            invnum = #{invnum,jdbcType=VARCHAR},
            invcod = #{invcod,jdbcType=VARCHAR},
            invamt = #{invamt,jdbcType=VARCHAR},
            opndat = #{opndat,jdbcType=DATE},
            vrfcod = #{vrfcod,jdbcType=VARCHAR},
            imgcod = #{imgcod,jdbcType=VARCHAR},
            isfnc = #{isfnc,jdbcType=VARCHAR},
            valflg = #{valflg,jdbcType=VARCHAR},
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <insert id="insert">
        insert into imfinv (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{bustyp,jdbcType=VARCHAR},
            #{busdcr,jdbcType=VARCHAR},
            #{antnum,jdbcType=VARCHAR},
            #{antnam,jdbcType=VARCHAR},
            #{antdat,jdbcType=DATE},
            #{antdtl,jdbcType=VARCHAR},
            #{smhinr,jdbcType=VARCHAR},
            #{regsmhinr,jdbcType=VARCHAR},
            #{selreg,jdbcType=VARCHAR},
            #{regsta,jdbcType=VARCHAR},
            #{prebnkdat,jdbcType=DATE},
            #{optusr,jdbcType=VARCHAR},
            #{optbranch,jdbcType=VARCHAR},
            #{invtyp,jdbcType=VARCHAR},
            #{invnum,jdbcType=VARCHAR},
            #{invcod,jdbcType=VARCHAR},
            #{invamt,jdbcType=VARCHAR},
            #{opndat,jdbcType=DATE},
            #{vrfcod,jdbcType=VARCHAR},
            #{imgcod,jdbcType=VARCHAR},
            #{isfnc,jdbcType=VARCHAR},
            #{valflg,jdbcType=VARCHAR},
        </trim>
    </insert>

    <select id="getInvlistBySmhInr" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from imfinv where smhinr = #{smhinr,jdbcType=VARCHAR}
    </select>
</mapper>