瀏覽代碼

名单的学生所属学校查询。

CrazyIter_Bin 3 年之前
父節點
當前提交
bff9fe0225
共有 1 個文件被更改,包括 12 次插入7 次删除
  1. 12 7
      TEAMModelOS.SDK/Models/Service/TriggerStuActivity.cs

+ 12 - 7
TEAMModelOS.SDK/Models/Service/TriggerStuActivity.cs

@@ -229,14 +229,19 @@ namespace TEAMModelFunction
                 }
                 if (studentss.IsNotEmpty())
                 {
-                    List<string> inidstus = new List<string>();
-                    studentss.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
-                    var insqlstu = string.Join(",", inidstus);
-                    var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
-                    {
-                        stuInfos.Add(item);
+                    var stuGroups = studentss.GroupBy(x => x.code).ToList().Select(x => new { key = x.Key, list = x.ToList() }) ;
+                    foreach (var gp in stuGroups) {
+                        List<string> inidstus = new List<string>();
+                        gp.list.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
+                        PartitionKey partitionKey = new PartitionKey($"Base-{gp.key.Replace("Base-", "")}");
+                        var insqlstu = string.Join(",", inidstus);
+                        var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey= partitionKey }))
+                        {
+                            stuInfos.Add(item);
+                        }
                     }
+                    
                 }
                 students.ForEach(x =>
                 {