Pārlūkot izejas kodu

优化查询学校列表

Li 2 gadi atpakaļ
vecāks
revīzija
9c70e18d69

+ 7 - 1
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -1827,9 +1827,15 @@ namespace TEAMModelBI.Controllers.BISchool
         [HttpPost("get-schools")]
         public async Task<IActionResult> GetSchools (JsonElement jsonElement)
         {
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
             List<ScBriefInfo> scBriefs = new();
             var cosmosClient = _azureCosmos.GetCosmosClient();
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryIterator<ScBriefInfo>(queryText:"select value(c) from c" ,requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
+
+            StringBuilder sql = new("select c.id,c.name,c.picture,c.areaId,c.size,c.period from c ");
+            if (!string.IsNullOrEmpty($"{areaId}"))
+                sql.Append($" where c.areaId = '{areaId}'");
+
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryIterator<ScBriefInfo>(queryText: sql.ToString(), requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
             {
                 scBriefs.Add(item);
             }

+ 1 - 0
TEAMModelBI/Models/ForeEndModel.cs

@@ -27,6 +27,7 @@ namespace TEAMModelBI.Models
         public string id { get; set; }
         public string name { get; set; }
         public string picture { get; set; }
+        public string areaId { get; set; }
         public int size { get; set; }
         public List<Period> period { get; set; }
     }