瀏覽代碼

优化首页课例查询速度,优化权限访问的问题

Li 3 年之前
父節點
當前提交
549880c1b2

+ 3 - 3
TEAMModelBI/Controllers/BIAbility/AbilityMgmtController.cs

@@ -101,7 +101,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("del-ability")]
         public async Task<IActionResult> DelAbility(JsonElement jsonElement)
         {
@@ -152,7 +152,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("upd-ability")]
         public async Task<IActionResult> UpdAbility(Ability ability)
         {
@@ -241,7 +241,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("upd-currency")]
         public async Task<IActionResult> UpdateCurrency(JsonElement jsonElement) 
         {

+ 2 - 2
TEAMModelBI/Controllers/BIAbility/AbilityTaskMgmtController.cs

@@ -118,7 +118,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="abilityTask"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles= "assist")]
+        [AuthToken(Roles= "admin,assist")]
         [HttpPost("upd-abilitytask")]
         public async Task<IActionResult> UpdAbilityTask(RecordAbilityTask recordAbilityTask)//AbilityTask abilityTask) 
         {
@@ -227,7 +227,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("del-abilitytask")]
         public async Task<IActionResult> DelAbilityTask(JsonElement jsonElement) 
         {

+ 88 - 18
TEAMModelBI/Controllers/BIHome/OnLineController.cs

@@ -78,16 +78,18 @@ namespace TEAMModelBI.Controllers.BIHome
             {
                 recStuOnLines.Add(item);
             }
-            onStuCnt = (from rs in recStuOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count();  //linq查询
-            //onStuCnt = recStuOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count();  //lambda 表达式查询 
 
             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 where array_length(c.loginInfos) > 0 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
             {
                 recTecOnLines.Add(item);
-            }                        
-            onTchCnt = (from rs in recTecOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count();  //linq查询
-            //onStuCnt = recTecOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count();  //lambda 表达式查询 
+            }
+
+            //onStuCnt = (from rs in recStuOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count();  //linq查询 学生在线人数
+            onStuCnt = recStuOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count();  //lambda 表达式查询   教师查询人数
+
+            //onTchCnt = (from rs in recTecOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count();  //linq查询  教师查询人数
+            onTchCnt = recTecOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count();  //lambda 表达式查询    教师查询人数
             
             return Ok(new { state = 200, areaCnt, scCnt, tchCnt, stuCnt, todayScCnt, todayTchCnt, todayStuCnt, onStuCnt, onTchCnt});
         }
@@ -239,30 +241,81 @@ namespace TEAMModelBI.Controllers.BIHome
             Dictionary<int, int> tchLessCnt = new();   //教师课例
             Dictionary<int, int> yesterdayCnt = new();  //昨天24小时课例
 
+            var (daySt, dayEt) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间    13位
+            var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{dateTime.Day - 1}"));   //昨天开始时间
+
+            List<RecLesn> scRecLesn = new(); //学校课例
+            List<RecLesn> tchRecLesn = new(); //个人课例
+            List<RecLesn> allRecLesn = new();  //昨天所有课例
+            string lesnSql = $"select c.id,c.name,c.code,c.school,c.scope,c.startTime  from c where c.pk='LessonRecord' and c.startTime >={daySt} and c.startTime <= {dayEt}";
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { }))
+            {
+                scRecLesn.Add(item);
+            }
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
+            {
+                tchRecLesn.Add(item);
+            }
+
+
+            string allLesnSql = $"select c.id,c.name,c.code,c.school,c.scope,c.startTime  from c where c.pk='LessonRecord' and c.startTime >={lastDayS} and c.startTime <= {lastdayE}";
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: allLesnSql, requestOptions: new QueryRequestOptions() { }))
+            {
+                allRecLesn.Add(item);
+            }
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: allLesnSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
+            {
+                allRecLesn.Add(item);
+            }
+
             for (int i = 0; i < 24; i++)
             {
                 if (hour >= i)
                 {
                     DateTimeOffset timeHour = new DateTime(year, month, day, i, 0, 0);
                     var (hourS, hourE) = TimeHelper.GetStartOrEnd(timeHour, type: "hour");
-                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { }))
-                    {
-                        scLessCnt.Add(i, item);
-                    }
 
-                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
-                    {
-                        tchLessCnt.Add(i, item);
-                    }
+                    var scLesn = scRecLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE).ToList();
+                    scLessCnt.Add(i, scLesn.Count());
+
+                    var tchLesn = scRecLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE).ToList();
+                    tchLessCnt.Add(i, tchLesn.Count());
                 }
 
                 DateTimeOffset yesterday = new DateTime(year, month, day - 1, i, 0, 0);
                 var (yHourS, yHourE) = TimeHelper.GetStartOrEnd(yesterday, type: "hour");
-                string sql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >= {yHourS} and c.startTime <= {yHourE}";
-                int hourLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string> { "School", "Teacher" }, sql);
-                yesterdayCnt.Add(i, hourLessCnt);
+
+                var allLesn = allRecLesn.Where(item => item.startTime >= yHourS && item.startTime <= yHourE).ToList();
+                yesterdayCnt.Add(i, allLesn.Count());
             }
 
+            ////通过循环实时查询课例统计
+            //for (int i = 0; i < 24; i++)
+            //{
+            //    if (hour >= i)
+            //    {
+            //        DateTimeOffset timeHour = new DateTime(year, month, day, i, 0, 0);
+            //        var (hourS, hourE) = TimeHelper.GetStartOrEnd(timeHour, type: "hour");
+            //        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { }))
+            //        {
+            //            scLessCnt.Add(i, item);
+            //        }
+
+            //        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
+            //        {
+            //            tchLessCnt.Add(i, item);
+            //        }
+            //    }
+
+            //    DateTimeOffset yesterday = new DateTime(year, month, day - 1, i, 0, 0);
+            //    var (yHourS, yHourE) = TimeHelper.GetStartOrEnd(yesterday, type: "hour");
+            //    string sql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >= {yHourS} and c.startTime <= {yHourE}";
+            //    int hourLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string> { "School", "Teacher" }, sql);
+            //    yesterdayCnt.Add(i, hourLessCnt);
+            //}
+
             return Ok(new { state = 200, scLessCnt = scLessCnt.ToList(), tchLessCnt = tchLessCnt.ToList(), yesterdayCnt = yesterdayCnt.ToList() });
         }
 
@@ -297,6 +350,9 @@ namespace TEAMModelBI.Controllers.BIHome
             return Ok(new { state = 200, scEdCnt });
         }
 
+        /// <summary>
+        /// 记录在线人数
+        /// </summary>
         public record RecOnLine
         {
             public string id { get; set; }
@@ -305,7 +361,10 @@ namespace TEAMModelBI.Controllers.BIHome
             public List<Teacher.LoginInfo> loginInfos { get; set; }
         }
 
-        public class RecScEd
+        /// <summary>
+        /// 记录学校版本信息
+        /// </summary>
+        public record RecScEd
         {
             public string id { get; set; }
             public string name { get; set; }
@@ -316,6 +375,17 @@ namespace TEAMModelBI.Controllers.BIHome
             public int hard { get; set; } = 0; //硬体
         }
 
-
+        /// <summary>
+        /// 记录课例
+        /// </summary>
+        public record RecLesn
+        {
+            public string id { get; set; }
+            public string name { get; set; }
+            public string code { get; set; }
+            public string school { get; set; }
+            public string scope{get;set;}
+            public long startTime { get; set; }
+        }
     }
 }

+ 4 - 4
TEAMModelBI/Controllers/BINormal/AppCompanyController.cs

@@ -106,7 +106,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="appCompany"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,company")]
+        [AuthToken(Roles = "admin,assist,company")]
         [HttpPost("set-info")]
         public async Task<IActionResult> SetAppInfo(AppCompany appCompany)
         {
@@ -214,7 +214,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("get-apply")]
         public async Task<IActionResult> SetAuditApp(JsonElement jsonElement)
         {
@@ -282,7 +282,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,company")]
+        [AuthToken(Roles = "admin,assist,company")]
         [HttpPost("set-applyapi")]
         public async Task<IActionResult> SetApplyApi(JsonElement jsonElement)
         {
@@ -409,7 +409,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,company")]
+        [AuthToken(Roles = "admin,assist,company")]
         [HttpPost("set-applyschool")]
         public async Task<IActionResult> SetAuditSchool(JsonElement jsonElement)
         {

+ 2 - 2
TEAMModelBI/Controllers/BINormal/BIOpenApiController.cs

@@ -39,7 +39,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("get-infos")]
         public async Task<IActionResult> GetOpenApi(JsonElement jsonElement) 
         {
@@ -87,7 +87,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="openApi"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-api")]
         public async Task<IActionResult> SetOpenApi(BIOpenApi  openApi) 
         {

+ 2 - 2
TEAMModelBI/Controllers/BINormal/CompanyController.cs

@@ -44,7 +44,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElenent"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,company")]
+        [AuthToken(Roles = "admin,assist,company")]
         [HttpPost("get-info")]
         public async Task<IActionResult> GetInfo(JsonElement jsonElenent)
         {
@@ -89,7 +89,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="appCompany"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,company")]
+        [AuthToken(Roles = "admin,assist,company")]
         [HttpPost("set-info")]
         public async Task<IActionResult> SetCompany(Company company)
         {

+ 1 - 1
TEAMModelBI/Controllers/BISchool/AreaRelevantController.cs

@@ -89,7 +89,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-areashiftschool")]
         public async Task<IActionResult> SetAreaShiftSchool(JsonElement jsonElement)
         {

+ 2 - 2
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -145,7 +145,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("batch-area")]
         public async Task<IActionResult> batchArea(JsonElement jsonElement)
         {
@@ -476,7 +476,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("cut-standard")]
         public async Task<IActionResult> CutStandard(JsonElement jsonElement)
         {

+ 2 - 2
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -125,7 +125,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="school"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("batch-school")]
         public async Task<IActionResult> BatchCreateSchool(FoundSchools foundSchools)
         {
@@ -543,7 +543,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,admin")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("upd-schoolassist")]
         public async Task<IActionResult> UpdSchoolAssist(JsonElement jsonElement)
         {

+ 1 - 1
TEAMModelBI/Controllers/BISchool/RoomController.cs

@@ -43,7 +43,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-bind")]
         public async Task<IActionResult> SetBindProduct(JsonElement jsonElement) 
         {

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

@@ -103,7 +103,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-schooljoinarea")]
         public async Task<IActionResult> SetSchoolJoinArea(JsonElement jsonElement)
         {
@@ -232,7 +232,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="school"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist,admin")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("upd-school")]
         public async Task<IActionResult> UpdSchool(School school)
         {
@@ -481,7 +481,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-aistschool")]
         public async Task<IActionResult> SetAssistSchool(JsonElement jsonElement)
         {

+ 1 - 1
TEAMModelBI/Controllers/BIServer/BiServersController.cs

@@ -52,7 +52,7 @@ namespace TEAMModelBI.Controllers.BIServer
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("get-coreinfo")]
         public async Task<IActionResult> GetCoreInfo(JsonElement jsonElement)
         {

+ 1 - 1
TEAMModelBI/Controllers/Core/BlobController.cs

@@ -50,7 +50,7 @@ namespace TEAMModelBI.Controllers.Core
         /// <param name="file"></param>
         /// <returns></returns>
         [HttpPost("upload-public")]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [RequestSizeLimit(102_400_000_00)]//最大10000m左右
         public async Task<IActionResult> UploadPublic([FromForm] IFormFile file)
         {

+ 3 - 3
TEAMModelBI/Controllers/DingDingStruc/TableDingDingInfoController.cs

@@ -316,7 +316,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// </summary>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-ddinductionuser")]
         public async Task<IActionResult> SetDingDingInductionUser(JsonElement jsonElement)
         {
@@ -391,7 +391,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// </summary>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("del-ddquituser")]
         public async Task<IActionResult> DeleteDDQuitUser(JsonElement jsonElement)
         {
@@ -668,7 +668,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "admin,assist")]
         [HttpPost("set-backenbind")]
         public async Task<IActionResult> SetBackenBind(JsonElement jsonElement) 
         {