<?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="ink.wgink.login.app.dao.appdeviceuser.IAppDeviceUserDao">

    <cache flushInterval="3600000"/>

    <resultMap id="appDeviceUserPO" type="ink.wgink.login.app.pojo.pos.appdeviceuser.AppDeviceUserPO">
        <result property="userId" column="user_id"/>
        <result property="deviceNo" column="device_no"/>
    </resultMap>

    <resultMap id="appDeviceUserDTO" type="ink.wgink.login.app.pojo.dtos.appdeviceuser.AppDeviceUserDTO">
        <result property="userId" column="user_id"/>
        <result property="deviceNo" column="device_no"/>
    </resultMap>

    <!-- 建表 -->
    <update id="createTable">
        CREATE TABLE IF NOT EXISTS `app_device_user` (
            `device_no` varchar(255) DEFAULT NULL,
            `user_id` char(36) DEFAULT NULL,
            KEY `device_no` (`device_no`),
            KEY `user_id` (`user_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    </update>

    <!-- 保存 -->
    <insert id="save" parameterType="map" flushCache="true">
        INSERT INTO app_device_user(
            device_no,
            user_id,
            gmt_create
        ) VALUES(
            #{deviceNo},
            #{userId},
            #{gmtCreate}
        )
    </insert>

    <!-- 删除 -->
    <delete id="delete" parameterType="map" flushCache="true">
        DELETE FROM
            app_device_user
        WHERE
            device_no = #{deviceNo}
        AND
            user_id = #{userId}
    </delete>

    <!-- 列表 -->
    <select id="list" parameterType="map" resultMap="appDeviceUserDTO" useCache="true">
        SELECT
            *
        FROM
            app_device_user
        WHERE
            user_id = #{userId}
    </select>

    <!-- 列表 -->
    <select id="listPO" parameterType="map" resultMap="appDeviceUserPO" useCache="true">
        SELECT
            *
        FROM
            app_device_user
        WHERE
            user_id = #{userId}
    </select>

</mapper>