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

    <resultMap id="baseResultMap" type="com.brilliance.isc.bo.Ack">
        <result column="INR" property="inr" jdbcType="VARCHAR"/>
        <result column="objtyp" property="objtyp" jdbcType="VARCHAR"/>
        <result column="objinr" property="objinr" jdbcType="VARCHAR"/>
        <result column="objsub" property="objsub" jdbcType="VARCHAR"/>
        <result column="outsrv" property="outsrv" jdbcType="VARCHAR"/>
        <result column="gendattim" property="gendattim" jdbcType="DATE"/>
        <result column="acksrv" property="acksrv" jdbcType="VARCHAR"/>
        <result column="extkey" property="extkey" jdbcType="VARCHAR"/>
        <result column="rcvdattim" property="rcvdattim" jdbcType="DATE"/>
        <result column="cla" property="cla" jdbcType="VARCHAR"/>
        <result column="sta" property="sta" jdbcType="VARCHAR"/>
        <result column="etgextkey" property="etgextkey" jdbcType="VARCHAR"/>
        <result column="acktxt" property="acktxt" jdbcType="VARCHAR"/>
        <result column="bchkeyinr" property="bchkeyinr" jdbcType="VARCHAR"/>
        <result column="sndref" property="sndref" jdbcType="VARCHAR"/>
        <result column="branchinr" property="branchinr" jdbcType="VARCHAR"/>
        <result column="docfil" property="docfil" jdbcType="VARCHAR"/>
        <result column="oldref" property="oldref" jdbcType="VARCHAR"/>
        <result column="msgref" property="msgref" jdbcType="VARCHAR"/>
    </resultMap>

    <resultMap id="AckResultMap" type="com.brilliance.isc.bo.AckVo">
        <result column="INR" property="inr" jdbcType="VARCHAR"/>
        <result column="objtyp" property="objtyp" jdbcType="VARCHAR"/>
        <result column="objinr" property="objinr" jdbcType="VARCHAR"/>
        <result column="objsub" property="objsub" jdbcType="VARCHAR"/>
        <result column="outsrv" property="outsrv" jdbcType="VARCHAR"/>
        <result column="gendattim" property="gendattim" jdbcType="DATE"/>
        <result column="acksrv" property="acksrv" jdbcType="VARCHAR"/>
        <result column="extkey" property="extkey" jdbcType="VARCHAR"/>
        <result column="rcvdattim" property="rcvdattim" jdbcType="DATE"/>
        <result column="cla" property="cla" jdbcType="VARCHAR"/>
        <result column="sta" property="sta" jdbcType="VARCHAR"/>
        <result column="etgextkey" property="etgextkey" jdbcType="VARCHAR"/>
        <result column="acktxt" property="acktxt" jdbcType="VARCHAR"/>
        <result column="bchkeyinr" property="bchkeyinr" jdbcType="VARCHAR"/>
        <result column="sndref" property="sndref" jdbcType="VARCHAR"/>
        <result column="branchinr" property="branchinr" jdbcType="VARCHAR"/>
        <result column="docfil" property="docfil" jdbcType="VARCHAR"/>
        <result column="oldref" property="oldref" jdbcType="VARCHAR"/>
        <result column="msgref" property="msgref" jdbcType="VARCHAR"/>
        <result property="smhinr" column="smhinr" jdbcType="VARCHAR"/>
        <result property="chlflg" column="chlflg" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="ack_column">
        inr,
        objtyp,
        objinr,
        objsub,
        outsrv,
        gendattim,
        acksrv,
        extkey,
        rcvdattim,
        cla,
        sta,
        etgextkey,
        acktxt,
        bchkeyinr,
        sndref,
        branchinr,
        docfil,
        oldref,
        msgref
    </sql>

    <update id="updateObjSubBySndRef">
        UPDATE ACK
        SET OBJSUB = #{objSub,jdbcType=VARCHAR}
        WHERE SNDREF = #{sndRef,jdbcType=VARCHAR}
    </update>

    <update id="updateObjSub">
        UPDATE ACK
        SET OBJSUB = #{newInr,jdbcType=VARCHAR}
        WHERE OBJSUB = #{oldInr,jdbcType=VARCHAR}
    </update>

    <select id="selectOneByVo" resultMap="baseResultMap">
        select
        <include refid="ack_column"/>
        from ACK
        <where>
            <if test="vo.objtyp != null and vo.objtyp != ''">
                and OBJTYP = #{vo.objtyp,jdbcType=VARCHAR}
            </if>
            <if test="vo.objinr != null and vo.objinr != ''">
                and OBJINR = #{vo.objinr,jdbcType=VARCHAR}
            </if>
            <if test="vo.objsub != null and vo.objsub != ''">
                and OBJSUB = #{vo.objsub,jdbcType=VARCHAR}
            </if>
            <if test="vo.acksrv != null and vo.acksrv != ''">
                and ACKSRV = #{vo.acksrv,jdbcType=VARCHAR}
            </if>
            <if test="vo.sndref != null and vo.sndref != ''">
                and SNDREF = #{vo.sndref,jdbcType=VARCHAR}
            </if>
        </where>
        limit 1
    </select>

    <insert id="insert">
        insert into ACK (<include refid="ack_column"/>)
        values (
        #{vo.inr,jdbcType=VARCHAR},
        #{vo.objtyp,jdbcType=VARCHAR},
        #{vo.objinr,jdbcType=VARCHAR},
        #{vo.objsub,jdbcType=VARCHAR},
        #{vo.outsrv,jdbcType=VARCHAR},
        #{vo.gendattim,jdbcType=DATE},
        #{vo.acksrv,jdbcType=VARCHAR},
        #{vo.extkey,jdbcType=VARCHAR},
        #{vo.rcvdattim,jdbcType=DATE},
        #{vo.cla,jdbcType=VARCHAR},
        #{vo.sta,jdbcType=VARCHAR},
        #{vo.etgextkey,jdbcType=VARCHAR},
        #{vo.acktxt,jdbcType=VARCHAR},
        #{vo.bchkeyinr,jdbcType=VARCHAR},
        #{vo.sndref,jdbcType=VARCHAR},
        #{vo.branchinr,jdbcType=VARCHAR},
        #{vo.docfil,jdbcType=VARCHAR},
        #{vo.oldref,jdbcType=VARCHAR},
        #{vo.msgref,jdbcType=VARCHAR}
        )
    </insert>

    <update id="update">
        update ACK
        <set>
            OBJTYP = #{vo.objtyp,jdbcType=VARCHAR},
            OBJINR = #{vo.objinr,jdbcType=VARCHAR},
            OBJSUB = #{vo.objsub,jdbcType=VARCHAR},
            OUTSRV = #{vo.outsrv,jdbcType=VARCHAR},
            GENDATTIM = #{vo.gendattim,jdbcType=DATE},
            ACKSRV = #{vo.acksrv,jdbcType=VARCHAR},
            EXTKEY = #{vo.extkey,jdbcType=VARCHAR},
            RCVDATTIM = #{vo.rcvdattim,jdbcType=DATE},
            CLA = #{vo.cla,jdbcType=VARCHAR},
            STA = #{vo.sta,jdbcType=VARCHAR},
            ETGEXTKEY = #{vo.etgextkey,jdbcType=VARCHAR},
            ACKTXT = #{vo.acktxt,jdbcType=VARCHAR},
            BCHKEYINR = #{vo.bchkeyinr,jdbcType=VARCHAR},
            SNDREF = #{vo.sndref,jdbcType=VARCHAR},
            BRANCHINR = #{vo.branchinr,jdbcType=VARCHAR},
            DOCFIL = #{vo.docfil,jdbcType=VARCHAR},
            OLDREF = #{vo.oldref,jdbcType=VARCHAR},
            MSGREF = #{vo.msgref,jdbcType=VARCHAR}
        </set>
        <where>
            INR = #{vo.inr,jdbcType=VARCHAR}
        </where>
    </update>

    <select id="selectPdaSta" resultMap="baseResultMap">
        select distinct sta from ACK
        where OBJTYP = #{vo.objtyp}
        and OBJINR = #{vo.objinr}
    </select>

    <select id="selectPdeSta" resultMap="baseResultMap">
        select distinct sta, acktxt from ACK
        where OBJTYP = #{vo.objtyp}
          and OBJINR = #{vo.objinr}
          and STA != 'A'
    </select>

    <select id="selectBySndrefAndAcksrv" resultMap="baseResultMap">
        select <include refid="ack_column"/> from ACK
        where SNDREF = #{vo.sndref}
          and ACKSRV = #{vo.acksrv}
          limit 1
    </select>

    <select id="selectByCondition" resultMap="AckResultMap">
        ${sql}
    </select>

    <select id="selTrnSelctionS" resultType="int">
        select count(1) from ACK WHERE OBJTYP = 'TRN'
        AND OBJINR = #{objinr}
        AND TRIM(OBJSUB) = #{objsub}
        AND ACKSRV = #{acksrv}
        AND SNDREF LIKE 'ST%'
    </select>

    <select id="selTrnSelctionG" resultType="int">
        select count(1) from ACK WHERE OBJTYP = 'TRN'
        AND OBJINR = #{objinr}
        AND TRIM(OBJSUB) = #{objsub}
        AND ACKSRV = #{acksrv}
        AND SNDREF LIKE 'GSP%'
    </select>

    <select id="selectOneByVoS" resultMap="baseResultMap">
        select
        <include refid="ack_column"/>
        from ACK
        <where>
            <if test="vo.objtyp != null and vo.objtyp != ''">
                and OBJTYP = #{vo.objtyp,jdbcType=VARCHAR}
            </if>
            <if test="vo.objinr != null and vo.objinr != ''">
                and OBJINR = #{vo.objinr,jdbcType=VARCHAR}
            </if>
            <if test="vo.objsub != null and vo.objsub != ''">
                and OBJSUB = #{vo.objsub,jdbcType=VARCHAR}
            </if>
            <if test="vo.acksrv != null and vo.acksrv != ''">
                and ACKSRV = #{vo.acksrv,jdbcType=VARCHAR}
            </if>
            <if test="vo.sndref != null and vo.sndref != ''">
                and SNDREF LIKE 'ST%'
            </if>
        </where>
        limit 1
    </select>


    <select id="selectOneByVoG" resultMap="baseResultMap">
        select
        <include refid="ack_column"/>
        from ACK
        <where>
            <if test="vo.inr != null and vo.inr != ''">
                and INR = #{vo.inr,jdbcType=VARCHAR}
            </if>
            <if test="vo.objtyp != null and vo.objtyp != ''">
                and OBJTYP = #{vo.objtyp,jdbcType=VARCHAR}
            </if>
            <if test="vo.objinr != null and vo.objinr != ''">
                and OBJINR = #{vo.objinr,jdbcType=VARCHAR}
            </if>
            <if test="vo.objsub != null and vo.objsub != ''">
                and OBJSUB = #{vo.objsub,jdbcType=VARCHAR}
            </if>
            <if test="vo.acksrv != null and vo.acksrv != ''">
                and ACKSRV = #{vo.acksrv,jdbcType=VARCHAR}
            </if>
            <if test="vo.sndref != null and vo.sndref != ''">
                and SNDREF LIKE 'GSP%'
            </if>
        </where>
        limit 1
    </select>

    <select id="selectOneByVoF" resultType="com.brilliance.isc.bo.Ack">
        select
        <include refid="ack_column"/>
        from ACK
        <where>
            <if test="vo.objtyp != null and vo.objtyp != ''">
                and OBJTYP = #{vo.objtyp,jdbcType=VARCHAR}
            </if>
            <if test="vo.objinr != null and vo.objinr != ''">
                and OBJINR = #{vo.objinr,jdbcType=VARCHAR}
            </if>
            <if test="vo.objsub != null and vo.objsub != ''">
                and OBJSUB = #{vo.objsub,jdbcType=VARCHAR}
            </if>
            <if test="vo.acksrv != null and vo.acksrv != ''">
                and ACKSRV = #{vo.acksrv,jdbcType=VARCHAR}
            </if>
            <if test="vo.sndref != null and vo.sndref != ''">
                and SNDREF LIKE 'GFIX%'
            </if>
        </where>
        limit 1
    </select>

    <select id="selectByCon" resultMap="AckResultMap">
        ${sql}
    </select>
    <select id="selectByObjtypAndObjinrAndSta" resultType="com.brilliance.isc.bo.Ack">
        select
        <include refid="ack_column"/>
        from ack
        where
        objtyp = #{objtyp,jdbcType=VARCHAR}
        AND objinr = #{objinr,jdbcType=VARCHAR}
        AND sta = #{sta,jdbcType=VARCHAR}
    </select>
    <select id="selectByObjtypAndObjinrAndStas" resultType="com.brilliance.isc.bo.Ack">
        select
        <include refid="ack_column"/>
        from ack
        where
        objtyp = #{objtyp,jdbcType=VARCHAR}
        AND objinr = #{objinr,jdbcType=VARCHAR}
        AND sta in
        <foreach collection="list" item="items" open="(" separator="," close=")">
            #{items}
        </foreach>
    </select>
    <select id="selectOneByObjtypAndObjinr" resultType="com.brilliance.isc.bo.Ack">
        select
        <include refid="ack_column"/>
        from ack
        where
        objtyp = #{objtyp,jdbcType=VARCHAR}
        AND objinr = #{objinr,jdbcType=VARCHAR}
        limit 1
    </select>
</mapper>