<?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.GatewayStrategyMapper">
    
    <resultMap type="GatewayStrategy" id="GatewayStrategyResult">
        <result property="id"    column="id"    />
        <result property="strategyName"    column="strategy_name"    />
        <result property="strategyType"    column="strategy_type"    />
        <result property="description"    column="description"    />
        <result property="requestMethod"    column="request_method"    />
        <result property="status"    column="status"    />
        <result property="currentLimitingThreshold"    column="current_limiting_threshold"    />
        <result property="currentLimitingTimeWindow"    column="current_limiting_time_window"    />
        <result property="currentLimitingResponse"    column="current_limiting_response"    />
        <result property="circuitBreakerThreshold"    column="circuit_breaker_threshold"    />
        <result property="circuitBreakerTimeWindow"    column="circuit_breaker_time_window"    />
        <result property="circuitBreakerRecoveryInterval"    column="circuit_breaker_recovery_interval"    />
        <result property="circuitBreakerResponse"    column="circuit_breaker_response"    />
        <result property="created"    column="created"    />
        <result property="createTime"    column="create_time"    />
        <result property="modified"    column="modified"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectGatewayStrategyVo">
        select id, strategy_name, strategy_type,
               description, request_method, status,
               current_limiting_threshold,current_limiting_time_window,current_limiting_response,
               circuit_breaker_threshold, circuit_breaker_time_window,circuit_breaker_recovery_interval,circuit_breaker_response,
               created, create_time, modified, update_time
        from Gateway_strategy
    </sql>

    <select id="selectGatewayStrategyList" parameterType="GatewayStrategy" resultMap="GatewayStrategyResult">
        <include refid="selectGatewayStrategyVo"/>
        <where>  
            <if test="strategyName != null  and strategyName != ''"> and strategy_name like concat('%', #{strategyName}, '%')</if>
            <if test="strategyType != null  and strategyType != ''"> and strategy_type = #{strategyType}</if>
            <if test="requestMethod != null  and requestMethod != ''"> and request_method = #{requestMethod}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="appCode != null  and appCode != ''"> 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="selectGatewayStrategyById" parameterType="Long" resultMap="GatewayStrategyResult">
        <include refid="selectGatewayStrategyVo"/>
        where id = #{id}
    </select>

    <select id="selectGatewayStrategyByIds" resultMap="GatewayStrategyResult">
        <include refid="selectGatewayStrategyVo"/>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertGatewayStrategy" parameterType="GatewayStrategy" useGeneratedKeys="true" keyProperty="id">
        insert into Gateway_strategy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="strategyName != null and strategyName != ''">strategy_name,</if>
            <if test="strategyType != null and strategyType != ''">strategy_type,</if>
            <if test="description != null">description,</if>
            <if test="requestMethod != null and requestMethod != ''">request_method,</if>
            <if test="status != null">status,</if>
            <if test="currentLimitingThreshold != null">current_limiting_threshold,</if>
            <if test="currentLimitingTimeWindow != null">current_limiting_time_window,</if>
            <if test="currentLimitingResponse != null">current_limiting_response,</if>
            <if test="circuitBreakerThreshold != null">circuit_breaker_threshold,</if>
            <if test="circuitBreakerTimeWindow != null">circuit_breaker_time_window,</if>
            <if test="circuitBreakerRecoveryInterval != null">circuit_breaker_recovery_interval,</if>
            <if test="circuitBreakerResponse != null">circuit_breaker_response,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="strategyName != null and strategyName != ''">#{strategyName},</if>
            <if test="strategyType != null and strategyType != ''">#{strategyType},</if>
            <if test="description != null">#{description},</if>
            <if test="requestMethod != null and requestMethod != ''">#{requestMethod},</if>
            <if test="status != null">#{status},</if>
            <if test="currentLimitingThreshold != null">#{currentLimitingThreshold},</if>
            <if test="currentLimitingTimeWindow != null">#{currentLimitingTimeWindow},</if>
            <if test="currentLimitingResponse != null">#{currentLimitingResponse},</if>
            <if test="circuitBreakerThreshold != null">#{circuitBreakerThreshold},</if>
            <if test="circuitBreakerTimeWindow != null">#{circuitBreakerTimeWindow},</if>
            <if test="circuitBreakerRecoveryInterval != null">#{circuitBreakerRecoveryInterval},</if>
            <if test="circuitBreakerResponse != null">#{circuitBreakerResponse},</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>
         </trim>
    </insert>

    <update id="updateGatewayStrategy" parameterType="GatewayStrategy">
        update Gateway_strategy
        <trim prefix="SET" suffixOverrides=",">
            <if test="strategyName != null and strategyName != ''">strategy_name = #{strategyName},</if>
            <if test="strategyType != null and strategyType != ''">strategy_type = #{strategyType},</if>
            <if test="description != null">description = #{description},</if>
            <if test="requestMethod != null and requestMethod != ''">request_method = #{requestMethod},</if>
            <if test="status != null">status = #{status},</if>
            <if test="currentLimitingThreshold != null">current_limiting_threshold = #{currentLimitingThreshold},</if>
            <if test="currentLimitingTimeWindow != null">current_limiting_time_window = #{currentLimitingTimeWindow},</if>
            <if test="currentLimitingResponse != null">current_limiting_response = #{currentLimitingResponse},</if>
            <if test="circuitBreakerThreshold != null">circuit_breaker_threshold = #{circuitBreakerThreshold},</if>
            <if test="circuitBreakerTimeWindow != null">circuit_breaker_time_window = #{circuitBreakerTimeWindow},</if>
            <if test="circuitBreakerRecoveryInterval != null">circuit_breaker_recovery_interval = #{circuitBreakerRecoveryInterval},</if>
            <if test="circuitBreakerResponse != null">circuit_breaker_response = #{circuitBreakerResponse},</if>
            <if test="modified != null">modified = #{modified},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

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

    <delete id="deleteGatewayStrategyById" parameterType="Long">
        delete from Gateway_strategy where id = #{id}
    </delete>

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