Browse Source

优化区域列表返回字段

Li 3 years ago
parent
commit
9b347d2594
1 changed files with 30 additions and 4 deletions
  1. 30 4
      TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

+ 30 - 4
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -19,6 +19,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Tool.Extension;
+using TEAMModelBI.Tool;
 
 namespace TEAMModelBI.Controllers.BISchool
 {
@@ -55,11 +56,20 @@ namespace TEAMModelBI.Controllers.BISchool
         {
             try
             {
-                List<Area> areas = new List<Area>();
+                List<Area> tempAreas = new();
+                List<RecArea> areas = new();
+
                 var azureClient = _azureCosmos.GetCosmosClient();
-                await foreach (var item in azureClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select * from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
+                await foreach (var item in azureClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
                 {
-                    areas.Add(item);
+                    tempAreas.Add(item);
+                }
+
+                foreach (var area in tempAreas) 
+                {
+                    RecArea recArea = new() { id = area.id, code = area.code, pk = area.pk, name = area.name, provCode = area.provCode, provName = area.provName, cityCode = area.cityCode, cityName = area.cityName, standard = area.standard, standardName = area.standardName};
+                    recArea.schoolCount = await CommonFind.FindTotals(azureClient, $"select count(c.id) as totals from c where c.areaId='{area.id}' and c.standard='{area.standard}'", "School", "Base");
+                    areas.Add(recArea);
                 }
 
                 return Ok(new { state = 200, areas });
@@ -676,6 +686,22 @@ namespace TEAMModelBI.Controllers.BISchool
             }
         }
 
-    }
 
+        public record RecArea 
+        {
+            public string id { get; set; }
+            public string code { get; set; }
+            public string pk { get; set; }
+            public string name { get; set; }
+            public string provCode { get; set; }
+            public string provName { get; set; }
+            public string cityCode { get; set; }
+            public string cityName { get; set; }
+            public string standard { get; set; }
+            public string standardName { get; set; }
+            public int schoolCount { get; set; }
+        }
+
+
+}
 }