<?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.GatewayRouteMapper">
    
    <resultMap type="GatewayRoute" id="GatewayRouteResult">
        <result property="id"    column="id"    />
        <result property="routeName"    column="route_name"    />
        <result property="requestProtocol"    column="request_protocol"    />
        <result property="routeType"    column="route_type"    />
        <result property="routeContent"    column="route_content"    />
        <result property="routeStatusActiveMonitoring"    column="route_status_active_monitoring"    />
        <result property="routeActiveMonitoringPath"    column="route_active_monitoring_path"    />
        <result property="routeActiveMonitoringTimeout"    column="route_active_monitoring_timeout"    />
        <result property="created"    column="created"    />
        <result property="createTime"    column="create_time"    />
        <result property="modified"    column="modified"    />
        <result property="updateTime"    column="update_time"    />
        <result property="appCode"    column="app_code"    />
        <result property="routeActiveStatus"    column="route_active_status"    />
    </resultMap>

    <sql id="selectGatewayRouteVo">
        select id, route_name, request_protocol, route_type,
               route_content, route_status_active_monitoring, route_active_monitoring_path,
               route_active_monitoring_timeout, created, create_time, 
               modified,update_time ,app_code,route_active_status
        from Gateway_route
    </sql>

    <select id="selectGatewayRouteList" parameterType="GatewayRoute" resultMap="GatewayRouteResult">
        <include refid="selectGatewayRouteVo"/>
        <where>  
            <if test="routeName != null  and routeName != ''"> and route_name like concat('%', #{routeName}, '%')</if>
            <if test="requestProtocol != null  and requestProtocol != ''"> and request_protocol = #{requestProtocol}</if>
            <if test="created != null "> and created = #{created}</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="selectGatewayRouteById" parameterType="Long" resultMap="GatewayRouteResult">
        <include refid="selectGatewayRouteVo"/>
        where id = #{id}
    </select>
    <select id="selectGatewayRouteByIds" resultMap="GatewayRouteResult">
        <include refid="selectGatewayRouteVo"/>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertGatewayRoute" parameterType="GatewayRoute" useGeneratedKeys="true" keyProperty="id">
        insert into Gateway_route
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="routeName != null and routeName != ''">route_name,</if>
            <if test="requestProtocol != null and requestProtocol != ''">request_protocol,</if>
            <if test="routeType != null and routeType != ''">route_type,</if>
            <if test="routeContent != null">route_content,</if>
            <if test="routeStatusActiveMonitoring != null">route_status_active_monitoring,</if>
            <if test="routeActiveMonitoringPath != null">route_active_monitoring_path,</if>
            <if test="routeActiveMonitoringTimeout != null">route_active_monitoring_timeout,</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="routeActiveStatus != null">route_active_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="routeName != null and routeName != ''">#{routeName},</if>
            <if test="requestProtocol != null and requestProtocol != ''">#{requestProtocol},</if>
            <if test="routeType != null and routeType != ''">#{routeType},</if>
            <if test="routeContent != null">#{routeContent},</if>
            <if test="routeStatusActiveMonitoring != null">#{routeStatusActiveMonitoring},</if>
            <if test="routeActiveMonitoringPath != null">#{routeActiveMonitoringPath},</if>
            <if test="routeActiveMonitoringTimeout != null">#{routeActiveMonitoringTimeout},</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="routeActiveStatus != null">#{routeActiveStatus},</if>
         </trim>
    </insert>

    <update id="updateGatewayRoute" parameterType="GatewayRoute">
        update Gateway_route
        <trim prefix="SET" suffixOverrides=",">
            <if test="routeName != null and routeName != ''">route_name = #{routeName},</if>
            <if test="requestProtocol != null and requestProtocol != ''">request_protocol = #{requestProtocol},</if>
            <if test="routeType != null and routeType != ''">route_type = #{routeType},</if>
            <if test="routeContent != null">route_content = #{routeContent},</if>
            <if test="routeStatusActiveMonitoring != null">route_status_active_monitoring = #{routeStatusActiveMonitoring},</if>
            <if test="routeActiveMonitoringPath != null">route_active_monitoring_path = #{routeActiveMonitoringPath},</if>
            <if test="routeActiveMonitoringTimeout != null">route_active_monitoring_timeout = #{routeActiveMonitoringTimeout},</if>
            <if test="created != null">created = #{created},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="modified != null">modified = #{modified},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="appCode != null">app_code = #{appCode},</if>
            <if test="routeActiveStatus != null">route_active_status = #{routeActiveStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGatewayRouteById" parameterType="Long">
        delete from Gateway_route where id = #{id}
    </delete>

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