<?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.sf.service.gateway.mapper.GatewayServerMapper">
    
    <resultMap type="GatewayServer" id="GatewayServerResult">
        <result property="id"    column="id"    />
        <result property="serverName"    column="server_name"    />
        <result property="serverAddress"    column="server_address"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
        <result property="created"    column="created"    />
        <result property="createTime"    column="create_time"    />
        <result property="modified"    column="modified"    />
        <result property="updateTime"    column="update_time"    />
        <result property="serviceModel"    column="service_model"    />
        <result property="routeId"    column="route_id"    />
    </resultMap>

    <sql id="selectGatewayServerVo">
        select id, server_name, server_address, remark,
               status, created, create_time, modified, update_time ,
               service_model,route_id
        from Gateway_server
    </sql>

    <select id="selectGatewayServerList" parameterType="GatewayServer" resultMap="GatewayServerResult">
        <include refid="selectGatewayServerVo"/>
        <where>  
            <if test="serverName != null  and serverName != ''"> and server_name like concat('%', #{serverName}, '%')</if>
            <if test="serverAddress != null  and serverAddress != ''"> and server_address = #{serverAddress}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="serviceModel != null"> and service_model = #{serviceModel}</if>
            <if test="created != null "> and created = #{created}</if>
            <if test="appCode != null "> and app_code = #{appCode}</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
            <if test="params.ids != null and params.ids.size() > 0">
                and id in
                <foreach item="id" collection="params.ids" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="params.excludedIds != null and params.excludedIds.size() > 0">
                and id not in
                <foreach item="id" collection="params.excludedIds" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectGatewayServerById" parameterType="Long" resultMap="GatewayServerResult">
        <include refid="selectGatewayServerVo"/>
        where id = #{id}
    </select>

    <select id="selectGatewayServerByIds"  resultMap="GatewayServerResult">
        <include refid="selectGatewayServerVo"/>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="selectGatewayServerByRouteIds"  resultMap="GatewayServerResult">
        <include refid="selectGatewayServerVo"/>
        where route_id in
        <foreach item="id" collection="routeIds" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertGatewayServer" parameterType="GatewayServer" useGeneratedKeys="true" keyProperty="id">
        insert into Gateway_server
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serverName != null and serverName != ''">server_name,</if>
            <if test="serverAddress != null and serverAddress != ''">server_address,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</if>
            <if test="created != null">created,</if>
            <if test="createTime != null">create_time,</if>
            <if test="modified != null">modified,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="appCode != null">app_code,</if>
            <if test="serviceModel != null">service_model,</if>
            <if test="routeId != null">route_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serverName != null and serverName != ''">#{serverName},</if>
            <if test="serverAddress != null and serverAddress != ''">#{serverAddress},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
            <if test="created != null">#{created},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="modified != null">#{modified},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="appCode != null">#{appCode},</if>
            <if test="serviceModel != null">#{serviceModel},</if>
            <if test="routeId != null">#{routeId},</if>
         </trim>
    </insert>

    <update id="updateGatewayServer" parameterType="GatewayServer">
        update Gateway_server
        <trim prefix="SET" suffixOverrides=",">
            <if test="serverName != null and serverName != ''">server_name = #{serverName},</if>
            <if test="serverAddress != null and serverAddress != ''">server_address = #{serverAddress},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
            <if test="modified != null">modified = #{modified},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="serviceModel != null">service_model = #{serviceModel},</if>
            <if test="routeId != null">route_id = #{routeId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateGatewayServerStatusByIds">
        update Gateway_server
        set status = #{status}
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteGatewayServerById" parameterType="Long">
        delete from Gateway_server where id = #{id}
    </delete>

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