private void GeneratedWhiteListReport(string title, ZoneEntity zone, List <List <CloudflareLog> > cloudflareLogs)
        {
            var cloundFlareApiService = new CloudFlareApiService();
            var whiteList             = cloundFlareApiService.GetAccessRuleList(zone.ZoneId, zone.AuthEmail, zone.AuthKey, EnumMode.whitelist);
            var subWhiteList          = whiteList.Where(a => a.notes.Contains("WHITELIST CLEINT'S IP ADDRESS SITEID"))
                                        .Select(a => new WhiteListModel
            {
                IP = a.configurationValue
            }).ToList();

            //var subWhiteList = new List< WhiteListModel>(){
            //    new WhiteListModel {
            //        IP= "131.242.135.253",
            //    },
            //    new WhiteListModel {
            //        IP= "131.242.135.252",
            //    }
            //};

            var totalList = cloudflareLogs.SelectMany(a => a)
                            .Join(subWhiteList,
                                  left => left.ClientIP,
                                  right => right.IP,
                                  (left, right) => new
            {
                left.ClientIP,
                left.ClientRequestHost
            })
                            .GroupBy(a => new { a.ClientIP, a.ClientRequestHost })
                            .Select(
                g => new
            {
                IP       = g.Key.ClientIP,
                HostName = g.Key.ClientRequestHost,
                Count    = g.Count(),
            })
                            .OrderByDescending(a => a.Count);

            List <string> ipList = new List <string>();

            foreach (var item in totalList)
            {
                //取不同的20个IP
                if (!ipList.Contains(item.IP))
                {
                    ipList.Add(item.IP);
                }

                if (ipList.Count > 20)
                {
                    break;
                }

                int           max      = GetMax(cloudflareLogs, item.IP, item.HostName);
                int           min      = GetMin(cloudflareLogs, item.IP, item.HostName);
                int           avg      = GetAvg(cloudflareLogs, item.IP, item.HostName);
                List <string> urls     = GetTop5Urls(cloudflareLogs, item.IP, item.HostName);
                string        urlsJson = JsonConvert.SerializeObject(urls);

                int?maxHistory = ActionReportBusiness.GetMaxForWhiteList(zone.ZoneId, item.IP, item.HostName);
                int?minHistory = ActionReportBusiness.GetMinForWhiteList(zone.ZoneId, item.IP, item.HostName);
                int?avgHistory = ActionReportBusiness.GetAvgForWhiteList(zone.ZoneId, item.IP, item.HostName);

                string maxDisplay = string.Format("{0}({1})", max, maxHistory.HasValue ? maxHistory.Value.ToString() : nothing);
                string minDisplay = string.Format("{0}({1})", min, minHistory.HasValue ? minHistory.Value.ToString() : nothing);
                string avgDisplay = string.Format("{0}({1})", avg, avgHistory.HasValue ? avgHistory.Value.ToString() : nothing);

                ActionReport report = new ActionReport
                {
                    IP          = item.IP,
                    HostName    = item.HostName,
                    Max         = max,
                    Min         = min,
                    Avg         = avg,
                    FullUrl     = urlsJson,
                    Title       = title,
                    ZoneId      = zone.ZoneId,
                    Count       = item.Count,
                    Mode        = "WhiteList",
                    CreatedTime = DateTime.UtcNow,
                    MaxDisplay  = maxDisplay,
                    MinDisplay  = minDisplay,
                    AvgDisplay  = avgDisplay,
                    Remark      = "",
                };
                ActionReportBusiness.Add(report);
            }
        }
        private void GeneratedActiveReport(string title, ZoneEntity zone, List <List <CloudflareLog> > cloudflareLogs)
        {
            var cloundFlareApiService = new CloudFlareApiService();
            var whiteList             = cloundFlareApiService.GetAccessRuleList(zone.ZoneId, zone.AuthEmail, zone.AuthKey, EnumMode.whitelist);
            var whiteListIps          = whiteList.Select(a => a.configurationValue);

            var totalList = cloudflareLogs.SelectMany(a => a)
                            .GroupBy(a => new { a.ClientIP, a.ClientRequestHost })
                            .Select(
                g => new
            {
                IP       = g.Key.ClientIP,
                HostName = g.Key.ClientRequestHost,
                Count    = g.Count(),
            })
                            .Where(a => !whiteListIps.Contains(a.IP))
                            .OrderByDescending(a => a.Count);

            List <string> ipList = new List <string>();

            foreach (var item in totalList)
            {
                //取不同的20个IP
                if (!ipList.Contains(item.IP))
                {
                    ipList.Add(item.IP);
                }

                if (ipList.Count > 20)
                {
                    break;
                }

                int           max      = GetMax(cloudflareLogs, item.IP, item.HostName);
                int           min      = GetMin(cloudflareLogs, item.IP, item.HostName);
                int           avg      = GetAvg(cloudflareLogs, item.IP, item.HostName);
                List <string> urls     = GetTop5Urls(cloudflareLogs, item.IP, item.HostName);
                string        urlsJson = JsonConvert.SerializeObject(urls);

                int?maxHistory = ActionReportBusiness.GetMaxForAction(zone.ZoneId, item.IP, item.HostName);
                int?minHistory = ActionReportBusiness.GetMinForAction(zone.ZoneId, item.IP, item.HostName);
                int?avgHistory = ActionReportBusiness.GetAvgForAction(zone.ZoneId, item.IP, item.HostName);

                string maxDisplay = string.Format("{0}({1})", max, maxHistory.HasValue ? maxHistory.Value.ToString() : nothing);
                string minDisplay = string.Format("{0}({1})", min, minHistory.HasValue ? minHistory.Value.ToString() : nothing);
                string avgDisplay = string.Format("{0}({1})", avg, avgHistory.HasValue ? avgHistory.Value.ToString() : nothing);

                ActionReport report = new ActionReport
                {
                    IP          = item.IP,
                    HostName    = item.HostName,
                    Max         = max,
                    Min         = min,
                    Avg         = avg,
                    FullUrl     = urlsJson,
                    Title       = title,
                    ZoneId      = zone.ZoneId,
                    Count       = item.Count,
                    Mode        = "Action",
                    CreatedTime = DateTime.UtcNow,
                    MaxDisplay  = maxDisplay,
                    MinDisplay  = minDisplay,
                    AvgDisplay  = avgDisplay,
                    Remark      = "",
                };
                ActionReportBusiness.Add(report);
            }
        }