using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using ZhonTai.Common.Helpers; using ZhonTai.Admin.Core.Dto; using ZhonTai.Admin.Services.OprationLog.Dto; using ZhonTai.Admin.Domain.OprationLog; using ZhonTai.Admin.Domain; using ZhonTai.DynamicApi; using ZhonTai.DynamicApi.Attributes; using Microsoft.AspNetCore.Mvc; using ZhonTai.Admin.Core.Consts; namespace ZhonTai.Admin.Services.OprationLog; /// /// 操作日志服务 /// [DynamicApi(Area = AdminConsts.AreaName)] public class OprationLogService : BaseService, IOprationLogService, IDynamicApi { private readonly IHttpContextAccessor _context; private readonly IOprationLogRepository _oprationLogRepository; public OprationLogService( IHttpContextAccessor context, IOprationLogRepository oprationLogRepository ) { _context = context; _oprationLogRepository = oprationLogRepository; } /// /// 查询分页 /// /// /// [HttpPost] public async Task> GetPageAsync(PageInput input) { var userName = input.Filter?.CreatedUserName; var list = await _oprationLogRepository.Select .WhereDynamicFilter(input.DynamicFilter) .WhereIf(userName.NotNull(), a => a.CreatedUserName.Contains(userName)) .Count(out var total) .OrderByDescending(true, c => c.Id) .Page(input.CurrentPage, input.PageSize) .ToListAsync(); var data = new PageOutput() { List = list, Total = total }; return data; } /// /// 新增 /// /// /// public async Task AddAsync(OprationLogAddInput input) { string ua = _context.HttpContext.Request.Headers["User-Agent"]; if (ua.NotNull()) { var client = UAParser.Parser.GetDefault().Parse(ua); var device = client.Device.Family; device = device.ToLower() == "other" ? "" : device; input.Browser = client.UA.Family; input.Os = client.OS.Family; input.Device = device; input.BrowserInfo = ua; } input.Name = User.Name; input.IP = IPHelper.GetIP(_context?.HttpContext?.Request); var entity = Mapper.Map(input); await _oprationLogRepository.InsertAsync(entity); return entity.Id; } }