油漆
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统监控
|
||||
/// </summary>
|
||||
public class MonitorController : BaseController
|
||||
{
|
||||
private OptionsSetting Options;
|
||||
private IWebHostEnvironment HostEnvironment;
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
public MonitorController(IOptions<OptionsSetting> options, IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
this.HostEnvironment = hostEnvironment;
|
||||
this.Options = options.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存监控数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("monitor/cache")]
|
||||
public IActionResult GetCache()
|
||||
{
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("monitor/server")]
|
||||
//[AllowAnonymous]
|
||||
public IActionResult Server()
|
||||
{
|
||||
//核心数
|
||||
int cpuNum = Environment.ProcessorCount;
|
||||
string computerName = Environment.MachineName;
|
||||
string osName = RuntimeInformation.OSDescription;
|
||||
string osArch = RuntimeInformation.OSArchitecture.ToString();
|
||||
string version = RuntimeInformation.FrameworkDescription;
|
||||
string appRAM = ((double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB";
|
||||
string startTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string sysRunTime = ComputerHelper.GetRunTime();
|
||||
string serverIP = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
|
||||
|
||||
var programStartTime = Process.GetCurrentProcess().StartTime;
|
||||
string programRunTime = DateTimeHelper.FormatTime((DateTime.Now - programStartTime).TotalMilliseconds.ToString().Split('.')[0].ParseToLong());
|
||||
var data = new
|
||||
{
|
||||
cpu = ComputerHelper.GetComputerInfo(),
|
||||
disk = ComputerHelper.GetDiskInfos(),
|
||||
sys = new { cpuNum, computerName, osName, osArch, serverIP, runTime = sysRunTime },
|
||||
app = new
|
||||
{
|
||||
name = HostEnvironment.EnvironmentName,
|
||||
rootPath = HostEnvironment.ContentRootPath,
|
||||
webRootPath = HostEnvironment.WebRootPath,
|
||||
version,
|
||||
appRAM,
|
||||
startTime,
|
||||
runTime = programRunTime,
|
||||
host = serverIP
|
||||
},
|
||||
};
|
||||
|
||||
return SUCCESS(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统访问记录
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("/monitor/logininfor")]
|
||||
public class SysLogininforController : BaseController
|
||||
{
|
||||
private ISysLoginService sysLoginService;
|
||||
|
||||
public SysLogininforController(ISysLoginService sysLoginService)
|
||||
{
|
||||
this.sysLoginService = sysLoginService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询登录日志
|
||||
/// </summary>
|
||||
/// <param name="sysLogininfoDto"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult LoignLogList([FromQuery] SysLogininfor sysLogininfoDto, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = sysLoginService.GetLoginLog(sysLogininfoDto, pagerInfo);
|
||||
|
||||
return SUCCESS(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空登录日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "清空登录日志", BusinessType= BusinessType.CLEAN)]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:remove")]
|
||||
[HttpDelete("clean")]
|
||||
public IActionResult CleanLoginInfo()
|
||||
{
|
||||
if (!HttpContextExtension.IsAdmin(HttpContext))
|
||||
{
|
||||
return ToResponse(ApiResult.Error("操作失败"));
|
||||
}
|
||||
sysLoginService.TruncateLogininfo();
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="infoIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "删除登录日志", BusinessType = BusinessType.DELETE)]
|
||||
[HttpDelete("{infoIds}")]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:remove")]
|
||||
public IActionResult Remove(string infoIds)
|
||||
{
|
||||
if (!HttpContextExtension.IsAdmin(HttpContext))
|
||||
{
|
||||
return ToResponse(ApiResult.Error("操作失败"));
|
||||
}
|
||||
long[] infoIdss = Tools.SpitLongArrary(infoIds);
|
||||
return SUCCESS(sysLoginService.DeleteLogininforByIds(infoIdss));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录日志导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "登录日志导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:export")]
|
||||
public IActionResult Export([FromQuery] SysLogininfor logininfoDto)
|
||||
{
|
||||
logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1);
|
||||
logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1);
|
||||
var exp = Expressionable.Create<SysLogininfor>()
|
||||
.And(it => it.LoginTime >= logininfoDto.BeginTime && it.LoginTime <= logininfoDto.EndTime);
|
||||
|
||||
var list = sysLoginService.Queryable().Where(exp.ToExpression())
|
||||
.ToList();
|
||||
|
||||
string sFileName = ExportExcel(list, "loginlog", "登录日志");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作日志记录
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("/monitor/operlog")]
|
||||
public class SysOperlogController : BaseController
|
||||
{
|
||||
private ISysOperLogService sysOperLogService;
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
|
||||
public SysOperlogController(ISysOperLogService sysOperLogService, IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
this.sysOperLogService = sysOperLogService;
|
||||
WebHostEnvironment = hostEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
/// <param name="sysOperLog"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult OperList([FromQuery] SysOperLogQueryDto sysOperLog)
|
||||
{
|
||||
sysOperLog.OperName = !HttpContextExtension.IsAdmin(HttpContext) ? HttpContextExtension.GetName(HttpContext) : sysOperLog.OperName;
|
||||
var list = sysOperLogService.SelectOperLogList(sysOperLog);
|
||||
|
||||
return SUCCESS(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除操作日志
|
||||
/// </summary>
|
||||
/// <param name="operIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "操作日志", BusinessType = BusinessType.DELETE)]
|
||||
[ActionPermissionFilter(Permission = "monitor:operlog:delete")]
|
||||
[HttpDelete("{operIds}")]
|
||||
public IActionResult Remove(string operIds)
|
||||
{
|
||||
if (!HttpContextExtension.IsAdmin(HttpContext))
|
||||
{
|
||||
return ToResponse(ApiResult.Error("操作失败"));
|
||||
}
|
||||
long[] operIdss = Tools.SpitLongArrary(operIds);
|
||||
return SUCCESS(sysOperLogService.DeleteOperLogByIds(operIdss));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空操作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "清空操作日志", BusinessType = BusinessType.CLEAN)]
|
||||
[ActionPermissionFilter(Permission = "monitor:operlog:delete")]
|
||||
[HttpDelete("clean")]
|
||||
public IActionResult ClearOperLog()
|
||||
{
|
||||
if (!HttpContextExtension.IsAdmin(HttpContext))
|
||||
{
|
||||
return ToResponse(Infrastructure.ResultCode.CUSTOM_ERROR,"操作失败");
|
||||
}
|
||||
sysOperLogService.CleanOperLog();
|
||||
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出操作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "操作日志", BusinessType = BusinessType.EXPORT)]
|
||||
[ActionPermissionFilter(Permission = "monitor:operlog:export")]
|
||||
[HttpGet("export")]
|
||||
public IActionResult Export([FromQuery] SysOperLogQueryDto sysOperLog)
|
||||
{
|
||||
sysOperLog.PageSize = 100000;
|
||||
var list = sysOperLogService.SelectOperLogList(sysOperLog);
|
||||
var result = ExportExcelMini(list.Result, "操作日志", "操作日志");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Hubs;
|
||||
using ZR.Model;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
[Verify]
|
||||
[Route("monitor/online")]
|
||||
public class SysUserOnlineController : BaseController
|
||||
{
|
||||
private IHubContext<Hub> HubContext;
|
||||
|
||||
public SysUserOnlineController(IHubContext<Hub> hubContext)
|
||||
{
|
||||
HubContext = hubContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取在线用户列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult Index([FromQuery] PagerInfo parm)
|
||||
{
|
||||
var result = MessageHub.clientUsers
|
||||
.OrderByDescending(f => f.LoginTime)
|
||||
.Skip(parm.PageNum - 1).Take(parm.PageSize);
|
||||
|
||||
return SUCCESS(new { result, totalNum = MessageHub.clientUsers.Count });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user