<?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.SinMapper">
    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Sin">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="ptyextkey" column="ptyextkey" jdbcType="VARCHAR"/>
        <result property="ptynam" column="ptynam" jdbcType="VARCHAR"/>
        <result property="fromflg" column="fromflg" jdbcType="VARCHAR"/>
        <result property="sinsta" column="sinsta" jdbcType="VARCHAR"/>
        <result property="sintime" column="sintime" jdbcType="DATE"/>
        <result property="ntfsta" column="ntfsta" jdbcType="VARCHAR"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,ptyextkey,ptynam,fromflg,sinsta,sintime,ntfsta,remark
    </sql>

    <insert id="insert">
        insert into sin
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="ptyextkey != null">ptyextkey,</if>
            <if test="ptynam != null">ptynam,</if>
            <if test="fromflg != null">fromflg,</if>
            <if test="sinsta != null">sinsta,</if>
            <if test="sintime != null">sintime,</if>
            <if test="ntfsta != null">ntfsta,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="ptyextkey != null">#{ptyextkey,jdbcType=VARCHAR}, </if>
            <if test="ptynam != null">#{ptynam,jdbcType=VARCHAR}, </if>
            <if test="fromflg != null">#{fromflg,jdbcType=VARCHAR}, </if>
            <if test="sinsta != null">#{sinsta,jdbcType=VARCHAR}, </if>
            <if test="sintime != null">#{sintime,jdbcType=DATE}, </if>
            <if test="ntfsta != null">#{ntfsta,jdbcType=VARCHAR}, </if>
            <if test="remark != null">#{remark,jdbcType=VARCHAR}, </if>
        </trim>
    </insert>

    <update id="updateSin">
        update sin
        <set>
            <trim suffixOverrides=",">
                <if test="ptyextkey != null">ptyextkey = #{ptyextkey,jdbcType=VARCHAR},</if>
                <if test="ptynam != null">ptynam = #{ptynam,jdbcType=VARCHAR},</if>
                <if test="fromflg != null">fromflg = #{fromflg,jdbcType=VARCHAR},</if>
                <if test="sinsta != null">sinsta = #{sinsta,jdbcType=VARCHAR},</if>
                <if test="sintime != null">sintime = #{sintime,jdbcType=DATE},</if>
                <if test="ntfsta != null">ntfsta = #{ntfsta,jdbcType=VARCHAR},</if>
                <if test="remark != null">remark = #{remark,jdbcType=VARCHAR},</if>
            </trim>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <select id="queryByid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from sin
        where inr  = #{inr}
    </select>

    <select id="queryByPtyCondition" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from sin
        <where>
            and ptyextkey = #{ptyextkey}
            <if test="fromflg != null and fromflg != ''">
                and fromflg = #{fromflg}
            </if>
            <if test="sinsta != null and sinsta != ''">
                and sinsta =#{sinsta}
            </if>
        </where>
    </select>

    <select id="queryByPtyinrAndFromflg" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from sin where ptyextkey = #{ptyextkey} and fromflg = #{fromflg}
    </select>

    <select id="queryByPtyextkeyAndFromflg" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from sin where ptyextkey = #{ptyextkey} and fromflg = #{fromflg}
        limit 1
    </select>

    <update id="updateSinstaByPtyextkeyAndFromflg">
        update sin
        set sinsta = #{sinsta} where ptyextkey = #{ptyextkey} and fromflg = #{fromflg}
    </update>

    <delete id="deleteByInr">
        delete from sin
        where inr  = #{inr}
    </delete>
</mapper>