<?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.sim.mapper.SeatMapper">

    <resultMap type="Seat" id="SeatResult">
        <result property="seatId" column="seat_id"/>
        <result property="seatNum" column="seat_num"/>
        <result property="seatBindIp" column="seat_bind_ip"/>
        <result property="currentUserId" column="current_user_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectSeatVo">
        select seat_id,
               seat_num,
               seat_bind_ip,
               current_user_id,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from mx_seat
    </sql>

    <select id="selectSeatList" parameterType="Seat" resultMap="SeatResult">
        <include refid="selectSeatVo"/>
        <where>
            <if test="seatNum != null ">and seat_num = #{seatNum}</if>
            <if test="seatBindIp != null  and seatBindIp != ''">and seat_bind_ip = #{seatBindIp}</if>
            <if test="currentUserId != null ">and current_user_id = #{currentUserId}</if>
        </where>
    </select>

    <select id="selectSeatBySeatId" parameterType="Long" resultMap="SeatResult">
        <include refid="selectSeatVo"/>
        where seat_id = #{seatId}
    </select>

    <insert id="insertSeat" parameterType="Seat" useGeneratedKeys="true" keyProperty="seatId">
        <selectKey keyProperty="seatId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into mx_seat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="seatNum != null">seat_num,</if>
            <if test="seatBindIp != null and seatBindIp != ''">seat_bind_ip,</if>
            <if test="currentUserId != null">current_user_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="seatNum != null">#{seatNum},</if>
            <if test="seatBindIp != null and seatBindIp != ''">#{seatBindIp},</if>
            <if test="currentUserId != null">#{currentUserId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateSeat" parameterType="Seat">
        update mx_seat
        <trim prefix="SET" suffixOverrides=",">
            <if test="seatNum != null">seat_num = #{seatNum},</if>
            <if test="seatBindIp != null and seatBindIp != ''">seat_bind_ip = #{seatBindIp},</if>
            <if test="currentUserId != null">current_user_id = #{currentUserId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where seat_id = #{seatId}
    </update>

    <delete id="deleteSeatBySeatId" parameterType="Long">
        delete
        from mx_seat
        where seat_id = #{seatId}
    </delete>

    <delete id="deleteSeatBySeatIds" parameterType="String">
        delete from mx_seat where seat_id in
        <foreach item="seatId" collection="array" open="(" separator="," close=")">
            #{seatId}
        </foreach>
    </delete>
</mapper>