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

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Swtchl">
        <result property="inr" column="inr" jdbcType="VARCHAR"/>
        <result property="msgref" column="msgref" jdbcType="VARCHAR"/>
        <result property="chlflg" column="chlflg" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        inr,msgref,chlflg
    </sql>

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

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

    <insert id="insert">
        insert into swtchl (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{inr,jdbcType=VARCHAR},
            #{msgref,jdbcType=VARCHAR},
            #{chlflg,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into swtchl
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inr != null">inr,</if>
            <if test="msgref != null">msgref,</if>
            <if test="chlflg != null">chlflg,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inr != null">#{inr,jdbcType=VARCHAR}, </if>
            <if test="msgref != null">#{msgref,jdbcType=VARCHAR}, </if>
            <if test="chlflg != null">#{chlflg,jdbcType=VARCHAR}, </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update swtchl
        <set>
            <if test="msgref != null">msgref = #{msgref,jdbcType=VARCHAR},</if>
            <if test="chlflg != null">chlflg = #{chlflg,jdbcType=VARCHAR},</if>
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update swtchl
        <set>
            msgref = #{msgref,jdbcType=VARCHAR},
            chlflg = #{chlflg,jdbcType=VARCHAR},
        </set>
        where inr = #{inr,jdbcType=VARCHAR}
    </update>

    <delete id="deleteByIds">
        delete from swtchl where inr in
        <foreach item="item" index="index" collection="collection" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <update id="dyncUpdate">
        update swtchl
        <set>
            <if test="module.msgref != null">msgref = #{module.msgref,jdbcType=VARCHAR},</if>
            <if test="module.chlflg != null">chlflg = #{module.chlflg,jdbcType=VARCHAR},</if>
        </set>
        ${conditions}
    </update>

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

    <select id="dyncRead" resultMap="BaseResultMap">
        ${sql}
    </select>
	
	<select id="selectChlflgByMsgref" resultType="java.lang.String">
        SELECT CHLFLG FROM SWTCHL WHERE msgref=#{msgref,jdbcType=VARCHAR} limit 1
    </select>

    <select id="selectCountByMsgref" resultType="java.lang.Integer"> <!--环境用的是oracle数据库,实际再调整-->
        select count(inr) FROM SWTCHL where chlflg='G' and msgref=#{msgref,jdbcType=VARCHAR}
    </select>

</mapper>