<?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.tongran.rocketmq.mapper.RmPppoeConfigMainMapper">
    
    <resultMap type="RmPppoeConfigMain" id="RmPppoeConfigMainResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="pppoeEnabled"    column="pppoe_enabled"    />
        <result property="pppoeConfigMode"    column="pppoe_config_mode"    />
        <result property="pppoeInterface"    column="pppoe_interface"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectRmPppoeConfigMainVo">
        select id, client_id, pppoe_enabled, pppoe_config_mode, pppoe_interface, create_time, update_time, create_by, update_by from rm_pppoe_config_main
    </sql>

    <select id="selectRmPppoeConfigMainList" parameterType="RmPppoeConfigMain" resultMap="RmPppoeConfigMainResult">
        <include refid="selectRmPppoeConfigMainVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="pppoeEnabled != null "> and pppoe_enabled = #{pppoeEnabled}</if>
            <if test="pppoeConfigMode != null  and pppoeConfigMode != ''"> and pppoe_config_mode = #{pppoeConfigMode}</if>
            <if test="pppoeInterface != null  and pppoeInterface != ''"> and pppoe_interface = #{pppoeInterface}</if>
        </where>
    </select>
    
    <select id="selectRmPppoeConfigMainById" parameterType="Long" resultMap="RmPppoeConfigMainResult">
        <include refid="selectRmPppoeConfigMainVo"/>
        where id = #{id}
    </select>
    <select id="selectRmPppoeConfigMainByClientId" parameterType="RmPppoeConfigMain" resultMap="RmPppoeConfigMainResult">
        <include refid="selectRmPppoeConfigMainVo"/>
        where client_id = #{clientId}
    </select>
    <insert id="insertRmPppoeConfigMain" parameterType="RmPppoeConfigMain" useGeneratedKeys="true" keyProperty="id">
        insert into rm_pppoe_config_main
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null">client_id,</if>
            <if test="pppoeEnabled != null">pppoe_enabled,</if>
            <if test="pppoeConfigMode != null">pppoe_config_mode,</if>
            <if test="pppoeInterface != null">pppoe_interface,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientId != null">#{clientId},</if>
            <if test="pppoeEnabled != null">#{pppoeEnabled},</if>
            <if test="pppoeConfigMode != null">#{pppoeConfigMode},</if>
            <if test="pppoeInterface != null">#{pppoeInterface},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
        ON DUPLICATE KEY UPDATE
        pppoe_enabled = CASE
        WHEN pppoe_enabled = VALUES(pppoe_enabled) THEN pppoe_enabled
        WHEN VALUES(pppoe_enabled) IS NULL THEN pppoe_enabled
        ELSE VALUES(pppoe_enabled)
        END,
        pppoe_config_mode = CASE
        WHEN pppoe_config_mode = VALUES(pppoe_config_mode) THEN pppoe_config_mode
        WHEN VALUES(pppoe_config_mode) IS NULL THEN pppoe_config_mode
        ELSE VALUES(pppoe_config_mode)
        END,
        pppoe_interface = CASE
        WHEN pppoe_interface = VALUES(pppoe_interface) THEN pppoe_interface
        WHEN VALUES(pppoe_interface) IS NULL THEN pppoe_interface
        ELSE VALUES(pppoe_interface)
        END
    </insert>

    <update id="updateRmPppoeConfigMain" parameterType="RmPppoeConfigMain">
        update rm_pppoe_config_main
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="pppoeEnabled != null">pppoe_enabled = #{pppoeEnabled},</if>
            <if test="pppoeConfigMode != null">pppoe_config_mode = #{pppoeConfigMode},</if>
            <if test="pppoeInterface != null">pppoe_interface = #{pppoeInterface},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRmPppoeConfigMainById" parameterType="Long">
        delete from rm_pppoe_config_main where id = #{id}
    </delete>

    <delete id="deleteRmPppoeConfigMainByIds" parameterType="String">
        delete from rm_pppoe_config_main where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>