<?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.nasc.custom.mapper.NascVncDesktopMapper">

    <resultMap id="vncDesktopResult" type="NascVncDesktop">
        <id          property="id"              column="id"             />
        <result      property="desktopName"     column="desktop_name"   />
        <result      property="vncIp"           column="vnc_ip"         />
        <result      property="vncPort"         column="vnc_port"       />
        <result      property="userName"        column="user_name"      />
        <result      property="password"        column="password"       />
        <result      property="path"            column="path"           />
        <result      property="sortNum"         column="sort_num"       />
        <result      property="createBy"        column="create_by"      />
        <result      property="createTime"      column="create_time"    />
        <result      property="updateBy"        column="update_by"      />
        <result      property="updateTime"      column="update_time"    />
    </resultMap>
    
    <select id="selectVncDesktopList" parameterType="NascVncDesktop" resultMap="vncDesktopResult">
		SELECT nvd.id, nvd.desktop_name, nvd.vnc_ip, nvd.vnc_port, nvd.user_name, nvd.`password`, nvd.path,
		       nvd.sort_num, nvd.create_by, nvd.create_time, nvd.update_by, nvd.update_time
		FROM nasc_vnc_desktop nvd
        <where>
            <if test="desktopName != null and desktopName != ''">
                AND nvd.desktop_name like concat('%', #{desktopName}, '%')
            </if>
            <if test="vncIp != null and vncIp != ''">
                AND nvd.vnc_ip like concat('%', #{vncIp}, '%')
            </if>
        </where>
        ORDER BY nvd.sort_num DESC
	</select>

    <select id="checkVncDesktopDuplicates" parameterType="NascVncDesktop" resultType="Long">
        SELECT COUNT(1)
        FROM nasc_vnc_desktop nvd
        WHERE nvd.vnc_ip = #{vncIp} AND nvd.vnc_port = #{vncPort}
        <if test="id != null and id != 0">
            AND nvd.id != #{id}
        </if>
    </select>

    <insert id="insertVncDesktop" parameterType="NascVncDesktop" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO nasc_vnc_desktop (desktop_name, vnc_ip, vnc_port, user_name, `password`, path, sort_num, create_by, create_time)
        VALUES (#{desktopName}, #{vncIp}, #{vncPort}, #{userName}, #{password}, #{path}, #{sortNum}, #{createBy}, sysdate())
    </insert>

    <update id="updateVncDesktop" parameterType="NascVncDesktop">
        UPDATE nasc_vnc_desktop
        SET desktop_name = #{desktopName}, vnc_ip = #{vncIp}, vnc_port = #{vncPort}, user_name = #{userName},
            `password` = #{password}, path = #{path}, sort_num = #{sortNum}, update_by = #{updateBy}, update_time = sysdate()
        WHERE id = #{id}
    </update>

    <delete id="deleteVncDesktopByIds" parameterType="Long">
        DELETE FROM nasc_vnc_desktop WHERE id IN
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getVncDesktopInfo" parameterType="Long" resultMap="vncDesktopResult">
        SELECT nvd.id, nvd.desktop_name, nvd.vnc_ip, nvd.vnc_port, nvd.user_name, nvd.`password`, nvd.path,
               nvd.sort_num, nvd.create_by, nvd.create_time, nvd.update_by, nvd.update_time
        FROM nasc_vnc_desktop nvd
        WHERE nvd.id = #{id}
    </select>

</mapper> 