瀏覽代碼

处理跨学校数据以及新增研修字段

zhouj1203@hotmail.com 3 年之前
父節點
當前提交
6affe2c5fe
共有 2 個文件被更改,包括 64 次插入22 次删除
  1. 1 0
      TEAMModelOS.SDK/Models/Cosmos/Common/Study.cs
  2. 63 22
      TEAMModelOS/Controllers/Common/ExamController.cs

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Study.cs

@@ -35,6 +35,7 @@ namespace TEAMModelOS.SDK.Models
         /// 教研组名单
         /// </summary>
         public List<string> tchLists { get; set; } = new List<string>();
+        public List<string> teacIds { get; set; } = new List<string>();
         public List<Dictionary<string, List<string>>> groupLists { get; set; } = new List<Dictionary<string, List<string>>>();
         /// <summary>
         /// student 学生名单类型    research 教研组名单

+ 63 - 22
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -59,7 +59,7 @@ namespace TEAMModelOS.Controllers
             _azureStorage = azureStorage;
             _azureRedis = azureRedis;
             _configuration = configuration;
-            _notificationService = notificationService; 
+            _notificationService = notificationService;
             _coreAPIHttpService = coreAPIHttpService;
         }
 
@@ -266,7 +266,8 @@ namespace TEAMModelOS.Controllers
                 {
                     using var json = await JsonDocument.ParseAsync(response.ContentStream);
                     ExamInfo exam = json.ToObject<ExamInfo>();
-                    if (request.TryGetProperty("time", out JsonElement time)) {
+                    if (request.TryGetProperty("time", out JsonElement time))
+                    {
                         exam.endTime = time.GetInt64();
                     }
                     if (request.TryGetProperty("name", out JsonElement name))
@@ -321,7 +322,8 @@ namespace TEAMModelOS.Controllers
                         flag = true;
                     }
                 }
-                if (flag) {
+                if (flag)
+                {
                     exam.ttl = 1;
                     exam.status = 404;
                     exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, exam.id, new PartitionKey($"{exam.code}"));
@@ -1121,31 +1123,66 @@ namespace TEAMModelOS.Controllers
                         }
                         result.sum[index] = result.studentScores[index].Sum();
                         bool flag = result.studentScores[index].Exists(r => r == -1);
-                        if (!flag) {
+                        if (!flag)
+                        {
                             if (s.type == 1)
                             {
-                                try {
+                                try
+                                {
                                     StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{s.id}"));
                                     activity.sStatus = 1;
                                     tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}")));
-                                } catch (Exception ex) {
-                                  await  _dingDing.SendBotMsg($"{_option.Location}\n{ex.Message}\n{ex.StackTrace}\n,id:{id},code:{s.id},school:{result?.school}", GroupNames.成都开发測試群組);
+                                }
+                                catch (Exception ex)
+                                {
+                                    await _dingDing.SendBotMsg($"{_option.Location}\n{ex.Message}\n{ex.StackTrace}\n,id:{id},code:{s.id},school:{result?.school}", GroupNames.成都开发測試群組);
                                 }
                             }
                             else
                             {
-                                try { 
-                                    StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{result.school}-{s.id}"));
-                                    activity.sStatus = 1;
-                                    tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}")));
+                                try
+                                {
+                                    var response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Activity-{result.school}-{s.id}"));
+                                    if (response.Status == 200)
+                                    {
+                                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                                        StuActivity activity = json.ToObject<StuActivity>();
+                                        activity.sStatus = 1;
+                                        tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}")));
+
+                                    }else
+                                    {
+                                        List<string> scode = new();
+                                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.shoolId from c where c.id = '{s.id}' and c.pk = 'Base'"))
+                                        {
+                                            using var stuJson = await JsonDocument.ParseAsync(item.ContentStream);
+                                            if (stuJson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                            {
+                                                var accounts = stuJson.RootElement.GetProperty("Documents").EnumerateArray();
+                                                while (accounts.MoveNext())
+                                                {
+                                                    JsonElement account = accounts.Current;
+                                                    scode.Add(account.GetProperty("shoolId").GetString());
+                                                }
+                                            }
+                                        }
+                                        foreach (var sid in scode)
+                                        {
+                                            StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{sid}-{s.id}"));
+                                            activity.sStatus = 1;
+                                            tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}")));
+                                        }
+                                    }
+                                    //StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{result.school}-{s.id}"));
+                                   
                                 }
                                 catch (Exception ex)
-                                {
+                                {                                  
                                     await _dingDing.SendBotMsg($"{_option.Location}\n{ex.Message}\n{ex.StackTrace}\n,id:{id},code:{s.id},school:{result?.school}", GroupNames.成都开发測試群組);
                                 }
                             }
                         }
-                        
+
                         index_sc++;
                     }
                     if (!result.progress)
@@ -1173,7 +1210,7 @@ namespace TEAMModelOS.Controllers
                                     s.classCount += 1;
                                 }
                             });
-                            await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"Exam-{code}"));                            
+                            await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"Exam-{code}"));
                         }
                     }
                     else
@@ -1245,18 +1282,19 @@ namespace TEAMModelOS.Controllers
                     examClassResults.Add(item);
                 }
                 List<string> ids = new();
-                foreach (ExamClassResult result in examClassResults) {
+                foreach (ExamClassResult result in examClassResults)
+                {
                     ids.AddRange(result.studentIds);
                 }
                 ///获取真实的名称 
                 List<ufo> ufos = new();
                 List<string> delIds = new();
-                if (ids.Count > 0) {
+                if (ids.Count > 0)
+                {
                     List<string> sIds = new();
                     List<string> tIds = new();
                     List<ufo> students = new List<ufo>();
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id,c.name from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})",
-                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id,c.name from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))}) and c.pk = 'Base'"))
                     {
                         using var stuJson = await JsonDocument.ParseAsync(item.ContentStream);
                         if (stuJson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
@@ -1282,7 +1320,8 @@ namespace TEAMModelOS.Controllers
                         {
                             sIds.Add(f.id);
                         }
-                        if (ids.Count > sIds.Count) { 
+                        if (ids.Count > sIds.Count)
+                        {
                             tIds = ids.Except(sIds).ToList();
                             var content = new StringContent(tIds.ToJsonString(), Encoding.UTF8, "application/json");
                             string json = await _coreAPIHttpService.GetUserInfos(content);
@@ -1310,7 +1349,8 @@ namespace TEAMModelOS.Controllers
                         }
                         delIds = ids.Except(sIds.Union(tIds)).ToList();
                     }
-                    else {
+                    else
+                    {
                         var content = new StringContent(ids.ToJsonString(), Encoding.UTF8, "application/json");
                         string json = await _coreAPIHttpService.GetUserInfos(content);
 
@@ -1337,7 +1377,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                 }
-                
+
                 /*if (StringHelper.getKeyCount(requert) == 1 && requert.TryGetProperty("code", out JsonElement code))
                 {
                     List<object> props = new List<object>();
@@ -3162,7 +3202,8 @@ namespace TEAMModelOS.Controllers
         public string id { get; set; }
         public int type { get; set; }
     }
-    public class ufo { 
+    public class ufo
+    {
         public string id { get; set; }
         public string name { get; set; }
         public int type { get; set; }