Bläddra i källkod

Merge branch 'develop5.0-tmd' into develop5.0

CrazyIter_Bin 3 år sedan
förälder
incheckning
3179f660d7

+ 9 - 6
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -140,7 +140,8 @@ namespace TEAMModelFunction
                 log.LogInformation($"{exams.ToJsonString()}");
                 log.LogInformation($"{exams.ToJsonString()}");
                 foreach (var info in exams)
                 foreach (var info in exams)
                 {
                 {
-                    if (!info.classes.IsNotEmpty())
+                    List<string> classes = ExamService.getClasses(info.classes,info.stuLists);
+                    if (!classes.IsNotEmpty())
                     {
                     {
                         continue;
                         continue;
                     }
                     }
@@ -149,7 +150,7 @@ namespace TEAMModelFunction
                     {
                     {
                         sub.Add(subject.id);
                         sub.Add(subject.id);
                     }
                     }
-                    (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, info.classes, info.school);
+                    (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, info.school);
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     if (tmdids.IsNotEmpty())
                     if (tmdids.IsNotEmpty())
@@ -238,12 +239,13 @@ namespace TEAMModelFunction
                 log.LogInformation($"{votes.ToJsonString()}");
                 log.LogInformation($"{votes.ToJsonString()}");
                 foreach (var info in votes)
                 foreach (var info in votes)
                 {
                 {
-                    if (!info.classes.IsNotEmpty())
+                    List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
+                    if (classes.IsNotEmpty())
                     {
                     {
                         continue;
                         continue;
                     }
                     }
 
 
-                    (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, info.classes, info.school);
+                    (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, info.school);
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     if (tmdids.IsNotEmpty())
                     if (tmdids.IsNotEmpty())
@@ -332,11 +334,12 @@ namespace TEAMModelFunction
                 log.LogInformation($"{surveys.ToJsonString()}");
                 log.LogInformation($"{surveys.ToJsonString()}");
                 foreach (var info in surveys)
                 foreach (var info in surveys)
                 {
                 {
-                    if (!info.classes.IsNotEmpty())
+                    List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
+                    if (!classes.IsNotEmpty())
                     {
                     {
                         continue;
                         continue;
                     }
                     }
-                    (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, info.classes, info.school);
+                    (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, info.school);
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     if (tmdids.IsNotEmpty())
                     if (tmdids.IsNotEmpty())

+ 4 - 4
TEAMModelFunction/MonitorServicesBus.cs

@@ -280,17 +280,17 @@ namespace TEAMModelFunction
                 //await StuListService.FixStuCourse(client, stuListChange);
                 //await StuListService.FixStuCourse(client, stuListChange);
                 //Vote投票 Survey问卷 Exam评测 Learn学习活动 Homework作业活动
                 //Vote投票 Survey问卷 Exam评测 Learn学习活动 Homework作业活动
                 //名单变动修改学生问卷关联信息
                 //名单变动修改学生问卷关联信息
-                await StuListService.FixActivity(client, stuListChange, "Survey");
+                await StuListService.FixActivity(client, _dingDing, stuListChange, "Survey");
                 //名单变动修改学生投票关联信息
                 //名单变动修改学生投票关联信息
-                await StuListService.FixActivity(client, stuListChange, "Vote");
+                await StuListService.FixActivity(client, _dingDing, stuListChange, "Vote");
                 //名单变动修改学生评测关联信息
                 //名单变动修改学生评测关联信息
-                await StuListService.FixActivity(client, stuListChange, "Exam");
+                await StuListService.FixActivity(client, _dingDing, stuListChange, "Exam");
                 //TODO学习活动
                 //TODO学习活动
                 //await FixActivity(client, stuListChange, "Learn");
                 //await FixActivity(client, stuListChange, "Learn");
                 //TODO作业活动
                 //TODO作业活动
                 // await FixActivity(client, stuListChange, "Homework");
                 // await FixActivity(client, stuListChange, "Homework");
                 //TODO课程名单变动修改学生课程关联信息
                 //TODO课程名单变动修改学生课程关联信息
-                await StuListService.FixStuCourse(client, stuListChange);
+                await StuListService.FixStuCourse(client, _dingDing, stuListChange);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {

+ 6 - 4
TEAMModelFunction/TriggerExam.cs

@@ -13,6 +13,7 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Models.Service;
 
 
 namespace TEAMModelFunction
 namespace TEAMModelFunction
 {
 {
@@ -92,7 +93,8 @@ namespace TEAMModelFunction
                         }
                         }
                         break;
                         break;
                     case "going":
                     case "going":
-                        (List<TmdInfo> tmdids, List<StuInfo> studentss,List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, info.classes, info.school);
+                        List<string> classes = ExamService.getClasses(info.classes,info.stuLists);
+                        (List<TmdInfo> tmdids, List<StuInfo> studentss,List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, info.school);
                         List<StuActivity> stuActivities = new List<StuActivity>();
                         List<StuActivity> stuActivities = new List<StuActivity>();
                         List<StuActivity> tmdActivities = new List<StuActivity>();
                         List<StuActivity> tmdActivities = new List<StuActivity>();
                         try
                         try
@@ -169,7 +171,7 @@ namespace TEAMModelFunction
                             #endregion
                             #endregion
                             if (examClassResults.Count == 0)
                             if (examClassResults.Count == 0)
                             {
                             {
-                                foreach (string cla in info.classes)
+                                foreach (string cla in classes)
                                 {
                                 {
                                     int m = 0;
                                     int m = 0;
                                     foreach (ExamSubject subject in info.subjects)
                                     foreach (ExamSubject subject in info.subjects)
@@ -343,7 +345,7 @@ namespace TEAMModelFunction
                                 int gno = 0;
                                 int gno = 0;
                                 foreach (ExamSubject subject in info.subjects)
                                 foreach (ExamSubject subject in info.subjects)
                                 {
                                 {
-                                    if (subject.classCount == info.classes.Count)
+                                    if (subject.classCount == classes.Count)
                                     {
                                     {
                                         await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage);
                                         await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage);
                                     }
                                     }
@@ -935,6 +937,6 @@ namespace TEAMModelFunction
 
 
             await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
             await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
 
 
-        }
+        }       
     }
     }
 }
 }

+ 3 - 1
TEAMModelFunction/TriggerSurvey.cs

@@ -17,6 +17,7 @@ using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
+using TEAMModelOS.SDK.Models.Service;
 
 
 namespace TEAMModelFunction
 namespace TEAMModelFunction
 {
 {
@@ -73,7 +74,8 @@ namespace TEAMModelFunction
                             }
                             }
                             break;
                             break;
                         case "going":
                         case "going":
-                            (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, survey.classes, survey.school);
+                            List<string> classes = ExamService.getClasses(survey.classes, survey.stuLists);
+                            (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, survey.school);
 #if DEBUG
 #if DEBUG
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}问卷调查{tdata.id}写入学生表作为活动列表!", GroupNames.成都开发測試群組);
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}问卷调查{tdata.id}写入学生表作为活动列表!", GroupNames.成都开发測試群組);
 #endif
 #endif

+ 4 - 2
TEAMModelFunction/TriggerVote.cs

@@ -14,6 +14,7 @@ using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
+using TEAMModelOS.SDK.Models.Service;
 
 
 namespace TEAMModelFunction
 namespace TEAMModelFunction
 {
 {
@@ -72,12 +73,13 @@ namespace TEAMModelFunction
                             }
                             }
                             break;
                             break;
                         case "going":
                         case "going":
-                            (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, vote.classes, vote.school);
+                            List<string> classes = ExamService.getClasses(vote.classes, vote.stuLists);
+                            (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, vote.school);
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}投票活动" +
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}投票活动" +
                                 $"{tmdids.ToJsonString()}\n" +
                                 $"{tmdids.ToJsonString()}\n" +
                                 $"{students.ToJsonString()}\n" +
                                 $"{students.ToJsonString()}\n" +
                                 $"{classLists.ToJsonString()}\n" +
                                 $"{classLists.ToJsonString()}\n" +
-                                $"{vote.classes.ToJsonString()}\n", GroupNames.成都开发測試群組);
+                                $"{classes.ToJsonString()}\n", GroupNames.成都开发測試群組);
                             List<string> tmds = new List<string>();
                             List<string> tmds = new List<string>();
                             if (tmdids.IsNotEmpty())
                             if (tmdids.IsNotEmpty())
                             {
                             {

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

@@ -28,5 +28,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// </summary>
         /// </summary>
         public string scope { get; set; }
         public string scope { get; set; }
         public string originCode { get; set; }
         public string originCode { get; set; }
+        public string school { get; set; }
+        public string creatorId { get; set; }
     }
     }
 }
 }

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

@@ -19,6 +19,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public string periodId { get; set; }
         public string periodId { get; set; }
         public string scope { get; set; }
         public string scope { get; set; }
         public string school { get; set; }
         public string school { get; set; }
+        public string creatorId { get; set; }
     }
     }
     public class Students
     public class Students
     {
     {

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

@@ -17,6 +17,7 @@ namespace TEAMModelOS.SDK.Models
             pk = "Survey";
             pk = "Survey";
             // questions = new List<Question>();
             // questions = new List<Question>();
             classes = new List<string>();
             classes = new List<string>();
+            stuLists = new List<string>();
             tmdids = new List<string>();
             tmdids = new List<string>();
         }
         }
         /// <summary>
         /// <summary>
@@ -55,6 +56,7 @@ namespace TEAMModelOS.SDK.Models
 
 
         public List<string> tmdids { get; set; }
         public List<string> tmdids { get; set; }
         public List<string> classes { get; set; }
         public List<string> classes { get; set; }
+        public List<string> stuLists { get; set; }
         /// <summary>
         /// <summary>
         ///class行政班/teach教学班
         ///class行政班/teach教学班
         /// </summary>
         /// </summary>

+ 1 - 4
TEAMModelOS.SDK/Models/Cosmos/Common/Vote.cs

@@ -82,10 +82,7 @@ namespace TEAMModelOS.SDK.Models
         ///  scope 为school时 是学校的班级 class行政班   为private 时是私人班级
         ///  scope 为school时 是学校的班级 class行政班   为private 时是私人班级
         /// </summary>
         /// </summary>
         public List<string> classes { get; set; }
         public List<string> classes { get; set; }
-        /// <summary>
-        ///teach教学班
-        /// </summary>
-        public List<string> teachclasses { get; set; }
+        public List<string> stuLists { get; set; }
         /// <summary>
         /// <summary>
         /// 开始时间
         /// 开始时间
         /// </summary>
         /// </summary>

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

@@ -21,6 +21,7 @@ namespace TEAMModelOS.SDK.Models
             subjects = new List<ExamSubject>();
             subjects = new List<ExamSubject>();
             papers = new List<PaperSimple>();
             papers = new List<PaperSimple>();
             classes = new List<string>();
             classes = new List<string>();
+            stuLists = new List<string>();
         }
         }
         /// <summary>
         /// <summary>
         ///发布层级 类型 school  teacher
         ///发布层级 类型 school  teacher
@@ -69,6 +70,7 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         /// </summary>
         public string classType { get; set; }
         public string classType { get; set; }
         public List<string> classes { get; set; }
         public List<string> classes { get; set; }
+        public List<string> stuLists { get; set; }
         public List<PaperSimple> papers { get; set; }
         public List<PaperSimple> papers { get; set; }
         ///考试类型 段考 stage  联考 union 平常考 normal 其他 other
         ///考试类型 段考 stage  联考 union 平常考 normal 其他 other
         /// </summary>
         /// </summary>

+ 36 - 0
TEAMModelOS.SDK/Models/Service/ExamService.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models.Service
+{
+    public static class ExamService
+    {
+        public static List<string> getClasses(List<string> cla, List<string> stus)
+        {
+            List<string> classes = new List<string>();
+            try
+            {
+                if (cla.Count > 0)
+                {
+                    foreach (string cl in cla)
+                    {
+                        classes.Add(cl);
+                    }
+                }
+                if (stus.Count > 0)
+                {
+                    foreach (string stu in stus)
+                    {
+                        classes.Add(stu);
+                    }
+                }
+                return classes;
+            }
+            catch (Exception)
+            {
+                return classes;
+            }
+        }
+    }
+}

+ 112 - 69
TEAMModelOS.SDK/Models/Service/StuListService.cs

@@ -15,108 +15,149 @@ namespace TEAMModelFunction
 {
 {
     public class StuListService
     public class StuListService
     {
     {
-        public static async Task FixActivity(CosmosClient client, StuListChange stuListChange, string type)
+        public static async Task FixActivity(CosmosClient client,DingDing _dingDing, StuListChange stuListChange, string type)
         {
         {
-            var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c  join A1 in c.classes  where  c.pk='{type}' and A1 in('{stuListChange.listid}') ";
-            List<MQActivity> datas = new List<MQActivity>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.originCode}") }))
+            try
             {
             {
-                datas.Add(item);
-            }
-            foreach (MQActivity activity in datas)
-            {
-                //已经完结的不再允许加入
-                if (activity.progress.Equals("finish") || activity.progress.Equals("pending"))
-                {
-                    continue;
+                var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c  join A1 in c.classes  where  c.pk='{type}' and A1 in('{stuListChange.listid}') ";
+                List<MQActivity> datas = new List<MQActivity>();
+                if (stuListChange.scope.Equals("school", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(stuListChange.school)) {
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
+                       requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.school}") }))
+                    {
+                        datas.Add(item);
+                    }
+                    ///还要处理该学校每个老师发布的班级的
+                    List<SchoolTeacher> teachers = new List<SchoolTeacher>();
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: $"SELECT c.id, c.name FROM c",
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{stuListChange.school}") }))
+                    {
+                        teachers.Add(item);
+                    }
+                    foreach (var techer in teachers) {
+                        var queryTech = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c " +
+                            $" join A1 in c.classes  where c.school='{stuListChange.school}'   and   c.pk='{type}' and A1 in('{stuListChange.listid}') ";
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: queryTech,
+                            requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{techer.id}") }))
+                        {
+                            datas.Add(item);
+                        }
+                    }
                 }
                 }
-                //学生新加入名单的
-                foreach (Students students in stuListChange.stujoin)
+                if (stuListChange.scope.Equals("private", StringComparison.OrdinalIgnoreCase)&&!string.IsNullOrEmpty(stuListChange.creatorId))
                 {
                 {
-                    var stucourse = new StuActivity
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.creatorId}") }))
                     {
                     {
-                        id = activity.id,
-                        scode = activity.code,
-                        name = activity.name,
-                        code = $"Activity-{activity.school}-{students.id}",
-                        scope = activity.scope, 
-                        school = activity.school,
-                        creatorId = activity.creatorId,
-                        pk = "Activity",
-                        type = type,
-                        subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
-                        startTime = activity.startTime,
-                        endTime = activity.endTime,
-                        blob=activity.blob,
-                        owner= activity.owner
-                    };
-                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
-                }//tmd新加入的
-                foreach (string tmdid in stuListChange.tmdjoin)
+                        datas.Add(item);
+                    }
+                }
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 需要处理的活动\n{datas.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                foreach (MQActivity activity in datas)
                 {
                 {
-                    var stucourse = new StuActivity
+                    //已经完结的不再允许加入
+                    if (activity.progress.Equals("finish") || activity.progress.Equals("pending"))
                     {
                     {
-                        id = activity.id,
-                        scode = activity.code,
-                        name = activity.name,
-                        code = $"Activity-{tmdid}",
-                        scope = activity.scope,
-                        school = activity.school,
-                        creatorId = activity.creatorId,
-                        pk = "Activity",
-                        type = type,
-                        subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
-                        startTime = activity.startTime,
-                        endTime = activity.endTime,
-                        blob = activity.blob,
-                        owner = activity.owner
-                    };
-                    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
-                }
-                foreach (Students students in stuListChange.stuleave) {
-                    try {
-
-                        await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{activity.school}-{students.id}"));
-                    } catch { 
-                        //仅处理未写入的数据。
+                        continue;
                     }
                     }
-                }
-                foreach (string tmdid in stuListChange.tmdhleave) {
-                    try
+                    //学生新加入名单的
+                    foreach (Students students in stuListChange.stujoin)
+                    {
+                        var stucourse = new StuActivity
+                        {
+                            id = activity.id,
+                            scode = activity.code,
+                            name = activity.name,
+                            code = $"Activity-{activity.school}-{students.id}",
+                            scope = activity.scope,
+                            school = activity.school,
+                            creatorId = activity.creatorId,
+                            pk = "Activity",
+                            type = type,
+                            subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
+                            startTime = activity.startTime,
+                            endTime = activity.endTime,
+                            blob = activity.blob,
+                            owner = activity.owner
+                        };
+                        await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 新建活动中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                    }//tmd新加入的
+                    foreach (string tmdid in stuListChange.tmdjoin)
+                    {
+                        var stucourse = new StuActivity
+                        {
+                            id = activity.id,
+                            scode = activity.code,
+                            name = activity.name,
+                            code = $"Activity-{tmdid}",
+                            scope = activity.scope,
+                            school = activity.school,
+                            creatorId = activity.creatorId,
+                            pk = "Activity",
+                            type = type,
+                            subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
+                            startTime = activity.startTime,
+                            endTime = activity.endTime,
+                            blob = activity.blob,
+                            owner = activity.owner
+                        }; 
+                        await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 新建活动中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                        await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                    }
+                    foreach (Students students in stuListChange.stuleave)
                     {
                     {
+                        try
+                        {
 
 
-                        await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
+                            await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{activity.school}-{students.id}"));
+                        }
+                        catch (CosmosException ex)
+                        {
+                            //仅处理未写入的数据。
+                        }
                     }
                     }
-                    catch
+                    foreach (string tmdid in stuListChange.tmdhleave)
                     {
                     {
-                        //仅处理未写入的数据。
+                        try
+                        {
+
+                            await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
+                        }
+                        catch(CosmosException ex )
+                        {
+                            //仅处理未写入的数据。
+                        }
                     }
                     }
                 }
                 }
             }
             }
+            catch(Exception ex ) {
+            
+            }
         }
         }
 
 
-        public static async Task FixStuCourse(CosmosClient client, StuListChange stuListChange)
+        public static async Task FixStuCourse(CosmosClient client,DingDing  _dingDing, StuListChange stuListChange)
         {
         {
             //1.查找学校或教师的课程是否包含该名单的课程。
             //1.查找学校或教师的课程是否包含该名单的课程。
             var query = $"select distinct c.code,c.id,c.no,c.name,c.scope, c.creatorId,c.school from c join A0 in c.schedule where A0.stulist = '{stuListChange.listid}'";
             var query = $"select distinct c.code,c.id,c.no,c.name,c.scope, c.creatorId,c.school from c join A0 in c.schedule where A0.stulist = '{stuListChange.listid}'";
             List<Course> courses = new List<Course>();
             List<Course> courses = new List<Course>();
-            if (stuListChange.scope.Equals("school"))
+            if (stuListChange.scope.Equals("school") && !string.IsNullOrEmpty(stuListChange.school))
             {
             {
                 await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
                 await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.originCode}") }))
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.school}") }))
                 {
                 {
                     courses.Add(item);
                     courses.Add(item);
                 }
                 }
             }
             }
-            else
+            if (stuListChange.scope.Equals("private") && !string.IsNullOrEmpty(stuListChange.creatorId))
             {
             {
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.originCode}") }))
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.creatorId}") }))
                 {
                 {
                     courses.Add(item);
                     courses.Add(item);
                 }
                 }
             }
             }
+            await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 需要处理的课程\n{courses.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
             //2.获取课程的id 并尝试添加或移除对应的学生课程记录StuCourse。
             //2.获取课程的id 并尝试添加或移除对应的学生课程记录StuCourse。
             foreach (var course in courses)
             foreach (var course in courses)
             {
             {
@@ -134,6 +175,7 @@ namespace TEAMModelFunction
                         creatorId = course.creatorId,
                         creatorId = course.creatorId,
                         pk = "StuCourse"
                         pk = "StuCourse"
                     };
                     };
+                    await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 新建课程中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                     await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                     await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                 }
                 }
                 //tmd新加入的
                 //tmd新加入的
@@ -150,6 +192,7 @@ namespace TEAMModelFunction
                         creatorId = course.creatorId,
                         creatorId = course.creatorId,
                         pk = "StuCourse"
                         pk = "StuCourse"
                     };
                     };
+                    await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 新建课程中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                     await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                     await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
                 }
                 }
                 //移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。
                 //移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。

+ 13 - 2
TEAMModelOS/ClientApp/src/common/BaseClassSelectPri.vue

@@ -2,7 +2,7 @@
     <div class="base-class-select dark-el-cascader">
     <div class="base-class-select dark-el-cascader">
         <RadioGroup v-model="evaluationInfo.scope" @on-change="onClassTypeChange" style="margin-bottom: 10px;">
         <RadioGroup v-model="evaluationInfo.scope" @on-change="onClassTypeChange" style="margin-bottom: 10px;">
             <Radio label="private">{{ $t('survey.form.privateClass') }}</Radio>
             <Radio label="private">{{ $t('survey.form.privateClass') }}</Radio>
-            <Radio label="school">{{ $t('survey.form.schoolClass') }}</Radio>
+            <Radio label="school" v-if="hasSchool">{{ $t('survey.form.schoolClass') }}</Radio>
         </RadioGroup>
         </RadioGroup>
         <el-cascader :props="props" :options="curCusList" @change="treeChange" :show-all-levels="false" clearable filterable></el-cascader>
         <el-cascader :props="props" :options="curCusList" @change="treeChange" :show-all-levels="false" clearable filterable></el-cascader>
     </div>
     </div>
@@ -27,7 +27,7 @@ export default {
             schoolClassList: [],
             schoolClassList: [],
             classes: [],
             classes: [],
             evaluationInfo: {
             evaluationInfo: {
-                scope: 'school'
+                scope: 'private'
             },
             },
             props: {
             props: {
                 multiple: true,
                 multiple: true,
@@ -211,6 +211,17 @@ export default {
             })
             })
             return nodes
             return nodes
         },
         },
+		hasSchool() {
+		  let user = JSON.parse(
+		    decodeURIComponent(localStorage.user_profile, "utf-8")
+		  );
+		  console.log('xxxx',user)
+		  return (
+			user.schools && 
+		    user.schools.length &&
+		    user.schools.filter((i) => i.status === "join").length > 0
+		  );
+		},
     }
     }
 };
 };
 </script>
 </script>

+ 3 - 2
TEAMModelOS/ClientApp/src/view/answersheet/index.vue

@@ -375,6 +375,7 @@
 			goBack() {
 			goBack() {
 				let params = {}
 				let params = {}
 				let curEditPaper = localStorage.getItem('c_edit_paper')
 				let curEditPaper = localStorage.getItem('c_edit_paper')
+				console.log(curEditPaper.paperGrade)
 				// 如果是从新建试卷或者编辑试卷 跳转过来的 则返回过去的时候带上编辑的信息
 				// 如果是从新建试卷或者编辑试卷 跳转过来的 则返回过去的时候带上编辑的信息
 				if (this.$route.params.paper && (this.fromRouter === 'newSchoolPaper' || this.fromRouter ===
 				if (this.$route.params.paper && (this.fromRouter === 'newSchoolPaper' || this.fromRouter ===
 						'newPrivatePaper') && curEditPaper) {
 						'newPrivatePaper') && curEditPaper) {
@@ -382,7 +383,7 @@
 						paper: JSON.parse(curEditPaper)
 						paper: JSON.parse(curEditPaper)
 					}
 					}
 				}
 				}
-				console.log(params)
+				console.log(params.paper.paperGrade)
 				// 如果是从试卷库预览试卷跳转过来的 就返回试卷库
 				// 如果是从试卷库预览试卷跳转过来的 就返回试卷库
 				if (this.$route.params.paper && (this.fromRouter === 'schoolBank' || this.fromRouter === 'personalBank')) {
 				if (this.$route.params.paper && (this.fromRouter === 'schoolBank' || this.fromRouter === 'personalBank')) {
 					params = {
 					params = {
@@ -528,7 +529,7 @@
 			})
 			})
 		},
 		},
 		beforeRouteLeave(to, from, next) {
 		beforeRouteLeave(to, from, next) {
-			if (to.name === 'newSchoolPaper' || to.name === 'newPrivatePaper' || to.name === 'schoolBank' || to.name ===
+			if (to.name === 'schoolBank' || to.name ===
 				'personalBank') {
 				'personalBank') {
 				// 设置下一个路由的 meta
 				// 设置下一个路由的 meta
 				to.meta.isKeep = true; // 让 A 缓存,即不刷新
 				to.meta.isKeep = true; // 让 A 缓存,即不刷新

+ 1 - 1
TEAMModelOS/ClientApp/src/view/evaluation/components/BaseExerciseList.vue

@@ -187,7 +187,7 @@
 						</Radio>
 						</Radio>
 						<Radio :label="4">
 						<Radio :label="4">
 							<Icon type="social-windows"></Icon>
 							<Icon type="social-windows"></Icon>
-							<span>{{$t('evaluation.exerciseList.rule4')}}{{$t('unit.text11')}}</span>
+							<span>{{$t('evaluation.exerciseList.rule4')}}</span>
 						</Radio>
 						</Radio>
 					</RadioGroup>
 					</RadioGroup>
 				</div>
 				</div>

+ 26 - 20
TEAMModelOS/ClientApp/src/view/evaluation/index/CreatePaper.vue

@@ -1204,16 +1204,24 @@
 			},
 			},
 			/* 渲染需要编辑的试卷信息 */
 			/* 渲染需要编辑的试卷信息 */
 			async doRender(paper) {
 			async doRender(paper) {
+				let schoolInfo = null
 				if(paper.paperGrade){
 				if(paper.paperGrade){
 					console.log('传进来缓存的paper')
 					console.log('传进来缓存的paper')
 					console.log(paper)
 					console.log(paper)
 					this.evaluationInfo = paper
 					this.evaluationInfo = paper
 					this.oldPaper = JSON.parse(JSON.stringify(this.evaluationInfo))
 					this.oldPaper = JSON.parse(JSON.stringify(this.evaluationInfo))
+					if (paper.scope === 'school') {
+						schoolInfo = await this.getSchoolBaseInfo()
+						// paper.paperGrade = paper.paperGrade.map(i => +i)
+						this.subjectList = schoolInfo ? this.schoolInfo.period[paper.paperPeriod]
+							.subjects : [],
+						this.gradeList = schoolInfo ? this.schoolInfo.period[paper.paperPeriod]
+							.grades : []	
+					}
 					return 
 					return 
 				}
 				}
 				console.log('渲染的试卷',paper)
 				console.log('渲染的试卷',paper)
 				// localStorage.setItem('c_edit_paper',JSON.stringify(paper))
 				// localStorage.setItem('c_edit_paper',JSON.stringify(paper))
-				let schoolInfo = null
 				if (paper.scope === 'school') {
 				if (paper.scope === 'school') {
 					schoolInfo = await this.getSchoolBaseInfo()
 					schoolInfo = await this.getSchoolBaseInfo()
 					this.subjectList = schoolInfo ? this.schoolInfo.period.filter(i => i.id === paper.periodId)[0]
 					this.subjectList = schoolInfo ? this.schoolInfo.period.filter(i => i.id === paper.periodId)[0]
@@ -1244,9 +1252,9 @@
 				this.oldPaper = JSON.parse(JSON.stringify(this.evaluationInfo))
 				this.oldPaper = JSON.parse(JSON.stringify(this.evaluationInfo))
 			}
 			}
 		},
 		},
-
 		mounted() {
 		mounted() {
 			let routerData = this.$route.params.paper
 			let routerData = this.$route.params.paper
+			console.log('xxxx',routerData)
 			if (routerData) {
 			if (routerData) {
 				console.log(routerData)
 				console.log(routerData)
 				this.doRender(routerData)
 				this.doRender(routerData)
@@ -1271,8 +1279,6 @@
 				return this.$route.name === 'newSchoolPaper'
 				return this.$route.name === 'newSchoolPaper'
 			},
 			},
 			propPeriod() {
 			propPeriod() {
-				console.log(this.evaluationInfo.paperPeriod)
-				console.log(this.schoolInfo)
 				return this.$route.name === 'newSchoolPaper' && this.subjectList.length && (this.evaluationInfo.paperPeriod || this.evaluationInfo.paperPeriod === 0 ) ? this.schoolInfo.period[this
 				return this.$route.name === 'newSchoolPaper' && this.subjectList.length && (this.evaluationInfo.paperPeriod || this.evaluationInfo.paperPeriod === 0 ) ? this.schoolInfo.period[this
 					.evaluationInfo
 					.evaluationInfo
 					.paperPeriod].id : null
 					.paperPeriod].id : null
@@ -1284,22 +1290,22 @@
 			}
 			}
 		},
 		},
 
 
-		beforeRouteEnter(to, from, next) {
-			if (from.name === 'answerSheet' && (to.name === 'newSchoolPaper' || to.name === 'newPrivatePaper')) {
-				to.meta.isKeep = true
-			}
-			next()
-		},
-		beforeRouteLeave(to, from, next) {
-			if(to.name === 'answerSheet'){
-				// 设置下一个路由的 meta
-				// from.meta.isKeep = true;  // 让 A 缓存,即不刷新
-			}
-			if(to.name === 'schoolBank' || to.name === 'personalBank'){
-				to.meta.isKeep = false
-			}
-			next();
-		},
+		// beforeRouteEnter(to, from, next) {
+		// 	if (from.name === 'answerSheet' && (to.name === 'newSchoolPaper' || to.name === 'newPrivatePaper')) {
+		// 		to.meta.isKeep = true
+		// 	}
+		// 	next()
+		// },
+		// beforeRouteLeave(to, from, next) {
+		// 	if(to.name === 'answerSheet'){
+		// 		// 设置下一个路由的 meta
+		// 		// from.meta.isKeep = true;  // 让 A 缓存,即不刷新
+		// 	}
+		// 	if(to.name === 'schoolBank' || to.name === 'personalBank'){
+		// 		to.meta.isKeep = false
+		// 	}
+		// 	next();
+		// },
 		watch: {
 		watch: {
 			paperScrollTop: {
 			paperScrollTop: {
 				handler(n) {
 				handler(n) {

+ 3 - 3
TEAMModelOS/ClientApp/src/view/evaluation/index/TestPaper.vue

@@ -302,9 +302,9 @@
 		},
 		},
 		mounted() {
 		mounted() {
 			// this.isShowSave = window.location.pathname === '/home/evaluation/testPaper'
 			// this.isShowSave = window.location.pathname === '/home/evaluation/testPaper'
-			let paper = this.paper || this.$route.params.paper || JSON.parse(localStorage.getItem('_paperInfo'))
+			let paper = this.paper || this.$route.params.paper || JSON.parse(localStorage.getItem('c_edit_paper'))
 			if (!paper) return
 			if (!paper) return
-			console.log(paper)
+			console.log('xxxx',paper)
 			// localStorage.setItem('_paperInfo', JSON.stringify(paper))
 			// localStorage.setItem('_paperInfo', JSON.stringify(paper))
 			this.paperInfo = paper // 自己页面的值
 			this.paperInfo = paper // 自己页面的值
 			this.paperDiff = paper.item ? this.handleDiffCalc(paper.item) : 0
 			this.paperDiff = paper.item ? this.handleDiffCalc(paper.item) : 0
@@ -324,7 +324,7 @@
 		watch: {
 		watch: {
 			paper: {
 			paper: {
 				handler(newValue, oldValue) {
 				handler(newValue, oldValue) {
-					console.log('TestPaper组件接受的paper',newValue)
+					console.log('TestPaper组件接受的paper',newValue.name)
 					this.paperInfo = newValue
 					this.paperInfo = newValue
 					// localStorage.setItem('_paperInfo', JSON.stringify(newValue))
 					// localStorage.setItem('_paperInfo', JSON.stringify(newValue))
 					this.paperDiff = newValue.item ? this.handleDiffCalc(newValue.item) : 4
 					this.paperDiff = newValue.item ? this.handleDiffCalc(newValue.item) : 4

+ 1 - 2
TEAMModelOS/Controllers/Analysis/AnalysisController.cs

@@ -299,7 +299,7 @@ namespace TEAMModelOS.Controllers.Analysis
                 //处理进线分数
                 //处理进线分数
                 gradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
                 gradeTotal.Sort((s1, s2) => { return s2.CompareTo(s1); });
                 ipoint = gradeTotal[personCount];
                 ipoint = gradeTotal[personCount];
-                //以班级为单位
+                //以班级为单位(此处处理的是行政班级,教学班暂未处理)
                 foreach (string classId in info.classes)
                 foreach (string classId in info.classes)
                 {
                 {
                     Class classroom = null;
                     Class classroom = null;
@@ -1651,6 +1651,5 @@ namespace TEAMModelOS.Controllers.Analysis
             }
             }
             return gradeId;
             return gradeId;
         }
         }
-
     }
     }
 }
 }

+ 6 - 5
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -25,7 +25,7 @@ using TEAMModelOS.SDK.Models.Table;
 using Azure.Messaging.ServiceBus;
 using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Configuration;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Filter;
-using TEAMModelOS.Services.Common;
+using TEAMModelOS.SDK.Models.Service;
 
 
 namespace TEAMModelOS.Controllers
 namespace TEAMModelOS.Controllers
 {
 {
@@ -100,12 +100,13 @@ namespace TEAMModelOS.Controllers
                     }
                     }
                 }
                 }
                 int stuCount = 0;
                 int stuCount = 0;
-                for (int i = 0; i < request.classes.Count; i++)
+                List<string> classes = ExamService.getClasses(request.classes,request.stuLists);
+                for (int i = 0; i < classes.Count; i++)
                 {
                 {
                     List<string> ids = new List<string>();
                     List<string> ids = new List<string>();
                     //处理班级人数(公共部分的校本名单)
                     //处理班级人数(公共部分的校本名单)
                     //List<Student> students = new List<Student>();
                     //List<Student> students = new List<Student>();
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{request.classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
                     {
                     {
                         using var json = await JsonDocument.ParseAsync(item.ContentStream);
                         using var json = await JsonDocument.ParseAsync(item.ContentStream);
                         if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
@@ -123,7 +124,7 @@ namespace TEAMModelOS.Controllers
 
 
                         //处理发布对象为自选名单(个人)
                         //处理发布对象为自选名单(个人)
                         List<StuList> stuLists = new List<StuList>();
                         List<StuList> stuLists = new List<StuList>();
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id = '{request.classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id = '{classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
                         {
                         {
                             stuLists.Add(item);
                             stuLists.Add(item);
                         }
                         }
@@ -177,7 +178,7 @@ namespace TEAMModelOS.Controllers
                         //request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
                         //request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
                         //发布对象为自选名单(校本)
                         //发布对象为自选名单(校本)
                         List<StuList> stuLists = new List<StuList>();
                         List<StuList> stuLists = new List<StuList>();
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id = '{request.classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{request.school}") }))
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id = '{classes[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{request.school}") }))
                         {
                         {
                             stuLists.Add(item);
                             stuLists.Add(item);
                         }
                         }

+ 27 - 14
TEAMModelOS/Controllers/School/CourseController.cs

@@ -299,7 +299,7 @@ namespace TEAMModelOS.Controllers
         }
         }
 
 
        public  (int status, StuList stuList) JoinList(StuList stuList, string _studentId,string _tmdId,string school)
        public  (int status, StuList stuList) JoinList(StuList stuList, string _studentId,string _tmdId,string school)
-        {
+       {
             int status = -1;
             int status = -1;
             if (string.IsNullOrEmpty($"{_studentId}") && string.IsNullOrEmpty($"{_tmdId}"))
             if (string.IsNullOrEmpty($"{_studentId}") && string.IsNullOrEmpty($"{_tmdId}"))
             {
             {
@@ -343,18 +343,20 @@ namespace TEAMModelOS.Controllers
         }
         }
         //处理通用名单
         //处理通用名单
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
+        [AuthToken(Roles = "teacher,admin")]
         [HttpPost("upsert-list")]
         [HttpPost("upsert-list")]
         public async Task<IActionResult> upsertList(JsonElement json)
         public async Task<IActionResult> upsertList(JsonElement json)
         {
         {
             try
             try
             {
             {
-
+                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
                 StuList stuList = new StuList();
                 StuList stuList = new StuList();
                 if (!json.TryGetProperty("stuList", out JsonElement student)) return BadRequest();
                 if (!json.TryGetProperty("stuList", out JsonElement student)) return BadRequest();
                 if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 stuList = student.ToObject<StuList>();
                 stuList = student.ToObject<StuList>();
-                stuList= await upsertList(stuList, $"{scope}");
+                stuList.creatorId = userid;
+                stuList.school = school;
+                stuList = await upsertList(stuList, $"{scope}");
                 return Ok(new { stuList });
                 return Ok(new { stuList });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
@@ -420,8 +422,11 @@ namespace TEAMModelOS.Controllers
                     stuList.scope = "school";
                     stuList.scope = "school";
                     StuListChange change = new StuListChange()
                     StuListChange change = new StuListChange()
                     {
                     {
+                        listid= stuList.id,
                         scope = $"{scope}",
                         scope = $"{scope}",
-                        originCode = originCode
+                        originCode = originCode,
+                        school=stuList.school,
+                        creatorId=stuList.creatorId
                     };
                     };
                     var query = $"SELECT distinct value(c)  FROM c where  c.id='{stuList.id}'";
                     var query = $"SELECT distinct value(c)  FROM c where  c.id='{stuList.id}'";
                     List<StuList> odlStus = new List<StuList>();
                     List<StuList> odlStus = new List<StuList>();
@@ -479,10 +484,13 @@ namespace TEAMModelOS.Controllers
                                 }
                                 }
                             }
                             }
                         }
                         }
-                        var messageChange = new ServiceBusMessage(change.ToJsonString());
-                        messageChange.ApplicationProperties.Add("name", "StuList");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        if (change.tmdjoin.Count != 0 || change.tmdhleave.Count != 0 || change.stujoin.Count != 0 || change.stuleave.Count != 0)
+                        {
+                            var messageChange = new ServiceBusMessage(change.ToJsonString());
+                            messageChange.ApplicationProperties.Add("name", "StuList");
+                            var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                            await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        }
                     }
                     }
                     stuList = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(stuList, new PartitionKey($"StuList-{originCode}"));
                     stuList = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(stuList, new PartitionKey($"StuList-{originCode}"));
                 }
                 }
@@ -491,8 +499,11 @@ namespace TEAMModelOS.Controllers
                     stuList.scope = "private";
                     stuList.scope = "private";
                     StuListChange change = new StuListChange()
                     StuListChange change = new StuListChange()
                     {
                     {
+                        listid= stuList.id,
                         scope = $"{scope}",
                         scope = $"{scope}",
-                        originCode = originCode
+                        originCode = originCode,
+                        school = stuList.school,
+                        creatorId = stuList.creatorId
                     };
                     };
 
 
                     var query = $"SELECT distinct value(c)  FROM c    where  c.id='{stuList.id}'";
                     var query = $"SELECT distinct value(c)  FROM c    where  c.id='{stuList.id}'";
@@ -551,10 +562,12 @@ namespace TEAMModelOS.Controllers
                                 }
                                 }
                             }
                             }
                         }
                         }
-                        var messageChange = new ServiceBusMessage(change.ToJsonString());
-                        messageChange.ApplicationProperties.Add("name", "StuList");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        if (change.tmdjoin.Count != 0 || change.tmdhleave.Count != 0 || change.stujoin.Count != 0 || change.stuleave.Count != 0) {
+                            var messageChange = new ServiceBusMessage(change.ToJsonString());
+                            messageChange.ApplicationProperties.Add("name", "StuList");
+                            var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                            await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        }
                     }
                     }
                     stuList.code = "StuList";
                     stuList.code = "StuList";
                     stuList = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stuList, new PartitionKey($"StuList"));
                     stuList = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stuList, new PartitionKey($"StuList"));

+ 16 - 10
TEAMModelOS/Controllers/School/SchoolTeacherController.cs

@@ -60,22 +60,28 @@ namespace TEAMModelOS.Controllers
             if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
             if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
             //string status_str = (request.TryGetProperty("join_status", out JsonElement status_json)) ? status_json.ToString() : "join";
             //string status_str = (request.TryGetProperty("join_status", out JsonElement status_json)) ? status_json.ToString() : "join";
             //資料取得
             //資料取得
-            List<object> teachers = new List<object>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"SELECT c.id, c.name, c.classes, c.picture ,c.status, c.job, c.createTime, ARRAY_LENGTH(c.permissions) as permissionCount, c.size FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
+            List<ScTeacher> teachers = new List<ScTeacher>();
+            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ScTeacher>(queryText: $"SELECT c.id, c.name,   c.picture ,c.status, c.job, c.createTime, ARRAY_LENGTH(c.permissions) as permissionCount, c.size FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
             {
             {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                {
-                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                    {
-                        teachers.Add(obj.ToObject<object>());
-                    }
+                if ($"{item.createTime}".Length > 10) {
+                    item.createTime = item.createTime / 1000;
                 }
                 }
+                teachers.Add(item);
             }
             }
 
 
             return Ok(new { teachers });
             return Ok(new { teachers });
         }
         }
-
+        public class ScTeacher
+        {
+            public string id { get; set; }
+            public string name { get; set; }
+            public string picture { get; set; }
+            public string status { get; set; }
+            public string job { get; set; }
+            public long createTime { get; set; }
+            public int permissionCount { get; set; }
+            public int size { get; set; }
+        }
         /// <summary>
         /// <summary>
         /// 取得某位老師的權限
         /// 取得某位老師的權限
         /// </summary>
         /// </summary>

+ 30 - 24
TEAMModelOS/Controllers/School/StudentController.cs

@@ -1927,39 +1927,45 @@ namespace TEAMModelOS.Controllers
         {
         {
             try
             try
             {
             {
-                if (!requert.TryGetProperty("students", out JsonElement students)) return BadRequest();
-                if (!requert.TryGetProperty("tmdIds", out JsonElement tmdIds)) return BadRequest();
-                var client = _azureCosmos.GetCosmosClient();
-                List<Students> stuList = students.ToObject<List<Students>>();
-                List<string> tmdids = tmdIds.ToObject<List<string>>();
+                requert.TryGetProperty("students", out JsonElement students);
+                requert.TryGetProperty("tmdIds", out JsonElement tmdIds);
+                
                 List<TmdInfo> tmdinfos = new List<TmdInfo>();
                 List<TmdInfo> tmdinfos = new List<TmdInfo>();
-                List<object> stus = new List<object>();               
-                foreach (Students stu in stuList) {
-                    var query = $"select c.id,c.name,c.picture,c.classId,c.code,c.groupId,c.groupName,c.no from c where c.id = '{stu.id}'";
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
-                    {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                List<object> stus = new List<object>();
+                var client = _azureCosmos.GetCosmosClient();
+                if (students.ValueKind.Equals(JsonValueKind.Array)) {
+                    List<Students> stuList = students.ToObject<List<Students>>();
+                    if (stuList.IsNotEmpty()) {
+                        foreach (Students stu in stuList)
                         {
                         {
-                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            var query = $"select c.id,c.name,c.picture,c.classId,c.code,c.groupId,c.groupName,c.no from c where c.id = '{stu.id}'";
+                            await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
                             {
                             {
-                                stus.Add(obj.ToObject<object>());
+                                using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                {
+                                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                                    {
+                                        stus.Add(obj.ToObject<object>());
+                                    }
+                                }
                             }
                             }
                         }
                         }
                     }
                     }
                 }
                 }
-                if (tmdids.IsNotEmpty())
+                if (tmdIds .ValueKind.Equals(JsonValueKind.Array))
                 {
                 {
-                    
-                    List<string> inids = new List<string>();
-                    tmdids.ForEach(x => { inids.Add($"'{x}'"); });
-                    var insql = string.Join(",", inids);
-                    var queryslt = $"SELECT c.id,c.name,c.picture FROM c where c.id in ({insql})";
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                    {
-                        tmdinfos.Add(item);
+                    List<string> tmdids = tmdIds.ToObject<List<string>>();
+                    if (tmdids.IsNotEmpty()) {
+                        List<string> inids = new List<string>();
+                        tmdids.ForEach(x => { inids.Add($"'{x}'"); });
+                        var insql = string.Join(",", inids);
+                        var queryslt = $"SELECT c.id,c.name,c.picture FROM c where c.id in ({insql})";
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                        {
+                            tmdinfos.Add(item);
+                        }
                     }
                     }
-                    //tmdinfos.AddRange(infos);
                 }
                 }
                 return Ok(new { stus, tmdinfos });
                 return Ok(new { stus, tmdinfos });
             }
             }

+ 5 - 4
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -66,12 +66,13 @@ namespace TEAMModelOS.Controllers
                 string defaultschool = null;
                 string defaultschool = null;
                 //TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
                 //TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
-                Teacher teacher = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
-                teacher.name = $"{name}";
-                teacher.picture = $"{picture}";
+                
                 int total = 0;
                 int total = 0;
                 int tsize = 0;
                 int tsize = 0;
                 try {
                 try {
+                    Teacher teacher = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
+                    teacher.name = $"{name}";
+                    teacher.picture = $"{picture}";
                     ///教师的个人空间
                     ///教师的个人空间
                     tsize = teacher.size;
                     tsize = teacher.size;
                     ///教师的总空间 包含 个人空间和学校赠送的空间累加
                     ///教师的总空间 包含 个人空间和学校赠送的空间累加
@@ -126,7 +127,7 @@ namespace TEAMModelOS.Controllers
                 { 
                 { 
                     if (ex.Status == 404) {
                     if (ex.Status == 404) {
                         //如果沒有,則初始化Teacher基本資料到Cosmos
                         //如果沒有,則初始化Teacher基本資料到Cosmos
-                        teacher = new Teacher
+                        Teacher teacher = new Teacher
                         {
                         {
                             id = id, 
                             id = id, 
                             pk = "Base",
                             pk = "Base",