瀏覽代碼

处理名单逻辑

CrazyIter_Bin 3 年之前
父節點
當前提交
52df16a401

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

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

+ 19 - 8
TEAMModelOS.SDK/Models/Service/StuListService.cs

@@ -21,12 +21,23 @@ namespace TEAMModelFunction
             {
                 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}") }))
+                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);
+                    }
+
+                    ///还要处理该学校每个老师发布的班级的
+                }
+                if (stuListChange.scope.Equals("private", StringComparison.OrdinalIgnoreCase)&&!string.IsNullOrEmpty(stuListChange.creatorId))
                 {
-                    datas.Add(item);
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.creatorId}") }))
+                    {
+                        datas.Add(item);
+                    }
                 }
-
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 需要处理的活动\n{datas.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                 foreach (MQActivity activity in datas)
                 {
@@ -116,18 +127,18 @@ namespace TEAMModelFunction
             //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}'";
             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,
-                    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);
                 }
             }
-            else
+            if (stuListChange.scope.Equals("private") && !string.IsNullOrEmpty(stuListChange.creatorId))
             {
                 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);
                 }

+ 11 - 5
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)
-        {
+       {
             int status = -1;
             if (string.IsNullOrEmpty($"{_studentId}") && string.IsNullOrEmpty($"{_tmdId}"))
             {
@@ -349,12 +349,14 @@ namespace TEAMModelOS.Controllers
         {
             try
             {
-
+                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
                 StuList stuList = new StuList();
                 if (!json.TryGetProperty("stuList", out JsonElement student)) return BadRequest();
                 if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 stuList = student.ToObject<StuList>();
-                stuList= await upsertList(stuList, $"{scope}");
+                stuList.creatorId = userid;
+                stuList.school = school;
+                stuList = await upsertList(stuList, $"{scope}");
                 return Ok(new { stuList });
             }
             catch (Exception ex)
@@ -422,7 +424,9 @@ namespace TEAMModelOS.Controllers
                     {
                         listid= stuList.id,
                         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}'";
                     List<StuList> odlStus = new List<StuList>();
@@ -497,7 +501,9 @@ namespace TEAMModelOS.Controllers
                     {
                         listid= stuList.id,
                         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}'";