<?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.InitialDiskInfoMapper">
    
    <resultMap type="InitialDiskInfo" id="InitialDiskInfoResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="name"    column="name"    />
        <result property="serial"    column="serial"    />
        <result property="total"    column="total"    />
        <result property="writeSpeed"    column="write_speed"    />
        <result property="readSpeed"    column="read_speed"    />
        <result property="writeTimes"    column="write_times"    />
        <result property="readTimes"    column="read_times"    />
        <result property="writeBytes"    column="write_bytes"    />
        <result property="readBytes"    column="read_bytes"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectInitialDiskInfoVo">
        select id, client_id, name, serial, total, write_speed, read_speed, write_times, read_times, write_bytes, read_bytes, create_by, update_by, create_time, update_time from initial_disk_info
    </sql>

    <select id="selectInitialDiskInfoList" parameterType="InitialDiskInfo" resultMap="InitialDiskInfoResult">
        <include refid="selectInitialDiskInfoVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="name != null  and name != ''"> and name = #{name}</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="selectInitialDiskInfoById" parameterType="Long" resultMap="InitialDiskInfoResult">
        <include refid="selectInitialDiskInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertInitialDiskInfo" parameterType="InitialDiskInfo">
        insert IGNORE into initial_disk_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="serial != null">serial,</if>
            <if test="total != null">total,</if>
            <if test="writeSpeed != null">write_speed,</if>
            <if test="readSpeed != null">read_speed,</if>
            <if test="writeTimes != null">write_times,</if>
            <if test="readTimes != null">read_times,</if>
            <if test="writeBytes != null">write_bytes,</if>
            <if test="readBytes != null">read_bytes,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="clientId != null and clientId != ''">#{clientId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="serial != null">#{serial},</if>
            <if test="total != null">#{total},</if>
            <if test="writeSpeed != null">#{writeSpeed},</if>
            <if test="readSpeed != null">#{readSpeed},</if>
            <if test="writeTimes != null">#{writeTimes},</if>
            <if test="readTimes != null">#{readTimes},</if>
            <if test="writeBytes != null">#{writeBytes},</if>
            <if test="readBytes != null">#{readBytes},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateInitialDiskInfo" parameterType="InitialDiskInfo">
        update initial_disk_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="serial != null">serial = #{serial},</if>
            <if test="total != null">total = #{total},</if>
            <if test="writeSpeed != null">write_speed = #{writeSpeed},</if>
            <if test="readSpeed != null">read_speed = #{readSpeed},</if>
            <if test="writeTimes != null">write_times = #{writeTimes},</if>
            <if test="readTimes != null">read_times = #{readTimes},</if>
            <if test="writeBytes != null">write_bytes = #{writeBytes},</if>
            <if test="readBytes != null">read_bytes = #{readBytes},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInitialDiskInfoById" parameterType="Long">
        delete from initial_disk_info where id = #{id}
    </delete>

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

    <insert id="batchInsertInitialDiskInfo" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT IGNORE INTO initial_disk_info
        (
        id,
        client_id,
        `name`,
        serial,
        total,
        write_speed,
        read_speed,
        write_times,
        read_times,
        write_bytes,
        read_bytes,
        create_by,
        update_by,
        create_time,
        update_time
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id},
            #{item.clientId},
            #{item.name},
            #{item.serial},
            #{item.total},
            #{item.writeSpeed},
            #{item.readSpeed},
            #{item.writeTimes},
            #{item.readTimes},
            #{item.writeBytes},
            #{item.readBytes},
            #{item.createBy},
            #{item.updateBy},
            <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>
            )
        </foreach>
    </insert>
    <select id="getDistDetailsMsgByClientId" parameterType="InitialDiskInfo" resultMap="InitialDiskInfoResult">
        <include refid="selectInitialDiskInfoVo"/>
        where client_id = #{clientId} and `name`= #{name}
        order by create_time desc
        limit 1
    </select>
    <select id="getAllDistName" parameterType="String" resultType="java.util.Map">
        select name from initial_disk_info
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        group by name
    </select>
</mapper>