<?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.system.mapper.SysUserOnlineMapper">

    <resultMap type="com.ruoyi.system.domain.vo.SysUserOnlineVO" id="SysUserOnlineResult">
        <id     property="id"         column="id"         />
        <result property="loginName"         column="login_name"        />
        <result property="deptName"          column="dept_name"         />
        <result property="ipaddr"            column="ipaddr"            />
        <result property="loginLocation"     column="login_location"    />
        <result property="browser"           column="browser"           />
        <result property="os"                column="os"                />
        <result property="status"            column="status"            />
        <result property="startTimestamp"    column="start_timestamp"   />
        <result property="lastAccessTime"    column="last_access_time"  />
        <result property="expireTime"        column="expire_time"       />
        <result property="tenantId" column="tenant_id" />
    </resultMap>

    <sql id="selectOnlineVo">
        select id, login_name, dept_name, ipaddr, login_location, browser, os, status, start_timestamp, last_access_time, expire_time
        from sys_user_online
    </sql>

    <select id="selectOnlineByExpired" parameterType="String" resultMap="SysUserOnlineResult">
        <include refid="selectOnlineVo"/> o
        WHERE o.last_access_time <![CDATA[ <= ]]> #{lastAccessTime} ORDER BY o.last_access_time ASC
    </select>

    <select id="selectOnlineById" parameterType="String" resultMap="SysUserOnlineResult">
        <include refid="selectOnlineVo"/>
        where id = #{sessionid}
    </select>

    <delete id="deleteOnlineById" parameterType="String">
        delete from sys_user_online where id = #{sessionId}
    </delete>

    <insert id="saveOnline" parameterType="PlatformUserOnlineDTO">
        replace into sys_user_online(id, login_name, dept_name, ipaddr, login_location,
            browser, os, status, start_timestamp, last_access_time, expire_time,tenant_id)
        values (#{id}, #{loginName}, #{deptName}, #{ipaddr}, #{loginLocation},
                #{browser}, #{os}, #{status}, #{startTimestamp}, #{lastAccessTime}, #{expireTime},#{tenantId})
    </insert>

</mapper> 