<?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.RmFrpcPortMappingMapper">
    
    <resultMap type="RmFrpcPortMapping" id="RmFrpcPortMappingResult">
        <result property="id"    column="id"    />
        <result property="startRemotePort"    column="start_remote_port"    />
        <result property="endRemotePort"    column="end_remote_port"    />
        <result property="serverPort"    column="server_port"    />
        <result property="serverAddr"    column="server_addr"    />
        <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="selectRmFrpcPortMappingVo">
        select id, start_remote_port, end_remote_port, server_port, server_addr, create_time, update_time, create_by, update_by from rm_frpc_port_mapping
    </sql>

    <select id="selectRmFrpcPortMappingList" parameterType="RmFrpcPortMapping" resultMap="RmFrpcPortMappingResult">
        <include refid="selectRmFrpcPortMappingVo"/>
        <where>  
            <if test="startRemotePort != null "> and start_remote_port = #{startRemotePort}</if>
            <if test="endRemotePort != null "> and end_remote_port = #{endRemotePort}</if>
            <if test="serverPort != null "> and server_port = #{serverPort}</if>
            <if test="serverAddr != null  and serverAddr != ''"> and server_addr = #{serverAddr}</if>
        </where>
    </select>
    
    <select id="selectRmFrpcPortMappingById" parameterType="Long" resultMap="RmFrpcPortMappingResult">
        <include refid="selectRmFrpcPortMappingVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmFrpcPortMapping" parameterType="RmFrpcPortMapping" useGeneratedKeys="true" keyProperty="id">
        insert into rm_frpc_port_mapping
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="startRemotePort != null">start_remote_port,</if>
            <if test="endRemotePort != null">end_remote_port,</if>
            <if test="serverPort != null">server_port,</if>
            <if test="serverAddr != null">server_addr,</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="startRemotePort != null">#{startRemotePort},</if>
            <if test="endRemotePort != null">#{endRemotePort},</if>
            <if test="serverPort != null">#{serverPort},</if>
            <if test="serverAddr != null">#{serverAddr},</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>
    </insert>

    <update id="updateRmFrpcPortMapping" parameterType="RmFrpcPortMapping">
        update rm_frpc_port_mapping
        <trim prefix="SET" suffixOverrides=",">
            <if test="startRemotePort != null">start_remote_port = #{startRemotePort},</if>
            <if test="endRemotePort != null">end_remote_port = #{endRemotePort},</if>
            <if test="serverPort != null">server_port = #{serverPort},</if>
            <if test="serverAddr != null">server_addr = #{serverAddr},</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="deleteRmFrpcPortMappingById" parameterType="Long">
        delete from rm_frpc_port_mapping where id = #{id}
    </delete>

    <delete id="deleteRmFrpcPortMappingByIds" parameterType="String">
        delete from rm_frpc_port_mapping where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <!-- 清空指定表 -->
    <delete id="truncateFrpcPortMapping">
        TRUNCATE TABLE rm_frpc_port_mapping
    </delete>
</mapper>