using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Repositories.Log.Entitys; using InterfaceForward.Repositories.Log.Services; using InterfaceForward.Repositories.Log.ValueObjects; using Microsoft.AspNetCore.Mvc; using SqlSugar.Extensions; namespace InterfaceForward.Application.Services.App { /// /// 日志服务 /// [Route("Log")] [ApiExplorerSettings(GroupName = "应用服务")] public class LogService : BaseService { private readonly ILogRepository _logRepository; /// /// /// public LogService( ILogRepository logRepository) { _logRepository = logRepository; } #region Get /// /// 列表 /// /// 入参 /// [HttpGet("GetList")] public async Task> GetList(LogGetListInputValueObject input) { var res = await _logRepository.GetListAsync(input); return new PagedListDto(res.list, (int)res.total); } /// /// 调用统计 /// /// 入参 /// [HttpGet("GetLogsStatistics")] public async Task> GetLogsStatistics(LogStatisticsInputValueObject input) { var esData = await _logRepository.GetLogsStatisticsAsync(input); var list = new List(); var time_aggs = esData.Aggregations.DateHistogram("time_aggs").Buckets; foreach (var _time_aggs in time_aggs) { string time_date = _time_aggs.KeyAsString; var name_aggs = _time_aggs.Terms("name_aggs").Buckets; foreach (var _name_aggs in name_aggs) { string name = _name_aggs.Key; var interfacename_aggs = _name_aggs.Terms("interfacename_aggs").Buckets; foreach (var _interfacename_aggs in interfacename_aggs) { string interfaceName = _interfacename_aggs.Key; int interfaceName_docCount = _interfacename_aggs.DocCount.GetValueOrDefault().ObjToInt(); var isSuccess_count = _interfacename_aggs.Terms("isSuccess_count").Buckets; var dic = isSuccess_count.ToDictionary(b => b.KeyAsString, b => b.DocCount.ObjToInt()); int succeedCount = dic.GetValueOrDefault("true"); list.Add(new LogGetListOutputValueObject { Date = time_date, Name = name, InterfaceName = interfaceName, Total = interfaceName_docCount, SucceedCount = succeedCount, FailCount = dic.GetValueOrDefault("false"), SuccessRate = $"{Math.Round((decimal)succeedCount / interfaceName_docCount * 100, 2)}%" }); } } } var res = list.OrderByDescending(x => x.Date) .Skip((input.PageIndex - 1) * input.PageSize) .Take(input.PageSize).ToList(); return new PagedListDto(res, list.Count); } /// /// 查询详情 /// /// /// [HttpGet("GetById")] public async Task GetByIdAsync(string id) { return await _logRepository.GetDetailsByIdAsync(id); } #endregion } }