|
@@ -1,6 +1,7 @@
|
|
|
using Azure.Cosmos;
|
|
|
using Azure.Messaging.ServiceBus;
|
|
|
using Azure.Storage.Blobs.Models;
|
|
|
+using Azure.Storage.Sas;
|
|
|
using Microsoft.Azure.Documents;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -39,7 +40,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)
|
|
|
{
|
|
|
|
|
@@ -47,14 +48,14 @@ namespace TEAMModelFunction
|
|
|
_azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
|
|
|
if (data != null)
|
|
|
{
|
|
|
- data.ttl = 1;
|
|
|
+
|
|
|
if (survey.scope == "school")
|
|
|
{
|
|
|
- data = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
|
|
|
+ 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").ReplaceItemAsync<ActivityData>(data, adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
|
|
|
+ data = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<ActivityData>( adid, new Azure.Cosmos.PartitionKey($"{data.code}"));
|
|
|
}
|
|
|
}
|
|
|
await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.成都开发測試群組);
|
|
@@ -163,61 +164,62 @@ namespace TEAMModelFunction
|
|
|
await _azureStorage.UploadFileByContainer(survey.owner, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
|
|
|
//结算每道题的答题情况
|
|
|
|
|
|
- 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>();
|
|
|
+ var ContainerClient = _azureStorage.GetBlobContainerClient(survey.owner);
|
|
|
+
|
|
|
//获取
|
|
|
-
|
|
|
- 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<string> items = await ContainerClient.List($"survey/{survey.id}/urecord");
|
|
|
+ List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
|
|
|
+ foreach (string item in items)
|
|
|
{
|
|
|
- if (record.ans.Count == survey.ans.Count)
|
|
|
+ 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)
|
|
|
{
|
|
|
- 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 +229,9 @@ namespace TEAMModelFunction
|
|
|
else
|
|
|
{
|
|
|
//异动,且已经有结算记录则不必再继续。
|
|
|
- break;
|
|
|
+ //break;
|
|
|
}
|
|
|
- await Task.WhenAll(tasks);
|
|
|
+ // await Task.WhenAll(tasks);
|
|
|
//更新结束状态
|
|
|
data.progress = "finish";
|
|
|
if (survey.scope == "school")
|
|
@@ -240,6 +242,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;
|
|
|
}
|
|
|
}
|