فهرست منبع

处理未加区的学校相关统计接口的逻辑。并统计

Li 2 سال پیش
والد
کامیت
a0c2be8344

+ 21 - 9
TEAMModelBI/Controllers/BINormal/AreaRelevantController.cs

@@ -11,6 +11,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Models;
+using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
@@ -415,6 +416,7 @@ namespace TEAMModelBI.Controllers.BINormal
             return Ok(new { state = RespondCode.Ok, teacher });
         }
 
+
         /// <summary>
         /// 通过区域ID查询学校列表   //已对接
         /// </summary>
@@ -424,7 +426,7 @@ namespace TEAMModelBI.Controllers.BINormal
         [HttpPost("get-schools")]
         public async Task<IActionResult> GetSchools(JsonElement jsonElement) 
         {
-            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
@@ -434,8 +436,13 @@ namespace TEAMModelBI.Controllers.BINormal
 
             List<AreaSchool> areaSchool = new();
 
-            string areaScSql = $"select c.id,c.name,c.picture,c.size,c.areaId,c.scale from c where c.areaId='{areaId}'";
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AreaSchool>(queryText: areaScSql,requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
+            StringBuilder areaScSql = new($"select c.id,c.name,c.picture,c.size,c.areaId,c.scale from c");
+            if (!string.IsNullOrEmpty($"{areaId}")) 
+                areaScSql.Append($" where c.areaId='{areaId}'");
+            else
+                areaScSql.Append(" where c.areaId = null or c.areaId = ''");
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AreaSchool>(queryText: areaScSql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
             {
                 areaSchool.Add(item);
             }
@@ -473,7 +480,7 @@ namespace TEAMModelBI.Controllers.BINormal
         [HttpPost("get-assists")]
         public async Task<IActionResult> GetAssists(JsonElement jsonElement)
         {
-            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
@@ -491,12 +498,17 @@ namespace TEAMModelBI.Controllers.BINormal
             List<string> scIds = new();
             HashSet<string> tchIds = new();
 
-            string scIdsSql = $"select value(c.id) from c where c.areaId='{areaId}'";
+            string scIdsSql = null;
+            if (!string.IsNullOrEmpty($"{areaId}"))
+                scIdsSql = $"select value(c.id) from c where c.areaId='{areaId}'";
+            else
+                scIdsSql = "select value(c.id) from c where c.areaId = null or c.areaId = ''";
+            scIds = await CommonFind.GetValueSingle(cosmosClient, "School", scIdsSql, "Base");
 
-            await foreach (var itemId in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scIdsSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) 
-            {
-                scIds.Add(itemId);
-            }
+            //await foreach (var itemId in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scIdsSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) 
+            //{
+            //    scIds.Add(itemId);
+            //}
 
             foreach (var scId in scIds)
             {

+ 9 - 8
TEAMModelBI/Controllers/Census/ActivitySticsController.cs

@@ -66,13 +66,20 @@ namespace TEAMModelBI.Controllers.Census
                 if (!string.IsNullOrEmpty($"{areaId}"))
                 {
                     string areaSc = $"select value(c.id) from c where c.pk='School' and c.areaId='{areaId}'";
-                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: areaSc, requestOptions: new QueryRequestOptions() { })) 
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: areaSc, requestOptions: new QueryRequestOptions() { }))
                     {
                         scIds.Add(item);
                     }
 
                     inSql = $" and {BICommonWay.ManyScSql("c.school", scIds)}";
                 }
+                else
+                {
+                    string scSql = "select value(c.id) from c where c.areaId = null or c.areaId = ''";
+                    scIds = await CommonFind.GetValueSingle(cosmosClient, "School", scSql, "Base");
+                    inSql = $" and {BICommonWay.ManyScSql("c.school", scIds)}";
+                }
+
 
                 foreach (var type in StaticValue.activityTypes)
                 {
@@ -159,9 +166,7 @@ namespace TEAMModelBI.Controllers.Census
             int carryOnCount = 0;   //进行中
             int noCount = 0;      //未开始
             List<AreaStudy> trains = new();
-
-            AreaSetting setting = null;
-           
+            AreaSetting setting = null;           
 
             string oftenSql = "select value(count(c.id)) from c";
             string scSql = "";
@@ -648,7 +653,6 @@ namespace TEAMModelBI.Controllers.Census
             return Ok(new {state = RespondCode.Ok, allLess, weekLess, termLess, monthLessCnt, actAllCnt, actWeekCnt, actTermCnt, actMonthCnt });
         }
 
-
         /// <summary>
         /// 统计活动 传醍摩豆则查询相关的学校活动
         /// </summary>
@@ -948,7 +952,6 @@ namespace TEAMModelBI.Controllers.Census
             //public int stuCnt { get; set; } = 0;
         }
 
-
         public class AreaStudy 
         {
             public string id { get; set; }
@@ -972,7 +975,6 @@ namespace TEAMModelBI.Controllers.Census
             /// 必修的
             /// </summary>
             public Currency currency { get; set; } = new Currency();
-
         }
 
         private class SchoolInfo
@@ -991,7 +993,6 @@ namespace TEAMModelBI.Controllers.Census
             public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
         }
 
-
         private record SchoolLesson
         {
             public string id { get; set; }

+ 10 - 1
TEAMModelBI/Controllers/Census/BlobLogController.cs

@@ -48,6 +48,7 @@ namespace TEAMModelBI.Controllers.Census
         {
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
             jsonElement.TryGetProperty("areaId", out JsonElement areaId);
+            jsonElement.TryGetProperty("isJoin", out JsonElement isJoin);
             var cosmosClient = _azureCosmos.GetCosmosClient();
             ////分开部署,就不需要,一站多用时,取消注释
             //if ($"{site}".Equals(BIConst.Global))
@@ -93,6 +94,14 @@ namespace TEAMModelBI.Controllers.Census
             }
             else
             {
+                StringBuilder scSql = new("select value(c.id) from c");
+                if ($"{isJoin}".Equals("noJoin")) 
+                {
+                    scSql.Append($" where c.areaId = null or c.areaId = ''");
+                }
+
+                schoolIds = await CommonFind.GetValueSingle(cosmosClient, "School",scSql.ToString(), "Base");
+
                 foreach (var item in StaticValue.fileType)
                 {
                     string typeSql = $"select value(count(c.id)) from c where c.pk='Bloblog' and c.type='{item}'";
@@ -101,7 +110,7 @@ namespace TEAMModelBI.Controllers.Census
                     typeCnt.Add(item, fileCnt);
                     recCount += fileCnt;
                 }
-                schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c", "Base");
+
                 foreach (var id in schoolIds)
                 {
                     long blobsize = 0;

+ 16 - 6
TEAMModelBI/Controllers/Census/LessonSticsController.cs

@@ -55,7 +55,7 @@ namespace TEAMModelBI.Controllers.Census
         [HttpPost("get-schoolan")]
         public async Task<IActionResult> GetSchoolsAn(JsonElement jsonElement)
         {
-            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
             //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
             var (lWeekS, lWeekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
             var (monthS, monthE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
@@ -66,7 +66,14 @@ namespace TEAMModelBI.Controllers.Census
             //    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
 
             List<AreaSchools> areaSchools = new();
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AreaSchools>(queryText: $"select c.id,c.name,c.picture from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
+
+            StringBuilder scSql = new("select c.id,c.name,c.picture from c ");
+            if (!string.IsNullOrEmpty($"{areaId}"))
+                scSql.Append($" where c.areaId='{areaId}'");
+            else
+                scSql.Append($" where c.areaId = null or c.areaId = ''");
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AreaSchools>(queryText: scSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
             {
                 areaSchools.Add(item);
             }
@@ -94,6 +101,7 @@ namespace TEAMModelBI.Controllers.Census
         public async Task<IActionResult> GetWeekCount(JsonElement jsonElement)
         {
             jsonElement.TryGetProperty("areaId", out JsonElement areaId);
+            jsonElement.TryGetProperty("isJoin", out JsonElement isJoin);
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
 
             //Dictionary<int, double> weeks = new();
@@ -112,13 +120,15 @@ namespace TEAMModelBI.Controllers.Census
             List<LessonCount> scount = new();
             List<LessonCount> tcount = new();
 
-            StringBuilder sqlTxt = new("select c.id from c");
+            StringBuilder sqlTxt = new("select value(c.id) from c");
             if (!string.IsNullOrEmpty($"{areaId}"))
-            {
                 sqlTxt.Append($" where c.areaId='{areaId}'");
+            else 
+            {
+                if ($"{isJoin}".Equals("noJoin"))
+                    sqlTxt.Append($" where c.areaId = null or c.areaId = ''");
             }
-
-            List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, sqlTxt.ToString(), "Base");
+            List<string> schools = await CommonFind.GetValueSingle(cosmosClient, "School",sqlTxt.ToString(), "Base");
 
             foreach (var sId in schools)
             {

+ 4 - 54
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -14,6 +14,7 @@ using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.Context.BI;
+using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
@@ -358,7 +359,7 @@ namespace TEAMModelBI.Controllers.Census
 
 
         /// <summary>
-        /// 未区域学校统计    未写完
+        /// 未区域学校统计   
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
@@ -389,7 +390,7 @@ namespace TEAMModelBI.Controllers.Census
         }
         
         /// <summary>
-        /// 未加区的学校统计详细
+        /// 未加区的学校统计
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
@@ -407,41 +408,8 @@ namespace TEAMModelBI.Controllers.Census
 
             List<AreaAssist> areaAssists = new();  //顾问信息
 
-            int scCnt = 0; //学校人数
-            int weekScCnt = 0; //本周学校人数
-            int motnhScCnt = 0; //本月学校人数
-
             int tchCnt = 0;   //所有区级老师
-            int weekTchCnt = 0;   //所有区级老师
-            int monthTchCnt = 0;   //所有区级老师
-
             int stuCnt = 0;   //所有区级学生
-            int weekStuCnt = 0;   //所有区级学生
-            int monthStuCnt = 0;   //所有区级学生
-
-            int areaSize = 0;   //区级空间
-            int weekSize = 0;   //本周空间
-            int monthSize = 0;   //本月空间
-
-            int allLess = 0; //所有课例
-            int weekLess = 0;  //周课例
-            int monthLess = 0;  //月课例
-            int termLess = 0;    //学期课例
-
-            int totalTime = 0;   //累计学时
-            int allActCnt = 0;   //所有活动
-            int weekActivity = 0; //周活动数量
-            int monthActCnt = 0; //月活动数量
-            int termActivity = 0;   //学期活动
-
-            int onLineCount = 0;    //线上研修人数
-            int offlineCount = 0;   //线下研修人数
-            int classRoomCount = 0;  //课堂实录人数
-            int submitCount = 0;     //认证材料人数
-
-            int fulfilCount = 0;    //已完成
-            int carryOnCount = 0;   //进行中
-            int noCount = 0;      //未开始
 
             HashSet<string> tchIds = new();
             List<string> scIds = new(); //学校id集合
@@ -502,25 +470,7 @@ namespace TEAMModelBI.Controllers.Census
                 else { noIds.Add(item); }
             }
 
-            AreaSetting setting = new()
-            {
-                allTime = 50,
-                classTime = 5,
-                submitTime = 15,
-                onlineTime = 20,
-                offlineTime = 10,
-                lessonMinutes = 45,
-            };
-            string oftenSql = "select value(count(c.id)) from c";
-
-
-
-
-
-
-
-
-            return Ok(new { state = 200 });
+            return Ok(new { state = RespondCode.Ok, scCnt = scIds.Count, tchCnt, stuCnt });
         }