|
@@ -4,9 +4,11 @@ using System.Net.Http;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using Azure.Cosmos;
|
|
using Azure.Cosmos;
|
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
using Microsoft.Azure.Documents;
|
|
using Microsoft.Azure.Documents;
|
|
using Microsoft.Azure.WebJobs;
|
|
using Microsoft.Azure.WebJobs;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
+using TEAMModelFunction.model;
|
|
using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
|
|
|
@@ -16,18 +18,20 @@ namespace TEAMModelFunction
|
|
{
|
|
{
|
|
private readonly IHttpClientFactory _clientFactory;
|
|
private readonly IHttpClientFactory _clientFactory;
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
|
|
|
- public MonitorCosmosDB(IHttpClientFactory clientFactory, AzureCosmosFactory azureCosmos)
|
|
|
|
|
|
+ public MonitorCosmosDB(IHttpClientFactory clientFactory, AzureCosmosFactory azureCosmos,AzureServiceBusFactory azureServiceBus)
|
|
{
|
|
{
|
|
_clientFactory = clientFactory;
|
|
_clientFactory = clientFactory;
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
|
|
+ _serviceBus = azureServiceBus;
|
|
}
|
|
}
|
|
|
|
|
|
[FunctionName("ActiveChange")]
|
|
[FunctionName("ActiveChange")]
|
|
public async Task School([CosmosDBTrigger(
|
|
public async Task School([CosmosDBTrigger(
|
|
databaseName: "TEAMModelOS",
|
|
databaseName: "TEAMModelOS",
|
|
collectionName: "Common",
|
|
collectionName: "Common",
|
|
- ConnectionStringSetting = "CosmosConnection",
|
|
|
|
|
|
+ ConnectionStringSetting = "AzureServiceCosmosConnectionString",
|
|
LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
|
|
LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
|
|
{
|
|
{
|
|
if (input != null && input.Count > 0)
|
|
if (input != null && input.Count > 0)
|
|
@@ -35,150 +39,273 @@ namespace TEAMModelFunction
|
|
log.LogInformation("Documents modified " + input.Count);
|
|
log.LogInformation("Documents modified " + input.Count);
|
|
log.LogInformation("First document Id " + input[0].Id);
|
|
log.LogInformation("First document Id " + input[0].Id);
|
|
}
|
|
}
|
|
- //input[0]
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- List<ExamInfo> exams = new List<ExamInfo>();
|
|
|
|
- string pk = input[0].GetPropertyValue<string>("pk");
|
|
|
|
- if (!string.IsNullOrEmpty(pk) && pk.Equals("Exam",StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ string pk = input[0].GetPropertyValue<string>("pk");
|
|
|
|
+ if (!string.IsNullOrEmpty(pk))
|
|
{
|
|
{
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ long stime = input[0].GetPropertyValue<long>("startTime");
|
|
|
|
+ long etime = input[0].GetPropertyValue<long>("endTime");
|
|
|
|
+ string school = input[0].GetPropertyValue<string>("school");
|
|
string code = input[0].GetPropertyValue<string>("code");
|
|
string code = input[0].GetPropertyValue<string>("code");
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.id = '{input[0].Id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
|
|
|
|
- {
|
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
|
- {
|
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
|
|
+ switch (pk) {
|
|
|
|
+ case "Exam":
|
|
|
|
+ ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(input[0].Id,new Azure.Cosmos.PartitionKey($"{code}"));
|
|
|
|
+ List<ExamClassResult> examClassResults = new List<ExamClassResult>();
|
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{school}") }))
|
|
{
|
|
{
|
|
-
|
|
|
|
- exams.Add(obj.ToObject<ExamInfo>());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- for (int i = 0; i < exams.Count; i++)
|
|
|
|
- {
|
|
|
|
- List<ExamClassResult> examClassResults = new List<ExamClassResult>();
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{exams[i].id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
|
|
|
|
- {
|
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
|
- {
|
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
{
|
|
{
|
|
- examClassResults.Add(obj.ToObject<ExamClassResult>());
|
|
|
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
+ {
|
|
|
|
+ examClassResults.Add(obj.ToObject<ExamClassResult>());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- /*if (exams[i].startTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) < 0
|
|
|
|
- && exams[i].endTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 0 )
|
|
|
|
- {*/
|
|
|
|
- if (examClassResults.Count < 0)
|
|
|
|
- {
|
|
|
|
- if (exams[i].progress.Equals("going",StringComparison.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
|
|
+ var message = new ServiceBusMessage(new { id = input[0].Id, name = "Exam", code = code }.ToJsonString());
|
|
|
|
+ message.Properties.Add("name", "Exam");
|
|
|
|
+ ChangeRecord record = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ChangeRecord>(input[0].Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
|
|
|
|
+ switch (info.progress) {
|
|
|
|
+ case "pending":
|
|
|
|
+ if (record != null)
|
|
|
|
+ {
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
|
+ record.sequenceNumber = start;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
|
+ {
|
|
|
|
+ id = input[0].Id,
|
|
|
|
+ code = "pending",
|
|
|
|
+ pk = "ChangeRecord",
|
|
|
|
+ sequenceNumber = start
|
|
|
|
+ };
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "going":
|
|
|
|
+ if (examClassResults.Count < 0) {
|
|
|
|
+ for (int j = 0; j < info.subjects.Count; j++)
|
|
|
|
+ {
|
|
|
|
+ for (int k = 0; k < info.targetClassIds.Count; k++)
|
|
|
|
+ {
|
|
|
|
+ ExamClassResult result = new ExamClassResult();
|
|
|
|
+ result.code = "ExamClassResult-" + info.school;
|
|
|
|
+ result.examId = info.id;
|
|
|
|
+ result.id = Guid.NewGuid().ToString();
|
|
|
|
+ result.subjectId = info.subjects[j].id;
|
|
|
|
+ result.year = info.year;
|
|
|
|
+ result.ttl = -1;
|
|
|
|
+ result.scope = info.scope;
|
|
|
|
+ result.pk = typeof(ExamClassResult).Name;
|
|
|
|
+ result.info.id = info.targetClassIds[k];
|
|
|
|
+ var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(info.targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
|
|
|
|
+ if (sresponse.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
|
|
|
|
+ Classroom classroom = json.ToObject<Classroom>();
|
|
|
|
+ result.info.name = classroom.name;
|
|
|
|
+ List<List<string>> ans = new List<List<string>>();
|
|
|
|
+ List<double> ansPoint = new List<double>();
|
|
|
|
+ foreach (double p in info.papers[j].point)
|
|
|
|
+ {
|
|
|
|
+ ans.Add(new List<string>());
|
|
|
|
+ ansPoint.Add(-1);
|
|
|
|
+ }
|
|
|
|
+ foreach (StudentSimple stu in classroom.students)
|
|
|
|
+ {
|
|
|
|
+ result.studentIds.Add(stu.id);
|
|
|
|
+ result.studentAnswers.Add(ans);
|
|
|
|
+ result.studentScores.Add(ansPoint);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.progress = info.progress;
|
|
|
|
+ result.school = info.school;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
|
|
|
|
|
|
- //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exams[i], exams[i].id.ToString(), new Azure.Cosmos.PartitionKey($"{exams[i].code}"));
|
|
|
|
- for (int j = 0; j < exams[i].subjects.Count; j++)
|
|
|
|
- {
|
|
|
|
- for (int k = 0; k < exams[i].targetClassIds.Count; k++)
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (record != null)
|
|
|
|
+ {
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", message, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
|
+ record.sequenceNumber = start;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", message, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
|
+ {
|
|
|
|
+ id = input[0].Id,
|
|
|
|
+ code = "going",
|
|
|
|
+ pk = "ChangeRecord",
|
|
|
|
+ sequenceNumber = start
|
|
|
|
+ };
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "finish":
|
|
|
|
+ for (int j = 0; j < info.subjects.Count; j++)
|
|
{
|
|
{
|
|
- ExamClassResult result = new ExamClassResult();
|
|
|
|
- result.code = "ExamClassResult-" + exams[i].school;
|
|
|
|
- result.examId = exams[i].id;
|
|
|
|
- result.id = Guid.NewGuid().ToString();
|
|
|
|
- result.subjectId = exams[i].subjects[j].id;
|
|
|
|
- result.year = exams[i].year;
|
|
|
|
|
|
+ ExamResult result = new ExamResult();
|
|
result.ttl = -1;
|
|
result.ttl = -1;
|
|
- result.scope = exams[i].scope;
|
|
|
|
- result.pk = typeof(ExamClassResult).Name;
|
|
|
|
- result.info.id = exams[i].targetClassIds[k];
|
|
|
|
- var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(exams[i].targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{exams[i].school}"));
|
|
|
|
- if (sresponse.Status == 200)
|
|
|
|
|
|
+ result.pk = typeof(ExamResult).Name;
|
|
|
|
+ result.code = "ExamResult-" + info.school;
|
|
|
|
+ result.school = info.school;
|
|
|
|
+ result.id = Guid.NewGuid().ToString();
|
|
|
|
+ result.examId = info.id;
|
|
|
|
+ result.subjectId = info.subjects[j].id;
|
|
|
|
+ result.year = info.year;
|
|
|
|
+ result.paper = info.papers[j];
|
|
|
|
+ result.point = info.papers[j].point;
|
|
|
|
+ result.scope = info.scope;
|
|
|
|
+ result.name = info.name;
|
|
|
|
+ //result.time
|
|
|
|
+
|
|
|
|
+ //人数总和
|
|
|
|
+ int Count = 0;
|
|
|
|
+ int m = 0;
|
|
|
|
+ List<ClassRange> classRanges = new List<ClassRange>();
|
|
|
|
+ foreach (ExamClassResult classResult in examClassResults)
|
|
{
|
|
{
|
|
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
|
|
|
|
- Classroom classroom = json.ToObject<Classroom>();
|
|
|
|
- result.info.name = classroom.name;
|
|
|
|
- List<List<string>> ans = new List<List<string>>();
|
|
|
|
- List<double> ansPoint = new List<double>();
|
|
|
|
- foreach (double p in exams[i].papers[j].point)
|
|
|
|
|
|
+ //处理班级信息
|
|
|
|
+ ClassRange range = new ClassRange();
|
|
|
|
+ range.id = classResult.info.id;
|
|
|
|
+ range.name = classResult.info.name;
|
|
|
|
+ List<int> ran = new List<int>();
|
|
|
|
+ int stuCount = classResult.studentIds.Count;
|
|
|
|
+ Count += stuCount;
|
|
|
|
+ if (m == 0)
|
|
|
|
+ {
|
|
|
|
+ ran.Add(0);
|
|
|
|
+ ran.Add(stuCount - 1);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ran.Add(Count - stuCount);
|
|
|
|
+ ran.Add(Count - 1);
|
|
|
|
+ }
|
|
|
|
+ m++;
|
|
|
|
+ range.range = ran;
|
|
|
|
+ classRanges.Add(range);
|
|
|
|
+ //处理学生ID
|
|
|
|
+ foreach (string id in classResult.studentIds)
|
|
{
|
|
{
|
|
- ans.Add(new List<string>());
|
|
|
|
- ansPoint.Add(-1);
|
|
|
|
|
|
+ result.studentIds.Add(id);
|
|
}
|
|
}
|
|
- foreach (StudentSimple stu in classroom.students)
|
|
|
|
|
|
+ foreach (List<double> scores in classResult.studentScores)
|
|
{
|
|
{
|
|
- result.studentIds.Add(stu.id);
|
|
|
|
- result.studentAnswers.Add(ans);
|
|
|
|
- result.studentScores.Add(ansPoint);
|
|
|
|
|
|
+ result.studentScores.Add(scores);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- result.progress = exams[i].progress;
|
|
|
|
- result.school = exams[i].school;
|
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
|
|
|
|
-
|
|
|
|
|
|
+ result.classes = classRanges;
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{result.school}"));
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "Vote":
|
|
|
|
+ Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(input[0].Id, new Azure.Cosmos.PartitionKey($"{code}"));
|
|
|
|
+ var messageVote = new ServiceBusMessage(new { id = input[0].Id, name = "Vote", code = code }.ToJsonString());
|
|
|
|
+ messageVote.Properties.Add("name", "Vote");
|
|
|
|
+ ChangeRecord voteRecord = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ChangeRecord>(input[0].Id, new Azure.Cosmos.PartitionKey($"{vote.progress}"));
|
|
|
|
+ switch (vote.progress) {
|
|
|
|
+ case "pending":
|
|
|
|
+ if (voteRecord != null)
|
|
|
|
+ {
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
|
+ voteRecord.sequenceNumber = start;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(voteRecord, voteRecord.id, new Azure.Cosmos.PartitionKey($"{voteRecord.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
|
+ {
|
|
|
|
+ id = input[0].Id,
|
|
|
|
+ code = "pending",
|
|
|
|
+ pk = "ChangeRecord",
|
|
|
|
+ sequenceNumber = start
|
|
|
|
+ };
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "going":
|
|
|
|
+ if (voteRecord != null)
|
|
|
|
+ {
|
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
|
+ voteRecord.sequenceNumber = end;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(voteRecord, voteRecord.id, new Azure.Cosmos.PartitionKey($"{voteRecord.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageVote, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
|
+ {
|
|
|
|
+ id = input[0].Id,
|
|
|
|
+ code = "going",
|
|
|
|
+ pk = "ChangeRecord",
|
|
|
|
+ sequenceNumber = end
|
|
|
|
+ };
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if (exams[i].progress.Equals("finish"))
|
|
|
|
- {
|
|
|
|
- for (int j = 0; j < exams[i].subjects.Count; j++)
|
|
|
|
|
|
+ break;
|
|
|
|
+ case "Survey":
|
|
|
|
+ Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(input[0].Id, new Azure.Cosmos.PartitionKey($"{code}"));
|
|
|
|
+ var messageSurvey = new ServiceBusMessage(new { id = input[0].Id, name = "Survey", code = code }.ToJsonString());
|
|
|
|
+ messageSurvey.Properties.Add("name", "Survey");
|
|
|
|
+ ChangeRecord surveyRecord = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ChangeRecord>(input[0].Id, new Azure.Cosmos.PartitionKey($"{survey.progress}"));
|
|
|
|
+ switch (survey.progress)
|
|
{
|
|
{
|
|
- ExamResult result = new ExamResult();
|
|
|
|
- result.ttl = -1;
|
|
|
|
- result.pk = typeof(ExamResult).Name;
|
|
|
|
- result.code = "ExamResult-" + exams[i].school;
|
|
|
|
- result.school = exams[i].school;
|
|
|
|
- result.id = Guid.NewGuid().ToString();
|
|
|
|
- result.examId = exams[i].id;
|
|
|
|
- result.subjectId = exams[i].subjects[j].id;
|
|
|
|
- result.year = exams[i].year;
|
|
|
|
- result.paper = exams[i].papers[j];
|
|
|
|
- result.point = exams[i].papers[j].point;
|
|
|
|
- result.scope = exams[i].scope;
|
|
|
|
- result.name = exams[i].name;
|
|
|
|
- //result.time
|
|
|
|
-
|
|
|
|
- //人数总和
|
|
|
|
- int Count = 0;
|
|
|
|
- int m = 0;
|
|
|
|
- List<ClassRange> classRanges = new List<ClassRange>();
|
|
|
|
- foreach (ExamClassResult classResult in examClassResults)
|
|
|
|
- {
|
|
|
|
- //处理班级信息
|
|
|
|
- ClassRange range = new ClassRange();
|
|
|
|
- range.id = classResult.info.id;
|
|
|
|
- range.name = classResult.info.name;
|
|
|
|
- List<int> ran = new List<int>();
|
|
|
|
- int stuCount = classResult.studentIds.Count;
|
|
|
|
- Count += stuCount;
|
|
|
|
- if (m == 0)
|
|
|
|
|
|
+ case "pending":
|
|
|
|
+ if (surveyRecord != null)
|
|
{
|
|
{
|
|
- ran.Add(0);
|
|
|
|
- ran.Add(stuCount - 1);
|
|
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
|
+ surveyRecord.sequenceNumber = start;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(surveyRecord, surveyRecord.id, new Azure.Cosmos.PartitionKey($"{surveyRecord.code}"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- ran.Add(Count - stuCount);
|
|
|
|
- ran.Add(Count - 1);
|
|
|
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(stime));
|
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
|
+ {
|
|
|
|
+ id = input[0].Id,
|
|
|
|
+ code = "pending",
|
|
|
|
+ pk = "ChangeRecord",
|
|
|
|
+ sequenceNumber = start
|
|
|
|
+ };
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
|
|
}
|
|
}
|
|
- m++;
|
|
|
|
- range.range = ran;
|
|
|
|
- classRanges.Add(range);
|
|
|
|
- //处理学生ID
|
|
|
|
- foreach (string id in classResult.studentIds)
|
|
|
|
|
|
+ break;
|
|
|
|
+ case "going":
|
|
|
|
+ if (surveyRecord != null)
|
|
{
|
|
{
|
|
- result.studentIds.Add(id);
|
|
|
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
|
+ surveyRecord.sequenceNumber = end;
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(surveyRecord, surveyRecord.id, new Azure.Cosmos.PartitionKey($"{surveyRecord.code}"));
|
|
}
|
|
}
|
|
- foreach (List<double> scores in classResult.studentScores)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- result.studentScores.Add(scores);
|
|
|
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync("active-task", messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(etime));
|
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
|
+ {
|
|
|
|
+ id = input[0].Id,
|
|
|
|
+ code = "going",
|
|
|
|
+ pk = "ChangeRecord",
|
|
|
|
+ sequenceNumber = end
|
|
|
|
+ };
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
|
|
}
|
|
}
|
|
- }
|
|
|
|
- result.classes = classRanges;
|
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{result.school}"));
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|