<?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.ruoyi.system.mapper.SysInterfaceForeignMapper">
    
    <resultMap type="SysInterfaceForeign" id="SysInterfaceForeignResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="secretKey"    column="secret_key"    />
        <result property="ip"    column="ip"    />
        <result property="equipId"    column="equip_id"    />
        <result property="number"    column="number"    />
        <result property="remainingNumber"    column="remaining_number"    />
    </resultMap>

    <sql id="selectSysInterfaceForeignVo">
        select id, name, secret_key, ip, equip_id, number, remaining_number from sys_interface_foreign
    </sql>

    <select id="selectSysInterfaceForeignList" parameterType="SysInterfaceForeign" resultMap="SysInterfaceForeignResult">
        <include refid="selectSysInterfaceForeignVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
        </where>
    </select>
    
    <select id="selectSysInterfaceForeignById" parameterType="Long" resultMap="SysInterfaceForeignResult">
        <include refid="selectSysInterfaceForeignVo"/>
        where id = #{id}
    </select>
    <select id="getForeignByKey" resultMap="SysInterfaceForeignResult">
        <include refid="selectSysInterfaceForeignVo"/>
        where secret_key = #{secretKey}
    </select>

    <insert id="insertSysInterfaceForeign" parameterType="SysInterfaceForeign">
        insert into sys_interface_foreign
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="secretKey != null">secret_key,</if>
            <if test="ip != null">ip,</if>
            <if test="equipId != null">equip_id,</if>
            <if test="number != null">number,</if>
            <if test="remainingNumber != null">remaining_number,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="secretKey != null">#{secretKey},</if>
            <if test="ip != null">#{ip},</if>
            <if test="equipId != null">#{equipId},</if>
            <if test="number != null">#{number},</if>
            <if test="remainingNumber != null">#{remainingNumber},</if>
         </trim>
    </insert>

    <update id="updateSysInterfaceForeign" parameterType="SysInterfaceForeign">
        update sys_interface_foreign
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="secretKey != null">secret_key = #{secretKey},</if>
            <if test="ip != null">ip = #{ip},</if>
            <if test="equipId != null">equip_id = #{equipId},</if>
            <if test="number != null">number = #{number},</if>
            <if test="remainingNumber != null">remaining_number = #{remainingNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysInterfaceForeignById" parameterType="Long">
        delete from sys_interface_foreign where id = #{id}
    </delete>

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