浏览代码

处理查询及初始化

CrazyIter_Bin 4 年之前
父节点
当前提交
42edeb4cbd

+ 8 - 7
TEAMModelFunction/TriggerVote.cs

@@ -8,6 +8,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos;
 
@@ -70,10 +71,11 @@ namespace TEAMModelFunction
                                 endTime = vote.endTime,
                                 scode = vote.code,
                                 scope = vote.scope,
-                                classes = vote.classes,
+                                classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
                                 tmdids = vote.tmdids,
                                 progress= "going",
-                                owner =vote.owner
+                                owner =vote.owner,
+                                subjects = new List<string> { "" }
                             };
                             await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
                         }
@@ -90,9 +92,10 @@ namespace TEAMModelFunction
                                 scode = vote.code,
                                 scope = vote.scope,
                                 progress = "going",
-                                classes = vote.classes,
-                                owner = vote.owner
-                                // tmdids = vote.tmdids
+                                classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
+                                owner = vote.owner,
+                                tmdids = new List<string> { "" },
+                                subjects= new List<string> { ""}
                             };
                             await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
                         }
@@ -155,8 +158,6 @@ namespace TEAMModelFunction
                         {
                             await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
                         }
-
-
                         //更新结束状态
                         if (vote.scope == "school" || vote.scope == "teacher")
                         {

+ 3 - 3
TEAMModelOS.SDK/Models/Cosmos/Common/ActivityData.cs

@@ -80,9 +80,9 @@ namespace TEAMModelOS.SDK.Models.Cosmos
         /// private/school/teacher
         /// </summary>
         public string scope { get; set; }
-        public List<string> classes { get; set; }
-        public List<string> tmdids { get; set; }
+        public List<string> classes { get; set; } = new List<string> { "" };
+        public List<string> tmdids { get; set; } = new List<string> { "" };
         public string owner { get; set; }
-        public List<string> subjects { get; set; }
+        public List<string> subjects { get; set; } = new List<string> { "" };
     }
 }

+ 17 - 14
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -330,24 +330,27 @@ namespace TEAMModelOS.Services.Common
                     }
                 }
             }
-            string querySchool = $" SELECT distinct  value c   FROM c  {joinSqlTmdids} {joinSqlClasses} {joinSqlSubjects}  where {stimesql}  {etimesql} and c.pk='Activity' {progresssql}  {typesql}  {andSqlSubjects}  {tgSql}";
             List<ActivityData> datas = new List<ActivityData>();
             var client = _azureCosmos.GetCosmosClient();
-            //查询数据归属学校的
-            await foreach (var item in client.GetContainer("TEAMModelOS","School").GetItemQueryStreamIterator(querySchool, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}") }))
-            {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+            if (!string.IsNullOrWhiteSpace(school)) {
+                string querySchool = $" SELECT distinct  value c   FROM c  {joinSqlTmdids} {joinSqlClasses} {joinSqlSubjects}  where {stimesql}  {etimesql} and c.pk='Activity' {progresssql}  {typesql}  {andSqlSubjects}  {tgSql}";
+               
+                //查询数据归属学校的
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(querySchool, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}") }))
                 {
-                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                     {
-                        datas.Add(obj.ToObject<ActivityData>());
-                    }
-                    //如果需要分页则跳出
-                    if (iscontinuation)
-                    {
-                        continuationTokenSchool = item.GetContinuationToken();
-                        break;
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            datas.Add(obj.ToObject<ActivityData>());
+                        }
+                        //如果需要分页则跳出
+                        if (iscontinuation)
+                        {
+                            continuationTokenSchool = item.GetContinuationToken();
+                            break;
+                        }
                     }
                 }
             }