package service

import (
	"be.ems/src/framework/token"
	"be.ems/src/modules/monitor/model"
)

// 实例化服务层 SysUserOnline 结构体
var NewSysUserOnline = &SysUserOnline{}

// SysUserOnline 在线用户 服务层处理
type SysUserOnline struct{}

// UserInfoToUserOnline 在线用户信息
func (s SysUserOnline) UserInfoToUserOnline(info token.UserInfo) model.SysUserOnline {
	if info.UserId <= 0 {
		return model.SysUserOnline{}
	}

	sysUserOnline := model.SysUserOnline{
		TokenID:       info.DeviceId,
		UserName:      info.User.UserName,
		LoginIp:       info.LoginIp,
		LoginLocation: info.LoginLocation,
		Browser:       info.Browser,
		OS:            info.OS,
		LoginTime:     info.LoginTime,
	}
	if info.User.DeptId > 0 {
		sysUserOnline.DeptName = info.User.Dept.DeptName
	}
	return sysUserOnline
}
