Przeglądaj źródła

活动结构调整以及区级发布内容调整、阅卷BUG修改

zhouj1203@hotmail.com 3 lat temu
rodzic
commit
2e0f3b0cf2

+ 9 - 1
TEAMModelFunction/TriggerExam.cs

@@ -101,8 +101,16 @@ namespace TEAMModelFunction
 
                             try
                             {
+                                List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                                if (info.groupLists.Count > 0)
+                                {
+                                    foreach (var gp in info.groupLists)
+                                    {
+                                        ps.Add((gp.Key, gp.Value));
+                                    }
+                                }
                                 List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
-                                (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, info.school);
+                                (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, info.school, ps);
                                 var addStudentsCls = tchList.FindAll(x => x.type == 2);
                                 var addTmdidsCls = tchList.FindAll(x => x.type == 1);
                                 List<StuActivity> stuActivities = new List<StuActivity>();

+ 9 - 1
TEAMModelFunction/TriggerExamLite.cs

@@ -70,7 +70,15 @@ namespace TEAMModelFunction
                             }
                             break;
                         case "going":
-                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, lite.tchLists, lite.school);
+                            List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                            if (lite.groupLists.Count > 0)
+                            {
+                                foreach (var gp in lite.groupLists)
+                                {
+                                    ps.Add((gp.Key, gp.Value));
+                                }
+                            }
+                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, lite.tchLists, lite.school, ps);
                             // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                             //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, lite.tchLists, lite.school);
                             List<StuActivity> tchActivities = new List<StuActivity>();

+ 10 - 2
TEAMModelFunction/TriggerHomework.cs

@@ -71,8 +71,16 @@ namespace TEAMModelFunction
                             }
                             break;
                         case "going":
+                            List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                            if (work.groupLists.Count > 0)
+                            {
+                                foreach (var gp in work.groupLists)
+                                {
+                                    ps.Add((gp.Key, gp.Value));
+                                }
+                            }
                             List<string> classes = ExamService.getClasses(work.classes, work.stuLists);
-                            (List<RMember> tmdids, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, work.school);
+                            (List<RMember> tmdids, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, work.school, ps);
                             var addStudentsCls = tmdids.FindAll(x => x.type == 2);
                             var addTmdidsCls = tmdids.FindAll(x => x.type == 1);
                             List<StuActivity> stuActivities = new List<StuActivity>();
@@ -130,7 +138,7 @@ namespace TEAMModelFunction
                                     });
                                 });
                             }
-                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, work.tchLists, work.school);
+                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, work.tchLists, work.school,ps);
                             // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                            // (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, work.tchLists, work.school);
                             if (tchList.IsNotEmpty())

+ 9 - 1
TEAMModelFunction/TriggerStudy.cs

@@ -70,7 +70,15 @@ namespace TEAMModelFunction
                             }
                             break;
                         case "going":
-                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, study.tchLists, study.school);
+                            List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                            if (study.groupLists.Count > 0)
+                            {
+                                foreach (var gp in study.groupLists)
+                                {
+                                    ps.Add((gp.Key, gp.Value));
+                                }
+                            }
+                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, study.tchLists, study.school,ps);
                             // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                             //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, study.tchLists, study.school);
                             List<StuActivity> tchActivities = new List<StuActivity>();

+ 8 - 1
TEAMModelFunction/TriggerSurvey.cs

@@ -79,6 +79,13 @@ namespace TEAMModelFunction
                             }
                             break;
                         case "going":
+                            List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                            if (survey.groupLists.Count >0) {
+                                foreach (var gp in survey.groupLists)
+                                {
+                                    ps.Add((gp.Key, gp.Value));
+                                }
+                            }                          
                             List<string> classes = ExamService.getClasses(survey.classes, survey.stuLists);
                             (List<RMember> tmdIds, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, survey.school);
                             var addStudentsCls = tmdIds.FindAll(x => x.type == 2);
@@ -139,7 +146,7 @@ namespace TEAMModelFunction
                                     });
                                 });
                             }
-                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, survey.tchLists, survey.school);
+                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, survey.tchLists, survey.school,ps);
                             // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                             //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, survey.tchLists, survey.school);
                             if (tchList.IsNotEmpty())

+ 10 - 2
TEAMModelFunction/TriggerVote.cs

@@ -79,8 +79,16 @@ namespace TEAMModelFunction
                             }
                             break;
                         case "going":
+                            List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                            if (vote.groupLists.Count > 0)
+                            {
+                                foreach (var gro in vote.groupLists)
+                                {
+                                    ps.Add((gro.Key, gro.Value));
+                                }
+                            }
                             List<string> classes = ExamService.getClasses(vote.classes, vote.stuLists);
-                            (List<RMember> tmdIds, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, vote.school);
+                            (List<RMember> tmdIds, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, vote.school,ps);
                             var addStudentsCls = tmdIds.FindAll(x => x.type == 2);
                             var addTmdidsCls = tmdIds.FindAll(x => x.type == 1);
                             //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}投票活动" +
@@ -146,7 +154,7 @@ namespace TEAMModelFunction
                                     });
                                 });
                             }
-                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, vote.tchLists, vote.school);
+                            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, vote.tchLists, vote.school,ps);
                             if (tchList.IsNotEmpty())
                             {
                                 tchList.ForEach(x => {

+ 3 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/ExamLite.cs

@@ -53,6 +53,7 @@ namespace TEAMModelOS.SDK.Models
         /// 教研组名单
         /// </summary>
         public List<string> tchLists { get; set; } = new List<string>();
+        public List<KeyValuePair<string, List<string>>> groupLists { get; set; } = new List<KeyValuePair<string, List<string>>>();
         /// <summary>
         /// student 学生名单类型    research 教研组名单
         /// </summary>
@@ -76,6 +77,8 @@ namespace TEAMModelOS.SDK.Models
         //容器名称 container name
         //public string cn { get; set; }
         public string progress { get; set; }
+        //发布层级 0校级,1区级
+        public int? publish { get; set; } = 0;
     }
     public class Record
     {

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Homework.cs

@@ -64,6 +64,7 @@ namespace TEAMModelOS.SDK.Models
         /// 教研组名单
         /// </summary>
         public List<string> tchLists { get; set; } = new List<string>();
+        public List<KeyValuePair<string, List<string>>> groupLists { get; set; } = new List<KeyValuePair<string, List<string>>>();
         /// <summary>
         /// student 学生名单类型    research 教研组名单
         /// </summary>
@@ -113,6 +114,7 @@ namespace TEAMModelOS.SDK.Models
         public List<Attachment> attachments { get; set; } = new List<Attachment>();
         public List<Submits> teachers { get; set; } = new List<Submits>();
         public string recordUrl { get; set; }
+        public int? publish { get; set; } = 0;
     }
 
     public class Submits

+ 3 - 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<KeyValuePair<string, List<string>>> groupLists { get; set; } = new List<KeyValuePair<string, List<string>>>();
         /// <summary>
         /// student 学生名单类型    research 教研组名单
         /// </summary>
@@ -66,6 +67,8 @@ namespace TEAMModelOS.SDK.Models
         public string workId { get; set; }
         public string surveyId { get; set; }
         public string examId { get; set; }
+        //发布层级 0校级,1区级
+        public int? publish { get; set; } = 0;
     }
     /*public class Setting
     {

+ 3 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Survey.cs

@@ -67,6 +67,7 @@ namespace TEAMModelOS.SDK.Models
         /// 教研组名单
         /// </summary>
         public List<string> tchLists { get; set; } = new List<string>();
+        public List<KeyValuePair<string, List<string>>> groupLists { get; set; } = new List<KeyValuePair<string, List<string>>>();
         /// <summary>
         /// student 学生名单类型    research 教研组名单
         /// </summary>
@@ -112,6 +113,8 @@ namespace TEAMModelOS.SDK.Models
         public long? size { get; set; } = 0;
         public string areaId { get; set; }
         public string pId { get; set; }
+        //发布层级 0校级,1区级
+        public int? publish { get; set; } = 0;
     }
 
     /// <summary>

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Vote.cs

@@ -90,6 +90,7 @@ namespace TEAMModelOS.SDK.Models
         /// 教研组名单
         /// </summary>
         public List<string> tchLists { get; set; } = new List<string>();
+        public List<KeyValuePair<string, List<string>>> groupLists { get; set; } = new List<KeyValuePair<string, List<string>>>();
         /// <summary>
         /// student 学生名单类型    research 教研组名单
         /// </summary>
@@ -125,6 +126,7 @@ namespace TEAMModelOS.SDK.Models
         public long? size { get; set; } = 0;
         public string areaId { get; set; }
         public string pId { get; set; }
+        public int? publish { get; set; } = 0;
     }
     /// <summary>
     /// 投票选项

+ 3 - 0
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -72,6 +72,8 @@ namespace TEAMModelOS.SDK.Models
         //public string classType { get; set; }
         public List<string> classes { get; set; }
         public List<string> stuLists { get; set; }
+        //标记名单与名单分组关系
+        public List<KeyValuePair<string, List<string>>> groupLists { get; set; } = new List<KeyValuePair<string, List<string>>>();
         /// <summary>
         /// 发布对象全部信息。由前端操作,用于前端回显发布对象的格式。
         /// </summary>
@@ -109,6 +111,7 @@ namespace TEAMModelOS.SDK.Models
         public int income { get; set; } = 0;
         //踩线比列
         public int touch { get; set; } = 0;
+        public int? publish { get; set; } = 0;
         //容器名称 container name
         //public string cn { get; set; }
     }

+ 9 - 2
TEAMModelOS.SDK/Models/Service/ExamService.cs

@@ -67,13 +67,20 @@ namespace TEAMModelOS.SDK.Models.Service
                 trExam.scope = "school";
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 trExam.createTime = now;
-                if (trExam.startTime > now)
+                if (trExam.publish == 1)
                 {
                     trExam.progress = "pending";
                 }
                 else
                 {
-                    trExam.progress = "going";
+                    if (trExam.startTime > now)
+                    {
+                        trExam.progress = "pending";
+                    }
+                    else
+                    {
+                        trExam.progress = "going";
+                    }
                 }
                 if (string.IsNullOrEmpty(trExam.id))
                 {

+ 12 - 5
TEAMModelOS.SDK/Models/Service/HomeworkService.cs

@@ -35,15 +35,22 @@ namespace TEAMModelOS.SDK.Models.Service
                 await _azureStorage.UploadFileByContainer(blobcntr, cods.ToJsonString(), "homework", $"{work.id}/record.json");
                 work.id = Guid.NewGuid().ToString();
                 if (string.IsNullOrEmpty(work.id))
-                {                   
-                    if (work.startTime > now)
+                {
+                    if (work.publish == 1)
                     {
                         work.progress = "pending";
                     }
-                    else
-                    {
-                        work.progress = "going";
+                    else {
+                        if (work.startTime > now)
+                        {
+                            work.progress = "pending";
+                        }
+                        else
+                        {
+                            work.progress = "going";
+                        }
                     }
+                    
                     await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(work, new PartitionKey($"{work.code}"));
                 }
                 else

+ 10 - 2
TEAMModelOS.SDK/Models/Service/SurveyService.cs

@@ -21,13 +21,21 @@ namespace TEAMModelOS.SDK.Models.Service
                 if (string.IsNullOrEmpty(survey.id))
                 {
                     survey.id = Guid.NewGuid().ToString();
-                    if (survey.startTime > now)
+
+                    if (survey.publish == 1)
                     {
                         survey.progress = "pending";
                     }
                     else
                     {
-                        survey.progress = "going";
+                        if (survey.startTime > now)
+                        {
+                            survey.progress = "pending";
+                        }
+                        else
+                        {
+                            survey.progress = "going";
+                        }
                     }
                     await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(survey, new PartitionKey($"{survey.code}"));
                 }

+ 26 - 54
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -237,19 +237,13 @@ namespace TEAMModelOS.Controllers
                     study.code = "Study-" + pa.sId;
                     study.createTime = now;
                     study.creatorId = userid;
-                    if (study.startTime > now)
-                    {
-                        study.progress = "pending";
-                    }
-                    else
-                    {
-                        study.progress = "going";
-                    }
+                    study.publish = 1;
+                    study.progress = "pending";
                     study.tchLists = pa.gId;
                     study.pId = areaStudy.id;
                     study.scope = "school";
                     study.targetType = "research";
-                    if (pa.gName.Count == 0)
+                    /*if (pa.gName.Count == 0)
                     {
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
@@ -271,7 +265,7 @@ namespace TEAMModelOS.Controllers
 
                         }
 
-                    }
+                    }*/
                     foreach (string setting in study.settings)
                     {
                         if (setting.Equals("exam"))
@@ -284,9 +278,10 @@ namespace TEAMModelOS.Controllers
                             trExam.tchLists = pa.gId;
                             trExam.creatorId = userid;
                             trExam.targetType = "research";
+                            trExam.publish = 1;
                             trExam.blob = $"/{trExam.areaId}/exam/{study.pId}/index.json";
                             //处理发布对象
-                            await getMoreExam(pa, trExam);
+                            //await getMoreExam(pa, trExam);
                             //保存更多得评测信息
                             string eId = await ExamService.saveMoreAsync(client, _dingDing, trExam);
                             if (string.IsNullOrEmpty(eId))
@@ -308,9 +303,10 @@ namespace TEAMModelOS.Controllers
                             trSurvey.tchLists = pa.gId;
                             trSurvey.scope = "school";
                             trSurvey.creatorId = userid;
+                            trSurvey.publish = 1;
                             trSurvey.targetType = "research";
                             trSurvey.blob = $"/{trSurvey.areaId}/survey/{study.pId}/index.json";
-                            await getMoreSurvey(pa, trSurvey);
+                            //await getMoreSurvey(pa, trSurvey);
                             string surveyId = await SurveyService.saveMoreAsync(client, _dingDing, trSurvey);
                             if (string.IsNullOrEmpty(surveyId))
                             {
@@ -331,9 +327,10 @@ namespace TEAMModelOS.Controllers
                             homework.tchLists = pa.gId;
                             homework.scope = "school";
                             homework.creatorId = userid;
+                            homework.publish = 1;
                             homework.targetType = "research";
                             //homework.blob = $"/{homework.areaId}/survey/{study.pId}/index.json";
-                            await getMoreWork(pa, homework);
+                            //await getMoreWork(pa, homework);
                             string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework, _serviceBus, _azureStorage, _configuration);
                             if (string.IsNullOrEmpty(workId))
                             {
@@ -851,20 +848,10 @@ namespace TEAMModelOS.Controllers
                     trVote.pId = areaVote.id;
                     trVote.tchLists = pa.gId;
                     trVote.targetType = "research";
-                    if (trVote.startTime <= 0)
-                    {
-                        trVote.startTime = now;
-                    }
-                    if (trVote.startTime > now)
-                    {
-                        trVote.progress = "pending";
-                    }
-                    else
-                    {
-                        trVote.progress = "going";
-                    }
+                    trVote.publish = 1;
+                    trVote.progress = "pending";
 
-                    if (pa.gName.Count == 0)
+                    /*if (pa.gName.Count == 0)
                     {
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
@@ -883,7 +870,7 @@ namespace TEAMModelOS.Controllers
                             allName.Add(sName);
                         }
 
-                    }
+                    }*/
                     if (string.IsNullOrEmpty(trVote.id))
                     {
                         trVote.id = Guid.NewGuid().ToString();
@@ -1043,20 +1030,10 @@ namespace TEAMModelOS.Controllers
                     trSurvey.tchLists = pa.gId;
                     trSurvey.pId = areaSurvey.id;
                     trSurvey.targetType = "research";
-                    if (trSurvey.startTime <= 0)
-                    {
-                        trSurvey.startTime = now;
-                    }
-                    if (trSurvey.startTime > now)
-                    {
-                        trSurvey.progress = "pending";
-                    }
-                    else
-                    {
-                        trSurvey.progress = "going";
-                    }
-
-                    if (pa.gName.Count == 0)
+                    trSurvey.publish = 1;
+                    trSurvey.progress = "pending";
+                   
+                    /*if (pa.gName.Count == 0)
                     {
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
@@ -1074,8 +1051,8 @@ namespace TEAMModelOS.Controllers
                             allName.Add(sName);
                         }
 
-                    }
-                    await getMoreSurvey(pa, trSurvey);
+                    }*/
+                    //await getMoreSurvey(pa, trSurvey);
 
                     trSurvey.id = Guid.NewGuid().ToString();
                     trSurvey.recordUrl = $"/survey/{trSurvey.id}/record.json";
@@ -1150,15 +1127,10 @@ namespace TEAMModelOS.Controllers
                     trExam.owner = "area";
                     trExam.pId = areaExam.id;
                     trExam.targetType = "research";
-                    if (trExam.startTime > now)
-                    {
-                        trExam.progress = "pending";
-                    }
-                    else
-                    {
-                        trExam.progress = "going";
-                    }
-                    if (pa.gName.Count == 0)
+                    trExam.progress = "pending";
+                    trExam.publish = 1;
+
+                    /*if (pa.gName.Count == 0)
                     {
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
@@ -1172,8 +1144,8 @@ namespace TEAMModelOS.Controllers
                             allName.Add(sName);
                         }
 
-                    }
-                    await getMoreExam(pa, trExam);
+                    }*/
+                    //await getMoreExam(pa, trExam);
                     if (string.IsNullOrEmpty(trExam.id))
                     {
                         trExam.id = Guid.NewGuid().ToString();

+ 72 - 51
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -47,7 +47,7 @@ namespace TEAMModelOS.Controllers
         private readonly NotificationService _notificationService;
 
         public ExamController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
-            IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, NotificationService notificationService,IConfiguration configuration)
+            IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, NotificationService notificationService, IConfiguration configuration)
         {
             _azureCosmos = azureCosmos;
             _serviceBus = serviceBus;
@@ -86,24 +86,30 @@ namespace TEAMModelOS.Controllers
                     request.startTime = now;
                 }
                 //查询所有学生名单
-               /* List<string> sids = new List<string>();
-                //List<Student> students = new List<Student>();
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
-                {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    {
-                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        while (accounts.MoveNext())
-                        {
-                            JsonElement account = accounts.Current;
-                            sids.Add(account.GetProperty("id").GetString());
-                        }
-                    }
-                }*/
+                /* List<string> sids = new List<string>();
+                 //List<Student> students = new List<Student>();
+                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
+                 {
+                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                     if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                     {
+                         var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                         while (accounts.MoveNext())
+                         {
+                             JsonElement account = accounts.Current;
+                             sids.Add(account.GetProperty("id").GetString());
+                         }
+                     }
+                 }*/
                 //int stuCount = 0;
+                List<(string pId, List<string> gid)> ps = new();
+                foreach (var gp in request.groupLists) {
+                    ps.Add((gp.Key, gp.Value));
+                }                
                 List<string> classes = ExamService.getClasses(request.classes, request.stuLists);
-                (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, request.school);
+                (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, request.school, ps);
+                request.stuCount = tchList.Count;
+
                 /*for (int i = 0; i < classes.Count; i++)
                 {
                     List<string> ids = new List<string>();
@@ -144,7 +150,7 @@ namespace TEAMModelOS.Controllers
                     }
                     stuCount += ids.Count;
                 }*/
-                request.stuCount = tchList.Count;
+
                 if (string.IsNullOrEmpty(request.id))
                 {
                     request.id = Guid.NewGuid().ToString();
@@ -568,7 +574,7 @@ namespace TEAMModelOS.Controllers
                 //确定当前学生所在班级且该班级参与该活动
                 List<string> cIds = new();
                 if (ids.Count == 0) return Ok(new { code = 1, msg = "未找到相关班级信息" });
-                if(string.IsNullOrEmpty(userId)) return Ok(new { code = 1, msg = "当前用户信息未找到" });
+                if (string.IsNullOrEmpty(userId)) return Ok(new { code = 1, msg = "当前用户信息未找到" });
                 foreach (string cId in ids)
                 {
                     //List<string> stus = new List<string>();
@@ -1217,7 +1223,7 @@ namespace TEAMModelOS.Controllers
                     requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList") }))
                 {
                     stuLists.Add(item);
-                }               
+                }
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: $"select c.id from c join A0 in c.students where A0.id = '{studentId}'",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
                 {
@@ -1745,7 +1751,7 @@ namespace TEAMModelOS.Controllers
         }*/
 
         [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Student")]
+        [AuthToken(Roles = "teacher,admin")]
         [HttpPost("scoring")]
         public async Task<IActionResult> scoring(JsonElement requert)
         {
@@ -1759,8 +1765,8 @@ namespace TEAMModelOS.Controllers
                 //if (!requert.TryGetProperty("type", out JsonElement type)) return BadRequest();
                 if (!requert.TryGetProperty("tmdId", out JsonElement tId)) return BadRequest();
                 if (!requert.TryGetProperty("count", out JsonElement scount)) return BadRequest();
-                
-                    var client = _azureCosmos.GetCosmosClient();
+
+                var client = _azureCosmos.GetCosmosClient();
                 //var redisClient = _azureRedis.GetRedisClient(8);
                 ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
                 List<ExamClassResult> classResults = new();
@@ -1833,7 +1839,8 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                 }
-                if (attr.Count > 0) {
+                if (attr.Count > 0)
+                {
                     foreach (SDK.Models.Cosmos.Common.Scoring ss in attr)
                     {
 
@@ -1865,18 +1872,21 @@ namespace TEAMModelOS.Controllers
                         var obj = new { ss.id, ss.stuId, ss.examId, ss.subjectId, item = sc, ss.qs, blob = ansBlob, ss.tIds, scores = scores, ss.model, ss.mode };
                         objs.Add(obj);
                     }
-                } else {
+                }
+                else
+                {
                     if (requert.TryGetProperty("stuId", out JsonElement stuId))
                     {
                         objs = await Review(attrSc, id.GetString(), code.GetString(), subjectId.GetString(), scount.GetInt32(), tId.GetString(), stuId.GetString());
                     }
-                    else {
+                    else
+                    {
                         objs = await Review(attrSc, id.GetString(), code.GetString(), subjectId.GetString(), scount.GetInt32(), tId.GetString(), "");
                     }
-                    
-                  
+
+
                 }
-                
+
                 var fp = attr.Count > 0 ? Math.Round(finishCount * 1.0 / (attrSc.Count * correct.num), 2) : 0;
                 return Ok(new { objs, paper = info.papers[index].blob, fp });
             }
@@ -1984,7 +1994,7 @@ namespace TEAMModelOS.Controllers
                 {
                     attr.Add(item);
                 }
-                
+
                 int index = 0;
                 foreach (ExamSubject subject in info.subjects)
                 {
@@ -2029,7 +2039,7 @@ namespace TEAMModelOS.Controllers
         }
 
         //批阅,给老师随机分配阅卷数据,以及查询改老师已有的阅卷数据
-        private async Task<List<dynamic>> Review(List<SDK.Models.Cosmos.Common.Scoring> attr, string id,string code,string subjectId,int count,string tId,string stuId)
+        private async Task<List<dynamic>> Review(List<SDK.Models.Cosmos.Common.Scoring> attr, string id, string code, string subjectId, int count, string tId, string stuId)
         {
             //ResponseBuilder builder = ResponseBuilder.custom();
             //var (id, school) = HttpContext.GetAuthTokenInfo();
@@ -2090,12 +2100,13 @@ namespace TEAMModelOS.Controllers
                         //var scc = ss.items.SelectMany(p => p.scores, (p, d) => new { p.ssc, d.sc, d.tmdId }).Where(x => x.tmdId.Equals(tId.GetString())).Select(m => new { m.sc, m.ssc });
                         List<dynamic> sc = new List<dynamic>();
                         int indexScore = 0;
+                        ss.qs = ss.qs.Where(s => !string.IsNullOrEmpty(s.tId)).ToList();
                         (string ansBlob, List<double> scores) = await getMoreStuInfo(client, ss.stuId, ss.examId, ss.subjectId, code);
                         foreach (Item item in ss.items)
                         {
                             List<double> scc = item.scores.Where(x => x.tmdId.Equals(tId)).Select(c => c.sc).ToList();
                             //item.scores.Where(x => x.tmdId.Equals(tId.GetString())).SelectMany(p => p.sc, (p, d) => new { });
-                            
+
                             if (scc.Count > 0)
                             {
                                 sc.Add(new { sc = scc.FirstOrDefault(), item.ssc });
@@ -2117,7 +2128,8 @@ namespace TEAMModelOS.Controllers
                     List<SDK.Models.Cosmos.Common.Scoring> notYet = new();
                     notYet = all.Where(x => x.tIds.Count < x.count * x.model - 1).ToList();
                     List<dynamic> objs = new List<dynamic>();
-                    for (int i = 0;i< count; i++) {
+                    for (int i = 0; i < count; i++)
+                    {
                         Random random = new Random();
                         SDK.Models.Cosmos.Common.Scoring item = new();
                         if (notYet.Count > 0)
@@ -2141,6 +2153,7 @@ namespace TEAMModelOS.Controllers
                         List<dynamic> sc = new List<dynamic>();
                         (string ansBlob, List<double> scores) = await getMoreStuInfo(client, item.stuId, item.examId, item.subjectId, code);
                         int indexScore = 0;
+                        item.qs = item.qs.Where(s => !string.IsNullOrEmpty(s.tId)).ToList();
                         foreach (Item its in item.items)
                         {
                             List<double> ssc = its.scores.Where(x => x.tmdId.Equals(tId)).Select(c => c.sc).ToList();
@@ -2209,12 +2222,12 @@ namespace TEAMModelOS.Controllers
                         return Ok(obj);
                     }*/
 
-                }                
+                }
             }
             catch (Exception ex)
             {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},exam/review\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
-                return new List<dynamic>() { new { code = 404,msg = "分配任务异常"} };
+                return new List<dynamic>() { new { code = 404, msg = "分配任务异常" } };
             }
 
         }
@@ -2309,14 +2322,15 @@ namespace TEAMModelOS.Controllers
                                 }
                                 else
                                 {
-                                    if (ssc[itemIndex] >= 0) {
+                                    if (ssc[itemIndex] >= 0)
+                                    {
                                         Info info = new();
                                         info.sc = ssc[itemIndex];
                                         info.tmdId = tId.GetString();
                                         info.mark = marks.Count > 0 ? marks[itemIndex] : "";
                                         info.index = itemIndex;
                                         item.scores.Add(info);
-                                    }                                    
+                                    }
                                 }
                                 itemIndex++;
                             }
@@ -2346,26 +2360,31 @@ namespace TEAMModelOS.Controllers
                 }
                 bool isFinish = false;
                 int scount = attr.Select(a => a.items[0].scores).ToList().Count;
-                foreach (SDK.Models.Cosmos.Common.Scoring sc in attr) {
-                    foreach (var item in sc.items) {
+                foreach (SDK.Models.Cosmos.Common.Scoring sc in attr)
+                {
+                    foreach (var item in sc.items)
+                    {
                         if (item.scores.Count == 0)
                         {
                             isFinish = false;
                             break;
                         }
-                        else {
+                        else
+                        {
                             if (item.scores.Count != correct.num)
                             {
                                 isFinish = false;
                                 break;
                             }
-                            else {
+                            else
+                            {
                                 isFinish = true;
                             }
                         }
                     }
                 }
-                if (isFinish) {
+                if (isFinish)
+                {
                     foreach (ExamClassResult exam in classResults)
                     {
                         foreach (SDK.Models.Cosmos.Common.Scoring scoring in attr)
@@ -2379,7 +2398,7 @@ namespace TEAMModelOS.Controllers
                                     var ace = item.scores.Where(x => string.IsNullOrEmpty(x.tmdId)).ToList();
                                     if (ace.Count > 0)
                                     {
-                                        return Ok(new { code = 1 ,msg = "用户信息未找到"});
+                                        return Ok(new { code = 1, msg = "用户信息未找到" });
                                     }
                                     //判定是否仲裁卷
                                     if (!item.flag)
@@ -2399,7 +2418,7 @@ namespace TEAMModelOS.Controllers
                                             from = $"ies5:{_option.Location}:private",
                                             to = ids,
                                             label = $"{bizcode}_school",
-                                            body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}",examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
+                                            body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}", examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
                                             expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
                                         };
                                         var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
@@ -2408,12 +2427,13 @@ namespace TEAMModelOS.Controllers
                                         var location = _option.Location;
                                         await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
                                         await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(scoring, scoring.id, new PartitionKey(scoring.code));
-                                        return Ok(new { msg = "需要仲裁" ,code = 2});
+                                        return Ok(new { msg = "需要仲裁", code = 2 });
                                     }
-                                    if (item.scores.Count > 0) {
+                                    if (item.scores.Count > 0)
+                                    {
                                         double sc = item.scores.Select(x => x.sc).ToList().Aggregate((i, j) => (i + j) / item.scores.Count);
                                         scoring.scores[itemIndex] = sc;
-                                    }                                  
+                                    }
                                     string tmdId = tId.GetString();
                                     //定位老师是几阅
                                     int indexOfSc = 0;
@@ -2460,7 +2480,7 @@ namespace TEAMModelOS.Controllers
                         }
                         await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, exam.id, new PartitionKey($"{exam.code}"));
                     }
-                }               
+                }
                 return Ok(new { code = 200 });
             }
             catch (Exception ex)
@@ -2517,7 +2537,7 @@ namespace TEAMModelOS.Controllers
                 schname = jsonschname.ToString();
 
             }
-            
+
             SDK.Models.Cosmos.Common.Scoring scoring = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<SDK.Models.Cosmos.Common.Scoring>(id.GetString(), new PartitionKey($"Scoring-{code}"));
             if (null != scoring)
             {
@@ -2552,7 +2572,7 @@ namespace TEAMModelOS.Controllers
                     from = $"ies5:{_option.Location}:private",
                     to = ids,
                     label = $"{bizcode}_school",
-                    body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}",examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
+                    body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}", examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
                     expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
                 };
                 var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
@@ -2882,7 +2902,8 @@ namespace TEAMModelOS.Controllers
                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsStreamAsync(correctIds, $"CorrectTask-{tId}");
             }
         }*/
-        private async Task<(string blob,List<double>)> getMoreStuInfo(CosmosClient client, string stuId, string examId,string subjectId,string code) {
+        private async Task<(string blob, List<double>)> getMoreStuInfo(CosmosClient client, string stuId, string examId, string subjectId, string code)
+        {
             var queryClass = $"select c.studentAnswers,c.studentIds,c.studentScores from c where array_contains(c.studentIds,'{stuId}') and c.examId = '{examId}' and c.subjectId = '{subjectId}'";
             List<List<string>> ans = new List<List<string>>();
             List<string> ids = new List<string>();

+ 24 - 22
TEAMModelOS/Controllers/Common/StudyController.cs

@@ -433,31 +433,33 @@ namespace TEAMModelOS.Controllers.Common
                 if (!request.TryGetProperty("type", out JsonElement type)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{tId}"));
-                if (response.Status == (int)HttpStatusCode.OK)
-                {
-                    var json = await JsonDocument.ParseAsync(response.ContentStream);
-                    StudyRecord study = json.ToObject<StudyRecord>();
-                    if (study.tId.Equals(tId.GetString()))
+                List<string> ids = tId.ToObject<List<string>>();
+                foreach (string teacId in ids) {
+                    var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{teacId}"));
+                    if (response.Status == (int)HttpStatusCode.OK)
                     {
-                        study.status = type.GetInt32();
-                        study.aTime = now;
+                        var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        StudyRecord study = json.ToObject<StudyRecord>();
+                        if (study.tId.Equals(tId.GetString()))
+                        {
+                            study.status = type.GetInt32();
+                            study.aTime = now;
+                        }
+                        await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
                     }
-                    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
-                }
-                else
-                {
-                    StudyRecord setting = new()
+                    else
                     {
-                        id = id.GetString(),
-                        tId = tId.GetString(),
-                        code = "StudyRecord-" + tId.GetString(),
-                        status = type.GetInt32(),
-                        aTime = now
-                    };
-                    await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
-                }
-
+                        StudyRecord setting = new()
+                        {
+                            id = id.GetString(),
+                            tId = tId.GetString(),
+                            code = "StudyRecord-" + tId.GetString(),
+                            status = type.GetInt32(),
+                            aTime = now
+                        };
+                        await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
+                    }
+                }               
                 return Ok(new { code = HttpStatusCode.OK });
             }
             catch (Exception ex)