<?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.GatewayInterfaceInfoMapper">
    
    <resultMap type="GatewayInterfaceInfo" id="GatewayInterfaceInfoResult">
        <result property="id"    column="id"    />
        <result property="interfaceName"    column="interface_name"    />
        <result property="interfacePath"    column="interface_path"    />
        <result property="requestMethod"    column="request_method"    />
        <result property="description"    column="description"    />
        <result property="version"    column="version"    />
        <result property="status"    column="status"    />
        <result property="document"    column="document"    />
        <result property="created"    column="created"    />
        <result property="createTime"    column="create_time"    />
        <result property="modified"    column="modified"    />
        <result property="updateTime"    column="update_time"    />
        <result property="uriRegular"    column="uri_regular"    />
        <result property="serverId"    column="server_id"    />
    </resultMap>

    <sql id="selectGatewayInterfaceInfoVo">
        select id, interface_name, interface_path, request_method,
               description, version, status, document, created,
               create_time, modified, update_time ,
               uri_regular,server_id
        from Gateway_interface_info
    </sql>

    <select id="selectGatewayInterfaceInfoList" parameterType="GatewayInterfaceInfo" resultMap="GatewayInterfaceInfoResult">
        <include refid="selectGatewayInterfaceInfoVo"/>
        <where>  
            <if test="interfaceName != null  and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</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>
        </where>
    </select>
    
    <select id="selectGatewayInterfaceInfoById" parameterType="Long" resultMap="GatewayInterfaceInfoResult">
        <include refid="selectGatewayInterfaceInfoVo"/>
        where id = #{id}
    </select>
    <select id="selectGatewayInterfaceInfoByServerIds" resultMap="GatewayInterfaceInfoResult">
        <include refid="selectGatewayInterfaceInfoVo"/>
        where server_id in
        <foreach item="serverId" collection="serverIds" open="(" separator="," close=")">
            #{serverId}
        </foreach>
    </select>

    <insert id="insertGatewayInterfaceInfo" parameterType="GatewayInterfaceInfo" useGeneratedKeys="true" keyProperty="id">
        insert into Gateway_interface_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="interfaceName != null and interfaceName != ''">interface_name,</if>
            <if test="interfacePath != null and interfacePath != ''">interface_path,</if>
            <if test="requestMethod != null and requestMethod != ''">request_method,</if>
            <if test="description != null">description,</if>
            <if test="version != null">version,</if>
            <if test="status != null">status,</if>
            <if test="document != null">document,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="appCode != null">app_code,</if>
            <if test="created != null">created,</if>
            <if test="modified != null">modified,</if>
            <if test="uriRegular != null">uri_regular,</if>
            <if test="serverId != null">server_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
            <if test="interfacePath != null and interfacePath != ''">#{interfacePath},</if>
            <if test="requestMethod != null and requestMethod != ''">#{requestMethod},</if>
            <if test="description != null">#{description},</if>
            <if test="version != null">#{version},</if>
            <if test="status != null">#{status},</if>
            <if test="document != null">#{document},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="appCode != null">#{appCode},</if>
            <if test="created != null">#{created},</if>
            <if test="modified != null">#{modified},</if>
            <if test="uriRegular != null">#{uriRegular},</if>
            <if test="serverId != null">#{serverId},</if>
         </trim>
    </insert>

    <update id="updateGatewayInterfaceInfo" parameterType="GatewayInterfaceInfo">
        update Gateway_interface_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</if>
            <if test="interfacePath != null and interfacePath != ''">interface_path = #{interfacePath},</if>
            <if test="requestMethod != null and requestMethod != ''">request_method = #{requestMethod},</if>
            <if test="description != null">description = #{description},</if>
            <if test="version != null">version = #{version},</if>
            <if test="status != null">status = #{status},</if>
            <if test="document != null">document = #{document},</if>
            <if test="modified != null">modified = #{modified},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="uriRegular != null">uri_regular = #{uriRegular},</if>
            <if test="serverId != null">server_id = #{serverId},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateGatewayInterfaceInfoStatusByIds">
        update Gateway_interface_info
        set status = #{status}
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteGatewayInterfaceInfoById" parameterType="Long">
        delete from Gateway_interface_info where id = #{id}
    </delete>

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