CrazyIter_Bin 4 anos atrás
pai
commit
48bfe71a62

+ 49 - 42
TEAMModelFunction/TriggerSurvey.cs

@@ -39,7 +39,7 @@ namespace TEAMModelFunction
                         data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
                     }
                 } catch { data = null; }
-                await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}---{survey.ttl}】正在操作", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}-ttl={survey.ttl}】正在操作", GroupNames.成都开发測試群組);
                 if (survey.ttl >= 1)
                 {
                   
@@ -163,61 +163,66 @@ namespace TEAMModelFunction
                             await _azureStorage.UploadFileByContainer(survey.owner, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
                             //结算每道题的答题情况
 
-                            var ContainerClient = _azureStorage.GetBlobContainerClient(survey.owner);
+                            var ContainerClient =  _azureStorage.GetBlobContainerClient(survey.owner);
                             var route = ContainerClient.Uri.ToString();
-                            List<BlobItem> items = await ContainerClient.List($"survey/{survey.id}/urecord");
-                            List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
+                           
                             //获取
 
-                            foreach (BlobItem item in items)
-                            {
-                                BlobAuth blobAuth = _azureStorage.GetBlobSasUriRead(survey.owner, $"{item.Name}");
-                                var url = $"{route}/{item.Name}?{blobAuth.sas}";
-                                var response = await _clientFactory.CreateClient().GetAsync(new Uri(url));
-                                var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
-                                var Record = json.RootElement.ToObject<SurveyRecord>();
-                                surveyRecords.Add(Record);
-                            }
-                            List<Task<string>> tasks = new List<Task<string>>();
-                            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)
+                            try {
+                                List<BlobItem> items = await ContainerClient.List($"survey/{survey.id}/urecord");
+                                List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
+                                foreach (BlobItem item in items)
                                 {
-                                    if (record.ans.Count == survey.ans.Count)
+                                    BlobAuth blobAuth = _azureStorage.GetBlobSasUriRead(survey.owner, $"{item.Name}");
+                                    var url = $"{route}/{item.Name}?{blobAuth.sas}";
+                                    var response = await _clientFactory.CreateClient().GetAsync(new Uri(url));
+                                    var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
+                                    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)
                                     {
-                                        foreach (var an in record.ans[index])
+                                        if (record.ans.Count == survey.ans.Count)
                                         {
-                                            //
-                                            if (question.opt.ContainsKey(an))
-                                            {
-                                                if (question.opt[an] != null)
-                                                {
-                                                    question.opt[an].Add(record.userid);
-                                                }
-                                                else
-                                                {
-                                                    question.opt[an] = new HashSet<string>() { record.userid };
-                                                }
-                                            }
-                                            else
+                                            foreach (var an in record.ans[index])
                                             {
-                                                if (survey.ans[index].Contains(an))
+                                                //
+                                                if (question.opt.ContainsKey(an))
                                                 {
-                                                    //如果是客观题code
-                                                    question.opt.Add(an, new HashSet<string> { record.userid });
+                                                    if (question.opt[an] != null)
+                                                    {
+                                                        question.opt[an].Add(record.userid);
+                                                    }
+                                                    else
+                                                    {
+                                                        question.opt[an] = new HashSet<string>() { record.userid };
+                                                    }
                                                 }
                                                 else
                                                 {
-                                                    //如果不是客观code
-                                                    question.other[record.userid] = an;
+                                                    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);
                                 }
-                                tasks.Add(_azureStorage.UploadFileByContainer(survey.owner, question.ToJsonString(), "survey", url, false));
+                            } catch (Exception ex) {
+                                await _dingDing.SendBotMsg($"问卷调查问题结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                             }
                             if (string.IsNullOrEmpty(survey.recordUrl))
                             {
@@ -227,9 +232,9 @@ namespace TEAMModelFunction
                             else
                             {
                                 //异动,且已经有结算记录则不必再继续。
-                                break;
+                                //break;
                             }
-                            await Task.WhenAll(tasks);
+                            // await Task.WhenAll(tasks);
                             //更新结束状态
                             data.progress = "finish";
                             if (survey.scope == "school")
@@ -240,6 +245,8 @@ namespace TEAMModelFunction
                             {
                                 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;
                     }
                 }

+ 5 - 2
TEAMModelFunction/TriggerVote.cs

@@ -40,6 +40,7 @@ namespace TEAMModelFunction
                 } catch {
                     data = null;
                 }
+                await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
                 if (vote.ttl >= 1)
                 {
                     //TODO  处理TTL删除业务
@@ -56,7 +57,7 @@ namespace TEAMModelFunction
                             data = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data,adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
                         }
                     }
-                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}】被删除", GroupNames.醍摩豆服務運維群組);
+                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
                     return;
                 }
                 else
@@ -187,7 +188,7 @@ namespace TEAMModelFunction
                             }
                             else { 
                                 //异动,且已经有结算记录则不必再继续。
-                                break; 
+                                //break; 
                             }
                             await Task.WhenAll(tasks);
                             data.progress = "finish";
@@ -200,6 +201,8 @@ namespace TEAMModelFunction
                             {
                                 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;
                     }
                 }

+ 2 - 3
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -297,7 +297,7 @@ namespace TEAMModelOS.Controllers
                 if (flag)
                 {
                     //使用ttl删除,并处理相关事务逻辑
-                    survey.ttl = 2;
+                    survey.ttl = 5;
                     survey = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
                     return Ok(new { flag });
                 }
@@ -478,7 +478,6 @@ namespace TEAMModelOS.Controllers
                 //活动分区
                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.GetString(), new PartitionKey($"{code}"));
-                survey.ttl = 1;
                 List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", $"{id}" }, { "PartitionKey", survey.progress } });
                 ActivityData data = null;
                 if (survey != null)
@@ -598,7 +597,7 @@ namespace TEAMModelOS.Controllers
                                 else
                                 {
                                     //异动,且已经有结算记录则不必再继续。
-                                    break;
+                                   // break;
                                 }
                                 await Task.WhenAll(tasks);
                                 //更新结束状态

+ 2 - 2
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -296,9 +296,9 @@ namespace TEAMModelOS.Controllers.Learn
                     }
                 }
                 if (flag)
-                { 
+                {
                     //使用ttl删除,并处理相关事务逻辑
-                    vote.ttl = 10;
+                    vote.ttl = 5;
                     vote = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(vote,  new PartitionKey($"{vote.code}"));
                     return Ok(new { flag });
                 }

+ 5 - 2
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -285,6 +285,9 @@ namespace TEAMModelOS.Services.Common
             } 
             //是否需要进行分页查询,默认不分页
             bool iscontinuation = false;
+            if (topcout != null && topcout.Value > 0) {
+                iscontinuation = true;
+            }
             //如果指定了返回大小
             if (requert.TryGetProperty("continuationTokenSchool", out JsonElement continuationSchool))
             {
@@ -292,7 +295,7 @@ namespace TEAMModelOS.Services.Common
                 if (!continuationSchool.ValueKind.Equals(JsonValueKind.Null) && continuationSchool.ValueKind.Equals(JsonValueKind.String))
                 {
                     continuationTokenSchool = continuationSchool.GetString();
-                    iscontinuation = true;
+                    
                 }
             }
             //如果指定了返回大小
@@ -302,7 +305,7 @@ namespace TEAMModelOS.Services.Common
                 if (!continuationTeacher.ValueKind.Equals(JsonValueKind.Null) && continuationTeacher.ValueKind.Equals(JsonValueKind.String))
                 {
                     continuationTokenTeacher = continuationTeacher.GetString();
-                    iscontinuation = true;
+                    
                 }
             }
             //个人tmdid

+ 5 - 1
TEAMModelOS/Services/Common/ActivityTeacherService.cs

@@ -86,6 +86,10 @@ namespace TEAMModelOS.Services.Common
             }
             //是否需要进行分页查询,默认不分页
             bool iscontinuation = false;
+            if (topcout != null && topcout.Value > 0)
+            {
+                iscontinuation = true;
+            }
             //如果指定了返回大小
             if (!requert.TryGetProperty("continuationToken", out JsonElement continuation))
             {
@@ -93,7 +97,7 @@ namespace TEAMModelOS.Services.Common
                 if (!continuation.ValueKind.Equals(JsonValueKind.Null) && continuation.ValueKind.Equals(JsonValueKind.String))
                 {
                     continuationToken = continuation.GetString();
-                    iscontinuation = true;
+                    
                 }
             }
             //班级