<?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.supervision.web.peopleGateManage.mapper.DeviceMapper">

    <resultMap id="DeviceResultMap" type="com.supervision.web.peopleGateManage.enity.Device">
        <id property="id" column="id"/>
        <result property="model" column="model"/>
        <result property="location" column="location"/>
        <result property="ip" column="ip"/>
        <result property="port" column="port"/>
        <result property="account" column="account"/>
        <result property="password" column="password"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <!-- 查询所有设备 -->
    <select id="selectAll" resultMap="DeviceResultMap">
        SELECT * FROM new_device ORDER BY id DESC
    </select>

    <!-- 根据ID查询 -->
    <select id="selectById" resultMap="DeviceResultMap">
        SELECT * FROM new_device WHERE id = #{id}
    </select>

    <!-- 插入设备 -->
    <insert id="insert" parameterType="com.supervision.web.peopleGateManage.enity.Device" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO new_device (model, location, ip, port, account, password, create_time, update_time)
        VALUES (#{model}, #{location}, #{ip}, #{port}, #{account}, #{password}, #{createTime}, #{updateTime})
    </insert>

    <!-- 更新设备 -->
    <update id="update" parameterType="com.supervision.web.peopleGateManage.enity.Device">
        UPDATE new_device
        SET id = #{id},
            model = #{model},
            location = #{location},
            ip = #{ip},
            port = #{port},
            account = #{account},
            password = #{password},
            update_time = #{updateTime}
        WHERE id = #{id}
    </update>

    <!-- 删除设备 -->
    <delete id="delete" parameterType="long">
        DELETE FROM new_device WHERE id = #{id}
    </delete>

</mapper>
