Browse Source

优化所有区的新结构的统计接口

Li 2 years ago
parent
commit
7b2b31b6cd

+ 53 - 25
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -1183,22 +1183,53 @@ namespace TEAMModelBI.Controllers.BITest
         [HttpPost("get-linqcount")]
         public async Task<IActionResult> GetLinqCount()
         {
-            List<Test> list1 = new();
-            list1.Add(new Test { score = 10, name = "001" });
-            list1.Add(new Test { score = 20, name = "002" });
-            list1.Add(new Test { score = 30, name = "003" });
-            list1.Add(new Test { score = 40, name = "004" });
-            list1.Add(new Test { score = 50, name = "005" });
-            list1.Add(new Test { score = 60, name = "006" });
-
-            List<Test> list2 = new();
-            list2.Add(new Test { score = 40, name = "004" });
-            list2.Add(new Test { score = 50, name = "005" });
-            list2.Add(new Test { score = 60, name = "006" });
-            list2.Add(new Test { score = 70, name = "007" });
-            list2.Add(new Test { score = 80, name = "008" });
-            list2.Add(new Test { score = 90, name = "009" });
-            list2.Add(new Test { score = 100, name = "010" });
+
+            List<linqTest> linqTests = new()
+            {
+                new linqTest  { id = "10110",aresid = "0",name ="明",linq1 =  new linq1 { id ="abc0", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 } } ,
+                new linqTest  { id = "10111",aresid = "1",name ="明1",linq1 =  new linq1 { id ="abc1", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 } } ,
+                new linqTest  { id = "10112",aresid = "2",name ="明2",linq1 =  new linq1 { id ="abc2", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 } } ,
+                new linqTest  { id = "10113",aresid = "3",name ="明3",linq1 = new linq1 { id ="abc3", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 } } ,
+                new linqTest  { id = "10114",aresid = "4",name ="明4",linq1 =  new linq1 { id ="abc4", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 }  },
+                new linqTest  { id = "10115",aresid = "5",name ="明5",linq1 = new linq1 { id ="abc5", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 } } ,
+                new linqTest  { id = "10116",aresid = "6",name ="明6",linq1 =  new linq1 { id ="abc6", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 }  },
+                new linqTest  { id = "10117",aresid = "7",name ="明7",linq1 = new linq1 { id ="abc7", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 }  },
+                new linqTest  { id = "10118",aresid = "8",name ="明8",linq1 = new linq1 { id ="abc8", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 }  },
+                new linqTest  { id = "10119",aresid = "9",name ="明9",linq1 =  new linq1 { id ="abc9", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10 }  },
+                new linqTest  { id = "10120",aresid = "10",name ="明10",linq1 =  new linq1 { id ="abc10", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),cnt=10  } }
+            };
+            for (int i = 0; i < 11; i++)
+            {
+                linqTest linqt = new() { id = $"qwe{i}", aresid = $"{i}", name = $"名字{i}", linq1 = new linq1 { id = $"abc{i}", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), cnt = (11 + i) } };
+                linqTests.Add(linqt);
+            }
+
+            var grup = linqTests.GroupBy(g => g.aresid).ToList();
+
+            var grup1 = linqTests.GroupBy(g => g.aresid).Select(s=>new { areid= s.Key,linq1Id = s.Select(sn => sn.linq1.id).ToList(), id = s.Select(sn => sn.id).ToList(), name = s.Select(sn => sn.name).ToList(), linq1Cnt = s.Select(sn => sn.linq1.cnt).ToList(), lescnt = s.Select(sf=>sf.linq1.cnt).Sum()}).ToList();
+
+            return Ok(new { state = RespondCode.Ok, grup1, grup });
+
+            List<Test> list1 = new()
+            {
+                new Test { score = 10, name = "001" },
+                new Test { score = 20, name = "002" },
+                new Test { score = 30, name = "003" },
+                new Test { score = 40, name = "004" },
+                new Test { score = 50, name = "005" },
+                new Test { score = 60, name = "006" }
+            };
+
+            List<Test> list2 = new()
+            {
+                new Test { score = 40, name = "004" },
+                new Test { score = 50, name = "005" },
+                new Test { score = 60, name = "006" },
+                new Test { score = 70, name = "007" },
+                new Test { score = 80, name = "008" },
+                new Test { score = 90, name = "009" },
+                new Test { score = 100, name = "010" }
+            };
 
             //list3 return 2
             List<Test> list3 = list1.Where(x => !list2.Any(x2 => x.score == x2.score && x.name == x2.name)).ToList();
@@ -1239,20 +1270,14 @@ namespace TEAMModelBI.Controllers.BITest
             var (lastWeekStart, lastWeekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastweek");
 
 
-            List<linqTest> linqTests = new();
-            for (int i = 0; i < 10; i++)
-            {
-                linqTest linqt = new() { id = $"qwe{i}", name = $"名字{i}", linq1s = new List<linq1> { new linq1 { id = $"abc{i}", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }, new linq1 { id = $"def{i}", times = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } } };
-                linqTests.Add(linqt);
-            }
 
             //var set = linqTests.Select((x, y) => x.linq1s.Find(l => l.id.Equals($"abc0"))).ToList();
-            var set = linqTests.Where(x => !string.IsNullOrEmpty(x.linq1s.Find(l => l.id.Equals($"abc0")).ToString()));
+            //var set = linqTests.Where(x => !string.IsNullOrEmpty(x.linq1s.Find(l => l.id.Equals($"abc0")).ToString()));
             //var tem220p = linqTests.ForEach(x => {
             //    var coreUser = linqTests.Find(c => c.id.Equals("abc0"));
             //   });  //.Except(linqTests.Select(y => y.linq1s.Find(n => n.times.Equals("abc0"))));
 
-            return Ok(new { state = 200, Mon, Sun, ss, sss, ssss, sssss, lastWeekStart, lastWeekEnd, have, en2, bingji, cha, jiaoji, chaji, list3, list4, temp, list1, linqTests, set });
+            return Ok(new { state = 200, Mon, Sun, ss, sss, ssss, sssss, lastWeekStart, lastWeekEnd, have, en2, bingji, cha, jiaoji, chaji, list3, list4, temp, list1, linqTests });
         }
 
         /// <summary>
@@ -2141,17 +2166,20 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { state = 200, statsInfo });
         }
 
+
         public class linqTest
         {
             public string id { get; set; }
+            public string aresid { get; set; }
             public string name { get; set; }
-            public List<linq1> linq1s { get; set; }
+            public linq1 linq1 { get; set; }
         }
 
         public class linq1
         {
             public string id { get; set; }
             public long times { get; set; }
+            public int cnt { get; set; }
         }
 
         public class Test

+ 8 - 2
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -1048,12 +1048,15 @@ namespace TEAMModelBI.Controllers.Census
             {
                 statsInfos.Add(item);
             }
-            var areaGrup = statsInfos.GroupBy(g => g.areaId).ToList().Select(s => s.Where(w => w.areaId.Equals(s.Key)));
+            var areaGrup = statsInfos.GroupBy(p => p.areaId).Select(s => new { areaId = s.Key, lessAct = (s.Select(sl => sl.lesson.all).Sum() + s.Select(sa => sa.activity.all).Sum()), lessCnt = s.Select(sl => sl.lesson.all).Sum(), actCnt = s.Select(sa => sa.activity.all).Sum() }).ToList();
 
             StatsInfo statsInfo = null;
             statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos);
             if (statsInfo != null)
             {
+                allScStats.sc = statsInfos.Count;
+                allScStats.weekSc = statsInfos.FindAll(f=>f.scCreateTime  >= weekS && f.scCreateTime <= weekE).Count;
+                allScStats.monthSc = statsInfos.FindAll(f => f.scCreateTime >= mthS && f.scCreateTime <= mthE).Count;
                 allScStats.tch = statsInfo.tch;
                 allScStats.dayTch = statsInfo.dayTch;
                 allScStats.weekTch = statsInfo.weekTch;
@@ -1108,7 +1111,7 @@ namespace TEAMModelBI.Controllers.Census
                 }
             }
 
-            return Ok(new { state = RespondCode.Ok, allScStats });
+            return Ok(new { state = RespondCode.Ok, allScStats, areaGrup });
         }
 
         #endregion   新的统计接口
@@ -1278,6 +1281,9 @@ namespace TEAMModelBI.Controllers.Census
         /// </summary>
         public record AllScStats
         {
+            public int sc { get; set; }
+            public int weekSc { get; set; }
+            public int monthSc { get; set; }
             public int tch { get; set; }
             public int dayTch { get; set; }
             public int weekTch { get; set; }