<?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.InitialDockerInfoMapper">
    
    <resultMap type="InitialDockerInfo" id="InitialDockerInfoResult">
        <result property="autoId"    column="auto_id"    />
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="status"    column="status"    />
        <result property="cpuUtil"    column="cpu_util"    />
        <result property="memUtil"    column="mem_util"    />
        <result property="netInSpeed"    column="net_in_speed"    />
        <result property="netOutSpeed"    column="net_out_speed"    />
        <result property="clientId"    column="client_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectInitialDockerInfoVo">
        select auto_id, id, name, status, cpu_util, mem_util, net_in_speed, net_out_speed, client_id, create_time, update_time, create_by, update_by from initial_docker_info
    </sql>

    <select id="selectInitialDockerInfoList" parameterType="InitialDockerInfo" resultMap="InitialDockerInfoResult">
        <include refid="selectInitialDockerInfoVo"/>
        <where>  
            <if test="id != null"> and id = #{id}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="startTime != null  and startTime != ''"> and create_time &gt;= #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and create_time &lt;= #{endTime}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectInitialDockerInfoById" parameterType="Long" resultMap="InitialDockerInfoResult">
        <include refid="selectInitialDockerInfoVo"/>
        where auto_id = #{autoId}
    </select>

    <insert id="insertInitialDockerInfo" parameterType="InitialDockerInfo" useGeneratedKeys="true" keyProperty="auto_id">
        insert IGNORE into initial_docker_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="cpuUtil != null">cpu_util,</if>
            <if test="memUtil != null">mem_util,</if>
            <if test="netInSpeed != null">net_in_speed,</if>
            <if test="netOutSpeed != null">net_out_speed,</if>
            <if test="clientId != null">client_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="cpuUtil != null">#{cpuUtil},</if>
            <if test="memUtil != null">#{memUtil},</if>
            <if test="netInSpeed != null">#{netInSpeed},</if>
            <if test="netOutSpeed != null">#{netOutSpeed},</if>
            <if test="clientId != null">#{clientId},</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>
         </trim>
    </insert>

    <update id="updateInitialDockerInfo" parameterType="InitialDockerInfo">
        update initial_docker_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="id != null and id != ''">id = #{id},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="cpuUtil != null">cpu_util = #{cpuUtil},</if>
            <if test="memUtil != null">mem_util = #{memUtil},</if>
            <if test="netInSpeed != null">net_in_speed = #{netInSpeed},</if>
            <if test="netOutSpeed != null">net_out_speed = #{netOutSpeed},</if>
            <if test="clientId != null">client_id = #{clientId},</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 id = #{id}
    </update>

    <delete id="deleteInitialDockerInfoById" parameterType="Long">
        delete from initial_docker_info where auto_id = #{autoId}
    </delete>

    <delete id="deleteInitialDockerInfoByIds" parameterType="String">
        delete from initial_docker_info where auto_id in
        <foreach item="autoId" collection="array" open="(" separator="," close=")">
            #{autoId}
        </foreach>
    </delete>

    <insert id="batchInsertInitialDockerInfo" parameterType="java.util.List">
        INSERT IGNORE INTO initial_docker_info
        (
        `id`,
        `name`,
        status,
        cpu_util,
        mem_util,
        net_in_speed,
        net_out_speed,
        client_id,
        create_time,
        update_time,
        create_by,
        update_by
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id},
            #{item.name},
            #{item.status},
            #{item.cpuUtil},
            #{item.memUtil},
            #{item.netInSpeed},
            #{item.netOutSpeed},
            #{item.clientId},
            <choose>
                <when test="item.createTime != null">
                    #{item.createTime}
                </when>
                <otherwise>
                    NOW()
                </otherwise>
            </choose>,
            <choose>
                <when test="item.updateTime != null">
                    #{item.updateTime}
                </when>
                <otherwise>
                    NOW()
                </otherwise>
            </choose>,
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>

    <select id="getDockerDetailsMsg" parameterType="InitialDockerInfo" resultMap="InitialDockerInfoResult">
        <include refid="selectInitialDockerInfoVo"/>
        where client_id = #{clientId} and `id` = #{id}
        order by create_time desc
        limit 1
    </select>
    <select id="getAllDockerId" parameterType="String" resultType="java.util.Map">
        select id from initial_docker_info
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        group by id
    </select>
</mapper>