<?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.RmAgentManagementMapper">

    <resultMap type="RmAgentManagement" id="RmAgentManagementResult">
        <result property="id"    column="id"    />
        <result property="hardwareSn"    column="hardware_sn"    />
        <result property="resourceName"    column="resource_name"    />
        <result property="internalIp"    column="internal_ip"    />
        <result property="status"    column="status"    />
        <result property="agentVersion"    column="agent_version"    />
        <result property="method"    column="method"    />
        <result property="scheduledUpdateTime"    column="scheduled_update_time"    />
        <result property="fileUrlType"    column="file_url_type"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileDirectory"    column="file_directory"    />
        <result property="lastUpdateResult"    column="last_update_result"    />
        <result property="lastUpdateTime"    column="last_update_time"    />
        <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="fileMd5"    column="file_md5"    />
        <result property="clientId"    column="client_id"    />
        <result property="deployDevice"    column="deploy_device"    />
    </resultMap>

    <sql id="selectRmAgentManagementVo">
        select id, hardware_sn, resource_name, internal_ip, status, agent_version, method, scheduled_update_time, file_url_type, file_url, file_directory, last_update_result, last_update_time, create_time, update_time, create_by, update_by, file_md5, client_id, deploy_device from rm_agent_management
    </sql>

    <select id="selectRmAgentManagementList" parameterType="RmAgentManagement" resultMap="RmAgentManagementResult">
        <include refid="selectRmAgentManagementVo"/>
        <where>
            <if test="hardwareSn != null  and hardwareSn != ''"> and hardware_sn = #{hardwareSn}</if>
            <if test="resourceName != null  and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
            <if test="internalIp != null  and internalIp != ''"> and internal_ip = #{internalIp}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="agentVersion != null  and agentVersion != ''"> and agent_version = #{agentVersion}</if>
            <if test="method != null "> and method = #{method}</if>
            <if test="scheduledUpdateTime != null  and scheduledUpdateTime != ''"> and scheduled_update_time = #{scheduledUpdateTime}</if>
            <if test="fileUrlType != null "> and file_url_type = #{fileUrlType}</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="fileDirectory != null  and fileDirectory != ''"> and file_directory = #{fileDirectory}</if>
            <if test="lastUpdateResult != null  and lastUpdateResult != ''"> and last_update_result = #{lastUpdateResult}</if>
            <if test="lastUpdateTime != null "> and last_update_time = #{lastUpdateTime}</if>
            <if test="fileMd5 != null  and fileMd5 != ''"> and file_md5 = #{fileMd5}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="deployDevice != null  and deployDevice != ''"> and deploy_device = #{deployDevice}</if>
            <if test="queryName != null and queryName != '' "> and (resource_name like concat('%', #{resourceName}, '%') or internal_ip = #{internalIp})</if>
        </where>
        order by last_update_time desc
    </select>

    <select id="selectRmAgentManagementById" parameterType="Long" resultMap="RmAgentManagementResult">
        <include refid="selectRmAgentManagementVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmAgentManagement" parameterType="RmAgentManagement" useGeneratedKeys="true" keyProperty="id">
        insert into rm_agent_management
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hardwareSn != null and hardwareSn != ''">hardware_sn,</if>
            <if test="resourceName != null and resourceName != ''">resource_name,</if>
            <if test="internalIp != null">internal_ip,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="agentVersion != null">agent_version,</if>
            <if test="method != null">method,</if>
            <if test="scheduledUpdateTime != null">scheduled_update_time,</if>
            <if test="fileUrlType != null">file_url_type,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="fileDirectory != null">file_directory,</if>
            <if test="lastUpdateResult != null">last_update_result,</if>
            <if test="lastUpdateTime != null">last_update_time,</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="fileMd5 != null">file_md5,</if>
            <if test="clientId != null">client_id,</if>
            <if test="deployDevice != null">deploy_device,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="hardwareSn != null and hardwareSn != ''">#{hardwareSn},</if>
            <if test="resourceName != null and resourceName != ''">#{resourceName},</if>
            <if test="internalIp != null">#{internalIp},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="agentVersion != null">#{agentVersion},</if>
            <if test="method != null">#{method},</if>
            <if test="scheduledUpdateTime != null">#{scheduledUpdateTime},</if>
            <if test="fileUrlType != null">#{fileUrlType},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileDirectory != null">#{fileDirectory},</if>
            <if test="lastUpdateResult != null">#{lastUpdateResult},</if>
            <if test="lastUpdateTime != null">#{lastUpdateTime},</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="fileMd5 != null">#{fileMd5},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="deployDevice != null">#{deployDevice},</if>
        </trim>
    </insert>

    <update id="updateRmAgentManagement" parameterType="RmAgentManagement">
        update rm_agent_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="hardwareSn != null and hardwareSn != ''">hardware_sn = #{hardwareSn},</if>
            <if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
            <if test="internalIp != null">internal_ip = #{internalIp},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="agentVersion != null">agent_version = #{agentVersion},</if>
            <if test="method != null">method = #{method},</if>
            <if test="scheduledUpdateTime != null">scheduled_update_time = #{scheduledUpdateTime},</if>
            <if test="fileUrlType != null">file_url_type = #{fileUrlType},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileDirectory != null">file_directory = #{fileDirectory},</if>
            <if test="lastUpdateResult != null">last_update_result = #{lastUpdateResult},</if>
            <if test="lastUpdateTime != null">last_update_time = #{lastUpdateTime},</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="fileMd5 != null">file_md5 = #{fileMd5},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="deployDevice != null">deploy_device = #{deployDevice},</if>
        </trim>
        <where>
            <choose>
                <when test="id != null">
                    and id = #{id}
                </when>
                <when test="clientId != null and clientId != ''">
                    and client_id = #{clientId}
                </when>
                <otherwise>
                    and 1=0 <!-- 如果没有提供任何条件，则不更新任何记录 -->
                </otherwise>
            </choose>
        </where>
    </update>

    <delete id="deleteRmAgentManagementById" parameterType="Long">
        delete from rm_agent_management where id = #{id}
    </delete>

    <delete id="deleteRmAgentManagementByIds" parameterType="String">
        delete from rm_agent_management where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="updateRmAgentManagementBySn" parameterType="RmAgentManagement">
        update rm_agent_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
            <if test="internalIp != null">internal_ip = #{internalIp},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="agentVersion != null">agent_version = #{agentVersion},</if>
            <if test="method != null">method = #{method},</if>
            <if test="scheduledUpdateTime != null">scheduled_update_time = #{scheduledUpdateTime},</if>
            <if test="fileUrlType != null">file_url_type = #{fileUrlType},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileDirectory != null">file_directory = #{fileDirectory},</if>
            <if test="lastUpdateResult != null">last_update_result = #{lastUpdateResult},</if>
            <if test="lastUpdateTime != null">last_update_time = #{lastUpdateTime},</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>
        </trim>
        <where>
            <choose>
                <when test="id != null">
                    and id = #{id}
                </when>
                <when test="clientId != null and clientId != ''">
                    and client_id = #{clientId}
                </when>
                <when test="hardwareSn != null and hardwareSn != ''">
                    and hardware_sn = #{hardwareSn}
                </when>
                <otherwise>
                    and 1=0 <!-- 如果没有提供任何条件，则不更新任何记录 -->
                </otherwise>
            </choose>
        </where>
    </update>
</mapper>