2019-02-28 16:44:50 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-03-01 02:00:47 +08:00
|
|
|
|
using System;
|
2019-02-28 16:44:50 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-03-01 02:00:47 +08:00
|
|
|
|
using System.Linq;
|
2019-02-28 16:44:50 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-03-01 02:00:47 +08:00
|
|
|
|
/// 在线用户接口
|
2019-02-28 16:44:50 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class OnlineUsersController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-03-01 02:00:47 +08:00
|
|
|
|
/// 获取所有在线用户数据
|
2019-02-28 16:44:50 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost()]
|
|
|
|
|
public IEnumerable<OnlineUser> Post([FromServices]IOnlineUsers onlineUSers)
|
|
|
|
|
{
|
|
|
|
|
return onlineUSers.OnlineUsers;
|
|
|
|
|
}
|
2019-03-01 02:00:47 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取指定IP地址的在线用户请求地址明细数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="onlineUSers"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public IEnumerable<KeyValuePair<DateTime, string>> Get(string id, [FromServices]IOnlineUsers onlineUSers)
|
|
|
|
|
{
|
|
|
|
|
var user = onlineUSers.OnlineUsers.FirstOrDefault(u => u.Ip == id);
|
|
|
|
|
return user?.RequestUrls ?? new KeyValuePair<DateTime, string>[0];
|
|
|
|
|
}
|
2019-02-28 16:44:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|