|
@@ -437,7 +437,46 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
List<Dictionary<string, List<string>>> acId = id.ToObject<List<Dictionary<string, List<string>>>>();
|
|
|
List<string> value = new List<string>();
|
|
|
- await foreach (var s in AuditTask(acId, client, type.GetInt32(), now, standard, school)) ;
|
|
|
+ List<Task> tasks = new();
|
|
|
+ List<Task<ItemResponse<StudyRecord>>> tasky = new();
|
|
|
+ foreach (var aId in acId)
|
|
|
+ {
|
|
|
+ foreach (KeyValuePair<string, List<string>> pair in aId)
|
|
|
+ {
|
|
|
+ foreach (var teacId in pair.Value)
|
|
|
+ {
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(pair.Key, new PartitionKey($"StudyRecord-{teacId}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ StudyRecord study = json.ToObject<StudyRecord>();
|
|
|
+ if (study.tId.Equals(teacId))
|
|
|
+ {
|
|
|
+ study.status = type.GetInt32();
|
|
|
+ study.aTime = now;
|
|
|
+ }
|
|
|
+ tasky.Add(client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}")));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ StudyRecord setting = new()
|
|
|
+ {
|
|
|
+ id = pair.Key,
|
|
|
+ tId = teacId,
|
|
|
+ code = "StudyRecord-" + teacId,
|
|
|
+ status = type.GetInt32(),
|
|
|
+ aTime = now
|
|
|
+ };
|
|
|
+ tasky.Add(client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}")));
|
|
|
+ }
|
|
|
+ tasks.Add(StatisticsService.SendServiceBus($"{standard}", $"{teacId}", $"{school}", StatisticsService.OfflineRecord, 1, _configuration, _serviceBus));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await Task.WhenAll(tasks);
|
|
|
+ await Task.WhenAll(tasky);
|
|
|
+ //await foreach (var s in AuditTask(acId, client, type.GetInt32(), now, standard, school)) ;
|
|
|
return Ok(new { code = HttpStatusCode.OK });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -449,16 +488,51 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
private async IAsyncEnumerable<(string op, string tId)> AuditTask(List<Dictionary<string, List<string>>> ids, CosmosClient client, int type, long now, object standard, string school)
|
|
|
{
|
|
|
-
|
|
|
+ List<Task> tasks = new();
|
|
|
+ List<Task<ItemResponse<StudyRecord>>> tasky = new();
|
|
|
foreach (var id in ids)
|
|
|
{
|
|
|
foreach (KeyValuePair<string, List<string>> pair in id)
|
|
|
{
|
|
|
- await foreach (var s in TeacTask(pair.Key, pair.Value, client, type, now, standard, school));
|
|
|
+ foreach (var teacId in pair.Value)
|
|
|
+ {
|
|
|
+ //var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(pair.Key, new PartitionKey($"StudyRecord-{teacId}"));
|
|
|
+ List<StudyRecord> studyRecords = new();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StudyRecord>(queryText: $"select value(c) from c where c.id = '{pair.Key}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StudyRecord-{teacId}") }))
|
|
|
+ {
|
|
|
+ studyRecords.Add(item);
|
|
|
+ }
|
|
|
+ if (studyRecords.Count > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (studyRecords[0].tId.Equals(teacId))
|
|
|
+ {
|
|
|
+ studyRecords[0].status = type;
|
|
|
+ studyRecords[0].aTime = now;
|
|
|
+ }
|
|
|
+ tasky.Add(client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(studyRecords[0], studyRecords[0].id, new PartitionKey($"{studyRecords[0].code}")));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ StudyRecord setting = new()
|
|
|
+ {
|
|
|
+ id = pair.Key,
|
|
|
+ tId = teacId,
|
|
|
+ code = "StudyRecord-" + teacId,
|
|
|
+ status = type,
|
|
|
+ aTime = now
|
|
|
+ };
|
|
|
+ tasky.Add(client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}")));
|
|
|
+ }
|
|
|
+ tasks.Add(StatisticsService.SendServiceBus($"{standard}", $"{teacId}", $"{school}", StatisticsService.OfflineRecord, 1, _configuration, _serviceBus));
|
|
|
+ }
|
|
|
+ yield return ("", "");
|
|
|
|
|
|
}
|
|
|
- yield return ("", "");
|
|
|
+
|
|
|
}
|
|
|
+ await Task.WhenAll(tasks);
|
|
|
+ await Task.WhenAll(tasky);
|
|
|
}
|
|
|
private async IAsyncEnumerable<(string op, string tId)> TeacTask(string id,List<string> ids, CosmosClient client, int type, long now, object standard, string school)
|
|
|
{
|
|
@@ -466,19 +540,22 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
List<Task> tasks = new();
|
|
|
foreach (var teacId in ids)
|
|
|
{
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id, new PartitionKey($"StudyRecord-{teacId}"));
|
|
|
+ /* var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id, new PartitionKey($"StudyRecord-{teacId}"));*/
|
|
|
+ List<StudyRecord> studyRecords = new();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StudyRecord>(queryText: $"select value(c) from c where c.id = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StudyRecord-{teacId}") }))
|
|
|
+ {
|
|
|
+ studyRecords.Add(item);
|
|
|
+ }
|
|
|
string op;
|
|
|
- if (response.Status == (int)HttpStatusCode.OK)
|
|
|
+ if (studyRecords.Count > 0)
|
|
|
{
|
|
|
- var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- StudyRecord study = json.ToObject<StudyRecord>();
|
|
|
- if (study.tId.Equals(teacId))
|
|
|
+ if (studyRecords[0].tId.Equals(teacId))
|
|
|
{
|
|
|
- study.status = type;
|
|
|
- study.aTime = now;
|
|
|
+ studyRecords[0].status = type;
|
|
|
+ studyRecords[0].aTime = now;
|
|
|
}
|
|
|
op = "update";
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(studyRecords[0], studyRecords[0].id, new PartitionKey($"{studyRecords[0].code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|