Browse Source

优化学校加区,和区域返回切换记录,编写解析网关数据

Li 3 years ago
parent
commit
46973cd714

+ 32 - 2
TEAMModelBI/Controllers/BIHome/AnalyseFileController.cs

@@ -1,12 +1,15 @@
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
 
 namespace TEAMModelBI.Controllers.BIHome
 {
@@ -22,8 +25,10 @@ namespace TEAMModelBI.Controllers.BIHome
         }
 
         [HttpPost("get-visitjson")]
-        public async Task<IActionResult> GetVisitJson() 
+        public async Task<IActionResult> GetVisitJson(JsonElement jsonElement) 
         {
+            jsonElement.TryGetProperty("path", out JsonElement _path);
+            jsonElement.TryGetProperty("time", out JsonElement _time);
             var path = $"{_environment.ContentRootPath}/JsonFile/TempFile/PT1H.json";
             StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
             List<object> objs = new(); 
@@ -46,12 +51,37 @@ namespace TEAMModelBI.Controllers.BIHome
             string input = visits.ToString();
             List<AGInfo> aGInfos = input.ToObject<List<AGInfo>>();
 
+            //var ipGroup = aGInfos.GroupBy(g => g.properties.clientIp).ToDictionary(k => k.Key, k => k.Count()).ToList();
 
-            return Ok(new { state = 200, aGInfos, objs, visits });
+            List<RecGWInfo> recInfo = aGInfos.Select(x => new RecGWInfo { hour = DateTimeOffset.Parse(x.time).ToString("yyyyMMddHH"),hostName=x.properties.hostname  }).ToList();
+
+
+            List<StatisNameCnt> ipCnt = aGInfos.GroupBy(g => g.properties.clientIp).Select(x => new StatisNameCnt { name = x.Key, cnt = x.Count() }).ToList();
+            ipCnt.Sort((x, y) => y.cnt.CompareTo(x.cnt));
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            var apiCnt = aGInfos.Select(s => s.properties.requestUri.Split("?").ToList().Count()>1 ? s.properties.requestUri.Split("?").ToList()[0]: s.properties.requestUri).GroupBy(g => g).Select(x=>new { key = x.Key,cnt =x.Count()}).ToList();
+
+            return Ok(new { state = 200, apiCnt, ipCnt });
+        }
+        public record RecGWInfo
+        {
+            public string hour { get; set; }
+            public string ip { get; set; }
+            public string api { get; set; }
+            public string hostName { get; set; }
         }
 
 
 
+
+
+        public record StatisNameCnt 
+        {
+            public string name { get; set; }
+            public int cnt { get; set; }
+        }
+
         public record AGInfo 
         {
             //public string resourceId { get; set; }

+ 4 - 7
TEAMModelBI/Controllers/BISchool/AreaRelevantController.cs

@@ -121,17 +121,14 @@ namespace TEAMModelBI.Controllers.BISchool
                 {
                     tempSchool.areaId = null;
                     tempSchool.standard = null;
-                    var temp = tempSchool.manyAreas.Find(ma => ma.areaId == $"{areaId}");
-                    if (temp != null)
-                        tempSchool.manyAreas.Remove(temp);
                 }
-                else
+
+                if (tempSchool.manyAreas.Count > 0)
                 {
                     var temp = tempSchool.manyAreas.Find(ma => ma.areaId == $"{areaId}");
-                    if (temp == null)
-                        tempSchool.manyAreas.Add(new ManyArea { areaId = $"{areaId}", standard = $"{standard}" });
+                    if (temp != null)
+                        tempSchool.manyAreas.Remove(new ManyArea { areaId = $"{areaId}", standard = $"{standard}" });
                 }
-
                 School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempSchool, tempSchool.id, new PartitionKey("Base"));
 
                 //保存操作记录

+ 6 - 4
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -64,11 +64,13 @@ namespace TEAMModelBI.Controllers.BISchool
                     areas.Add(item);
                 }
 
-                areas.ForEach(async recArea => {
+                foreach (var recArea in areas)
+                {
                     recArea.schoolCount = await CommonFind.GetSqlValueCount(azureClient, "School", $"select value(count(c.id)) from c where c.areaId='{recArea.id}' and c.standard='{recArea.standard}'", "Base");
-                    recArea.aquoteRec = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and  areaId eq '{recArea.id}'");
-                });
-
+                    List<AreaQuoteRecord> aqr = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and  areaId eq '{recArea.id}'");
+                    aqr.Sort((x, y) => y.RowKey.CompareTo(x.RowKey));
+                    recArea.aquoteRec = aqr;
+                }
                 return Ok(new { state = 200, areas });
             }
             catch (Exception ex)

+ 4 - 4
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -142,11 +142,11 @@ namespace TEAMModelBI.Controllers.BISchool
                             {
                                 school.standard = $"{standard}";
                                 school.areaId = $"{_areaId}";
-                                var marea = school.manyAreas.Find(ma => ma.areaId == $"{_areaId}" && ma.standard == $"{standard}");
-                                if (marea == null)
-                                    school.manyAreas.Add(new ManyArea { areaId = $"{_areaId}", standard = $"{standard}" });
                             }
-                            else 
+
+                            if (school.manyAreas.Count == 0)
+                                school.manyAreas.Add(new ManyArea { areaId = $"{_areaId}", standard = $"{standard}" });
+                            else
                             {
                                 var marea = school.manyAreas.Find(ma => ma.areaId == $"{_areaId}" && ma.standard == $"{standard}");
                                 if (marea == null)

+ 29 - 2
TEAMModelOS.SDK/Models/Cosmos/BI/AreaQuoteRecord.cs

@@ -18,6 +18,33 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         public string quoteId { get; set; }
         public string quoteName { get; set; }
         public string standard { get; set; }
-        public long time { get; set; }
-    }   
+    }
+
+    public class AppGWRecHour : TableEntity 
+    {
+        /// <summary>
+        /// 小时      yyyyMMddHH
+        /// </summary>
+        public string hour { get; set; }
+        /// <summary>
+        /// 次数
+        /// </summary>
+        public int cnt { get; set; }
+        public string hostName { get; set; }
+    }
+
+    public class AppGWRecDay : TableEntity 
+    {
+        /// <summary>
+        /// 天      yyyyMMdd
+        /// </summary>
+        public int day { get; set; }
+        /// <summary>
+        /// 次数
+        /// </summary>
+        public int cnt { get; set; }
+        public string hostName { get; set; }
+    }
+
+
 }