Просмотр исходного кода

优化所有区活动和课例接口

Li 2 лет назад
Родитель
Сommit
f6dc1fbdbe

+ 23 - 7
TEAMModelBI/Controllers/Census/LessonSticsController.cs

@@ -18,6 +18,7 @@ using TEAMModelBI.Tool;
 using MathNet.Numerics.LinearAlgebra.Double;
 using MathNet.Numerics.LinearAlgebra.Double;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelOS.SDK.Context.BI;
 using TEAMModelOS.SDK.Context.BI;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 
 namespace TEAMModelBI.Controllers.Census
 namespace TEAMModelBI.Controllers.Census
 {
 {
@@ -546,13 +547,27 @@ namespace TEAMModelBI.Controllers.Census
 
 
             foreach (var area in areaInfos)
             foreach (var area in areaInfos)
             {
             {
-                List<string> schooId = await CommonFind.FindSchoolIds(cosmosClient,$"select c.id from c where c.areaId='{area.id}'","Base");
-                List<string> tecId = await CommonFind.FindRolesId(cosmosClient, schooId);
+                string comSql = $"select value(c.id) from c where c.areaId='{area.id}'";
+                List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", comSql, "Base");
+                int tLessCnt = 0; 
+                int tActCnt = 0;
 
 
-                area.lessCount = await LessonStatisWay.GetAll(cosmosClient, schooId, tecId);
-                area.activityCount = await ActivityWay.GetAll(cosmosClient, schooId, tecId);
-            }
+                string Sql = $"select value(c.id) from c where c.areaId='{area.id}'";
+                if (scIds.Count > 0) 
+                {
+                    comSql = BICommonWay.ManyScSql("c.school", scIds);
+                    string lesSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {comSql}";
+                    tLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School", "Teacher" }, lesSql);
 
 
+                    comSql = BICommonWay.ManyScSql(" and c.school", scIds);
+                    tActCnt = await ActivityWay.GetCnt(cosmosClient, comSql);
+                }
+
+                area.lessCnt = tLessCnt;
+                area.actCnt = tActCnt;
+                area.allCnt = tLessCnt + tActCnt;
+            }
+            areaInfos = areaInfos.Where(w => w.allCnt != 0).ToList();
 
 
             return Ok(new { state = 200 , areaInfos });
             return Ok(new { state = 200 , areaInfos });
         }
         }
@@ -594,8 +609,9 @@ namespace TEAMModelBI.Controllers.Census
             public string name { get; set; }
             public string name { get; set; }
             public string standard { get; set; }
             public string standard { get; set; }
             public string standardName { get; set; }
             public string standardName { get; set; }
-            public int lessCount { get; set; }
-            public int activityCount { get; set; }
+            public int lessCnt { get; set; }
+            public int actCnt { get; set; }
+            public int allCnt { get; set; }
 
 
         }
         }
 
 

+ 29 - 2
TEAMModelBI/Tool/CosmosBank/ActivityWay.cs

@@ -65,21 +65,48 @@ namespace TEAMModelBI.Tool.CosmosBank
         /// 统计活动
         /// 统计活动
         /// </summary>
         /// </summary>
         /// <param name="cosmosClient"></param>
         /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
         /// <param name="factorSQL"></param>
         /// <param name="factorSQL"></param>
         /// <param name="code"></param>
         /// <param name="code"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static async Task<int> GetCnt(CosmosClient cosmosClient, string factorSQL = null, string code = null) 
+        public static async Task<int> GetCnt(CosmosClient cosmosClient, string container = "Common", string factorSQL = null, string code = null) 
         {
         {
             int total = 0;
             int total = 0;
             foreach (string type in types)
             foreach (string type in types)
             {
             {
                 string sqlTxt = $"select value(count(c.id)) from c where c.pk='{type}' {factorSQL}";
                 string sqlTxt = $"select value(count(c.id)) from c where c.pk='{type}' {factorSQL}";
-                await foreach (var cnt in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<int>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") })) 
+                await foreach (var cnt in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") })) 
                 {
                 {
                     total += cnt;
                     total += cnt;
                 }
                 }
             }
             }
             return total;
             return total;
         }
         }
+
+        /// <summary>
+        /// 统计活动多个容器获取
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="factorSQL"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetCnt(CosmosClient cosmosClient, List<string> containers, string factorSQL = null, string code = null)
+        {
+            int total = 0;
+            foreach (var container in containers)
+            {
+                foreach (string type in types)
+                {
+                    string sqlTxt = $"select value(count(c.id)) from c where c.pk='{type}' {factorSQL}";
+                    await foreach (var cnt in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+                    {
+                        total += cnt;
+                    }
+                }
+            }
+            return total;
+        }
+
     }
     }
 }
 }