<?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.rocketmq.mapper.RmResourceRemoteMapper">

    <resultMap type="RmResourceRemote" id="RmResourceRemoteResult">
        <result property="id"    column="id"    />
        <result property="hardwareSn"    column="hardware_sn"    />
        <result property="resourceType"    column="resource_type"    />
        <result property="resourceName"    column="resource_name"    />
        <result property="description"    column="description"    />
        <result property="internalIp"    column="internal_ip"    />
        <result property="externalIp"    column="external_ip"    />
        <result property="managementPort"    column="management_port"    />
        <result property="onlineStatus"    column="online_status"    />
        <result property="connectionMethod"    column="connection_method"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="clientId"    column="client_id"    />
        <result property="resultFlag"    column="result_flag"    />
        <result property="scriptId"    column="script_id"    />
    </resultMap>

    <sql id="selectRmResourceRemoteVo">
        select id, hardware_sn, resource_type, resource_name, description, internal_ip, external_ip, management_port, online_status, connection_method, create_time, update_time, create_by, update_by, client_id, result_flag, script_id from rm_resource_remote
    </sql>

    <select id="selectRmResourceRemoteList" parameterType="RmResourceRemote" resultMap="RmResourceRemoteResult">
        <include refid="selectRmResourceRemoteVo"/>
        <where>
            <if test="hardwareSn != null  and hardwareSn != ''"> and hardware_sn = #{hardwareSn}</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
            <if test="resourceName != null  and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="internalIp != null  and internalIp != ''"> and internal_ip = #{internalIp}</if>
            <if test="externalIp != null  and externalIp != ''"> and external_ip = #{externalIp}</if>
            <if test="managementPort != null "> and management_port = #{managementPort}</if>
            <if test="onlineStatus != null  and onlineStatus != ''"> and online_status = #{onlineStatus}</if>
            <if test="connectionMethod != null  and connectionMethod != ''"> and connection_method = #{connectionMethod}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="resultFlag != null "> and result_flag = #{resultFlag}</if>
            <if test="scriptId != null "> and script_id = #{scriptId}</if>
        </where>
    </select>

    <select id="selectRmResourceRemoteById" parameterType="Long" resultMap="RmResourceRemoteResult">
        <include refid="selectRmResourceRemoteVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmResourceRemote" parameterType="RmResourceRemote" useGeneratedKeys="true" keyProperty="id">
        insert into rm_resource_remote
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hardwareSn != null and hardwareSn != ''">hardware_sn,</if>
            <if test="resourceType != null and resourceType != ''">resource_type,</if>
            <if test="resourceName != null and resourceName != ''">resource_name,</if>
            <if test="description != null">description,</if>
            <if test="internalIp != null">internal_ip,</if>
            <if test="externalIp != null">external_ip,</if>
            <if test="managementPort != null">management_port,</if>
            <if test="onlineStatus != null and onlineStatus != ''">online_status,</if>
            <if test="connectionMethod != null">connection_method,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="clientId != null">client_id,</if>
            <if test="resultFlag != null">result_flag,</if>
            <if test="scriptId != null">script_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="hardwareSn != null and hardwareSn != ''">#{hardwareSn},</if>
            <if test="resourceType != null and resourceType != ''">#{resourceType},</if>
            <if test="resourceName != null and resourceName != ''">#{resourceName},</if>
            <if test="description != null">#{description},</if>
            <if test="internalIp != null">#{internalIp},</if>
            <if test="externalIp != null">#{externalIp},</if>
            <if test="managementPort != null">#{managementPort},</if>
            <if test="onlineStatus != null and onlineStatus != ''">#{onlineStatus},</if>
            <if test="connectionMethod != null">#{connectionMethod},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="resultFlag != null">#{resultFlag},</if>
            <if test="scriptId != null">#{scriptId},</if>
        </trim>
    </insert>

    <update id="updateRmResourceRemote" parameterType="RmResourceRemote">
        update rm_resource_remote
        <trim prefix="SET" suffixOverrides=",">
            <if test="hardwareSn != null and hardwareSn != ''">hardware_sn = #{hardwareSn},</if>
            <if test="resourceType != null and resourceType != ''">resource_type = #{resourceType},</if>
            <if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="internalIp != null">internal_ip = #{internalIp},</if>
            <if test="externalIp != null">external_ip = #{externalIp},</if>
            <if test="managementPort != null">management_port = #{managementPort},</if>
            <if test="onlineStatus != null and onlineStatus != ''">online_status = #{onlineStatus},</if>
            <if test="connectionMethod != null">connection_method = #{connectionMethod},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="resultFlag != null">result_flag = #{resultFlag},</if>
            <if test="scriptId != null">script_id = #{scriptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRmResourceRemoteById" parameterType="Long">
        delete from rm_resource_remote where id = #{id}
    </delete>

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