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

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Umd">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="ownref" column="ownref" jdbcType="VARCHAR"/>
        <result property="inifrm" column="inifrm" jdbcType="VARCHAR"/>
        <result property="transid" column="transid" jdbcType="VARCHAR"/>
        <result property="credat" column="credat" jdbcType="DATE"/>
        <result property="extkey" column="extkey" jdbcType="VARCHAR"/>
        <result property="branch" column="branch" jdbcType="VARCHAR"/>
        <result property="mac" column="mac" jdbcType="VARCHAR"/>
        <result property="request" column="request" jdbcType="VARCHAR"/>
        <result property="response" column="response" jdbcType="VARCHAR"/>
        <result property="sta" column="sta" jdbcType="VARCHAR"/>
        <result property="caseno" column="caseno" jdbcType="VARCHAR"/>
        <result property="casecode" column="casecode" jdbcType="VARCHAR"/>
        <result property="usr" column="usr" jdbcType="VARCHAR"/>
        <result property="docfil" column="docfil" jdbcType="VARCHAR"/>
        <result property="docpth" column="docpth" jdbcType="VARCHAR"/>
        <result property="code" column="code" jdbcType="VARCHAR"/>
        <result property="ver" column="ver" jdbcType="VARCHAR"/>
        <result property="lstdat" column="lstdat" jdbcType="DATE"/>
        <result property="trninr" column="trninr" jdbcType="VARCHAR"/>
        <result property="ordinr" column="ordinr" jdbcType="VARCHAR"/>
        <result property="objtyp" column="objtyp" jdbcType="VARCHAR"/>
        <result property="objinr" column="objinr" jdbcType="VARCHAR"/>
        <result property="sptinr" column="sptinr" jdbcType="VARCHAR"/>
        <result property="orgcode" column="orgcode" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,ownref,inifrm,transid,credat,extkey,branch,mac,request,response,sta,caseno,casecode,usr,docfil,docpth,code,ver,lstdat,trninr,ordinr,objtyp,objinr,sptinr,orgcode
    </sql>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List" />
        from umd
        where inr = #{inr,jdbcType=VARCHAR}
    </select>
    <select id="selectByMac" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from umd
        where mac = #{mac,jdbcType=VARCHAR} and ownref = #{ownref}
    </select>
    <select id="selectBySptInr" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from umd
        where sptinr = #{sptinr}
    </select>
    <select id="selectBySptToday" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from umd
        where DATEDIFF(CREDAT ,NOW())=0 and code='001' and casecode !='100' and casecode!='101'
        <if test="inifrm != null and inifrm != ''"> and inifrm = #{inifrm}</if>
        and branch = #{branch}
    </select>
    <select id="selectUmdByOwnref" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from umd
        where ownref = #{ownref,jdbcType=VARCHAR} and substring(INIFRM,1,6) = #{inifrm,jdbcType=VARCHAR} order by length(inr) desc, inr desc
    </select>
    <delete id="deleteByPrimaryKey">
        delete from umd
        where inr = #{inr,jdbcType=VARCHAR}
    </delete>

    <insert id="insert">
        insert into umd (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{ownref,jdbcType=VARCHAR},
            #{inifrm,jdbcType=VARCHAR},
            #{transid,jdbcType=VARCHAR},
            #{credat,jdbcType=DATE},
            #{extkey,jdbcType=VARCHAR},
            #{branch,jdbcType=VARCHAR},
            #{mac,jdbcType=VARCHAR},
            #{request,jdbcType=VARCHAR},
            #{response,jdbcType=VARCHAR},
            #{sta,jdbcType=VARCHAR},
            #{caseno,jdbcType=VARCHAR},
            #{casecode,jdbcType=VARCHAR},
            #{usr,jdbcType=VARCHAR},
            #{docfil,jdbcType=VARCHAR},
            #{docpth,jdbcType=VARCHAR},
            #{code,jdbcType=VARCHAR},
            #{ver,jdbcType=VARCHAR},
            #{lstdat,jdbcType=DATE},
            #{trninr,jdbcType=VARCHAR},
            #{ordinr,jdbcType=VARCHAR},
            #{objtyp,jdbcType=VARCHAR},
            #{objinr,jdbcType=VARCHAR},
            #{sptinr,jdbcType=VARCHAR},
            #{orgcode,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into umd
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="ownref != null">ownref,</if>
            <if test="inifrm != null">inifrm,</if>
            <if test="transid != null">transid,</if>
            <if test="credat != null">credat,</if>
            <if test="extkey != null">extkey,</if>
            <if test="branch != null">branch,</if>
            <if test="mac != null">mac,</if>
            <if test="request != null">request,</if>
            <if test="response != null">response,</if>
            <if test="sta != null">sta,</if>
            <if test="caseno != null">caseno,</if>
            <if test="casecode != null">casecode,</if>
            <if test="usr != null">usr,</if>
            <if test="docfil != null">docfil,</if>
            <if test="docpth != null">docpth,</if>
            <if test="code != null">code,</if>
            <if test="ver != null">ver,</if>
            <if test="lstdat != null">lstdat,</if>
            <if test="trninr != null">trninr,</if>
            <if test="ordinr != null">ordinr,</if>
            <if test="objtyp != null">objtyp,</if>
            <if test="objinr != null">objinr,</if>
            <if test="sptinr != null">sptinr,</if>
            <if test="orgcode != null">orgcode,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="ownref != null">#{ownref,jdbcType=VARCHAR}, </if>
            <if test="inifrm != null">#{inifrm,jdbcType=VARCHAR}, </if>
            <if test="transid != null">#{transid,jdbcType=VARCHAR}, </if>
            <if test="credat != null">#{credat,jdbcType=DATE}, </if>
            <if test="extkey != null">#{extkey,jdbcType=VARCHAR}, </if>
            <if test="branch != null">#{branch,jdbcType=VARCHAR}, </if>
            <if test="mac != null">#{mac,jdbcType=VARCHAR}, </if>
            <if test="request != null">#{request,jdbcType=VARCHAR}, </if>
            <if test="response != null">#{response,jdbcType=VARCHAR}, </if>
            <if test="sta != null">#{sta,jdbcType=VARCHAR}, </if>
            <if test="caseno != null">#{caseno,jdbcType=VARCHAR}, </if>
            <if test="casecode != null">#{casecode,jdbcType=VARCHAR}, </if>
            <if test="usr != null">#{usr,jdbcType=VARCHAR}, </if>
            <if test="docfil != null">#{docfil,jdbcType=VARCHAR}, </if>
            <if test="docpth != null">#{docpth,jdbcType=VARCHAR}, </if>
            <if test="code != null">#{code,jdbcType=VARCHAR}, </if>
            <if test="ver != null">#{ver,jdbcType=VARCHAR}, </if>
            <if test="lstdat != null">#{lstdat,jdbcType=DATE}, </if>
            <if test="trninr != null">#{trninr,jdbcType=VARCHAR}, </if>
            <if test="ordinr != null">#{ordinr,jdbcType=VARCHAR}, </if>
            <if test="objtyp != null">#{objtyp,jdbcType=VARCHAR}, </if>
            <if test="objinr != null">#{objinr,jdbcType=VARCHAR}, </if>
            <if test="sptinr != null">#{sptinr,jdbcType=VARCHAR}, </if>
            <if test="orgcode != null">#{orgcode,jdbcType=VARCHAR}, </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update umd
        <set>
            <if test="ownref != null">ownref = #{ownref,jdbcType=VARCHAR},</if>
            <if test="inifrm != null">inifrm = #{inifrm,jdbcType=VARCHAR},</if>
            <if test="transid != null">transid = #{transid,jdbcType=VARCHAR},</if>
            <if test="credat != null">credat = #{credat,jdbcType=DATE},</if>
            <if test="extkey != null">extkey = #{extkey,jdbcType=VARCHAR},</if>
            <if test="branch != null">branch = #{branch,jdbcType=VARCHAR},</if>
            <if test="mac != null">mac = #{mac,jdbcType=VARCHAR},</if>
            <if test="request != null">request = #{request,jdbcType=VARCHAR},</if>
            <if test="response != null">response = #{response,jdbcType=VARCHAR},</if>
            <if test="sta != null">sta = #{sta,jdbcType=VARCHAR},</if>
            <if test="caseno != null">caseno = #{caseno,jdbcType=VARCHAR},</if>
            <if test="casecode != null">casecode = #{casecode,jdbcType=VARCHAR},</if>
            <if test="usr != null">usr = #{usr,jdbcType=VARCHAR},</if>
            <if test="docfil != null">docfil = #{docfil,jdbcType=VARCHAR},</if>
            <if test="docpth != null">docpth = #{docpth,jdbcType=VARCHAR},</if>
            <if test="code != null">code = #{code,jdbcType=VARCHAR},</if>
            <if test="ver != null">ver = #{ver,jdbcType=VARCHAR},</if>
            <if test="lstdat != null">lstdat = #{lstdat,jdbcType=DATE},</if>
            <if test="trninr != null">trninr = #{trninr,jdbcType=VARCHAR},</if>
            <if test="ordinr != null">ordinr = #{ordinr,jdbcType=VARCHAR},</if>
            <if test="objtyp != null">objtyp = #{objtyp,jdbcType=VARCHAR},</if>
            <if test="objinr != null">objinr = #{objinr,jdbcType=VARCHAR},</if>
            <if test="sptinr != null">sptinr = #{sptinr,jdbcType=VARCHAR},</if>
            <if test="orgcode != null">orgcode = #{orgcode,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update umd
        <set>
            ownref = #{ownref,jdbcType=VARCHAR},
            inifrm = #{inifrm,jdbcType=VARCHAR},
            transid = #{transid,jdbcType=VARCHAR},
            credat = #{credat,jdbcType=DATE},
            extkey = #{extkey,jdbcType=VARCHAR},
            branch = #{branch,jdbcType=VARCHAR},
            mac = #{mac,jdbcType=VARCHAR},
            request = #{request,jdbcType=VARCHAR},
            response = #{response,jdbcType=VARCHAR},
            sta = #{sta,jdbcType=VARCHAR},
            caseno = #{caseno,jdbcType=VARCHAR},
            casecode = #{casecode,jdbcType=VARCHAR},
            usr = #{usr,jdbcType=VARCHAR},
            docfil = #{docfil,jdbcType=VARCHAR},
            docpth = #{docpth,jdbcType=VARCHAR},
            code = #{code,jdbcType=VARCHAR},
            ver = #{ver,jdbcType=VARCHAR},
            lstdat = #{lstdat,jdbcType=DATE},
            trninr = #{trninr,jdbcType=VARCHAR},
            ordinr = #{ordinr,jdbcType=VARCHAR},
            objtyp = #{objtyp,jdbcType=VARCHAR},
            objinr = #{objinr,jdbcType=VARCHAR},
            sptinr = #{sptinr,jdbcType=VARCHAR},
            orgcode = #{orgcode,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 umd
        <set>
            <if test="module.ownref != null">ownref = #{module.ownref,jdbcType=VARCHAR},</if>
            <if test="module.inifrm != null">inifrm = #{module.inifrm,jdbcType=VARCHAR},</if>
            <if test="module.transid != null">transid = #{module.transid,jdbcType=VARCHAR},</if>
            <if test="module.credat != null">credat = #{module.credat,jdbcType=DATE},</if>
            <if test="module.extkey != null">extkey = #{module.extkey,jdbcType=VARCHAR},</if>
            <if test="module.branch != null">branch = #{module.branch,jdbcType=VARCHAR},</if>
            <if test="module.mac != null">mac = #{module.mac,jdbcType=VARCHAR},</if>
            <if test="module.request != null">request = #{module.request,jdbcType=VARCHAR},</if>
            <if test="module.response != null">response = #{module.response,jdbcType=VARCHAR},</if>
            <if test="module.sta != null">sta = #{module.sta,jdbcType=VARCHAR},</if>
            <if test="module.caseno != null">caseno = #{module.caseno,jdbcType=VARCHAR},</if>
            <if test="module.casecode != null">casecode = #{module.casecode,jdbcType=VARCHAR},</if>
            <if test="module.usr != null">usr = #{module.usr,jdbcType=VARCHAR},</if>
            <if test="module.docfil != null">docfil = #{module.docfil,jdbcType=VARCHAR},</if>
            <if test="module.docpth != null">docpth = #{module.docpth,jdbcType=VARCHAR},</if>
            <if test="module.code != null">code = #{module.code,jdbcType=VARCHAR},</if>
            <if test="module.ver != null">ver = #{module.ver,jdbcType=VARCHAR},</if>
            <if test="module.lstdat != null">lstdat = #{module.lstdat,jdbcType=DATE},</if>
            <if test="module.trninr != null">trninr = #{module.trninr,jdbcType=VARCHAR},</if>
            <if test="module.ordinr != null">ordinr = #{module.ordinr,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.sptinr != null">sptinr = #{module.sptinr,jdbcType=VARCHAR},</if>
            <if test="module.orgcode != null">orgcode = #{module.orgcode,jdbcType=VARCHAR},</if>
        </set>
        ${conditions}
    </update>

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

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

</mapper>