Browse Source

移除ActivityData相关业务代码

CrazyIter_Bin 4 years ago
parent
commit
c8b24ec643

+ 82 - 35
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelFunction
 {
@@ -64,45 +65,91 @@ namespace TEAMModelFunction
                     {
                         sub.Add(subject.id);
                     }
-                    ActivityData dataa;
-                    if (info.scope == "school")
+                    //ActivityData dataa;
+                    //if (info.scope == "school")
+                    //{
+                    //    dataa = new ActivityData
+                    //    {
+                    //        id = info.id,
+                    //        code = $"Activity-{info.school}",
+                    //        type = "exam",
+                    //        name = info.name,
+                    //        startTime = info.startTime,
+                    //        endTime = info.endTime,
+                    //        scode = info.code,
+                    //        scope = info.scope,
+                    //        classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
+                    //        tmdids = new List<string> { "" },
+                    //        progress = "going",
+                    //        subjects = sub
+                    //    };
+                    //    await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(dataa, new Azure.Cosmos.PartitionKey(dataa.code));
+                    //}
+                    //else if (info.scope == "private")
+                    //{
+                    //    dataa = new ActivityData
+                    //    {
+                    //        id = info.id,
+                    //        code = $"Activity-Common",
+                    //        type = "exam",
+                    //        name = info.name,
+                    //        startTime = info.startTime,
+                    //        endTime = info.endTime,
+                    //        scode = info.code,
+                    //        scope = info.scope,
+                    //        progress = "going",
+                    //        classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
+                    //        tmdids = new List<string> { "" },
+                    //        subjects = sub
+                    //    };
+                    //    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(dataa, new Azure.Cosmos.PartitionKey(dataa.code));
+                    //}
+
+                    (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
+                    List<StuActivity> stuActivities = new List<StuActivity>();
+                    List<StuActivity> tmdActivities = new List<StuActivity>();
+                    if (tmdids.IsNotEmpty())
                     {
-                        dataa = new ActivityData
-                        {
-                            id = info.id,
-                            code = $"Activity-{info.school}",
-                            type = "exam",
-                            name = info.name,
-                            startTime = info.startTime,
-                            endTime = info.endTime,
-                            scode = info.code,
-                            scope = info.scope,
-                            classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
-                            tmdids = new List<string> { "" },
-                            progress = "going",
-                            subjects = sub
-                        };
-                        await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(dataa, new Azure.Cosmos.PartitionKey(dataa.code));
+                        tmdids.ForEach(x => {
+                            tmdActivities.Add(new StuActivity
+                            {
+                                pk = "Activity",
+                                id = info.id,
+                                code = $"Activity-{x}",
+                                type = "exam",
+                                name = info.name,
+                                startTime = info.startTime,
+                                endTime = info.endTime,
+                                scode = info.code,
+                                scope = info.scope,
+                                school = info.school,
+                                creatorId = info.creatorId,
+                                subjects = sub
+
+                            });
+                        });
                     }
-                    else if (info.scope == "private")
+                    if (studentss.IsNotEmpty())
                     {
-                        dataa = new ActivityData
-                        {
-                            id = info.id,
-                            code = $"Activity-Common",
-                            type = "exam",
-                            name = info.name,
-                            startTime = info.startTime,
-                            endTime = info.endTime,
-                            scode = info.code,
-                            scope = info.scope,
-                            progress = "going",
-                            classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
-                            tmdids = new List<string> { "" },
-                            subjects = sub
-                        };
-                        await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(dataa, new Azure.Cosmos.PartitionKey(dataa.code));
+                        studentss.ForEach(x => {
+                            stuActivities.Add(new StuActivity
+                            {
+                                pk = "Activity",
+                                id = info.id,
+                                code = $"Activity-{info.school}-{x.id}",
+                                type = "exam",
+                                name = info.name,
+                                startTime = info.startTime,
+                                endTime = info.endTime,
+                                scode = info.code,
+                                scope = info.scope,
+                                school = info.school,
+                                creatorId = info.creatorId,
+                                subjects = sub
+                            });
+                        });
                     }
+                    await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
                 }
             }
             return new OkObjectResult(new { });

+ 67 - 65
TEAMModelFunction/TriggerSurvey.cs

@@ -41,19 +41,19 @@ namespace TEAMModelFunction
                 adcode = $"Activity-{tdata.creatorId}";
                  blobcntr = tdata.creatorId;
             }
-            ActivityData data = null;
-            try
-            {
-                if (tdata.scope == "school")
-                {
-                    data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                }
-                else if (tdata.scope == "private")
-                {
-                    data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                }
-            }
-            catch { data = null; }
+            //ActivityData data = null;
+            //try
+            //{
+            //    if (tdata.scope == "school")
+            //    {
+            //        data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+            //    }
+            //    else if (tdata.scope == "private")
+            //    {
+            //        data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+            //    }
+            //}
+            //catch { data = null; }
             Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
             List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", survey.progress } });
             if (survey != null) {
@@ -83,44 +83,44 @@ namespace TEAMModelFunction
                         }
                         break;
                     case "going":
-                        if (survey.scope == "school")
-                        {
-                            data = new ActivityData
-                            {
-                                id = survey.id,
-                                code = $"Activity-{survey.school}",
-                                type = "survey",
-                                name = survey.name,
-                                startTime = survey.startTime,
-                                endTime = survey.endTime,
-                                scode = survey.code,
-                                scope = survey.scope,
-                                classes = survey.classes.IsNotEmpty() ? survey.classes : new List<string> { "" },
-                                tmdids = survey.tmdids.IsNotEmpty() ? survey.tmdids : new List<string> { "" },
-                                progress = "going",
-                                subjects = new List<string> { "" }
-                            };
-                            await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                        }
-                        else if (survey.scope == "private")
-                        {
-                            data = new ActivityData
-                            {
-                                id = survey.id,
-                                code = $"Activity-Common",
-                                type = "survey",
-                                name = survey.name,
-                                startTime = survey.startTime,
-                                endTime = survey.endTime,
-                                scode = survey.code,
-                                scope = survey.scope,
-                                progress = "going",
-                                classes = survey.classes.IsNotEmpty() ? survey.classes : new List<string> { "" },
-                                tmdids = new List<string> { "" },
-                                subjects = new List<string> { "" }
-                            };
-                            await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                        }
+                        //if (survey.scope == "school")
+                        //{
+                        //    data = new ActivityData
+                        //    {
+                        //        id = survey.id,
+                        //        code = $"Activity-{survey.school}",
+                        //        type = "survey",
+                        //        name = survey.name,
+                        //        startTime = survey.startTime,
+                        //        endTime = survey.endTime,
+                        //        scode = survey.code,
+                        //        scope = survey.scope,
+                        //        classes = survey.classes.IsNotEmpty() ? survey.classes : new List<string> { "" },
+                        //        tmdids = survey.tmdids.IsNotEmpty() ? survey.tmdids : new List<string> { "" },
+                        //        progress = "going",
+                        //        subjects = new List<string> { "" }
+                        //    };
+                        //    await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
+                        //else if (survey.scope == "private")
+                        //{
+                        //    data = new ActivityData
+                        //    {
+                        //        id = survey.id,
+                        //        code = $"Activity-Common",
+                        //        type = "survey",
+                        //        name = survey.name,
+                        //        startTime = survey.startTime,
+                        //        endTime = survey.endTime,
+                        //        scode = survey.code,
+                        //        scope = survey.scope,
+                        //        progress = "going",
+                        //        classes = survey.classes.IsNotEmpty() ? survey.classes : new List<string> { "" },
+                        //        tmdids = new List<string> { "" },
+                        //        subjects = new List<string> { "" }
+                        //    };
+                        //    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
 
                         (List<string> tmdids,List<Students> students) =   await TriggerStuActivity. GetStuList(client, survey.classes, survey.school);
                         await _dingDing.SendBotMsg($"问卷调查{tdata.id}写入学生表作为活动列表!", GroupNames.成都开发測試群組);
@@ -130,7 +130,7 @@ namespace TEAMModelFunction
                             tmdids.ForEach(x=> {
                                 tmdActivities.Add(new StuActivity
                                 {
-                                    pk= "Activity",
+                                    pk = "Activity",
                                     id = survey.id,
                                     code = $"Activity-{x}",
                                     type = "survey",
@@ -139,9 +139,10 @@ namespace TEAMModelFunction
                                     endTime = survey.endTime,
                                     scode = survey.code,
                                     scope = survey.scope,
-                                    school=survey.school,
-                                    creatorId=survey.creatorId,
-                                    subjects = new List<string> { "" }
+                                    school = survey.school,
+                                    creatorId = survey.creatorId,
+                                    subjects = new List<string> { "" },
+                                    blob = survey.blob
 
                                 });
                             });
@@ -160,7 +161,8 @@ namespace TEAMModelFunction
                                     scope = survey.scope,
                                     school = survey.school,
                                     creatorId = survey.creatorId,
-                                    subjects = new List<string> { "" }
+                                    subjects = new List<string> { "" },
+                                    blob = survey.blob
                                 });
                             });
                         }
@@ -280,15 +282,15 @@ namespace TEAMModelFunction
                         }
                         
                         //更新结束状态
-                        data.progress = "finish";
-                        if (survey.scope == "school")
-                        {
-                            await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                        }
-                        else if (survey.scope == "private")
-                        {
-                            await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                        }
+                        //data.progress = "finish";
+                        //if (survey.scope == "school")
+                        //{
+                        //    await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
+                        //else if (survey.scope == "private")
+                        //{
+                        //    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
                         
                         break;
                 }

+ 63 - 63
TEAMModelFunction/TriggerVote.cs

@@ -40,22 +40,22 @@ namespace TEAMModelFunction
                 adcode = $"Activity-{tdata.creatorId}";
                 blobcntr = tdata.creatorId;
             }
-            ActivityData data = null;
-            try
-            {
-                if (tdata.scope == "school")
-                {
-                    data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                }
-                else if (tdata.scope == "private")
-                {
-                    data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                }
-            }
-            catch
-            {
-                data = null;
-            }
+           // ActivityData data = null;
+            //try
+            //{
+            //    if (tdata.scope == "school")
+            //    {
+            //        data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+            //    }
+            //    else if (tdata.scope == "private")
+            //    {
+            //        data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+            //    }
+            //}
+            //catch
+            //{
+            //    data = null;
+            //}
             await _dingDing.SendBotMsg($"投票活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
             Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
             List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", vote.progress } });
@@ -86,44 +86,44 @@ namespace TEAMModelFunction
                         }
                         break;
                     case "going":
-                        if (vote.scope == "school")
-                        {
-                            data = new ActivityData
-                            {
-                                id = vote.id,
-                                code = $"Activity-{vote.school}",
-                                type = "vote",
-                                name = vote.name,
-                                startTime = vote.startTime,
-                                endTime = vote.endTime,
-                                scode = vote.code,
-                                scope = vote.scope,
-                                classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
-                                tmdids = vote.tmdids.IsNotEmpty() ? vote.tmdids : new List<string> { "" },
-                                progress = "going",
-                                subjects = new List<string> { "" }
-                            };
-                            await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                        }
-                        else if (vote.scope == "private")
-                        {
-                            data = new ActivityData
-                            {
-                                id = vote.id,
-                                code = $"Activity-Common",
-                                type = "vote",
-                                name = vote.name,
-                                startTime = vote.startTime,
-                                endTime = vote.endTime,
-                                scode = vote.code,
-                                scope = vote.scope,
-                                progress = "going",
-                                classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
-                                tmdids = new List<string> { "" },
-                                subjects = new List<string> { "" }
-                            };
-                            await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                        }
+                        //if (vote.scope == "school")
+                        //{
+                        //    data = new ActivityData
+                        //    {
+                        //        id = vote.id,
+                        //        code = $"Activity-{vote.school}",
+                        //        type = "vote",
+                        //        name = vote.name,
+                        //        startTime = vote.startTime,
+                        //        endTime = vote.endTime,
+                        //        scode = vote.code,
+                        //        scope = vote.scope,
+                        //        classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
+                        //        tmdids = vote.tmdids.IsNotEmpty() ? vote.tmdids : new List<string> { "" },
+                        //        progress = "going",
+                        //        subjects = new List<string> { "" }
+                        //    };
+                        //    await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
+                        //else if (vote.scope == "private")
+                        //{
+                        //    data = new ActivityData
+                        //    {
+                        //        id = vote.id,
+                        //        code = $"Activity-Common",
+                        //        type = "vote",
+                        //        name = vote.name,
+                        //        startTime = vote.startTime,
+                        //        endTime = vote.endTime,
+                        //        scode = vote.code,
+                        //        scope = vote.scope,
+                        //        progress = "going",
+                        //        classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
+                        //        tmdids = new List<string> { "" },
+                        //        subjects = new List<string> { "" }
+                        //    };
+                        //    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
 
                         (List<string> tmdids, List<Students> students) = await TriggerStuActivity.GetStuList(client, vote.classes, vote.school);
                         List<string> tmds = vote.tmdids.IsNotEmpty() ? vote.tmdids : new List<string>() ;
@@ -241,16 +241,16 @@ namespace TEAMModelFunction
                             break; 
                         }
                         await Task.WhenAll(tasks);
-                        data.progress = "finish";
+                        //data.progress = "finish";
                         //更新结束状态
-                        if (vote.scope == "school")
-                        {
-                            await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                        }
-                        else if (vote.scope == "private")
-                        {
-                            await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                        }
+                        //if (vote.scope == "school")
+                        //{
+                        //    await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
+                        //else if (vote.scope == "private")
+                        //{
+                        //    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
+                        //}
                         //_azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
                         //_azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
                         break;