12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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<string> 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"
- };
- /// <summary>
- /// 修改教师学校信息
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [HttpPost("get-teachersc")]
- public async Task<IActionResult> SetTeacherSchool(JsonElement json)
- {
- var cosmosClient = _azureCosmos.GetCosmosClient();
- foreach (var item in schools)
- {
- School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{item}", new PartitionKey("Base"));
- List<Teacher> teachers = new();
- await foreach (var tch in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(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, teacher.id, new PartitionKey("Base"));
- }
- }
- }
- return Ok(new { state = 200 });
- }
- }
- }
|