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

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Lgb">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="cur" column="cur" jdbcType="VARCHAR"/>
        <result property="amt" column="amt" jdbcType="DECIMAL"/>
        <result property="sta" column="sta" jdbcType="VARCHAR"/>
        <result property="expdat" column="expdat" jdbcType="DATE"/>
        <result property="typ" column="typ" jdbcType="VARCHAR"/>
        <result property="ptyinr" column="ptyinr" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,cur,amt,sta,expdat,typ,ptyinr
    </sql>

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

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

    <insert id="insert">
        insert into lgb (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{cur,jdbcType=VARCHAR},
            #{amt,jdbcType=DECIMAL},
            #{sta,jdbcType=VARCHAR},
            #{expdat,jdbcType=DATE},
            #{typ,jdbcType=VARCHAR},
            #{ptyinr,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into lgb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="cur != null">cur,</if>
            <if test="amt != null">amt,</if>
            <if test="sta != null">sta,</if>
            <if test="expdat != null">expdat,</if>
            <if test="typ != null">typ,</if>
            <if test="ptyinr != null">ptyinr,</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="amt != null">#{amt,jdbcType=DECIMAL}, </if>
            <if test="sta != null">#{sta,jdbcType=VARCHAR}, </if>
            <if test="expdat != null">#{expdat,jdbcType=DATE}, </if>
            <if test="typ != null">#{typ,jdbcType=VARCHAR}, </if>
            <if test="ptyinr != null">#{ptyinr,jdbcType=VARCHAR}, </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update lgb
        <set>
            <if test="cur != null">cur = #{cur,jdbcType=VARCHAR},</if>
            <if test="amt != null">amt = #{amt,jdbcType=DECIMAL},</if>
            <if test="sta != null">sta = #{sta,jdbcType=VARCHAR},</if>
            <if test="expdat != null">expdat = #{expdat,jdbcType=DATE},</if>
            <if test="typ != null">typ = #{typ,jdbcType=VARCHAR},</if>
            <if test="ptyinr != null">ptyinr = #{ptyinr,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update lgb
        <set>
            cur = #{cur,jdbcType=VARCHAR},
            amt = #{amt,jdbcType=DECIMAL},
            sta = #{sta,jdbcType=VARCHAR},
            expdat = #{expdat,jdbcType=DATE},
            typ = #{typ,jdbcType=VARCHAR},
            ptyinr = #{ptyinr,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 lgb
        <set>
            <if test="module.cur != null">cur = #{module.cur,jdbcType=VARCHAR},</if>
            <if test="module.amt != null">amt = #{module.amt,jdbcType=DECIMAL},</if>
            <if test="module.sta != null">sta = #{module.sta,jdbcType=VARCHAR},</if>
            <if test="module.expdat != null">expdat = #{module.expdat,jdbcType=DATE},</if>
            <if test="module.typ != null">typ = #{module.typ,jdbcType=VARCHAR},</if>
            <if test="module.ptyinr != null">ptyinr = #{module.ptyinr,jdbcType=VARCHAR},</if>
        </set>
        ${conditions}
    </update>

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

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

    <select id="getLgbInrFromPtyInr" resultMap="BaseResultMap">
        SELECT LGB.TYP, LGB.STA, LGB.CUR, LGB.AMT, LGA.USEAMT, LGA.NACAMT, LGB.EXPDAT FROM LGB
            LEFT OUTER JOIN LGA ON LGA.LGBINR=LGB.INR
        WHERE LGB.PTYINR = #{ptyinr,jdbcType=VARCHAR}
    </select>

    <select id="getLgbStm" resultType="com.brilliance.isc.vo.manager.LgbStmVo">
        select lgb.inr lgbinr, lgb.typ lgbtyp, lgb.sta lgbsta, lgb.cur lgbcur, lgb.amt lgbamt, lga.useamt lgauseamt, lga.nacamt lganacamt, lgb.expdat lgbexpdat from lgb
            left outer join lga on lga.lgbinr=lgb.inr
        <where>
            <if test="ptyinr != null and ptyinr != '' ">
                AND lgb.ptyinr = #{ptyinr,jdbcType=VARCHAR}
            </if>
            <if test="lgbtyp != null and lgbtyp != '' ">
                AND lgb.typ = #{lgbtyp,jdbcType=VARCHAR}
            </if>
            <if test="lgbsta != null and lgbsta != '' ">
                AND lgb.sta = #{lgbsta,jdbcType=VARCHAR}
            </if>
            <if test="expdatsta != null and expdatsta != ''">
                AND lgb.expdat &gt; DATE_FORMAT(#{expdatsta}, '%Y-%m-%d')
            </if>
            <if test="expdatend != null and expdatend != ''">
                AND lgb.expdat &lt; DATE_FORMAT(#{expdatend}, '%Y-%m-%d')
            </if>
        </where>
    </select>

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

    <select id="selectByInrAndTyp" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from lgb
        where inr = #{inr,jdbcType=VARCHAR}
        and typ ='FFT'
    </select>

    <select id="getInrFromPty" resultMap="BaseResultMap">
    </select>

    <select id="getLgbInrFromPtyInr" resultMap="BaseResultMap">
        SELECT lgb.typ, lgb.sta, lgb.cur, lgb.amt, lgb.useamt, lgb.nacamt, lgb.expdat FROM lgb
            LEFT OUTER JOIN lga ON lga.lgbinr=lgb.inr
        WHERE lgb.ptyinr = #{ptyinr,jdbcType=VARCHAR}
    </select>

    <select id="queryAllByIdFromLgbAndLga" resultMap="BaseResultMap">
    </select>

    <select id="queryPageByIdFromLgbAndLga" resultMap="BaseResultMap">
    </select>

    <select id="queryByIdFromLgbAndLga" resultMap="BaseResultMap">
    </select>

    <select id="queryByIdFromLgo" resultMap="BaseResultMap">
    </select>

    <select id="count" resultMap="BaseResultMap">
    </select>

    <select id="insert" resultMap="BaseResultMap">
    </select>

    <select id="insertLgaFromLgb" resultMap="BaseResultMap">
    </select>

    <select id="queryLgbKey" resultMap="BaseResultMap">
    </select>

    <select id="queryLgaKey" resultMap="BaseResultMap">
    </select>

    <select id="update" resultMap="BaseResultMap">
    </select>

    <select id="getLgaInrFromLgbInr" resultMap="BaseResultMap">
    </select>

    <select id="deleteLgaDataFromLgb" resultMap="BaseResultMap">
    </select>

    <select id="deleteById" resultMap="BaseResultMap">
    </select>

    <select id="queryLgbByPtyInrAndTyp" resultMap="BaseResultMap">
        SELECT
            <include refid="Base_Column_List" />
        FROM lgb
        WHERE typ = #{typ,jdbcType=VARCHAR}
        AND ptyinr = #{ptyinr,jdbcType=VARCHAR}
        AND sta IN ('N', 'B')
    </select>

    <select id="queryLgbByPtyInrAndTypAndSta" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM lgb
        WHERE typ = #{typ,jdbcType=VARCHAR}
        AND ptyinr = #{ptyinr,jdbcType=VARCHAR}
        AND sta = #{sta,jdbcType=VARCHAR}
    </select>
</mapper>