|
@@ -38,6 +38,7 @@ using DocumentFormat.OpenXml.Drawing.Diagrams;
|
|
|
using TEAMModelOS.SDK.Models.Dtos;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
using System.Formats.Asn1;
|
|
|
+using System.Xml.Linq;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -3448,6 +3449,65 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 学校id将大写转换小写 并新增学校相关数据信息;修改教师学校的id
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("fix-uppertolower")]
|
|
|
+ public async Task<IActionResult> RepairUpperToLower(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ string large = "GXJCXX";
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ List<string> containe = new() { "School", "Student", "Teacher" };
|
|
|
+
|
|
|
+ List<dynamic> noFail = new();
|
|
|
+ foreach (var itemC in containe)
|
|
|
+ {
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, itemC).GetItemQueryStreamIterator(queryText: $"select value(c) from c where (contains(c.code,'{large}') or contains(c.id,'{large}'))"))
|
|
|
+ {
|
|
|
+ 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())
|
|
|
+ {
|
|
|
+ string oldId = obj.GetProperty("id").GetString();
|
|
|
+ string oldCode = obj.GetProperty("code").GetString();
|
|
|
+ var jsonElm = obj.ToJsonString().Replace(large, large.ToLower()).ToObject<JsonElement>();
|
|
|
+ jsonElm.TryGetProperty("code", out JsonElement code);
|
|
|
+ byte[] bytes = Encoding.UTF8.GetBytes(jsonElm.GetRawText());
|
|
|
+ var memoryStream = new MemoryStream(bytes);
|
|
|
+ var resp = await cosmosClient.GetContainer(Constant.TEAMModelOS, itemC).CreateItemStreamAsync(memoryStream, new PartitionKey($"{code}"));
|
|
|
+ if (resp.Status != 201)
|
|
|
+ noFail.Add(new { container = itemC, id = oldId, code = oldCode });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c join sc in c.schools where sc.schoolId='{large}'",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)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ var jsonElm = obj.ToJsonString().Replace(large, large.ToLower()).ToObject<JsonElement>();
|
|
|
+ jsonElm.TryGetProperty("id", out JsonElement id);
|
|
|
+ jsonElm.TryGetProperty("code", out JsonElement code);
|
|
|
+ byte[] bytes = Encoding.UTF8.GetBytes(jsonElm.GetRawText());
|
|
|
+ var memoryStream = new MemoryStream(bytes);
|
|
|
+ var resp = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemStreamAsync(memoryStream, $"{id}", new PartitionKey($"Base"));
|
|
|
+ if(resp.Status != 200)
|
|
|
+ noFail.Add(new { container = "Teacher", id = id, code = code });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = 200, noFail });
|
|
|
+ }
|
|
|
+
|
|
|
public record TrainingId
|
|
|
{
|
|
|
public string oldId { get; set; }
|