123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using Microsoft.Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Pipelines.Sockets.Unofficial.Arenas;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using static TEAMModelOS.SDK.Models.Teacher;
- 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").GetItemQueryIteratorSql<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 });
- }
- /// <summary>
- /// 修复教师个人信息学校重复的问题
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [HttpPost("set-tchsc")]
- public async Task<IActionResult> SetTchSchool(JsonElement jsonElement)
- {
- jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- StringBuilder tchSql = new($"select * from c");
- if (!string.IsNullOrEmpty($"{tmdId}"))
- tchSql.Append($" where c.id='{tmdId}'");
- List<Teacher> tchs = new();
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIteratorSql<Teacher>(queryText: tchSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- tchs.Add(item);
- }
- foreach (Teacher tch in tchs)
- {
- int oldScCnt = 0;
- List<TeacherSchool> remoSc = new();
- oldScCnt = tch.schools.Count();
- if (tch != null)
- {
- foreach (var teacher in tch.schools)
- {
- var resSc = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{teacher.schoolId}", new PartitionKey("Base"));
- if (resSc.StatusCode == System.Net.HttpStatusCode.OK)
- {
- using var areaBase = await JsonDocument.ParseAsync(resSc.Content);
- School school = areaBase.ToObject<School>();
- if (teacher.areaId != school.areaId)
- teacher.areaId = school.areaId;
- }
- else
- {
- remoSc.Add(teacher);
- }
- }
- }
- remoSc.ForEach(fe => tch.schools.Remove(fe));
- List<TeacherSchool> tchSc = tch.schools.Where((x, i) => tch.schools.FindIndex(y => y.schoolId.Equals(x.schoolId)) == i).ToList();
- if (oldScCnt > tchSc.Count)
- {
- tch.schools = tchSc;
- await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(tch, tch.id, new PartitionKey("Base"));
- }
- }
- return Ok(new { state = 200 });
- }
- }
- }
|