1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204 |
- using Azure.Cosmos;
- using Azure.Storage.Sas;
- 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;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using TEAMModelOS.SDK.Models.Cosmos.School;
- using TEAMModelOS.SDK.Models.Service;
- namespace TEAMModelOS.Controllers
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [Route("school/area")]
- [ApiController]
- public class AreaController : 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 AreaController(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;
- }
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-group")]
- public async Task<IActionResult> Find(JsonElement requert)
- {
- try
- {
- //区级Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- //获取区级以下所有学校编码和基础信息
- List<string> baseIds = new();
- List<(string id, string name, string picture)> scInfos = new List<(string id, string name, string picture)>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name,c.picture from c where c.areaId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- baseIds.Add(account.GetProperty("id").GetString());
- scInfos.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString(), account.GetProperty("picture").GetString()));
- }
- }
- }
- List<(string id, List<string> gId, List<string> name)> groups = new List<(string id, List<string> gId, List<string> name)>();
- foreach (string sId in baseIds)
- {
- List<(string id, string name)> group = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"SELECT c.id, c.name FROM c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TchList-{sId}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- group.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString()));
- //group.Add();
- }
- }
- }
- group = group.Where(g => !string.IsNullOrEmpty(g.id)).ToList();
- groups.Add((sId, group.Select(s=>s.id).ToList(), group.Select(s => s.name).ToList()));
- }
- //var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS("hbcn", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
- var gr = groups.Select(o => new
- {
- o.id,
- o.gId,
- uri = _azureStorage.GetBlobContainerSAS(o.id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List).uri,
- sas = _azureStorage.GetBlobContainerSAS(o.id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List).sas,
- sname = scInfos.FirstOrDefault(c => c.id == o.id).name,
- o.name
- });
- return Ok(new { gr });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},school/area/find-group()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find")]
- public async Task<IActionResult> FindGroup(JsonElement requert)
- {
- try
- {
- //区级Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- //获取区级以下所有学校编码和基础信息
- List<string> baseIds = new();
- List<(string id, string name, string picture)> scInfos = new List<(string id, string name, string picture)>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name,c.picture from c where c.areaId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- baseIds.Add(account.GetProperty("id").GetString());
- scInfos.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString(), account.GetProperty("picture").GetString()));
- }
- }
- }
- //获取所有学校人数
- List<(string id, int count)> scCount = new List<(string id, int count)>();
- foreach (string sId in baseIds)
- {
- List<string> tIds = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join A0 in c.schools where A0.schoolId = '{sId}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- tIds.Add(account.GetProperty("id").GetString());
- }
- }
- }
- scCount.Add((sId, tIds.Count));
- }
- var info = scInfos.Select(o =>
- new
- {
- o.id,
- o.name,
- o.picture,
- areaId = id,
- count = scCount.FirstOrDefault(c => c.id == o.id).count,
- }
- );
- return Ok(new { info });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},school/area/find()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 保存研修信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher,admin")]
- [HttpPost("save-study")]
- public async Task<IActionResult> SaveStudy(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("para", out JsonElement para)) return BadRequest();
- if (!request.TryGetProperty("study", out JsonElement stu)) return BadRequest();
- List<parameter> parameters = para.ToObject<List<parameter>>();
- var client = _azureCosmos.GetCosmosClient();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- List<Study> studies = new();
- Study areaStudy = stu.ToObject<Study>();
- areaStudy.owner = "area";
- areaStudy.ttl = -1;
- areaStudy.code = "Study-" + id.GetString();
- areaStudy.createTime = now;
- if (string.IsNullOrEmpty(areaStudy.id))
- {
- areaStudy.id = Guid.NewGuid().ToString();
- }
- List<string> allName = new();
- foreach (parameter pa in parameters)
- {
- Study study = stu.ToObject<Study>();
- //string code = pa.sId;
- study.areaId = id.GetString();
- study.school = pa.sId;
- study.owner = "area";
- study.ttl = -1;
- study.code = "Study-" + pa.sId;
- study.createTime = now;
- study.tchLists = pa.gId;
- study.pId = areaStudy.id;
- study.targetType = "research";
- if (pa.gName.Count == 0)
- {
- string sName = pa.sName + "-" + "所有老师(未分组)";
- allName.Add(sName);
- string json = "所有老师(未分组)";
- study.targets.Add(json.ToJsonString().ToObject<JsonElement>());
- //study.targets.Add("所有老师(未分组)");
-
- }
- else
- {
- //study.targets = pa.gName;
- var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
- study.targets = tn;
- foreach (string name in pa.gName)
- {
- //处理区级target
- string sName = pa.sName + "-" + name;
- allName.Add(sName);
- }
- }
- foreach (string setting in study.settings)
- {
- if (setting.Equals("exam"))
- {
- if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
- ExamLite trExam = exam.ToObject<ExamLite>();
- trExam.owner = "area";
- trExam.school = pa.sId;
- trExam.areaId = id.GetString();
- trExam.tchLists = pa.gId;
- trExam.targetType = "research";
- trExam.blob = $"/{trExam.areaId}/exam/{study.pId}/index.json";
- //处理发布对象
- await getMoreExam(pa, trExam);
- //保存更多得评测信息
- string eId = await ExamService.saveMoreAsync(client, _dingDing, trExam);
- if (string.IsNullOrEmpty(eId))
- {
- return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "评测信息异常" });
- }
- else
- {
- study.examId = eId;
- }
- }
- if (setting.Equals("survey"))
- {
- if (!request.TryGetProperty("survey", out JsonElement survey)) return BadRequest();
- Survey trSurvey = survey.ToObject<Survey>();
- trSurvey.owner = "area";
- trSurvey.school = pa.sId;
- trSurvey.areaId = id.GetString();
- trSurvey.tchLists = pa.gId;
- trSurvey.targetType = "research";
- trSurvey.blob = $"/{trSurvey.areaId}/survey/{study.pId}/index.json";
- await getMoreSurvey(pa, trSurvey);
- string surveyId = await SurveyService.saveMoreAsync(client, _dingDing, trSurvey);
- if (string.IsNullOrEmpty(surveyId))
- {
- return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "问卷信息异常" });
- }
- else
- {
- study.surveyId = surveyId;
- }
- }
- }
- if (string.IsNullOrEmpty(study.id))
- {
- study.id = Guid.NewGuid().ToString();
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(study, new PartitionKey($"{study.code}"));
- }
- else
- {
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(study, new PartitionKey($"{study.code}"));
- }
- studies.Add(study);
- }
- //areaStudy.targets = allName;
- var atn = allName.ToJsonString().ToObject<List<JsonElement>>();
- areaStudy.targets = atn;
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaStudy, new PartitionKey($"{areaStudy.code}"));
- var ids = studies.Select(s => new { s.id, s.school, s.examId, s.surveyId });
- return Ok(new { id, ids, code = (int)HttpStatusCode.OK, acId = areaStudy.id });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/save-study()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-all-study")]
- public async Task<IActionResult> FindAllStudy(JsonElement requert)
- {
- try
- {
- //区级Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- // List<string> baseIds = await getId(client, id.GetString());
- List<object> studies = new();
- var query = $"select c.id,c.img,c.name,c.type,c.startTime,c.endTime,c.presenter,c.topic,c.address,c.owner,c.school from c ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{id}") }))
- {
- 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},area/find-all-study()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-all-study-teachers")]
- public async Task<IActionResult> FindAllStudyTeacher(JsonElement requert)
- {
- try
- {
- //区级活动Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!requert.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<string> baseIds = await getId(client, areaId.GetString());
- List<Study> studies = new();
- List<(string id, string name)> ps = await getInfo(client, areaId.GetString());
- //List<string> aName = new();
- var query = $"select value(c) from c where c.pId = '{id}'";
- foreach (string code in baseIds)
- {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Study>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{code}") }))
- {
- studies.Add(item);
- }
- }
-
- List<Survey> trSurveys = new List<Survey>();
- List<ExamLite> trExams = new List<ExamLite>();
- List<(List<TmdInfo> teac, Study stu)> moreInfo = new List<(List<TmdInfo> teac, Study stu)>();
- foreach (Study study in studies) {
- (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, study.tchLists, study.school);
- if (!string.IsNullOrEmpty(study.surveyId))
- {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Survey>(queryText: $"select value(c) from c where c.id = '{study.surveyId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{study.school}") }))
- {
- trSurveys.Add(item);
- }
- }
- if (!string.IsNullOrEmpty(study.examId)) {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamLite>(queryText: $"select value(c) from c where c.id = '{study.examId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamLite-{study.school}") }))
- {
- trExams.Add(item);
- }
- }
- moreInfo.Add((tchList,study));
- } ;
- var survey = trSurveys.Select(s => new {
- count = s.answers.Count,
- ansCount = s.answers.Count,
- });
- var exam = trExams.Select(s => new {
- count = s.teachers.Count,
- ansCount = s.teachers.Where(h => h.answer.Count > 0).ToList().Count,
- });
- var info = studies.Select(s => new {
- s.id,
- name = ps.FirstOrDefault(c => c.id == s.id).name,
- count = s.teachers.Count,
- //hwCount = s.teachers.Where(h => h.hwTime > 0).ToList().Count,
- signCount = s.teachers.Where(h => h.signTime > 0).ToList().Count,
- lateCount = s.teachers.Where(h =>!string.IsNullOrEmpty(h.sign) && h.sign.Equals("1")).ToList().Count,
- acount = s.teachers.Where(h => h.aTime > 0).ToList().Count
- });
- return Ok(new { survey,exam, info, studies = moreInfo.Select(m => new { m.teac,m.stu}) });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-study-teachers()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-all-vote")]
- public async Task<IActionResult> FindAllVote(JsonElement requert)
- {
- try
- {
- //区级Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- //List<string> baseIds = await getId(client, id.GetString());
- List<object> votes = new();
- //List<string> aName = new();
- var query = $"select c.id,c.name,c.startTime,c.progress,c.owner,c.school from c ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{id}") }))
- {
- 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())
- {
- votes.Add(obj.ToObject<object>());
- }
- }
- }
-
- return Ok(new { votes });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-vote()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-vote-id")]
- public async Task<IActionResult> FindAllVoteTeacher(JsonElement requert)
- {
- try
- {
- //区级活动Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!requert.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<string> baseIds = await getId(client, areaId.GetString());
- //List<object> votes = new();
- List<(string id, string name)> ps = await getInfo(client, areaId.GetString()) ;
- //List<string> aName = new();
- List<Vote> votes = new List<Vote>();
- Vote vote = null;
- List<(string code,string url, int count)> recordUrl = new List<(string code, string url, int count)>();
- var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Vote-{areaId}"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- vote = json.ToObject<Vote>();
- var query = $"select c.tchLists,c.recordUrl from c where c.pId = '{id}'";
- foreach (string code in baseIds)
- {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{code}") }))
- {
- using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
- if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = sjson.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- List<string> tcs = account.GetProperty("tchLists").ToObject<List<string>>();
- (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, tcs, code);
- recordUrl.Add((code,account.GetProperty("recordUrl").GetString(),tchList.Count));
- }
- }
- }
- }
- }
-
- //var info = ps.Select(p => new { p.id, p.name });
- return Ok(new { vote , code = recordUrl.Select(r => new { r.code, r.url,r.count }) });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-vote-teachers()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-all-survey")]
- public async Task<IActionResult> FindAllSurvey(JsonElement requert)
- {
- try
- {
- //区级Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- //List<string> baseIds = await getId(client, id.GetString());
- List<object> surveys = new();
- // List<string> aName = new();
- var query = $"select c.id,c.name,c.startTime,c.progress,c.sType,c.owner,c.school from c ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{id}") }))
- {
- 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())
- {
- surveys.Add(obj.ToObject<object>());
- }
- }
- }
-
- return Ok(new { surveys });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-survey()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-survey-id")]
- public async Task<IActionResult> FindAllSurveyTeacher(JsonElement requert)
- {
- try
- {
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!requert.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<string> baseIds = await getId(client, areaId.GetString());
- List<object> surveys = new();
- Survey survey = null;
- List<(string code, string url, int count)> recordUrl = new List<(string code, string url, int count)>();
- var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Survey-{areaId}"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- survey = json.ToObject<Survey>();
- var query = $"select c.tchLists,c.recordUrl from c where c.pId = '{id}'";
- foreach (string code in baseIds)
- {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{code}") }))
- {
- using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
- if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = sjson.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- List<string> tcs = account.GetProperty("tchLists").ToObject<List<string>>();
- (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, tcs, code);
- recordUrl.Add((code,account.GetProperty("recordUrl").GetString(),tchList.Count));
- }
- }
- }
- }
- }
- //var info = ps.Select(p => new { p.id, p.name });
- return Ok(new { survey, code = recordUrl.Select(r => new { r.code,r.url,r.count }) });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-survey-teachers()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-all-Exam")]
- public async Task<IActionResult> FindAllExam(JsonElement requert)
- {
- try
- {
- //区级Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- //List<string> baseIds = await getId(client, id.GetString());
- List<object> exams = new();
- // List<string> aName = new();
- var query = $"select c.id,c.name,c.createTime,c.sType,c.owner,c.school from c ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamLite-{id}") }))
- {
- 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())
- {
- exams.Add(obj.ToObject<object>());
- }
- }
- }
-
- return Ok(new { exams });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-exam()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("find-all-exam-teachers")]
- public async Task<IActionResult> FindAllExamTeacher(JsonElement requert)
- {
- try
- {
- //区级活动Id
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!requert.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<string> baseIds = await getId(client, areaId.GetString());
- List<object> exams = new();
- List<(string id, string name)> ps = await getInfo(client, areaId.GetString());
- //List<string> aName = new();
- var query = $"select c.school,c.teachers from c where c.acId = '{id}'";
- foreach (string code in baseIds)
- {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TrExam-{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())
- {
- exams.Add(obj.ToObject<object>());
- }
- }
- }
- }
- var info = ps.Select(p => new { p.id, p.name });
- return Ok(new {info,exams });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-exam-teachers()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 保存投票信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher,admin")]
- [HttpPost("save-vote")]
- public async Task<IActionResult> SaveVote(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("para", out JsonElement para)) return BadRequest();
- if (!request.TryGetProperty("vote", out JsonElement vote)) return BadRequest();
- List<parameter> parameters = para.ToObject<List<parameter>>();
- List<Vote> votes = new();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- var client = _azureCosmos.GetCosmosClient();
- Vote areaVote = vote.ToObject<Vote>();
- areaVote.owner = "area";
- areaVote.ttl = -1;
- areaVote.code = "Vote-" + id.GetString();
- areaVote.createTime = now;
- if (areaVote.startTime <= 0)
- {
- areaVote.startTime = now;
- }
- if (areaVote.startTime > now)
- {
- areaVote.progress = "pending";
- }
- else
- {
- areaVote.progress = "going";
- }
- if (string.IsNullOrEmpty(areaVote.id))
- {
- areaVote.id = Guid.NewGuid().ToString();
- }
- List<string> allName = new();
- foreach (parameter pa in parameters)
- {
- Vote trVote = vote.ToObject<Vote>();
- string code = pa.sId;
- trVote.school = code;
- trVote.ttl = -1;
- trVote.code = "Vote-" + code;
- trVote.createTime = now;
- trVote.areaId = id.GetString();
- trVote.owner = "area";
- trVote.pId = areaVote.id;
- trVote.tchLists = pa.gId;
- trVote.targetType = "research";
- if (trVote.startTime <= 0)
- {
- trVote.startTime = now;
- }
- if (trVote.startTime > now)
- {
- trVote.progress = "pending";
- }
- else
- {
- trVote.progress = "going";
- }
-
- if (pa.gName.Count == 0)
- {
- string sName = pa.sName + "-" + "所有老师(未分组)";
- allName.Add(sName);
- string json = "所有老师(未分组)";
- //var json = new { name = "所有老师(未分组)" };
- trVote.targets.Add(json.ToJsonString().ToObject<JsonElement>());
- }
- else
- {
- var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
- trVote.targets = tn;
- foreach (string name in pa.gName)
- {
- //处理区级target
- string sName = pa.sName + "-" + name;
- allName.Add(sName);
- }
- }
- if (string.IsNullOrEmpty(trVote.id))
- {
- trVote.id = Guid.NewGuid().ToString();
- string url = $"/vote/{trVote.id}/record.json";
- trVote.recordUrl = url;
- await _azureStorage.UploadFileByContainer(code, new { options = new List<string>(), records = new List<VoteRecord>() }.ToJsonString(), "vote", $"{trVote.id}/record.json");
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(trVote, new PartitionKey($"{trVote.code}"));
- }
- else
- {
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(trVote, trVote.id, new PartitionKey($"{trVote.code}"));
- }
- votes.Add(trVote);
- }
- var atn = allName.ToJsonString().ToObject<List<JsonElement>>();
- /*List<JsonElement> atn = new List<JsonElement>();
- foreach (string agn in allName)
- {
- atn.Add(agn.ToObject<JsonElement>());
- }*/
- areaVote.targets =atn;
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaVote, new PartitionKey($"{areaVote.code}"));
- var ids = votes.Select(s => new { s.id, s.school });
- return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/save-vote()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "Teacher")]
- [HttpPost("delete")]
- public async Task<IActionResult> Delete(JsonElement request)
- {
- try
- {
- //区级活动Id
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- //区级id
- if (!request.TryGetProperty("areaId", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("pk", out JsonElement pk)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{pk}-{code}"));
- List<string> bascId = await getId(client,code.GetString());
- List<(string id, string name)> ids = new();
- foreach (string sId in bascId) {
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select c.id,c.code from c where c.pId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{pk}-{sId}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- ids.Add((account.GetProperty("id").GetString(), account.GetProperty("code").GetString()));
- }
- }
- }
- }
- if (ids.Count > 0)
- {
- foreach ((string s, string c) in ids)
- {
- if (c.Contains("Study")) {
- var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(s.ToString(), new PartitionKey($"{c}"));
- 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-{study.school}"));
- }
- if (!string.IsNullOrEmpty(study.surveyId))
- {
- await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(study.surveyId, new PartitionKey($"Survey-{study.school}"));
- }
- }
- }
- await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(s.ToString(), new PartitionKey($"{c}"));
- }
- }
- return Ok(new { id, code = response.Status });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/delete()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 保存问卷信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher,admin")]
- [HttpPost("save-survey")]
- public async Task<IActionResult> SaveSurvey(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("para", out JsonElement para)) return BadRequest();
- if (!request.TryGetProperty("survey", out JsonElement survey)) return BadRequest();
- List<parameter> parameters = para.ToObject<List<parameter>>();
- List<Survey> surveys = new();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- var client = _azureCosmos.GetCosmosClient();
- Survey areaSurvey = survey.ToObject<Survey>();
- areaSurvey.owner = "area";
- areaSurvey.ttl = -1;
- areaSurvey.code = "Survey-" + id.GetString();
- areaSurvey.createTime = now;
- if (areaSurvey.startTime <= 0)
- {
- areaSurvey.startTime = now;
- }
- if (areaSurvey.startTime > now)
- {
- areaSurvey.progress = "pending";
- }
- else
- {
- areaSurvey.progress = "going";
- }
- if (string.IsNullOrEmpty(areaSurvey.id))
- {
- areaSurvey.id = Guid.NewGuid().ToString();
- }
- List<string> allName = new();
- foreach (parameter pa in parameters)
- {
- Survey trSurvey = survey.ToObject<Survey>();
- string code = pa.sId;
- trSurvey.ttl = -1;
- trSurvey.school = code;
- trSurvey.code = "Survey-" + code;
- trSurvey.createTime = now;
- trSurvey.areaId = id.GetString();
- trSurvey.owner = "area";
- trSurvey.tchLists = pa.gId;
- trSurvey.pId = areaSurvey.id;
- trSurvey.targetType = "research";
- if (areaSurvey.startTime <= 0)
- {
- areaSurvey.startTime = now;
- }
- if (trSurvey.startTime > now)
- {
- trSurvey.progress = "pending";
- }
- else
- {
- trSurvey.progress = "going";
- }
-
- if (pa.gName.Count == 0)
- {
- string sName = pa.sName + "-" + "所有老师(未分组)";
- allName.Add(sName);
- string json = "所有老师(未分组)";
- trSurvey.targets.Add(json.ToJsonString().ToObject<JsonElement>());
- }
- else
- {
- var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
- trSurvey.targets = tn;
- foreach (string name in pa.gName)
- {
- //处理区级target
- string sName = pa.sName + "-" + name;
- allName.Add(sName);
- }
- }
- await getMoreSurvey(pa, trSurvey);
- if (string.IsNullOrEmpty(trSurvey.id))
- {
- trSurvey.id = Guid.NewGuid().ToString();
- trSurvey.recordUrl = $"/survey/{trSurvey.id}/record.json";
- var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
- await _azureStorage.UploadFileByContainer(code, cods.ToJsonString(), "survey", $"{trSurvey.id}/record.json");
- // trSurvey.blob = SurveyService.getBlob(trSurvey.id);
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(trSurvey, new PartitionKey($"{trSurvey.code}"));
- }
- else
- {
- // trSurvey.blob = SurveyService.getBlob(trSurvey.id);
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(trSurvey, new PartitionKey($"{trSurvey.code}"));
- }
- surveys.Add(trSurvey);
- }
- //areaSurvey.targets = allName;
- var atn = allName.ToJsonString().ToObject<List<JsonElement>>();
- areaSurvey.targets = atn;
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaSurvey, new PartitionKey($"{areaSurvey.code}"));
- var ids = surveys.Select(s => new { s.id, s.school });
- return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/save-survey()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 保存评测信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher,admin")]
- [HttpPost("save-exam")]
- public async Task<IActionResult> SaveExam(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("para", out JsonElement para)) return BadRequest();
- if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
- List<parameter> parameters = para.ToObject<List<parameter>>();
- List<ExamLite> exams = new();
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- var client = _azureCosmos.GetCosmosClient();
- ExamLite areaExam = exam.ToObject<ExamLite>();
- areaExam.owner = "area";
- areaExam.ttl = -1;
- areaExam.code = "TrExam-" + id.GetString();
- areaExam.createTime = now;
- if (string.IsNullOrEmpty(areaExam.id))
- {
- areaExam.id = Guid.NewGuid().ToString();
- }
- List<string> allName = new();
- foreach (parameter pa in parameters)
- {
- ExamLite trExam = exam.ToObject<ExamLite>();
- string code = pa.sId;
- trExam.ttl = -1;
- trExam.school = code;
- trExam.code = "TrExam-" + code;
- trExam.createTime = now;
- trExam.areaId = id.GetString();
- trExam.owner = "area";
- trExam.pId = areaExam.id;
- trExam.targetType = "research";
- if (pa.gName.Count == 0)
- {
- string sName = pa.sName + "-" + "所有老师(未分组)";
- allName.Add(sName);
- }
- else
- {
- foreach (string name in pa.gName)
- {
- //处理区级target
- string sName = pa.sName + "-" + name;
- allName.Add(sName);
- }
- }
- await getMoreExam(pa, trExam);
- if (string.IsNullOrEmpty(trExam.id))
- {
- trExam.id = Guid.NewGuid().ToString();
- // trExam.blob = ExamService.getBlob(trExam.id);
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(trExam, new PartitionKey($"{trExam.code}"));
- }
- else
- {
- //trExam.blob = ExamService.getBlob(trExam.id);
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(trExam, trExam.id, new PartitionKey($"{trExam.code}"));
- }
- exams.Add(trExam);
- }
- //areaExam.targets = allName;
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaExam, new PartitionKey($"{areaExam.code}"));
- var ids = exams.Select(s => new { s.id, s.school });
- return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},area/save-exam()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- private async Task<List<string>> getId(CosmosClient client, string id)
- {
- //获取区级以下所有学校编码和基础信息
- List<string> baseIds = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.areaId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- baseIds.Add(account.GetProperty("id").GetString());
- }
- }
- }
- return baseIds;
- }
- private async Task<List<teacherInfo>> GetTeacherAll(string name, string code)
- {
- var client = _azureCosmos.GetCosmosClient();
- string query = string.Empty;
- List<teacherInfo> teachers = new List<teacherInfo>();
- if (string.IsNullOrEmpty(name))
- {
- query = $"SELECT c.id, c.name, c.groupName FROM c ";
- }
- else
- {
- query = $"SELECT c.id, c.name, c.groupName FROM c where c.groupName = '{name}'";
- }
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<teacherInfo>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{code}") }))
- {
- teachers.Add(item);
- }
- return teachers;
- }
- private Task<ExamLite> getMoreExam(parameter pa, ExamLite trExam)
- {
- if (pa.gName.Count == 0)
- {
- string json = "所有老师(未分组)";
- trExam.targets.Add(json.ToJsonString().ToObject<JsonElement>());
-
- }
- else
- {
- var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
- trExam.targets = tn;
- }
- return Task.FromResult(trExam);
- }
- private Task<Survey> getMoreSurvey(parameter pa, Survey trSurvey)
- {
- if (pa.gName.Count == 0)
- {
- //trSurvey.targets.Add("所有老师(未分组)");
- string json = "所有老师(未分组)";
- trSurvey.targets.Add(json.ToJsonString().ToObject<JsonElement>());
- }
- else
- {
- var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
- trSurvey.targets = tn;
- }
- return Task.FromResult(trSurvey);
- }
- private async Task<List<(string id, string name)>> getInfo(CosmosClient client, string id) {
- List<(string id, string name)> scInfos = new List<(string id, string name)>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name from c where c.areaId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- scInfos.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString()));
- }
- }
- }
- return scInfos;
- }
- public class parameter
- {
- public string sId { get; set; }
- public string sName { get; set; }
- public List<string> gName { get; set; }
- public List<string> gId { get; set; }
- }
- public class teacherInfo
- {
- public string id { get; set; }
- public string name { get; set; }
- public string groupName { get; set; }
- }
- }
- }
|