public async Task <List <int> > GetContentIdsAsync(Site site, Channel channel, bool isPeriods, string dateFrom, string dateTo, bool?checkedState)
        {
            var repository = await GetRepositoryAsync(site, channel);

            var query = Q
                        .Select(nameof(Content.Id))
                        .Where(nameof(Content.ChannelId), channel.Id)
                        .OrderByDesc(nameof(Content.Taxis), nameof(Content.Id));

            if (isPeriods)
            {
                if (!string.IsNullOrEmpty(dateFrom))
                {
                    query.WhereDate(nameof(Content.AddDate), ">=", TranslateUtils.ToDateTime(dateFrom));
                }
                if (!string.IsNullOrEmpty(dateTo))
                {
                    query.WhereDate(nameof(Content.AddDate), "<=", TranslateUtils.ToDateTime(dateTo).AddDays(1));
                }
            }

            if (checkedState.HasValue)
            {
                query.Where(nameof(Content.Checked), checkedState.Value);
            }

            return(await repository.GetAllAsync <int>(query));
        }
Beispiel #2
0
        public async Task <ActionResult <GetResult> > Get([FromBody] GetRequest request)
        {
            if (!await _authManager.HasAppPermissionsAsync(Types.AppPermissions.SettingsAnalysisSiteContent))
            {
                return(Unauthorized());
            }

            var lowerDate  = TranslateUtils.ToDateTime(request.DateFrom);
            var higherDate = TranslateUtils.ToDateTime(request.DateTo, DateTime.Now);

            var sites = await _siteRepository.GetCascadeChildrenAsync(0);

            sites.Insert(0, new Cascade <int>
            {
                Value = 0,
                Label = "<所有站点>"
            });

            var addStats = await _statRepository.GetStatsAsync(lowerDate, higherDate, StatType.ContentAdd, request.SiteId);

            var editStats = await _statRepository.GetStatsAsync(lowerDate, higherDate, StatType.ContentEdit, request.SiteId);

            var getStats  = new List <GetStat>();
            var totalDays = (higherDate - lowerDate).TotalDays;

            for (var i = 0; i <= totalDays; i++)
            {
                var date = lowerDate.AddDays(i).ToString("M-d");

                var add  = addStats.FirstOrDefault(x => x.CreatedDate.HasValue && x.CreatedDate.Value.ToString("M-d") == date);
                var edit = editStats.FirstOrDefault(x => x.CreatedDate.HasValue && x.CreatedDate.Value.ToString("M-d") == date);

                getStats.Add(new GetStat
                {
                    Date = date,
                    Add  = add?.Count ?? 0,
                    Edit = edit?.Count ?? 0
                });
            }

            var days      = getStats.Select(x => x.Date).ToList();
            var addCount  = getStats.Select(x => x.Add).ToList();
            var editCount = getStats.Select(x => x.Edit).ToList();

            return(new GetResult
            {
                Sites = sites,
                Days = days,
                AddCount = addCount,
                EditCount = editCount
            });
        }
Beispiel #3
0
        private Query GetQuery(string category, string pluginId, string keyword, string dateFrom, string dateTo)
        {
            var query = Q.OrderByDesc(nameof(ErrorLog.Id));

            if (string.IsNullOrEmpty(category) && string.IsNullOrEmpty(pluginId) && string.IsNullOrEmpty(keyword) && string.IsNullOrEmpty(dateFrom) && string.IsNullOrEmpty(dateTo))
            {
                return(query);
            }

            if (!string.IsNullOrEmpty(category))
            {
                query.Where(nameof(ErrorLog.Category), category);
            }

            if (!string.IsNullOrEmpty(pluginId))
            {
                query.Where(nameof(ErrorLog.PluginId), pluginId);
            }

            if (!string.IsNullOrEmpty(keyword))
            {
                var keywordId = TranslateUtils.ToInt(keyword);
                if (keywordId > 0)
                {
                    query.Where(nameof(ErrorLog.Id), keywordId);
                }
                else
                {
                    var like = $"%{keyword}%";
                    query.Where(q =>
                                q.WhereLike(nameof(ErrorLog.Message), like)
                                .OrWhereLike(nameof(ErrorLog.StackTrace), like)
                                .OrWhereLike(nameof(ErrorLog.Summary), like)
                                );
                }
            }

            if (!string.IsNullOrEmpty(dateFrom))
            {
                query.WhereDate(nameof(ErrorLog.CreatedDate), ">=", TranslateUtils.ToDateTime(dateFrom));
            }
            if (!string.IsNullOrEmpty(dateTo))
            {
                query.WhereDate(nameof(ErrorLog.CreatedDate), "<=", TranslateUtils.ToDateTime(dateTo));
            }

            return(query);
        }
Beispiel #4
0
        public Query GetQuery(List <int> siteIds, string logType, int adminId, string keyword, string dateFrom, string dateTo)
        {
            var query = Q.OrderByDesc(nameof(SiteLog.Id));

            if (siteIds != null && siteIds.Count > 0)
            {
                query.WhereIn(nameof(SiteLog.SiteId), siteIds);
            }

            if (!string.IsNullOrEmpty(logType))
            {
                if (StringUtils.EqualsIgnoreCase(logType, "Channel"))
                {
                    query.Where(nameof(SiteLog.ChannelId), ">", 0).Where(nameof(SiteLog.ContentId), 0);
                }
                else if (StringUtils.EqualsIgnoreCase(logType, "Content"))
                {
                    query.Where(nameof(SiteLog.ChannelId), ">", 0).Where(nameof(SiteLog.ContentId), ">", 0);
                }
            }

            if (adminId > 0)
            {
                query.Where(nameof(SiteLog.AdminId), adminId);
            }

            if (!string.IsNullOrEmpty(keyword))
            {
                var like = $"%{keyword}%";
                query.Where(q =>
                            q.WhereLike(nameof(SiteLog.Action), like).OrWhereLike(nameof(SiteLog.Summary), like)
                            );
            }

            if (!string.IsNullOrEmpty(dateFrom))
            {
                query.WhereDate(nameof(SiteLog.CreatedDate), ">=", TranslateUtils.ToDateTime(dateFrom));
            }
            if (!string.IsNullOrEmpty(dateTo))
            {
                query.WhereDate(nameof(SiteLog.CreatedDate), "<=", TranslateUtils.ToDateTime(dateTo));
            }

            return(query);
        }
        public async Task <ActionResult <GetResult> > Get([FromBody] GetRequest request)
        {
            if (!await _authManager.HasAppPermissionsAsync(Types.AppPermissions.SettingsAnalysisUser))
            {
                return(Unauthorized());
            }

            var lowerDate  = TranslateUtils.ToDateTime(request.DateFrom);
            var higherDate = TranslateUtils.ToDateTime(request.DateTo, DateTime.Now);

            var registerStats = await _statRepository.GetStatsAsync(lowerDate, higherDate, StatType.UserRegister);

            var loginStats = await _statRepository.GetStatsAsync(lowerDate, higherDate, StatType.UserLogin);

            var getStats  = new List <GetStat>();
            var totalDays = (higherDate - lowerDate).TotalDays;

            for (var i = 0; i <= totalDays; i++)
            {
                var date = lowerDate.AddDays(i).ToString("M-d");

                var register = registerStats.FirstOrDefault(x => x.CreatedDate.HasValue && x.CreatedDate.Value.ToString("M-d") == date);
                var login    = loginStats.FirstOrDefault(x => x.CreatedDate.HasValue && x.CreatedDate.Value.ToString("M-d") == date);

                getStats.Add(new GetStat
                {
                    Date     = date,
                    Register = register?.Count ?? 0,
                    Login    = login?.Count ?? 0
                });
            }

            var days          = getStats.Select(x => x.Date).ToList();
            var registerCount = getStats.Select(x => x.Register).ToList();
            var loginCount    = getStats.Select(x => x.Login).ToList();

            return(new GetResult
            {
                Days = days,
                RegisterCount = registerCount,
                LoginCount = loginCount
            });
        }