Selaa lähdekoodia

处理研修入口 发布作业活动的内容

zj 2 vuotta sitten
vanhempi
commit
7c8ff4cd6a
1 muutettua tiedostoa jossa 148 lisäystä ja 130 poistoa
  1. 148 130
      TEAMModelOS.FunctionV4/CosmosDB/TriggerHomework.cs

+ 148 - 130
TEAMModelOS.FunctionV4/CosmosDB/TriggerHomework.cs

@@ -191,168 +191,186 @@ namespace TEAMModelOS.FunctionV4
 
             }
             List<string> sub = new();
-            if (work.targets.Count > 0) {
-                foreach (var course in work.targets) {
-                   var info =  course.ToObject<List<string>>();
-                    if (info.Count > 1) {
-                        sub.Add(info[0]);
-                    }
-                }
-            }
-            if (addTmdidsCls.IsNotEmpty())
+            try
             {
-                addTmdidsCls.ForEach(x =>
-                {
-                    HashSet<string> classIds = new HashSet<string>();
-                    classLists.ForEach(z =>
+                if (work.tchLists.Count == 0) {
+                    if (work.targets.Count > 0)
                     {
-                        z.members.ForEach(y =>
+                        foreach (var course in work.targets)
                         {
-                            if (y.id.Equals(x.id) && y.type == 1)
+                            var info = course.ToObject<List<string>>();
+                            if (info.Count > 1)
                             {
-                                classIds.Add(z.id);
+                                sub.Add(info[0]);
                             }
-                        });
-                    });
-                    int sta = -1;
-                    if (tac.Count > 0)
-                    {
-                        StuActivity activity = tac.Where(t => t.code.Equals($"Activity-{x.id}")).FirstOrDefault();
-                        if (activity != null)
-                        {
-                            sta = activity.taskStatus;
                         }
                     }
-                    tmdActivities.Add(new StuActivity
-                    {
-                        pk = "Activity",
-                        id = work.id,
-                        code = $"Activity-{x.id}",
-                        type = "Homework",
-                        name = work.name,
-                        startTime = work.startTime,
-                        endTime = work.endTime,
-                        scode = work.code,
-                        scope = work.scope,
-                        school = work.school,
-                        creatorId = work.creatorId,
-                        subjects = sub,
-                        blob = work.blob,
-                        owner = work.owner,
-                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                        taskStatus = sta,
-                        mustSubmit = work.mustSubmit,
-                        classIds = classIds.ToList()
-                    });
-                });
+                }
+                
             }
-            if (addStudentsCls.IsNotEmpty())
+            catch (Exception e)
             {
-                addStudentsCls.ForEach(x =>
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动发布对象异常{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+            }
+            finally {
+                if (addTmdidsCls.IsNotEmpty())
                 {
-                    HashSet<string> classIds = new HashSet<string>();
-                    classLists.ForEach(z =>
+                    addTmdidsCls.ForEach(x =>
                     {
-                        z.members.ForEach(y =>
+                        HashSet<string> classIds = new HashSet<string>();
+                        classLists.ForEach(z =>
                         {
-                            if (y.id.Equals(x.id) && y.type == 2)
+                            z.members.ForEach(y =>
                             {
-                                classIds.Add(z.id);
+                                if (y.id.Equals(x.id) && y.type == 1)
+                                {
+                                    classIds.Add(z.id);
+                                }
+                            });
+                        });
+                        int sta = -1;
+                        if (tac.Count > 0)
+                        {
+                            StuActivity activity = tac.Where(t => t.code.Equals($"Activity-{x.id}")).FirstOrDefault();
+                            if (activity != null)
+                            {
+                                sta = activity.taskStatus;
                             }
+                        }
+                        tmdActivities.Add(new StuActivity
+                        {
+                            pk = "Activity",
+                            id = work.id,
+                            code = $"Activity-{x.id}",
+                            type = "Homework",
+                            name = work.name,
+                            startTime = work.startTime,
+                            endTime = work.endTime,
+                            scode = work.code,
+                            scope = work.scope,
+                            school = work.school,
+                            creatorId = work.creatorId,
+                            subjects = sub,
+                            blob = work.blob,
+                            owner = work.owner,
+                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                            taskStatus = sta,
+                            mustSubmit = work.mustSubmit,
+                            classIds = classIds.ToList()
                         });
                     });
-                    int sta = -1;
-                    if (tac.Count > 0)
+                }
+                if (addStudentsCls.IsNotEmpty())
+                {
+                    addStudentsCls.ForEach(x =>
                     {
-                        StuActivity activity = tac.Where(t => t.code.Equals($"Activity-{x.code.Replace("Base-", "")}-{x.id}")).FirstOrDefault();
-                        if (activity != null)
+                        HashSet<string> classIds = new HashSet<string>();
+                        classLists.ForEach(z =>
+                        {
+                            z.members.ForEach(y =>
+                            {
+                                if (y.id.Equals(x.id) && y.type == 2)
+                                {
+                                    classIds.Add(z.id);
+                                }
+                            });
+                        });
+                        int sta = -1;
+                        if (tac.Count > 0)
                         {
-                            sta = activity.taskStatus;
+                            StuActivity activity = tac.Where(t => t.code.Equals($"Activity-{x.code.Replace("Base-", "")}-{x.id}")).FirstOrDefault();
+                            if (activity != null)
+                            {
+                                sta = activity.taskStatus;
+                            }
                         }
-                    }
 
-                    stuActivities.Add(new StuActivity
-                    {
-                        pk = "Activity",
-                        id = work.id,
-                        code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
-                        type = "Homework",
-                        name = work.name,
-                        startTime = work.startTime,
-                        endTime = work.endTime,
-                        scode = work.code,
-                        scope = work.scope,
-                        school = work.school,
-                        creatorId = work.creatorId,
-                        subjects = sub,
-                        blob = work.blob,
-                        owner = work.owner,
-                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                        taskStatus = sta,
-                        classIds = classIds.ToList(),
-                        mustSubmit = work.mustSubmit
+                        stuActivities.Add(new StuActivity
+                        {
+                            pk = "Activity",
+                            id = work.id,
+                            code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
+                            type = "Homework",
+                            name = work.name,
+                            startTime = work.startTime,
+                            endTime = work.endTime,
+                            scode = work.code,
+                            scope = work.scope,
+                            school = work.school,
+                            creatorId = work.creatorId,
+                            subjects = sub,
+                            blob = work.blob,
+                            owner = work.owner,
+                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                            taskStatus = sta,
+                            classIds = classIds.ToList(),
+                            mustSubmit = work.mustSubmit
+                        });
                     });
-                });
-            }
-            (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, work.tchLists, work.school, ps);
-            (string standard, List<string> tmdids, string school, List<string> update, int statistics) list = (null, null, null, new List<string> { StatisticsService.OfflineRecord }, 0);
-            if (tchList.IsNotEmpty())
-            {
-                list.tmdids = tchList.Select(x => x.id).ToList();
-                School school = null;
-                if (!string.IsNullOrEmpty(work.school))
-                {
-                    school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(work.school, new Azure.Cosmos.PartitionKey("Base"));
-                    list.school = school.id;
-                    list.standard = school.standard;
                 }
-                tchList.ForEach(x =>
+                (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, work.tchLists, work.school, ps);
+                (string standard, List<string> tmdids, string school, List<string> update, int statistics) list = (null, null, null, new List<string> { StatisticsService.OfflineRecord }, 0);
+                if (tchList.IsNotEmpty())
                 {
-                    HashSet<string> classIds = new();
-                    classInfos.ForEach(z =>
+                    list.tmdids = tchList.Select(x => x.id).ToList();
+                    School school = null;
+                    if (!string.IsNullOrEmpty(work.school))
                     {
-                        z.members.ForEach(y =>
+                        school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(work.school, new Azure.Cosmos.PartitionKey("Base"));
+                        list.school = school.id;
+                        list.standard = school.standard;
+                    }
+                    tchList.ForEach(x =>
+                    {
+                        HashSet<string> classIds = new();
+                        classInfos.ForEach(z =>
                         {
-                            if (y.id.Equals(x.id) && y.type == 1)
+                            z.members.ForEach(y =>
                             {
-                                classIds.Add(z.id);
-                            }
+                                if (y.id.Equals(x.id) && y.type == 1)
+                                {
+                                    classIds.Add(z.id);
+                                }
+                            });
                         });
-                    });
-                    int sta = -1;
-                    if (tac.Count > 0)
-                    {
-                        StuActivity activity = tac.Where(t => t.code.Equals($"Activity-{x.id}")).FirstOrDefault();
-                        if (activity != null)
+                        int sta = -1;
+                        if (tac.Count > 0)
                         {
-                            sta = activity.taskStatus;
+                            StuActivity activity = tac.Where(t => t.code.Equals($"Activity-{x.id}")).FirstOrDefault();
+                            if (activity != null)
+                            {
+                                sta = activity.taskStatus;
+                            }
                         }
-                    }
-                    tchActivities.Add(new StuActivity
-                    {
-                        pk = "Activity",
-                        id = work.id,
-                        code = $"Activity-{x.id}",
-                        type = "Homework",
-                        name = work.name,
-                        startTime = work.startTime,
-                        endTime = work.endTime,
-                        scode = work.code,
-                        scope = work.scope,
-                        school = work.school,
-                        creatorId = work.creatorId,
-                        subjects = new List<string> { "" },
-                        blob = work.blob,
-                        owner = work.owner,
-                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                        taskStatus = sta,
-                        classIds = classIds.ToList()
+                        tchActivities.Add(new StuActivity
+                        {
+                            pk = "Activity",
+                            id = work.id,
+                            code = $"Activity-{x.id}",
+                            type = "Homework",
+                            name = work.name,
+                            startTime = work.startTime,
+                            endTime = work.endTime,
+                            scode = work.code,
+                            scope = work.scope,
+                            school = work.school,
+                            creatorId = work.creatorId,
+                            subjects = new List<string> { "" },
+                            blob = work.blob,
+                            owner = work.owner,
+                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                            taskStatus = sta,
+                            classIds = classIds.ToList()
+                        });
+
                     });
 
-                });
+                }
+                await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, tchActivities);
+                await StatisticsService.SendServiceBus(list, _configuration, _serviceBus, client);
+
             }
-            await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, tchActivities);
-            await StatisticsService.SendServiceBus(list, _configuration, _serviceBus, client);
+         
         }
     }
 }