<?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.InitialSystemInfoMapper">
    
    <resultMap type="InitialSystemInfo" id="InitialSystemInfoResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="os"    column="os"    />
        <result property="arch"    column="arch"    />
        <result property="maxProc"    column="max_proc"    />
        <result property="runProcNum"    column="run_proc_num"    />
        <result property="usersNum"    column="users_num"    />
        <result property="diskSizeTotal"    column="disk_size_total"    />
        <result property="bootTime"    column="boot_time"    />
        <result property="uname"    column="uname"    />
        <result property="localTime"    column="local_time"    />
        <result property="upTime"    column="up_time"    />
        <result property="procNum"    column="proc_num"    />
        <result property="timeStamp"    column="time_stamp"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="uuid"    column="uuid"    />
    </resultMap>

    <sql id="selectInitialSystemInfoVo">
        select id, client_id, os, arch, max_proc, run_proc_num, users_num, disk_size_total, boot_time, uname, local_time, up_time, proc_num, time_stamp, create_by, update_by, create_time, update_time, uuid from initial_system_info
    </sql>

    <select id="selectInitialSystemInfoList" parameterType="InitialSystemInfo" resultMap="InitialSystemInfoResult">
        <include refid="selectInitialSystemInfoVo"/>
        <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="selectInitialSystemInfoById" parameterType="Long" resultMap="InitialSystemInfoResult">
        <include refid="selectInitialSystemInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertInitialSystemInfo" parameterType="InitialSystemInfo" useGeneratedKeys="true" keyProperty="id">
        insert into initial_system_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="os != null">os,</if>
            <if test="arch != null">arch,</if>
            <if test="maxProc != null">max_proc,</if>
            <if test="runProcNum != null">run_proc_num,</if>
            <if test="usersNum != null">users_num,</if>
            <if test="diskSizeTotal != null">disk_size_total,</if>
            <if test="bootTime != null">boot_time,</if>
            <if test="uname != null">uname,</if>
            <if test="localTime != null">local_time,</if>
            <if test="upTime != null">up_time,</if>
            <if test="procNum != null">proc_num,</if>
            <if test="timeStamp != null">time_stamp,</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>
            <if test="uuid != null">uuid,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">#{clientId},</if>
            <if test="os != null">#{os},</if>
            <if test="arch != null">#{arch},</if>
            <if test="maxProc != null">#{maxProc},</if>
            <if test="runProcNum != null">#{runProcNum},</if>
            <if test="usersNum != null">#{usersNum},</if>
            <if test="diskSizeTotal != null">#{diskSizeTotal},</if>
            <if test="bootTime != null">#{bootTime},</if>
            <if test="uname != null">#{uname},</if>
            <if test="localTime != null">#{localTime},</if>
            <if test="upTime != null">#{upTime},</if>
            <if test="procNum != null">#{procNum},</if>
            <if test="timeStamp != null">#{timeStamp},</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>
            <if test="uuid != null">#{uuid},</if>
         </trim>
    </insert>

    <update id="updateInitialSystemInfo" parameterType="InitialSystemInfo">
        update initial_system_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="os != null">os = #{os},</if>
            <if test="arch != null">arch = #{arch},</if>
            <if test="maxProc != null">max_proc = #{maxProc},</if>
            <if test="runProcNum != null">run_proc_num = #{runProcNum},</if>
            <if test="usersNum != null">users_num = #{usersNum},</if>
            <if test="diskSizeTotal != null">disk_size_total = #{diskSizeTotal},</if>
            <if test="bootTime != null">boot_time = #{bootTime},</if>
            <if test="uname != null">uname = #{uname},</if>
            <if test="localTime != null">local_time = #{localTime},</if>
            <if test="upTime != null">up_time = #{upTime},</if>
            <if test="procNum != null">proc_num = #{procNum},</if>
            <if test="timeStamp != null">time_stamp = #{timeStamp},</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>
            <if test="uuid != null">uuid = #{uuid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInitialSystemInfoById" parameterType="Long">
        delete from initial_system_info where id = #{id}
    </delete>

    <delete id="deleteInitialSystemInfoByIds" parameterType="String">
        delete from initial_system_info where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="batchInsertInitialSystemInfo" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO initial_system_info
        (
        client_id,
        os,
        arch,
        max_proc,
        run_proc_num,
        users_num,
        disk_size_total,
        boot_time,
        uname,
        local_time,
        up_time,
        proc_num,
        time_stamp,
        create_by,
        update_by,
        create_time,
        update_time,
        uuid
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.clientId},
            #{item.os},
            #{item.arch},
            #{item.maxProc},
            #{item.runProcNum},
            #{item.usersNum},
            #{item.diskSizeTotal},
            #{item.bootTime},
            #{item.uname},
            #{item.localTime},
            #{item.upTime},
            #{item.procNum},
            #{item.timeStamp},
            #{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>,
            #{item.uuid}
            )
        </foreach>
    </insert>

    <select id="getSystemMsgByClientId" parameterType="String" resultType="SystemMsgVo">
        select os os,arch arch,max_proc maxProc,disk_size_total diskSizeTotal,boot_time bootTime,uname uname,local_time `localTime`,up_time upTime from initial_system_info
        where client_id = #{clientId}
        limit 1
    </select>
</mapper>