Browse Source

1.修改StuActivity的type字段的属性值:"type":"Vote"/"Exam"/"Homework"/"Learn"/"Survey" 首字母小写变大写,并完成数据清理。
2.完成课程名单,学生名单变更,相应学生活动类型列表,课程列表的数据补偿。

CrazyIter_Bin 4 years ago
parent
commit
4a29082f64

+ 60 - 32
TEAMModelFunction/CourseServiceBus.cs

@@ -1,3 +1,4 @@
+using Azure.Cosmos;
 using Microsoft.Azure.WebJobs;
 using System;
 using System.Collections.Generic;
@@ -19,44 +20,71 @@ namespace TEAMModelFunction
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
         }
+
         /// <summary>
         /// 完善课程变更
         /// </summary>
         /// <data msg>
-        /// "ids":["s111","t1111"]//学生
-        /// "opt":"join/leave",//状态
-        /// "no":"CLASS001"//教室编号
-        /// "source":1/2  //学生名单数据来源 1是不同学校的学生账号,2是扫码加入的醍摩豆ID
+        /// CourseChange
         ///// </data>
         /// <param name="msg"></param>
         /// <returns></returns>
-        //[FunctionName("Course")]
-        //public async Task StuList([ServiceBusTrigger("active-task", "course", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
-        //{
-        //   var client= _azureCosmos.GetCosmosClient();
-        //    try
-        //    {
-        //        await _dingDing.SendBotMsg($"ServiceBus,CourseChange:{msg}", GroupNames.醍摩豆服務運維群組);
-        //        var jsonMsg = JsonDocument.Parse(msg);
-        //        CourseChange courseChange=  msg.ToObject<CourseChange>();
-        //        //根据新增名单获取 新增的学生id 及timdid
-        //        (List<string> addTmdids, List<Students> addStudents)= await TriggerStuActivity.GetStuList(client,courseChange.addList,courseChange.school);
-        //        //根据新增名单获取 新增的学生id 及timdid
-        //        (List<string>delTmdids, List<Students> delStudents) = await TriggerStuActivity.GetStuList(client,courseChange.delList,courseChange.school);
-        //        foreach (var addStu in addStudents) { 
-                
-        //        }
-        //        foreach (var addTmd in addTmdids)
-        //        {
-
-        //        }
-
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        await _dingDing.SendBotMsg($"ServiceBus,Blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
-        //    }
-        //}
-
+        [FunctionName("Course")]
+        public async Task Course([ServiceBusTrigger("active-task", "course", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            try
+            {
+                await _dingDing.SendBotMsg($"ServiceBus,CourseChange:{msg}", GroupNames.醍摩豆服務運維群組);
+                var jsonMsg = JsonDocument.Parse(msg);
+                CourseChange courseChange = msg.ToObject<CourseChange>();
+                //根据新增名单获取 新增的学生id 及timdid
+                (List<string> addTmdids, List<Students> addStudents) = await TriggerStuActivity.GetStuList(client, courseChange.addList, courseChange.school);
+                //根据删除名单获取 新增的学生id 及timdid
+                (List<string> delTmdids, List<Students> delStudents) = await TriggerStuActivity.GetStuList(client, courseChange.delList, courseChange.school);
+                foreach (var addStu in addStudents)
+                {
+                    var course = new StuCourse
+                    {
+                        id = courseChange.id,
+                        scode = courseChange.code,
+                        name = courseChange.name,
+                        code = $"Course-{courseChange.school}-{addStu.id}",
+                        scope = courseChange.scope,
+                        school = courseChange.school,
+                        creatorId = courseChange.creatorId,
+                        pk = "Course"
+                    };
+                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(course, new PartitionKey(course.code));
+                }
+                foreach (var addTmd in addTmdids)
+                {
+                    var course = new StuCourse
+                    {
+                        id = courseChange.id,
+                        scode = courseChange.code,
+                        name = courseChange.name,
+                        code = $"Course-{addTmd}",
+                        scope = courseChange.scope,
+                        //school = courseChange.school,
+                        creatorId = courseChange.creatorId,
+                        pk = "Course"
+                    };
+                    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(course, new PartitionKey(course.code));
+                }
+                foreach (var delStu in delStudents)
+                {
+                    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{courseChange.school}-{delStu.id}"));
+                }
+                foreach (var delTmd in delTmdids)
+                {
+                    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{delTmd}"));
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"CourseServiceBus-Course\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+        }
     }
 }

+ 203 - 0
TEAMModelFunction/StuListServiceBus.cs

@@ -0,0 +1,203 @@
+using Azure.Cosmos;
+using Microsoft.Azure.WebJobs;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+
+namespace TEAMModelFunction
+{
+    public class MQActivity { 
+    
+        public string id { get; set; }
+        public string code { get; set; }
+        public string owner { get; set; }
+        public List<string> classes { get; set; }
+        //如果已经完成则不写入???
+        public string progress { get; set; }
+        public string scope { get; set; }
+        public string school { get; set; }
+        public string creatorId { get; set; }
+        public string pk { get; set; }
+        public string name { get; set; }
+        public List<string> subjects { get; set; }
+        public string blob { get; set; }
+        public long startTime { get; set; }
+        public long endTime { get; set; }
+
+    }
+
+    public class StuListServiceBus
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        public StuListServiceBus(AzureCosmosFactory azureCosmos, DingDing dingDing)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+        }
+        /// <summary>
+        /// 完善课程变更,StuListChange,  originCode是学校编码 则表示名单是学校自定义名单,如果是tmdid则表示醍摩豆的私有名单,scope=school,private。
+        /// </summary>
+        /// <data msg>
+        /// CourseChange
+        ///// </data>
+        /// <param name="msg"></param>
+        /// <returns></returns>
+        [FunctionName("StuList")]
+        public async Task StuList([ServiceBusTrigger("active-task", "stulist", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            try
+            {
+                await _dingDing.SendBotMsg($"ServiceBus,StuList:{msg}", GroupNames.醍摩豆服務運維群組);
+                var jsonMsg = JsonDocument.Parse(msg);
+                StuListChange stuListChange = msg.ToObject<StuListChange>();
+                //名单变动修改学生课程关联信息
+                await FixStuCourse(client, stuListChange);
+                //Vote投票 Survey问卷 Exam评测 Learn学习活动 Homework作业活动
+                //TODO名单变动修改学生问卷关联信息
+                await FixActivity(client, stuListChange, "Survey");
+                //TODO名单变动修改学生投票关联信息
+                await FixActivity(client, stuListChange, "Vote");
+                //TODO名单变动修改学生评测关联信息
+                await FixActivity(client, stuListChange, "Exam");
+                //学习活动
+                await FixActivity(client, stuListChange, "Learn");
+                //作业活动
+                await FixActivity(client, stuListChange, "Homework");
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"StuListServiceBus-StuList\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+        }
+
+        public async Task FixActivity(CosmosClient client, 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}") }))
+            {
+                datas.Add(item);
+            }
+            foreach (MQActivity activity in datas) {
+                //已经完结的不在允许加入
+                if (activity.progress.Equals("finish")) {
+                    continue;
+                }
+                //学生新加入名单的
+                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 = type.Equals("Exam") ? activity.subjects : new List<string>() { "" },
+                        startTime = activity.startTime,
+                        endTime = activity.endTime
+                    };
+                    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= type.ToLower().Equals("Exam")?activity.subjects:new List<string>() {"" }
+                    };
+                    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                }
+            }
+        }
+
+        public async Task FixStuCourse(CosmosClient client, StuListChange stuListChange) {
+            //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"))
+            {
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.originCode}") }))
+                {
+                    courses.Add(item);
+                }
+            }
+            else
+            {
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.originCode}") }))
+                {
+                    courses.Add(item);
+                }
+            }
+            //2.获取课程的id 并尝试添加或移除对应的学生课程记录StuCourse。
+            foreach (var course in courses)
+            {
+                //学生新加入名单的
+                foreach (Students students in stuListChange.stujoin)
+                {
+                    var stucourse = new StuCourse
+                    {
+                        id = course.id,
+                        scode = course.code,
+                        name = course.name,
+                        code = $"Course-{course.school}-{students.id}",
+                        scope = course.scope,
+                        school = course.school,
+                        creatorId = course.creatorId,
+                        pk = "Course"
+                    };
+                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(course, new PartitionKey(course.code));
+                }
+                //tmd新加入的
+                foreach (string tmdid in stuListChange.tmdjoin)
+                {
+                    var stucourse = new StuCourse
+                    {
+                        id = course.id,
+                        scode = course.code,
+                        name = course.name,
+                        code = $"Course-{tmdid}",
+                        scope = course.scope,
+                        school = course.school,
+                        creatorId = course.creatorId,
+                        pk = "Course"
+                    };
+                    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(course, new PartitionKey(course.code));
+                }
+                //移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。
+                //foreach (var delStu in stuListChange.stuleave)
+                //{
+                //    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{course.school}-{delStu.id}"));
+                //}
+                //foreach (var delTmd in stuListChange.tmdhleave)
+                //{
+                //    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(course.id, new PartitionKey($"Course-{delTmd}"));
+                //}
+            }
+
+        }
+    }
+}

+ 2 - 2
TEAMModelFunction/TriggerExam.cs

@@ -139,7 +139,7 @@ namespace TEAMModelFunction
                                 pk = "Activity",
                                 id = info.id,
                                 code = $"Activity-{x}",
-                                type = "exam",
+                                type = "Exam",
                                 name = info.name,
                                 startTime = info.startTime,
                                 endTime = info.endTime,
@@ -161,7 +161,7 @@ namespace TEAMModelFunction
                                 pk = "Activity",
                                 id = info.id,
                                 code = $"Activity-{info.school}-{x.id}",
-                                type = "exam",
+                                type = "Exam",
                                 name = info.name,
                                 startTime = info.startTime,
                                 endTime = info.endTime,

+ 2 - 2
TEAMModelFunction/TriggerSurvey.cs

@@ -133,7 +133,7 @@ namespace TEAMModelFunction
                                     pk = "Activity",
                                     id = survey.id,
                                     code = $"Activity-{x}",
-                                    type = "survey",
+                                    type = "Survey",
                                     name = survey.name,
                                     startTime = survey.startTime,
                                     endTime = survey.endTime,
@@ -153,7 +153,7 @@ namespace TEAMModelFunction
                                     pk = "Activity",
                                     id = survey.id,
                                     code = $"Activity-{survey.school}-{x.id}",
-                                    type = "survey",
+                                    type = "Survey",
                                     name = survey.name,
                                     startTime = survey.startTime,
                                     endTime = survey.endTime,

+ 2 - 2
TEAMModelFunction/TriggerVote.cs

@@ -140,7 +140,7 @@ namespace TEAMModelFunction
                                     pk = "Activity",
                                     id = vote.id,
                                     code = $"Activity-{x}",
-                                    type = "vote",
+                                    type = "Vote",
                                     name = vote.name,
                                     startTime = vote.startTime,
                                     endTime = vote.endTime,
@@ -161,7 +161,7 @@ namespace TEAMModelFunction
                                     pk = "Activity",
                                     id = vote.id,
                                     code = $"Activity-{vote.school}-{x.id}",
-                                    type = "vote",
+                                    type = "Vote",
                                     name = vote.name,
                                     startTime = vote.startTime,
                                     endTime = vote.endTime,

+ 0 - 34
TEAMModelOS.SDK/Models/Cosmos/Common/Inner/ClassChange.cs

@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace TEAMModelOS.SDK.Models.Cosmos.Common.Inner
-{
-    /// <summary>
-    /// 学生名单变动
-    /// </summary>
-    public class ClassChange
-    {
-        /// <summary>
-        /// 教师名单加入的
-        /// </summary>
-        public List<string> tchjoin { get; set; } = new List<string>();
-        /// <summary>
-        /// 教师名单离开的
-        /// </summary>
-        public List<string> tchleave { get; set; } = new List<string>();
-        /// <summary>
-        /// 学校名单加入的
-        /// </summary>
-        public List<string> schjoin { get; set; } = new List<string>();
-        /// <summary>
-        /// 学校名单离开的
-        /// </summary>
-        public List<string> schleave { get; set; } = new List<string>();
-        public string listid { get; set; }
-        /// <summary>
-        /// 分区
-        /// </summary>
-        public string scope { get; set; }
-    }
-}

TEAMModelOS.SDK/Models/Cosmos/Common/CourseChange.cs → TEAMModelOS.SDK/Models/Cosmos/Common/Inner/CourseChange.cs


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

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Common
+{
+    public class StuListChange
+    {
+        /// <summary>
+        /// 教师名单加入的成员
+        /// </summary>
+        public List<string> tmdjoin { get; set; } = new List<string>();
+        /// <summary>
+        /// 教师名单离开的成员
+        /// </summary>
+        public List<string> tmdhleave { get; set; } = new List<string>();
+        /// <summary>
+        /// 学校学生名单加入的成员
+        /// </summary>
+        public List<Students> stujoin { get; set; } = new List<Students>();
+        /// <summary>
+        /// 学校学生名单离开的成员
+        /// </summary>
+        public List<Students> stuleave { get; set; } = new List<Students>();
+        public string listid { get; set; }
+        /// <summary>
+        /// 分区
+        /// </summary>
+        public string scope { get; set; }
+        public string originCode { get; set; }
+    }
+}

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/StuCourse.cs

@@ -9,7 +9,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// <summary>
         /// 课程的分区键课程Code
         /// </summary>
-        public string scode { get; set; } = "Course";
+        public string scode { get; set; } 
         public string name { get; set; }
         public  string scope { get; set; }
         public string school { get; set; }

+ 1 - 1
TEAMModelOS/Controllers/School/StudentCommonController.cs

@@ -36,7 +36,7 @@ namespace TEAMModelOS.Controllers
         /// </summary>
         /// <param name="request">
         ///加入的班级信息                      ?classes:[{"classid":"S-C-00001","scope":"school"},{"classid":"P-C-00004","scope":"private"}]
-        ///活动类型                            ?"type":"vote"/"exam"/"homework"/"learn"/"survey"" // vote投票 survey问卷 exam评测 learn学习活动 homework作业活动
+        ///活动类型                            ?"type":"Vote"/"Exam"/"Homework"/"Learn"/"Survey"" // Vote投票 Survey问卷 Exam评测 Learn学习活动 Homework作业活动
         ///时间筛选范围开始时间 默认30天之前   ?"stime":1608274766154  
         ///时间筛选范围结束时间 默认当前时间   ?"etime":1608274766666 
         ///是否展示列表的 Tips                 ? "tips":true/false

+ 5 - 0
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -117,6 +117,11 @@ namespace TEAMModelOS.Controllers.XTest
         }
 
 
+
+
+
+
+
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]
         [HttpPost("fixExamActivity")]