Ejemplo n.º 1
0
        public async Task <PagedResultDto <EasyLoggerRecordListDto> > GetEasyLoggerAsync(EasyLoggerRecordInput input)
        {
            // 获取查询的时间范围
            var dateList = _linkBase.DynamicLinkOrm(input).OrderByDescending(s => s).ToList();
            var result   = new PagedResultDto <EasyLoggerRecordListDto>();
            // 查询初始数据库数据
            var projectList = _sqlRepository.GetCurrentSqlSugar().Queryable <EasyLoggerProject>().ToList();
            var DbName      = IocManager.Configuration["EasyLogger:DbName"];
            var entityList  = new List <EasyLoggerRecord>();
            // 为跨库查询定义的参数
            int Sumtotal = 0;

            foreach (var item in dateList)
            {
                var dayList = TimeTools.GetDayDiff(item.AddDays(1 - DateTime.Now.Day).Date, item.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1));
                using (_sqlRepository.ChangeProvider($"{DbName}-" + item.ToString("yyyy-MM")))
                {
                    var sqlSugarClient = _sqlRepository.GetCurrentSqlSugar();
                    var queryables     = new List <ISugarQueryable <EasyLoggerRecord> >();
                    _sqlRepository.GetCurrentSqlSugar().Queryable <EasyLoggerRecord>();
                    foreach (var day in dayList)
                    {
                        queryables.Add(sqlSugarClient.Queryable <EasyLoggerRecord>().AS($"EasyLoggerRecord_{day}"));
                    }
                    var sqlSugarLogger = sqlSugarClient.UnionAll(queryables);
                    var data           = sqlSugarLogger
                                         .Where(s => s.CreateTime >= input.TimeStart)
                                         .Where(s => s.CreateTime <= input.TimeEnd)
                                         .WhereIF(!string.IsNullOrWhiteSpace(input.LogTitle), s => s.LogTitle == input.LogTitle)
                                         .WhereIF(!string.IsNullOrWhiteSpace(input.LogType), s => s.LogType == input.LogType)
                                         .WhereIF(input.ProjectId != null, s => s.ProjectId == input.ProjectId)
                                         .WhereIF(input.LogState != null, s => s.LogState == input.LogState)
                                         .OrderBy(s => s.CreateTime, OrderByType.Desc)
                                         .ToPageList(input.PageIndex, input.PageSize, ref Sumtotal);
                    entityList.AddRange(data);
                }
            }
            result.Total = Sumtotal;
            result.List  = _mapper.Map <List <EasyLoggerRecordListDto> >(entityList);
            foreach (var item in result.List)
            {
                var project = projectList.Where(s => s.Id == item.ProjectId).FirstOrDefault();
                item.EasyLoggerProject = _mapper.Map <EasyLoggerProjectEditDto>(project);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <PagedResultDto <EasyLoggerProjectListDto> > GetEasyLoggerProjectAsync(EasyLoggerProjectInput input)
        {
            // 定义返回参数
            var result = new PagedResultDto <EasyLoggerProjectListDto>();
            var total  = 0;
            // 因为项目的数据存储在默认的数据库中所以这里不用做切换
            var sqlSugarClient = _repository.GetCurrentSqlSugar();

            var entityList = sqlSugarClient.Queryable <EasyLoggerProject>()
                             .OrderBy(s => s.Code, OrderByType.Desc)
                             .ToPageList(input.PageIndex, input.PageSize, ref total);


            result.List  = _mapper.Map <List <EasyLoggerProjectListDto> >(entityList);
            result.Total = total;
            return(result);
        }