<?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.tongran.rocketmq.mapper.InitialMountPointInfoMapper">
    
    <resultMap type="InitialMountPointInfo" id="InitialMountPointInfoResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="mount"    column="mount"    />
        <result property="vfsType"    column="vfs_type"    />
        <result property="vfsFree"    column="vfs_free"    />
        <result property="vfsTotal"    column="vfs_total"    />
        <result property="vfsUtil"    column="vfs_util"    />
        <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="selectInitialMountPointInfoVo">
        select id, client_id, mount, vfs_type, vfs_free, vfs_total, vfs_util, create_by, update_by, create_time, update_time from initial_mount_point_info
    </sql>

    <select id="selectInitialMountPointInfoList" parameterType="InitialMountPointInfo" resultMap="InitialMountPointInfoResult">
        <include refid="selectInitialMountPointInfoVo"/>
        <where>  
            <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="selectInitialMountPointInfoById" parameterType="Long" resultMap="InitialMountPointInfoResult">
        <include refid="selectInitialMountPointInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertInitialMountPointInfo" parameterType="InitialMountPointInfo" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into initial_mount_point_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="mount != null and mount != ''">mount,</if>
            <if test="vfsType != null">vfs_type,</if>
            <if test="vfsFree != null">vfs_free,</if>
            <if test="vfsTotal != null">vfs_total,</if>
            <if test="vfsUtil != null">vfs_util,</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="clientId != null and clientId != ''">#{clientId},</if>
            <if test="mount != null and mount != ''">#{mount},</if>
            <if test="vfsType != null">#{vfsType},</if>
            <if test="vfsFree != null">#{vfsFree},</if>
            <if test="vfsTotal != null">#{vfsTotal},</if>
            <if test="vfsUtil != null">#{vfsUtil},</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="updateInitialMountPointInfo" parameterType="InitialMountPointInfo">
        update initial_mount_point_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="mount != null and mount != ''">mount = #{mount},</if>
            <if test="vfsType != null">vfs_type = #{vfsType},</if>
            <if test="vfsFree != null">vfs_free = #{vfsFree},</if>
            <if test="vfsTotal != null">vfs_total = #{vfsTotal},</if>
            <if test="vfsUtil != null">vfs_util = #{vfsUtil},</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="deleteInitialMountPointInfoById" parameterType="Long">
        delete from initial_mount_point_info where id = #{id}
    </delete>

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

    <insert id="batchInsertInitialMountPointInfo" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT IGNORE INTO initial_mount_point_info
        (
        client_id,
        mount,
        vfs_type,
        vfs_free,
        vfs_total,
        vfs_util,
        create_by,
        update_by,
        create_time,
        update_time
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.clientId},
            #{item.mount},
            #{item.vfsType},
            #{item.vfsFree},
            #{item.vfsTotal},
            #{item.vfsUtil},
            #{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="pointDetailsMsg" parameterType="InitialMountPointInfo" resultMap="InitialMountPointInfoResult">
        <include refid="selectInitialMountPointInfoVo"/>
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="mount != null  and mount != ''"> and mount = #{mount}</if>
        </where>
        order by create_time desc
        limit 1
    </select>
    <select id="getAllMountName" parameterType="String" resultType="java.util.Map">
        select mount from initial_mount_point_info
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        group by mount
    </select>
</mapper>