Browse Source

删除逻辑

CrazyIter_Bin 4 years ago
parent
commit
af7a835924

+ 42 - 9
TEAMModelFunction/MonitorCosmosDB.cs

@@ -16,15 +16,13 @@ namespace TEAMModelFunction
 {
     public class MonitorCosmosDB
     {
-        private readonly IHttpClientFactory _clientFactory;
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly AzureServiceBusFactory _serviceBus;
         private readonly AzureStorageFactory _azureStorage;
         private readonly DingDing _dingDing;
         private readonly AzureRedisFactory _azureRedis;
-        public MonitorCosmosDB(IHttpClientFactory clientFactory, AzureCosmosFactory azureCosmos, AzureServiceBusFactory azureServiceBus, AzureStorageFactory azureStorage, DingDing dingDing, AzureRedisFactory azureRedis)
+        public MonitorCosmosDB( AzureCosmosFactory azureCosmos, AzureServiceBusFactory azureServiceBus, AzureStorageFactory azureStorage, DingDing dingDing, AzureRedisFactory azureRedis)
         {
-            _clientFactory = clientFactory;
             _azureCosmos = azureCosmos;
             _serviceBus = azureServiceBus;
             _azureStorage = azureStorage;
@@ -32,6 +30,13 @@ namespace TEAMModelFunction
             _azureRedis = azureRedis;
         }
 
+        //[FunctionName("Common")]
+        //public async Task Common([HttpTrigger(
+        //    databaseName: "TEAMModelOS",
+        //    collectionName: "Common",
+        //    ConnectionStringSetting = "Azure:Cosmos:ConnectionString",
+        //    LeaseCollectionName = "leases")]IReadOnlyList<Document> inputs, ILogger log)
+
         [FunctionName("Common")]
         public async Task Common([CosmosDBTrigger(
             databaseName: "TEAMModelOS",
@@ -50,13 +55,29 @@ namespace TEAMModelFunction
                     string pk = input.GetPropertyValue<string>("pk");
                     if (!string.IsNullOrWhiteSpace(pk))
                     {
+                        int ttl = input.GetPropertyValue<int>("ttl");
                         long stime = input.GetPropertyValue<long>("startTime");
                         long etime = input.GetPropertyValue<long>("endTime");
                         string school = input.GetPropertyValue<string>("school");
                         string code = input.GetPropertyValue<string>("code");
-                        await _dingDing.SendBotMsg($"CosmosDBTrigger,{pk}\n" +
-                                        $"Start Time:{DateTimeOffset.FromUnixTimeMilliseconds(stime).AddHours(8)}\n" +
-                                        $"End Time:{DateTimeOffset.FromUnixTimeMilliseconds(etime).AddHours(8)}",
+                        string owner = input.GetPropertyValue<string>("owner");
+                        string progress = input.GetPropertyValue<string>("progress");
+                        string scope = input.GetPropertyValue<string>("scope");
+                        string name = input.GetPropertyValue<string>("name");
+                        int? status = input.GetPropertyValue<int?>("status");
+                        var data = new TriggerData {
+                            stime = stime,
+                            etime = etime,
+                            school = school,
+                            code = code,
+                            owner = owner,
+                            progress = progress,
+                            scope = scope,
+                            ttl = ttl,
+                            id = input.Id,
+                            status = status
+                        };
+                        await _dingDing.SendBotMsg($"CosmosDBTrigger,{pk}触发变更\n{data.ToJsonString()}"  ,
                                         GroupNames.成都开发測試群組);
                         switch (pk)
                         {
@@ -64,10 +85,10 @@ namespace TEAMModelFunction
                                 TriggerExam.Trigger(_azureCosmos, _serviceBus, _azureStorage, _dingDing, client,input,code,stime,etime,school);
                                 break;
                             case "Vote":
-                                TriggerVote.Trigger(_azureCosmos, _serviceBus, _azureStorage, _dingDing, client, input, code, stime, etime, school, _azureRedis);
+                                TriggerVote.Trigger( _serviceBus, _azureStorage, _dingDing, client, input, data, _azureRedis);
                                 break;
                             case "Survey":
-                                TriggerSurvey.Trigger(_azureCosmos, _serviceBus, _azureStorage, _dingDing, client, input, code, stime, etime, school, _azureRedis, _clientFactory);
+                                TriggerSurvey.Trigger( _serviceBus, _azureStorage, _dingDing, client, input, data, _azureRedis);
                                 break;
 
                         }
@@ -75,6 +96,18 @@ namespace TEAMModelFunction
                 }
             }
         }
-        
+    }
+    public class TriggerData {
+        public int? status { get; set; }
+        public string name { get; set; }
+        public long stime { get; set; }
+        public long etime { get; set; }
+        public string school { get; set; }
+        public string code { get; set; }
+        public string owner { get; set; }
+        public string progress { get; set; }
+        public string scope { get; set; }
+        public int ttl { get; set; }
+        public string id { get; set; }
     }
 }

+ 173 - 199
TEAMModelFunction/TriggerSurvey.cs

@@ -21,235 +21,209 @@ namespace TEAMModelFunction
 {
    public class TriggerSurvey
     {
-        public static async void Trigger(AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
-               CosmosClient client, Document input, string code, long stime, long etime, string school,AzureRedisFactory _azureRedis, System.Net.Http.IHttpClientFactory _clientFactory)
+        public static async void Trigger( AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+               CosmosClient client, Document input, TriggerData tdata,AzureRedisFactory _azureRedis)
         {
-            Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
+            if ((tdata.status != null && tdata.status.Value == 404) || tdata.ttl > 0)
+            {
+                return;
+            }
+            var adid = tdata.id;
+            var adcode = $"Activity-{tdata.owner}";
+            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 } });
-            ActivityData data = null ;
             if (survey != null) {
-                var adid = survey.id;
-                var adcode = $"Activity-{survey.owner}";
-                try {
-                    if (survey.scope == "school")
-                    {
-                        data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                    }
-                    else if (survey.scope == "private")
-                    {
-                        data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                    }
-                } catch { data = null; }
-                await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}-ttl={survey.ttl}】正在操作", GroupNames.成都开发測試群組);
-                if (survey.ttl >= 1)
+                switch (survey.progress)
                 {
-                  
-                    _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
-                    _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
-                    if (data != null)
-                    {
-                        
-                        if (survey.scope == "school")
+                    case "pending":
+                        var messageSurvey = new ServiceBusMessage(new { id = input.Id, progress = "going", code = tdata.code }.ToJsonString());
+                        messageSurvey.ApplicationProperties.Add("name", "Survey");
+                        if (changeRecords.Count > 0)
                         {
-                            data = await client.GetContainer("TEAMModelOS", "School").DeleteItemAsync<ActivityData>(  adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
+                            await _serviceBus.GetServiceBusClient().cancelMessage("active-task", changeRecords[0].sequenceNumber);
+                            long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
+                            changeRecords[0].sequenceNumber = start;
+                            await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                         }
-                        else if (survey.scope == "private")
+                        else
                         {
-                            data = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<ActivityData>( adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
-                        }
-                    }
-                    await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.成都开发測試群組);
-                    return;
-                }
-                else {
-                    switch (survey.progress)
-                    {
-                        case "pending":
-                            var messageSurvey = new ServiceBusMessage(new { id = input.Id, progress = "going", code = code }.ToJsonString());
-                            messageSurvey.ApplicationProperties.Add("name", "Survey");
-                            if (changeRecords.Count > 0)
-                            {
-                                await _serviceBus.GetServiceBusClient().cancelMessage("active-task", changeRecords[0].sequenceNumber);
-                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(stime));
-                                changeRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
-                            }
-                            else
+                            long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
+                            ChangeRecord changeRecord = new ChangeRecord
                             {
-                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(stime));
-                                ChangeRecord changeRecord = new ChangeRecord
-                                {
-                                    RowKey = input.Id,
-                                    PartitionKey = "pending",
-                                    sequenceNumber = start,
-                                    msgId = messageSurvey.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
-                            }
-                            break;
-                        case "going":
-
-                            if (survey.scope == "school")
+                                RowKey = input.Id,
+                                PartitionKey = "pending",
+                                sequenceNumber = start,
+                                msgId = messageSurvey.MessageId
+                            };
+                            await _azureStorage.Save<ChangeRecord>(changeRecord);
+                        }
+                        break;
+                    case "going":
+                        if (survey.scope == "school")
+                        {
+                            data = new ActivityData
                             {
-                                data = new ActivityData
-                                {
-                                    id = survey.id,
-                                    code = $"Activity-{survey.owner}",
-                                    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",
-                                    owner = survey.owner,
-                                    subjects = new List<string> { "" }
-                                };
-                                await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                            }
-                            else if (survey.scope == "private")
+                                id = survey.id,
+                                code = $"Activity-{survey.owner}",
+                                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",
+                                owner = survey.owner,
+                                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
                             {
-                                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> { "" },
-                                    owner = survey.owner,
-                                    tmdids = new List<string> { "" },
-                                    subjects = new List<string> { "" }
-                                };
-                                await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                            }
-                            var messageSurveyEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = code }.ToJsonString());
-                            messageSurveyEnd.ApplicationProperties.Add("name", "Survey");
-                            if (changeRecords.Count > 0)
+                                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> { "" },
+                                owner = survey.owner,
+                                tmdids = new List<string> { "" },
+                                subjects = new List<string> { "" }
+                            };
+                            await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        }
+                        var messageSurveyEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = tdata.code }.ToJsonString());
+                        messageSurveyEnd.ApplicationProperties.Add("name", "Survey");
+                        if (changeRecords.Count > 0)
+                        {
+                            long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurveyEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
+                            await _serviceBus.GetServiceBusClient().cancelMessage("active-task", changeRecords[0].sequenceNumber);
+                            changeRecords[0].sequenceNumber = end;
+                            await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                        }
+                        else
+                        {
+                            long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurveyEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
+                            ChangeRecord changeRecord = new ChangeRecord
                             {
-                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurveyEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
-                                await _serviceBus.GetServiceBusClient().cancelMessage("active-task", changeRecords[0].sequenceNumber);
-                                changeRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
-                            }
-                            else
+                                RowKey = input.Id,
+                                PartitionKey = "going",
+                                sequenceNumber = end,
+                                msgId = messageSurveyEnd.MessageId
+                            };
+                            await _azureStorage.Save<ChangeRecord>(changeRecord);
+                        }
+                        break;
+                    case "finish":
+                        var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{survey.id}");
+                        List<dynamic> recs = new List<dynamic>();
+                        foreach (var rcd in records)
+                        {
+                            var value = rcd.Value.ToString().ToObject<JsonElement>();
+                            recs.Add(new { index = rcd.Name.ToString(), ans = value });
+                        }
+                        var cods = new { records = recs };
+                        //问卷整体情况
+                        await _azureStorage.UploadFileByContainer(survey.owner, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
+                        //结算每道题的答题情况
+                        var ContainerClient =  _azureStorage.GetBlobContainerClient(survey.owner);
+                           
+                        //获取
+                        try {
+                            List<string> items = await ContainerClient.List($"survey/{survey.id}/urecord");
+                            List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
+                            foreach (string item in items)
                             {
-                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurveyEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
-                                ChangeRecord changeRecord = new ChangeRecord
-                                {
-                                    RowKey = input.Id,
-                                    PartitionKey = "going",
-                                    sequenceNumber = end,
-                                    msgId = messageSurveyEnd.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                var Download = await _azureStorage.GetBlobContainerClient(survey.owner).GetBlobClient(item).DownloadAsync();
+                                var json = await JsonDocument.ParseAsync(Download.Value.Content);
+                                var Record = json.RootElement.ToObject<SurveyRecord>();
+                                surveyRecords.Add(Record);
                             }
-                            break;
-                        case "finish":
-                            var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{survey.id}");
-                            List<dynamic> recs = new List<dynamic>();
-                            foreach (var rcd in records)
+                            await _dingDing.SendBotMsg($"问卷调查问题结算数据{surveyRecords.ToJsonString()}", GroupNames.成都开发測試群組);
+                            for (int index = 0; index < survey.ans.Count; index++)
                             {
-                                var value = rcd.Value.ToString().ToObject<JsonElement>();
-                                recs.Add(new { index = rcd.Name.ToString(), ans = value });
-                            }
-                            var cods = new { records = recs };
-                            //问卷整体情况
-                            await _azureStorage.UploadFileByContainer(survey.owner, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
-                            //结算每道题的答题情况
-
-                            var ContainerClient =  _azureStorage.GetBlobContainerClient(survey.owner);
-                           
-                            //获取
-                            try {
-                                List<string> items = await ContainerClient.List($"survey/{survey.id}/urecord");
-                                List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
-                                foreach (string item in items)
-                                {
-                                    var Download = await _azureStorage.GetBlobContainerClient(survey.owner).GetBlobClient(item).DownloadAsync();
-                                    var json = await JsonDocument.ParseAsync(Download.Value.Content);
-                                    var Record = json.RootElement.ToObject<SurveyRecord>();
-                                    surveyRecords.Add(Record);
-                                }
-                                await _dingDing.SendBotMsg($"问卷调查问题结算数据{surveyRecords.ToJsonString()}", GroupNames.成都开发測試群組);
-                                for (int index = 0; index < survey.ans.Count; index++)
+                                string url = $"{survey.id}/qrecord/{index}.json";
+                                QuestionRecord question = new QuestionRecord() { index = index };
+                                foreach (SurveyRecord record in surveyRecords)
                                 {
-                                    string url = $"{survey.id}/qrecord/{index}.json";
-                                    QuestionRecord question = new QuestionRecord() { index = index };
-                                    foreach (SurveyRecord record in surveyRecords)
+                                    if (record.ans.Count == survey.ans.Count)
                                     {
-                                        if (record.ans.Count == survey.ans.Count)
+                                        foreach (var an in record.ans[index])
                                         {
-                                            foreach (var an in record.ans[index])
+                                            //
+                                            if (question.opt.ContainsKey(an))
                                             {
-                                                //
-                                                if (question.opt.ContainsKey(an))
+                                                if (question.opt[an] != null)
                                                 {
-                                                    if (question.opt[an] != null)
-                                                    {
-                                                        question.opt[an].Add(record.userid);
-                                                    }
-                                                    else
-                                                    {
-                                                        question.opt[an] = new HashSet<string>() { record.userid };
-                                                    }
+                                                    question.opt[an].Add(record.userid);
                                                 }
                                                 else
                                                 {
-                                                    if (survey.ans[index].Contains(an))
-                                                    {
-                                                        //如果是客观题code
-                                                        question.opt.Add(an, new HashSet<string> { record.userid });
-                                                    }
-                                                    else
-                                                    {
-                                                        //如果不是客观code
-                                                        question.other[record.userid] = an;
-                                                    }
+                                                    question.opt[an] = new HashSet<string>() { record.userid };
+                                                }
+                                            }
+                                            else
+                                            {
+                                                if (survey.ans[index].Contains(an))
+                                                {
+                                                    //如果是客观题code
+                                                    question.opt.Add(an, new HashSet<string> { record.userid });
+                                                }
+                                                else
+                                                {
+                                                    //如果不是客观code
+                                                    question.other[record.userid] = an;
                                                 }
                                             }
                                         }
                                     }
-                                    await _azureStorage.UploadFileByContainer(survey.owner, question.ToJsonString(), "survey", url);
                                 }
-                            } catch (Exception ex) {
-                                await _dingDing.SendBotMsg($"问卷调查问题结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
-                            }
-                            if (string.IsNullOrEmpty(survey.recordUrl))
-                            {
-                                survey.recordUrl = $"/survey/{survey.id}/record.json";
-                                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new Azure.Cosmos.PartitionKey(survey.code));
-                            }
-                            else
-                            {
-                                //异动,且已经有结算记录则不必再继续。
-                                //break;
-                            }
-                            // await Task.WhenAll(tasks);
-                            //更新结束状态
-                            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));
+                                await _azureStorage.UploadFileByContainer(survey.owner, question.ToJsonString(), "survey", url);
                             }
-                            _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
-                            _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
-                            break;
-                    }
+                        } catch (Exception ex) {
+                            await _dingDing.SendBotMsg($"问卷调查问题结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                        }
+                        if (string.IsNullOrEmpty(survey.recordUrl))
+                        {
+                            survey.recordUrl = $"/survey/{survey.id}/record.json";
+                            await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new Azure.Cosmos.PartitionKey(survey.code));
+                        }
+                        // await Task.WhenAll(tasks);
+                        //更新结束状态
+                        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));
+                        }
+                        _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
+                        _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
+                        break;
                 }
-               
             }
-            
         }
     }
     /**

+ 157 - 172
TEAMModelFunction/TriggerVote.cs

@@ -19,192 +19,177 @@ namespace TEAMModelFunction
     public static class TriggerVote
     {
 
-        public static async void Trigger(AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
-            CosmosClient client, Document input, string code, long stime, long etime, string school, AzureRedisFactory _azureRedis)
+        public static async void Trigger(AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+            CosmosClient client, Document input, TriggerData tdata, AzureRedisFactory _azureRedis)
         {
-            Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
+            if ((tdata.status != null && tdata.status.Value == 404)||tdata.ttl>0)
+            {
+                return;
+            }
+            var adid = tdata.id;
+            var adcode = $"Activity-{tdata.owner}";
+            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 } });
-            ActivityData data=null;
             if (vote != null) {
-                var adid = vote.id;
-                var adcode =   $"Activity-{vote.owner}";
-                try {
-                    if (vote.scope == "school")
-                    {
-                        data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                    }
-                    else if (vote.scope == "private")
-                    {
-                        data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                    }
-                } catch {
-                    data = null;
-                }
-                await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
-                if (vote.ttl >= 1)
+                switch (vote.progress)
                 {
-                    //TODO  处理TTL删除业务
-                    _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
-                    _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
-                    if (data != null) {
-                        data.ttl = 1;
-                        if (vote.scope == "school")
+                    case "pending":
+                        var messageVote = new ServiceBusMessage(new { id = input.Id, progress = "going", code = tdata.code }.ToJsonString());
+                        messageVote.ApplicationProperties.Add("name", "Vote");
+                        if (voteRecords.Count > 0)
                         {
-                            data = await client.GetContainer("TEAMModelOS", "School").DeleteItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
+                            long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
+                            await _serviceBus.GetServiceBusClient().cancelMessage("active-task", voteRecords[0].sequenceNumber);
+                            voteRecords[0].sequenceNumber = start;
+                            await _azureStorage.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
                         }
-                        else if (vote.scope == "private")
+                        else
                         {
-                            data = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
-                        }
-                    }
-                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
-                    return;
-                }
-                else
-                {
-                    switch (vote.progress)
-                    {
-                        case "pending":
-                            var messageVote = new ServiceBusMessage(new { id = input.Id, progress = "going", code = code }.ToJsonString());
-                            messageVote.ApplicationProperties.Add("name", "Vote");
-                            if (voteRecords.Count > 0)
-                            {
-                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(stime));
-                                await _serviceBus.GetServiceBusClient().cancelMessage("active-task", voteRecords[0].sequenceNumber);
-                                voteRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
-                            }
-                            else
+                            long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
+                            ChangeRecord changeRecord = new ChangeRecord
                             {
-                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(stime));
-                                ChangeRecord changeRecord = new ChangeRecord
-                                {
-                                    RowKey = input.Id,
-                                    PartitionKey = "pending",
-                                    sequenceNumber = start,
-                                    msgId = messageVote.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
-                            }
-                            break;
-                        case "going":
-                            if (vote.scope == "school")
-                            {
-                                data = new ActivityData
-                                {
-                                    id = vote.id,
-                                    code = $"Activity-{vote.owner}",
-                                    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",
-                                    owner = vote.owner,
-                                    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> { "" },
-                                    owner = vote.owner,
-                                    tmdids = new List<string> { "" },
-                                    subjects = new List<string> { "" }
-                                };
-                                await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
-                            }
-                            var messageVoteEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = code }.ToJsonString());
-                            messageVoteEnd.ApplicationProperties.Add("name", "Vote");
-                            if (voteRecords.Count > 0)
-                            {
-                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
-                                await _serviceBus.GetServiceBusClient().cancelMessage("active-task", voteRecords[0].sequenceNumber);
-                                voteRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
-                            }
-                            else
+                                RowKey = input.Id,
+                                PartitionKey = "pending",
+                                sequenceNumber = start,
+                                msgId = messageVote.MessageId
+                            };
+                            await _azureStorage.Save<ChangeRecord>(changeRecord);
+                        }
+                        break;
+                    case "going":
+                        if (vote.scope == "school")
+                        {
+                            data = new ActivityData
                             {
-                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
-                                ChangeRecord changeRecord = new ChangeRecord
-                                {
-                                    RowKey = input.Id,
-                                    PartitionKey = "going",
-                                    sequenceNumber = end,
-                                    msgId = messageVoteEnd.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
-                            }
-                            break;
-                        case "finish":
-                            //获取投票活动的所有投票记录
-                            var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{vote.id}");
-                            //获取投票活动的选项及投票数
-                            var counts = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Vote:Count:{vote.id}");
-                            List<dynamic> countcds = new List<dynamic>();
-                            if (counts != null && counts.Length > 0)
+                                id = vote.id,
+                                code = $"Activity-{vote.owner}",
+                                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",
+                                owner = vote.owner,
+                                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
                             {
-                                foreach (var count in counts)
-                                {
-                                    countcds.Add(new { code = count.Element.ToString(), count = (int)count.Score });
-                                }
-                            }
-                            List<Task<string>> tasks = new List<Task<string>>();
-                            List<VoteRecord> recordsBlob = new List<VoteRecord>();
-                            foreach (var rcd in records)
+                                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> { "" },
+                                owner = vote.owner,
+                                tmdids = new List<string> { "" },
+                                subjects = new List<string> { "" }
+                            };
+                            await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        }
+                        var messageVoteEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = tdata.code }.ToJsonString());
+                        messageVoteEnd.ApplicationProperties.Add("name", "Vote");
+                        if (voteRecords.Count > 0)
+                        {
+                            long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
+                            await _serviceBus.GetServiceBusClient().cancelMessage("active-task", voteRecords[0].sequenceNumber);
+                            voteRecords[0].sequenceNumber = end;
+                            await _azureStorage.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
+                        }
+                        else
+                        {
+                            long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
+                            ChangeRecord changeRecord = new ChangeRecord
                             {
-                                var value = rcd.Value.ToString().ToObject<VoteRecord>();
-                                recordsBlob.Add(value);
-                            }
-                            //分组每个人的 
-                            var gp = recordsBlob.GroupBy(x => x.userid).Select(x => new { key = x.Key, list = x.ToList() });
-                            foreach (var g in gp)
+                                RowKey = input.Id,
+                                PartitionKey = "going",
+                                sequenceNumber = end,
+                                msgId = messageVoteEnd.MessageId
+                            };
+                            await _azureStorage.Save<ChangeRecord>(changeRecord);
+                        }
+                        break;
+                    case "finish":
+                        //获取投票活动的所有投票记录
+                        var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{vote.id}");
+                        //获取投票活动的选项及投票数
+                        var counts = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Vote:Count:{vote.id}");
+                        List<dynamic> countcds = new List<dynamic>();
+                        if (counts != null && counts.Length > 0)
+                        {
+                            foreach (var count in counts)
                             {
-                                tasks.Add(_azureStorage.UploadFileByContainer(vote.owner, g.list.ToJsonString(), "vote", $"{vote.id}/urecord/{g.key}.json"));
+                                countcds.Add(new { code = count.Element.ToString(), count = (int)count.Score });
                             }
-                            //处理活动方的记录, 
-                            string url = $"/vote/{vote.id}/record.json";
-                            tasks.Add(_azureStorage.UploadFileByContainer(vote.owner, new { options = countcds, records = recordsBlob }.ToJsonString(), "vote", $"{vote.id}/record.json"));
-                            //处理投票者的记录
+                        }
+                        List<Task<string>> tasks = new List<Task<string>>();
+                        List<VoteRecord> recordsBlob = new List<VoteRecord>();
+                        foreach (var rcd in records)
+                        {
+                            var value = rcd.Value.ToString().ToObject<VoteRecord>();
+                            recordsBlob.Add(value);
+                        }
+                        //分组每个人的 
+                        var gp = recordsBlob.GroupBy(x => x.userid).Select(x => new { key = x.Key, list = x.ToList() });
+                        foreach (var g in gp)
+                        {
+                            tasks.Add(_azureStorage.UploadFileByContainer(vote.owner, g.list.ToJsonString(), "vote", $"{vote.id}/urecord/{g.key}.json"));
+                        }
+                        //处理活动方的记录, 
+                        string url = $"/vote/{vote.id}/record.json";
+                        tasks.Add(_azureStorage.UploadFileByContainer(vote.owner, new { options = countcds, records = recordsBlob }.ToJsonString(), "vote", $"{vote.id}/record.json"));
+                        //处理投票者的记录
 
-                            if (string.IsNullOrEmpty(vote.recordUrl))
-                            {
-                                vote.recordUrl = url;
-                                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
-                            }
-                            else { 
-                                //异动,且已经有结算记录则不必再继续。
-                                //break; 
-                            }
-                            await Task.WhenAll(tasks);
-                            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));
-                            }
-                            _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
-                            _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
-                            break;
-                    }
+                        if (string.IsNullOrEmpty(vote.recordUrl))
+                        {
+                            vote.recordUrl = url;
+                            await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
+                        }
+                        else { 
+                            //异动,且已经有结算记录则不必再继续。
+                            //break; 
+                        }
+                        await Task.WhenAll(tasks);
+                        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));
+                        }
+                        _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
+                        _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
+                        break;
                 }
             }
            

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

@@ -76,7 +76,10 @@ namespace TEAMModelOS.SDK.Models
         /// 客观题所有选项[["A","B","C","D"],["A","B"],[],["A","B"]]
         /// </summary>
         public List<List<string>> ans { get; set; }
-
+        /// <summary>
+        /// TTL删除改变状态使用
+        /// </summary>
+        public int? status { get; set; } = 0;
     }
 
     /// <summary>

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

@@ -74,10 +74,7 @@ namespace TEAMModelOS.SDK.Models
         ///  scope 为school时 是学校的班级  为private 时是私人班级
         /// </summary>
         public List<string> classes { get; set; }
-        /// <summary>
-        /// (100:待发布 200:已发布 300:已结束)
-        /// </summary>
-        public int status { get; set; }
+        
         /// <summary>
         /// 开始时间
         /// </summary>
@@ -98,6 +95,10 @@ namespace TEAMModelOS.SDK.Models
         /// 投票记录
         /// </summary>
         public string recordUrl { get; set; }
+        /// <summary>
+        /// TTL删除改变状态使用
+        /// </summary>
+        public int? status { get; set; } = 0;
     }
     /// <summary>
     /// 投票选项

+ 5 - 1
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -57,7 +57,7 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         public string publish { get; set; }
 
-        public int status { get; set; }
+       
         public int year { get; set; }
         public string range { get; set; }
         public string source { get; set; }
@@ -79,6 +79,10 @@ namespace TEAMModelOS.SDK.Models
         /// 所有试卷阅卷状态
         /// </summary>
         //public List<int> marks { get; set; }
+        /// <summary>
+        /// TTL删除改变状态使用
+        /// </summary>
+        public int? status { get; set; } = 0;
     }
     public class Custom {
         public string id { get; set; }

+ 31 - 1
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -298,8 +298,38 @@ namespace TEAMModelOS.Controllers
                 if (flag)
                 {
                     //使用ttl删除,并处理相关事务逻辑
-                    survey.ttl = 5;
+                    survey.ttl = 1;
+                    survey.status = 404;
                     survey = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
+                    var adid = survey.id;
+                    var adcode = $"Activity-{survey.owner}";
+                    ActivityData data = null;
+                    try
+                    {
+                        if (survey.scope == "school")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+                        }
+                        else if (survey.scope == "private")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+                        }
+                    }
+                    catch { data = null; }
+                    _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
+                    _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
+                    if (data != null)
+                    {
+                        if (survey.scope == "school")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "School").DeleteItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
+                        }
+                        else if (survey.scope == "private")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
+                        }
+                    }
+                    await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.成都开发測試群組);
                     return Ok(new { flag });
                 }
                 else

+ 36 - 3
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -298,15 +298,48 @@ namespace TEAMModelOS.Controllers.Learn
                 if (flag)
                 {
                     //使用ttl删除,并处理相关事务逻辑
-                    vote.ttl = 5;
+                    vote.ttl = 1;
+                    vote.status = 404;
                     vote = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(vote,  new PartitionKey($"{vote.code}"));
+                    var adid = vote.id;
+                    var adcode = $"Activity-{vote.owner}";
+                    ActivityData data = null;
+                    try
+                    {
+                        if (vote.scope == "school")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+                        }
+                        else if (vote.scope == "private")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
+                        }
+                    }
+                    catch
+                    {
+                        data = null;
+                    }
+                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
+                    _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
+                    _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
+                    if (data != null)
+                    {
+                        data.ttl = 1;
+                        if (vote.scope == "school")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "School").DeleteItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
+                        }
+                        else if (vote.scope == "private")
+                        {
+                            data = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
+                        }
+                    }
+                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
                     return Ok(new { flag });
                 }
                 else {
                     return Ok(new { flag });
                 }
-                //var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
-                //   return Ok(new { code = response.Status });
             }
             catch (Exception e)
             {