Explorar o código

BI代码在线首页的未完成

Li %!s(int64=3) %!d(string=hai) anos
pai
achega
6346a7b026

+ 83 - 0
TEAMModelBI/Controllers/BIHome/OnLineController.cs

@@ -0,0 +1,83 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelBI.Tool;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Models;
+
+namespace TEAMModelBI.Controllers.BIHome
+{
+    [Route("online")]
+    [ApiController]
+    public class OnLineController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly AzureStorageFactory _azureStorage;
+
+        public OnLineController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage)
+        {
+            _azureCosmos = azureCosmos;
+            _azureStorage = azureStorage;
+        }
+
+        [HttpPost("get-count")]
+        public async Task<IActionResult> GetCount() 
+        {
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);  //今天开始时间
+            var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTime.UtcNow.Year}-{DateTime.UtcNow.Month}-{DateTime.UtcNow.Day - 1}"));   //昨天开始时间
+            
+            var near7S = DateTimeOffset.UtcNow.AddDays(-7).ToUnixTimeMilliseconds();  //前七天的开始时间
+            var near7E = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();     //当前结束时间
+
+            int areaCount = 0;   //学区总数
+            int scCount = 0;  //学校总数
+            int tecCount = 0; //教师总数
+            int stuCount = 0; //学生总数
+            int onCount = 0;  //当前在线人数
+
+            string currentSql = "select value(count(c.id)) from c";
+
+            areaCount = await CommonFind.GetSqlValueCount(cosmosClient, "Normal", currentSql, "Base-Area");
+            scCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", currentSql, "Base");
+            tecCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", currentSql, "Base");
+            stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", "select value(count(c.id)) from c where c.pk='Base'");
+
+            long hour1 = DateTimeOffset.UtcNow.AddHours(-1).ToUnixTimeMilliseconds();
+
+            List<RecOnLine> recStuOnLines = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where c.pk='Base' ",requestOptions:new QueryRequestOptions() { }))
+            {
+                recStuOnLines.Add(item);
+            }
+
+            List<RecOnLine> recTecOnLines = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            {
+                recTecOnLines.Add(item);
+            }
+
+            //var tempRec = recOnLines.Select((x,y) => x.loginInfos.Find(l => l.exp >= hour1)).ToList();
+
+
+
+
+            return Ok(new { state = 200, areaCount, scCount, tecCount, stuCount });
+        }
+
+
+        public record RecOnLine
+        {
+            public string id { get; set; }
+            public string name { get; set; }
+            public string code { get; set; }
+            public List<Teacher.LoginInfo> loginInfos { get; set; }
+        }
+
+    }
+}

+ 30 - 30
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -654,7 +654,7 @@ namespace TEAMModelBI.Controllers.BITest
             int year = DateTimeOffset.UtcNow.Year;
             int month = DateTimeOffset.UtcNow.Month;
 
-            
+            var datetime7 = DateTimeOffset.UtcNow.AddDays(-7); //前七天的时间
 
             List<string> strList = monthsOfYear("2021-1");
 
@@ -686,7 +686,7 @@ namespace TEAMModelBI.Controllers.BITest
             //return Ok(new { strList, dateTime, year, start, end, endList, endList1, endList2 });
 
 
-            return Ok(new { start1, end1, start2, end2, start3, end3, start4, end4 , start5, end5 , start6, end6 , start7, end7 });
+            return Ok(new { datetime7, start1, end1, start2, end2, start3, end3, start4, end4 , start5, end5 , start6, end6 , start7, end7 });
         }
 
         public static List<string> monthsOfYear(string yearMonth)
@@ -1244,17 +1244,38 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { state = 200});
         }
 
-        [HttpPost("get-vlaue")]
-        public async Task<IActionResult> GetValueCount() 
+        [HttpPost("get-linqcount")]
+        public async Task<IActionResult> GetLinqCount() 
         {
-            var cosmosClient = _azureCosmos.GetCosmosClient();
-            int counts = 0;
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<int>(queryText: "select value(count(c.id)) from c", requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            List<linqTest> linqTests = new();
+            for (int i = 0; i < 10; i++)
             {
-                counts += item;
+                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);
             }
 
-            return Ok(new { state = 200, counts }); 
+            //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 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, linqTests, set });
+        }
+
+
+
+        public class linqTest
+        {
+            public string id{ get; set; }
+            public string name { get; set; }
+            public List<linq1> linq1s { get; set; }
+        }
+
+        public class linq1 
+        {
+            public string id { get; set; }
+            public long times { get; set; }
         }
 
         public class Test
@@ -1307,27 +1328,6 @@ namespace TEAMModelBI.Controllers.BITest
             return iLastDay;
         }
 
-        public record lessons 
-        {
-            public long countB { get; set; }
-            public long countP { get; set; }
-            public long countT { get; set; }
-            public long countPT { get; set; }
-            public LessonCount lesson { get; set; }
-        }
-
-        public record pageTest
-        {
-            public string keyt { get; set; }
-            public string listv { get; set; }
-        }
-
-        public record pageTest1
-        {
-            public string keyt { get; set; }
-            public List<string> listv { get; set; }
-        }
-
         public class GenerateRandom1
         {
             /// <summary>

+ 41 - 0
TEAMModelBI/Tool/CommonFind.cs

@@ -217,5 +217,46 @@ namespace TEAMModelBI.Tool
 
             return totals;
         }
+
+        /// <summary>
+        /// 单个容器数据统计
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="SqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetSqlValueCount(CosmosClient cosmosClient, string container, string SqlTxt,string code = null) 
+        {
+            int totals = 0;
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt,requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            {
+                totals += item;
+            }
+
+            return totals;
+        }
+
+        /// <summary>
+        /// 多个容器数据统计
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="SqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetSqlValueCount(CosmosClient cosmosClient, List<string> containers, string SqlTxt, string code = null)
+        {
+            int totals = 0;
+            foreach (var container in containers)
+            {
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+                {
+                    totals += item;
+                }
+            }
+
+            return totals;
+        }
     }
 }

+ 14 - 14
TEAMModelBI/Tool/TimeHelper.cs

@@ -188,19 +188,19 @@ namespace TEAMModelBI.Tool
             int month = dateTime.Month;
             int day = dateTime.Day;
             DateTimeOffset tempStrart = new();
-            DateTimeOffset tempEnt = new();
+            DateTimeOffset tempEnd = new();
             switch (type) 
             {
                 case "year":
                     tempStrart = new DateTime(year, 1, 1);
-                    tempEnt = new DateTime(year, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59);
+                    tempEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59);
                     break;
 
                 case "term":
                     if (month <= 8 && month >= 3)
                     {
                         tempStrart = new DateTime(year, 3, 1);
-                        tempEnt = new DateTime(year, 8, 31, 23, 59, 59);
+                        tempEnd = new DateTime(year, 8, 31, 23, 59, 59);
                     }
                     else
                     {
@@ -209,11 +209,11 @@ namespace TEAMModelBI.Tool
                         if (month >= 9)
                         {
                             tempStrart = new DateTime(year, 9, 1);
-                            tempEnt = new DateTime(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);                        }
+                            tempEnd = new DateTime(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);                        }
                         else
                         {
                             tempStrart = new DateTime(year - 1, 9, 1);
-                            tempEnt = new DateTime(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);
+                            tempEnd = new DateTime(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);
                         }
                     }
 
@@ -230,7 +230,7 @@ namespace TEAMModelBI.Tool
                         if (month <= 8 && month >= 3)
                         {
                             tempStrart = new DateTime(year, 3, 1);
-                            tempEnt = new DateTime(year, 8, 31, 23, 59, 59);
+                            tempEnd = new DateTime(year, 8, 31, 23, 59, 59);
                         }
                         else
                         {
@@ -239,12 +239,12 @@ namespace TEAMModelBI.Tool
                             if (month >= 9)
                             {
                                 tempStrart = new DateTime(year, 9, 1);
-                                tempEnt = new DateTime(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);
+                                tempEnd = new DateTime(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);
                             }
                             else
                             {
                                 tempStrart = new DateTime(year - 1, 9, 1);
-                                tempEnt = new DateTime(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);
+                                tempEnd = new DateTime(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59);
                             }
                         }
                     }
@@ -252,14 +252,14 @@ namespace TEAMModelBI.Tool
                     break;
                 case "month":
                     tempStrart = new DateTime(year, month, 1);
-                    tempEnt = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59);
+                    tempEnd = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59);
 
                     break;
                 case "week":
                     DateTimeOffset weekStrart = dateTime.AddDays(-(int)(dateTime.DayOfWeek) + 1);
                     DateTimeOffset weekEnd  = dateTime.AddDays(7-(int)(dateTime.DayOfWeek));
                     tempStrart = new DateTime(weekStrart.Year, weekStrart.Month, weekStrart.Day);
-                    tempEnt = new DateTime(weekEnd.Year, weekEnd.Month, weekEnd.Day, 23, 59, 59); 
+                    tempEnd = new DateTime(weekEnd.Year, weekEnd.Month, weekEnd.Day, 23, 59, 59); 
 
                     break;
                 case "lastweek":
@@ -268,24 +268,24 @@ namespace TEAMModelBI.Tool
                     var Mon = dateTime.AddDays((-7 - m));//星期一
                     var Sun = dateTime.AddDays((-7 - s));  //星期日
                     tempStrart = new DateTime(Mon.Year, Mon.Month, Mon.Day);
-                    tempEnt = new DateTime(Sun.Year, Sun.Month, Sun.Day, 23, 59, 59);
+                    tempEnd = new DateTime(Sun.Year, Sun.Month, Sun.Day, 23, 59, 59);
 
                     break;
                 default:
                     tempStrart = new DateTime(year, month, day);
-                    tempEnt = new DateTime(year, month, day, 23, 59, 59);
+                    tempEnd = new DateTime(year, month, day, 23, 59, 59);
                     //start = dateLenth ? DateTimeOffset.Parse($"{dayStart}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dayStart}").ToUnixTimeSeconds();
                     //end = dateLenth ? DateTimeOffset.Parse($"{dayEnd}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dayEnd}").ToUnixTimeSeconds();
                     break;            
             }
 
             start = dateLenth ? DateTimeOffset.Parse($"{tempStrart}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{tempStrart}").ToUnixTimeSeconds();
-            end = dateLenth ? DateTimeOffset.Parse($"{tempEnt}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{tempEnt}").ToUnixTimeSeconds();
+            end = dateLenth ? DateTimeOffset.Parse($"{tempEnd}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{tempEnd}").ToUnixTimeSeconds();
 
             return (start, end);
-
         }
 
 
+
     }
 }