|
@@ -0,0 +1,140 @@
|
|
|
+using Azure;
|
|
|
+using Azure.Cosmos;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+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.Helper.Common.CollectionHelper;
|
|
|
+
|
|
|
+namespace TEAMModelOS.SDK.Models.Service
|
|
|
+{
|
|
|
+ public static class FixDataService
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 修复学生数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="client"></param>
|
|
|
+ /// <param name="_dingDing"></param>
|
|
|
+ /// <param name="_azureStorage"></param>
|
|
|
+ /// <param name="data"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static async Task FixStudentInfo(CosmosClient client, DingDing _dingDing, AzureStorageFactory _azureStorage, JsonElement data) {
|
|
|
+ var code = data.GetProperty("code").GetString();
|
|
|
+ var ids = data.GetProperty("ids").ToObject<List<string>>();
|
|
|
+ var dict = data.GetProperty("dict").ToObject<Dictionary<string, object>>();
|
|
|
+ string queryText = $"SELECT VALUE c FROM c WHERE c.id IN ({string.Join(",", ids.Select(o => $"'{o}'"))})";
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Student")
|
|
|
+ .GetItemQueryIterator<Student>(
|
|
|
+ queryText: queryText,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") })) {
|
|
|
+ foreach (var key in dict.Keys) {
|
|
|
+ switch (key) {
|
|
|
+ case "classId":
|
|
|
+ item.classId =$"{ dict[key]}";
|
|
|
+ break;
|
|
|
+ case "periodId":
|
|
|
+ item.periodId = $"{ dict[key]}";
|
|
|
+ break;
|
|
|
+ case "schoolId":
|
|
|
+ item.schoolId = $"{ dict[key]}";
|
|
|
+ break;
|
|
|
+ case "year":
|
|
|
+ int year = DateTime.Now.Year;
|
|
|
+ int.TryParse($"dict[key]", out year);
|
|
|
+ item.year = year;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ students.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Task<ItemResponse<Student>>> studen = new List<Task<ItemResponse<Student>>>();
|
|
|
+ students.ForEach(x => {
|
|
|
+ studen.Add(client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<Student>(x,x.id,new PartitionKey(x.code)));
|
|
|
+ });
|
|
|
+ await Task.WhenAll(studen);
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 修复内容模块数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="client"></param>
|
|
|
+ /// <param name="_dingDing"></param>
|
|
|
+ /// <param name="_azureStorage"></param>
|
|
|
+ /// <param name="data"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static async Task FixBlobContent(CosmosClient client, DingDing _dingDing, AzureStorageFactory _azureStorage, JsonElement data)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (data.TryGetProperty("name", out JsonElement _name))
|
|
|
+ {
|
|
|
+ List<string> names = _name.ToObject<List<string>>();
|
|
|
+ foreach (string name in names)
|
|
|
+ {
|
|
|
+ List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
|
|
|
+ var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
|
|
|
+ string scope = "private";
|
|
|
+ if (data.TryGetProperty("scope", out JsonElement _scope))
|
|
|
+ {
|
|
|
+ scope = $"{_scope}";
|
|
|
+ }
|
|
|
+ var tb = "Teacher";
|
|
|
+ if (scope != "private")
|
|
|
+ {
|
|
|
+ tb = "School";
|
|
|
+ }
|
|
|
+ List<string> ids = new List<string>();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", tb).GetItemQueryIterator<Bloblog>(queryDefinition: new QueryDefinition("select c.id from c "), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
+ {
|
|
|
+ ids.Add(item.id);
|
|
|
+ }
|
|
|
+ await client.GetContainer("TEAMModelOS", tb).DeleteItemsStreamAsync(ids, $"Bloblog-{name}");
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ foreach (var prefix in prefixs)
|
|
|
+ {
|
|
|
+ if (prefix.Equals("res"))
|
|
|
+ {
|
|
|
+ List<string> itemres = await ContainerClient.List(prefix);
|
|
|
+ if (itemres.IsNotEmpty()) {
|
|
|
+ HashSet<string> set = new HashSet<string>();
|
|
|
+ itemres.ForEach(x =>
|
|
|
+ {
|
|
|
+ var uri = x.Split("/");
|
|
|
+ set.Add($"res/{uri[1]}");
|
|
|
+ });
|
|
|
+ foreach (var item in set)
|
|
|
+ {
|
|
|
+ var urlsSize = await ContainerClient.GetBlobsSize(item);
|
|
|
+ var url = item;
|
|
|
+ if (!item.EndsWith(".hte", StringComparison.OrdinalIgnoreCase) && !item.EndsWith(".HTEX", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ url += ".HTEX";
|
|
|
+ }
|
|
|
+ Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = url, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
|
|
|
+ await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ List<string> items = await ContainerClient.List(prefix);
|
|
|
+ if (items.IsNotEmpty()) {
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ var urlsSize = await ContainerClient.GetBlobsSize(item);
|
|
|
+ Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = item, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
|
|
|
+ await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|