123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- using Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- namespace TEAMModelOS.Controllers.Common
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- //[Authorize(Roles = "IES5")
- [Route("common/study")]
- [ApiController]
- public class StudyController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly SnowflakeId _snowflakeId;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureRedisFactory _azureRedis;
- public IConfiguration _configuration { get; set; }
- public StudyController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
- IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
- {
- _azureCosmos = azureCosmos;
- _serviceBus = serviceBus;
- _snowflakeId = snowflakeId;
- _dingDing = dingDing;
- _option = option?.Value;
- _azureStorage = azureStorage;
- _azureRedis = azureRedis;
- _configuration = configuration;
- }
- /// <summary>
- /// 保存研修信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("save")]
- public async Task<IActionResult> Save(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("study", out JsonElement stu)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- Study study = stu.ToObject<Study>();
- string code = study.school;
- study.publish = 0;
- study.ttl = -1;
- study.progress = "going";
- if (!study.owner.Equals("area")) {
- study.owner = "school";
- study.code = "Study-" + code;
- study.scope = "school";
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- study.createTime = now;
- }
- if (string.IsNullOrEmpty(study.id))
- {
- study.id = Guid.NewGuid().ToString();
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(study, new PartitionKey($"{study.code}"));
- }
- else
- {
- if (request.TryGetProperty("ids", out JsonElement ids))
- {
- List<string> gIds = study.tchLists;
- List<string> tIds = ids.ToObject<List<string>>();
- foreach (string gId in gIds)
- {
- var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(gId, new PartitionKey($"GroupList"));
- if (response.Status == 200)
- {
- var json = await JsonDocument.ParseAsync(response.ContentStream);
- GroupList group = json.ToObject<GroupList>();
- foreach (string id in tIds)
- {
- /* bool flag = group.members.Exists(m => m.id.Equals(id));
- if (flag)
- {
- continue;
- }*/
- //else {
- Member member = new();
- member.id = id;
- member.type = 1;
- member.code = study.school;
- group.members.Add(member);
- //}
- }
- await GroupListService.UpsertList(group,_azureCosmos,_configuration,_serviceBus);
- // await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(group, group.id, new PartitionKey($"{group.code}"));
- }
- }
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
- }
- return Ok(new { study });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/save()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 签到
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher,admin")]
- [HttpPost("sign-in")]
- public async Task<IActionResult> Sign(JsonElement request)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/sign-in()\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{tId}"));
- var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
- if (sresponse.Status == (int)HttpStatusCode.OK)
- {
- var sJson = await JsonDocument.ParseAsync(sresponse.ContentStream);
- Study study = sJson.ToObject<Study>();
- if (response.Status == (int)HttpStatusCode.OK)
- {
- var json = await JsonDocument.ParseAsync(response.ContentStream);
- StudyRecord record = json.ToObject<StudyRecord>();
- record.sign = study.startTime < now ? "2" : "1";
- record.signTime = now;
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
- }
- else
- {
- StudyRecord setting = new();
- setting.id = id.GetString();
- setting.tId = tId.GetString();
- setting.signTime = now;
- setting.code = "StudyRecord-" + tId.GetString();
- setting.sign = study.startTime < now ? "2" : "1";
- await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
- }
- }
- else
- {
- return Ok(new { code = HttpStatusCode.NotFound });
- }
- return Ok();
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/sign-in()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /*/// <summary>
- /// 上传作业
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("upload")]
- public async Task<IActionResult> Upload(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- if (!request.TryGetProperty("hw", out JsonElement hw)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
- if (response.Status == (int)HttpStatusCode.OK)
- {
- var json = await JsonDocument.ParseAsync(response.ContentStream);
- Study study = json.ToObject<Study>();
- bool flag = study.teachers.Exists(s => s.id.Equals(tId.GetString()));
- if (flag)
- {
- foreach (Setting setting in study.teachers)
- {
- if (setting.id.Equals(tId.GetString()))
- {
- setting.hwTime = now;
- setting.hw = hw.GetString();
- }
- }
- }
- else {
- Setting setting = new Setting();
- setting.id = tId.GetString();
- setting.hwTime = now;
- setting.hw = hw.GetString();
- study.teachers.Add(setting);
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
- }
- else
- {
- return Ok(new { code = HttpStatusCode.NotFound });
- }
- return Ok(new { code = HttpStatusCode.OK});
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/upload()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }*/
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("delete")]
- public async Task<IActionResult> Delete(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
- if (sresponse.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
- Study study = json.ToObject<Study>();
- if (!string.IsNullOrEmpty(study.examId))
- {
- await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(study.examId, new PartitionKey($"ExamLite-{code}"));
- }
- if (!string.IsNullOrEmpty(study.surveyId))
- {
- await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(study.surveyId, new PartitionKey($"Survey-{code}"));
- }
- if (!string.IsNullOrEmpty(study.workId))
- {
- await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(study.workId, new PartitionKey($"Homework-{code}"));
- }
- }
- var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
- return Ok(new { id, code = response.Status });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/delete()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("find")]
- public async Task<IActionResult> Find(JsonElement requert)
- {
- try
- {
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- var query = $"select c.id,c.img,c.name,c.type,c.startTime,c.endTime,c.presenter,c.topic,c.address,c.owner,c.progress from c ";
- string continuationToken = string.Empty;
- string token = default;
- //是否需要进行分页查询,默认不分页
- bool iscontinuation = false;
- if (requert.TryGetProperty("token", out JsonElement token_1))
- {
- token = token_1.GetString();
- iscontinuation = true;
- };
- //默认不指定返回大小
- int? topcout = null;
- if (requert.TryGetProperty("count", out JsonElement jcount))
- {
- if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
- {
- topcout = data;
- }
- }
- List<object> studies = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Study-{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())
- {
- studies.Add(obj.ToObject<object>());
- }
- }
- if (iscontinuation)
- {
- continuationToken = item.GetContinuationToken();
- break;
- }
- }
- return Ok(new { studies });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/find()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("find-summary")]
- public async Task<IActionResult> FindSummary(JsonElement requert)
- {
- try
- {
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- Study study = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Study>(id.GetString(), new PartitionKey($"Study-{code}"));
- if (study != null)
- {
- (List<RMember> tchList, List<RGroupList> classInfo) = await GroupListService.GetStutmdidListids(client, _dingDing, study.tchLists, study.school);
- List<StudyRecord> records = new();
- foreach (var member in tchList)
- {
- var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{member.id}"));
- if (response.Status == (int)HttpStatusCode.OK)
- {
- var json = await JsonDocument.ParseAsync(response.ContentStream);
- StudyRecord record = json.ToObject<StudyRecord>();
- records.Add(record);
- }
- }
- // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
- //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, study.tchLists, study.school);
- return Ok(new { study, records, status = 200 });
- }
- else
- {
- return Ok(new { study, status = 404 });
- }
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/FindSummary()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return Ok(new { status = 404 });
- }
- }
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("find-by-teacher")]
- public async Task<IActionResult> FindByTeacher(JsonElement requert)
- {
- try
- {
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!requert.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- var query = $"select c.id,c.img,c.name,c.startTime,c.type,c.endTime,c.presenter,c.topic,c.address,c.owner from c join A0 in c.teachers where A0.id = '{tId}'";
- List<object> studies = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{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())
- {
- studies.Add(obj.ToObject<object>());
- }
- }
- }
- return Ok(new { studies });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/find-by-teacher()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("find-summary-by-teacher")]
- public async Task<IActionResult> FindSummaryByTeacher(JsonElement requert)
- {
- try
- {
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!requert.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<object> studies = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.teachers where A0.id = '{tId}' and c.id = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{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())
- {
- studies.Add(obj.ToObject<object>());
- }
- }
- }
- return Ok(new { studies });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},study/find-summary-by-teacher()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin,area")]
- [HttpPost("audit")]
- public async Task<IActionResult> Audit(JsonElement request)
- {
- try
- {
- (string tmdid, _, _, string school) = HttpContext.GetAuthTokenInfo();
- if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- //if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- if (!request.TryGetProperty("type", out JsonElement type)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- List<Dictionary<string, List<string>>> acId = id.ToObject<List<Dictionary<string, List<string>>>>();
- List<string> value = new List<string>();
- List<Task> tasks = new();
- List<Task<ItemResponse<StudyRecord>>> tasky = new();
- List<(string op, string tId)> opp = new List<(string op, string tId)>();
- int statu = type.GetInt32();
- (string standard, List<string> tmdid, string school, List<string> update, int statistics) list = ( $"{standard}", null, school, new List<string> { StatisticsService.OfflineRecord } , 1);
- HashSet<string> tch= new HashSet<string>();
- foreach (var aId in acId)
- {
- foreach (KeyValuePair<string, List<string>> pair in aId)
- {
- /* await foreach (var key in TeacTask(pair.Key, pair.Value, client, type.GetInt32(), now, standard, school)) {
- opp.Add((key.op,key.tId));
- };*/
- 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 == statu)
- {
- continue;
- }
- else
- {
- study.status = statu;
- 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 = statu,
- aTime = now
- };
- tasky.Add(client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}")));
- }
- tch.Add($"{teacId}");
-
- }
- }
- }
- list.tmdid = new List<string>(tch);
- await tasky.TaskPage(10);
- await StatisticsService.SendServiceBus(list, _configuration, _serviceBus);
- return Ok(new { code = HttpStatusCode.OK });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},Study/audit()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- 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)
- {
- 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 ("", "");
- }
- }
- 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)
- {
- List<Task> tasks = new();
- foreach (var teacId in ids)
- {
- /* 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 (studyRecords.Count > 0)
- {
- if (studyRecords[0].tId.Equals(teacId))
- {
- studyRecords[0].status = type;
- studyRecords[0].aTime = now;
- }
- op = "update";
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(studyRecords[0], studyRecords[0].id, new PartitionKey($"{studyRecords[0].code}"));
- }
- else
- {
- StudyRecord setting = new()
- {
- id = id,
- tId = teacId,
- code = "StudyRecord-" + teacId,
- status = type,
- aTime = now
- };
- op = "insert";
- await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
- }
- //tasks.Add(StatisticsService.SendServiceBus($"{standard}", $"{teacId}", $"{school}", StatisticsService.OfflineRecord, 1, _configuration, _serviceBus));
- yield return (op, teacId);
- }
- await Task.WhenAll(tasks);
- }
- }
- }
|