using Azure.Cosmos; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; using TEAMModelOS.SDK.DI; using TEAMModelOS.SDK.Models; namespace TEAMModelBI.Controllers.RepairApi { [Route("teacherrep")] [ApiController] public class TeacherREPController : ControllerBase { private readonly AzureCosmosFactory _azureCosmos; public TeacherREPController(AzureCosmosFactory azureCosmos) { _azureCosmos = azureCosmos; } List schools = new() { "dghznx", "cxhhlx", "xjaxx", "zjqxx", "xnygxx", "lxxcfx", "gxjrxx", "cdgxsx", "yzxx", "kjyxx", "wjylxx", "dsgjxx", "ydzt", "xndbxx", "sqtszx", "cdxczx", "ghsyzx", "lqsx", "cdxxps", "xcfx", "xyqxx", "xncbyy", "cdlqjk", "lqdmxx", "lqyx", "pclxxx", "cdfzx", "xnblxx", "ghsx", "khdycz", "khbmxx", "khdecz", "khzx", "khhbzx", "gxxcxx", "khhtxx", "khdxxx", "khsyxx" }; /// /// 修改教师学校信息 /// /// /// [HttpPost("get-teachersc")] public async Task SetTeacherSchool(JsonElement json) { var cosmosClient = _azureCosmos.GetCosmosClient(); foreach (var item in schools) { School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync($"{item}", new PartitionKey("Base")); List teachers = new(); await foreach (var tch in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator(queryText: $"SELECT value(c) FROM c join s in c.schools where s.schoolId='dghznx' and c.code='Base'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) { teachers.Add(tch); } if (teachers.Count > 0) { foreach (var teacher in teachers) { teacher.schools.ForEach(tch => { if (tch.schoolId.Equals(item)) { tch.areaId = school.areaId; } }); await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(teacher, teacher.id, new PartitionKey("Base")); } } } return Ok(new { state = 200 }); } } }