瀏覽代碼

为归区的基础信息统计

Li 2 年之前
父節點
當前提交
d12e4413f7
共有 1 個文件被更改,包括 19 次插入11 次删除
  1. 19 11
      TEAMModelBI/Controllers/Census/ActivitySticsController.cs

+ 19 - 11
TEAMModelBI/Controllers/Census/ActivitySticsController.cs

@@ -111,7 +111,7 @@ namespace TEAMModelBI.Controllers.Census
         [HttpPost("get-areastics")]
         [HttpPost("get-areastics")]
         public async Task<IActionResult> GetAreaStics(JsonElement jsonElement)
         public async Task<IActionResult> GetAreaStics(JsonElement jsonElement)
         {
         {
-            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
             var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
             var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
             var (weekS, weekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
             var (weekS, weekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
@@ -161,14 +161,25 @@ namespace TEAMModelBI.Controllers.Census
             List<AreaStudy> trains = new();
             List<AreaStudy> trains = new();
 
 
             AreaSetting setting = null;
             AreaSetting setting = null;
-            try
-            {
-                setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
-            }
-            catch (CosmosException)
+           
+
+            string oftenSql = "select value(count(c.id)) from c";
+            string scSql = "";
+            if (!string.IsNullOrEmpty($"{areaId}"))
             {
             {
-                setting = null;
+                scSql = $"select value(c.id) from c where c.areaId='{areaId}'";
+                try
+                {
+                    setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
+                }
+                catch (CosmosException)
+                {
+                    setting = null;
+                }
             }
             }
+            else            
+                scSql = "select value(c.id) from c where c.areaId = null or c.areaId = ''";
+            
             if (setting == null)
             if (setting == null)
             {
             {
                 setting = new AreaSetting
                 setting = new AreaSetting
@@ -181,10 +192,7 @@ namespace TEAMModelBI.Controllers.Census
                     lessonMinutes = 45,
                     lessonMinutes = 45,
                 };
                 };
             }
             }
-
-            string oftenSql = "select value(count(c.id)) from c";
-            string scSql = $"{oftenSql} where c.areaId='{areaId}'";
-            List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", $"select value(c.id) from c where c.areaId='{areaId}'", "Base");
+            List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", scSql, "Base");
             if (scIds.Count > 0)
             if (scIds.Count > 0)
             {
             {
                 string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
                 string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";