<?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.fjhx.common.mapper.on.OnLineInfoMapper">
    <select id="getOnLineTimeByUserId" resultType="java.lang.Long">
        SELECT IFNULL(sum(on_line_duration), 0)
        FROM on_line_info
        WHERE on_line_date >= NOW() - INTERVAL 7 DAY
          AND user_id = #{userId}
    </select>

    <select id="getOnLineTimeByDeptIds" resultType="com.fjhx.common.entity.on.vo.OnLineInfoVo">
        SELECT
        oli.user_id,
        IFNULL( sum( on_line_duration ), 0 ) on_line_duration,
        dt.dept_id,
        ur.nick_name userName
        FROM
        on_line_info oli
        LEFT JOIN bytesailing_base.sys_user ur ON oli.user_id = ur.user_id
        LEFT JOIN bytesailing_base.sys_dept dt ON dt.dept_id = ur.dept_id
        <where>
            on_line_date >= NOW() - INTERVAL 7 DAY
            <if test="deptIds neq null and deptIds.size() > 0">
                <foreach collection="deptIds" item="deptId" open="AND dt.dept_id IN (" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
        </where>
        GROUP BY
        oli.user_id
    </select>

</mapper>
