|
@@ -32,6 +32,8 @@ using System.Text;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
+using static TEAMModelBI.Controllers.RepairApi.InitialAreaController;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BINormal
|
|
|
{
|
|
@@ -1005,6 +1007,285 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
else return Ok(new { state = 404,msg="依据Id未找到该区!" });
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 同步两个区到新的区中
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
+ [HttpPost("cut-full-statndard")]
|
|
|
+ public async Task<IActionResult> CutFullStandard(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ string _oldId = "bde5c011-2ae4-461a-b46c-5483ba72ae45";
|
|
|
+ string _oldStandard = "standard27";
|
|
|
+ string standardFileId = "02944f32-f534-3397-ea56-e6f1fc6c3714";
|
|
|
+ string standard = "standard2";
|
|
|
+
|
|
|
+ List<CopyStandard> copyStand = new()
|
|
|
+ {
|
|
|
+ new CopyStandard() { id = standardFileId, standard = standard },
|
|
|
+ new CopyStandard() { id = "99a4a33b-e21b-44ac-80a1-b31dc40496e0", standard = "standard3" }
|
|
|
+ };
|
|
|
+
|
|
|
+ var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var serBusClient = _serviceBus.GetServiceBusClient();
|
|
|
+ var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
|
|
|
+
|
|
|
+ var table = tableClient.GetTableReference("IESLogin");
|
|
|
+
|
|
|
+ var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
|
|
|
+ if (responseSet.Status == 200)
|
|
|
+ {
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
|
|
|
+ AreaSetting delSet = fileJson.ToObject<AreaSetting>();
|
|
|
+ if (!string.IsNullOrEmpty(delSet.accessConfig))
|
|
|
+ return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
|
|
|
+ }
|
|
|
+
|
|
|
+ List<string> abilityIds = new List<string>(); //册别的ID集合
|
|
|
+
|
|
|
+ //查询册别信息
|
|
|
+ await foreach (var tempAbility in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{_oldStandard}") }))
|
|
|
+ {
|
|
|
+ abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
|
|
|
+ }
|
|
|
+ //删除册别
|
|
|
+ if (abilityIds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{_oldStandard}");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<string> abilityTaskIds = new List<string>(); //章节ID集合
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{_oldStandard}") }))
|
|
|
+ {
|
|
|
+ abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
|
|
|
+ }
|
|
|
+ //删除章节
|
|
|
+ if (abilityTaskIds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{_oldStandard}");
|
|
|
+ }
|
|
|
+ List<Task<ItemResponse<Ability>>> abilities = new(); //存储册别数据
|
|
|
+ List<Task<ItemResponse<AbilityTask>>> abilityTasks = new(); //存储章节
|
|
|
+
|
|
|
+ List<string> repeatAbilityId = new();
|
|
|
+ List<string> repeatAbilityTaskId = new();
|
|
|
+
|
|
|
+ foreach (var newstand in copyStand)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //查询要复制区域的能力标准点
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{newstand.standard}") }))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(item.blob))
|
|
|
+ item.blob = item.blob.Replace($"/{newstand.standard}/", $"/{_oldStandard}/");
|
|
|
+
|
|
|
+ item.standard = $"{_oldStandard}";
|
|
|
+ item.code = $"Ability-{_oldStandard}";
|
|
|
+ item.school = $"{_oldStandard}";
|
|
|
+
|
|
|
+ //添加区能力标准点
|
|
|
+ //abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
|
|
|
+ //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}"));
|
|
|
+
|
|
|
+ var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(item.id, new PartitionKey(item.code));
|
|
|
+ if (respond.Status != 200)
|
|
|
+ abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
|
|
|
+ else
|
|
|
+ repeatAbilityId.Add(item.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (abilities.Count < 256)
|
|
|
+ {
|
|
|
+ await Task.WhenAll(abilities);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (abilities.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempAbility);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //微能力点
|
|
|
+ await foreach (var atask in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{newstand.standard}") }))
|
|
|
+ {
|
|
|
+ List<Tnode> tnodes = new();
|
|
|
+ foreach (Tnode tnode in atask.children)
|
|
|
+ {
|
|
|
+ if (tnode.rnodes != null)
|
|
|
+ {
|
|
|
+ List<Rnode> rnodes = new();
|
|
|
+ foreach (Rnode rnode in tnode.rnodes)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty($"{rnode.link}"))
|
|
|
+ {
|
|
|
+ rnode.link = rnode.link.Replace($"/{newstand.standard}/", $"/{_oldStandard}/");
|
|
|
+ }
|
|
|
+ rnodes.Add(rnode);
|
|
|
+ }
|
|
|
+ tnode.rnodes = rnodes;
|
|
|
+ }
|
|
|
+ tnodes.Add(tnode);
|
|
|
+ }
|
|
|
+
|
|
|
+ atask.children = tnodes;
|
|
|
+ atask.code = $"AbilityTask-{_oldStandard}";
|
|
|
+ atask.standard = $"{_oldStandard}";
|
|
|
+ atask.codeval = $"{_oldStandard}";
|
|
|
+
|
|
|
+ var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(atask.id, new PartitionKey(atask.code));
|
|
|
+ if (respond.Status != 200)
|
|
|
+ ////添加区能力标准点中的节点
|
|
|
+ //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}"));
|
|
|
+ else
|
|
|
+ repeatAbilityTaskId.Add(atask.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送消息分区键
|
|
|
+ string partitionCode = "DelBeforeCopyAbility-mark";
|
|
|
+
|
|
|
+ //执行复制操作
|
|
|
+ BatchCopyFile batchCopyFile = new();
|
|
|
+ batchCopyFile.blobCntr = "teammodelos";
|
|
|
+ batchCopyFile.oldFileName = $"{newstand.standard}";
|
|
|
+ batchCopyFile.newFileName = $"{_oldStandard}";
|
|
|
+ batchCopyFile.tmdid = $"{_tmdId}";
|
|
|
+ batchCopyFile.tmdIds = new List<string> { $"{_tmdId}" };
|
|
|
+ batchCopyFile.codeKey = partitionCode;
|
|
|
+ batchCopyFile.tmdName = $"{_tmdName}";
|
|
|
+ var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
|
|
|
+ messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制 单一
|
|
|
+ await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送消息实体
|
|
|
+ Notification notification = new()
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"BI:{_option.Location}:private",
|
|
|
+ to = new List<string> { $"{_tmdId}" },
|
|
|
+ label = $"{partitionCode}_start",
|
|
|
+ body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
|
|
|
+ }
|
|
|
+
|
|
|
+ StandardFile saveFile = new();
|
|
|
+ //新政策文件
|
|
|
+ await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
|
|
|
+ {
|
|
|
+ if (standardFile != null)
|
|
|
+ {
|
|
|
+ standardFile.standard = $"{_oldStandard}";
|
|
|
+ standardFile.id = $"{_oldId}";
|
|
|
+
|
|
|
+ saveFile = standardFile;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ StandardFile tempFile = new();
|
|
|
+ if (saveFile.id != null)
|
|
|
+ {
|
|
|
+ var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
|
|
|
+ if (respFile.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
|
|
|
+ tempFile = json.ToObject<StandardFile>();
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
|
|
|
+ }
|
|
|
+
|
|
|
+ tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
|
|
|
+ }
|
|
|
+
|
|
|
+ //if (tempFile.id != null)
|
|
|
+ //{
|
|
|
+ // if (tempFile.id.Equals(saveFile.id))
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
|
|
|
+ // else
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
|
|
|
+ //}
|
|
|
+
|
|
|
+ //新的区域设置
|
|
|
+ AreaSetting saveSetting = new();
|
|
|
+ await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
|
|
|
+ {
|
|
|
+ if (areaSetting != null)
|
|
|
+ {
|
|
|
+ areaSetting.accessConfig = null;
|
|
|
+ areaSetting.id = $"{_oldId}";
|
|
|
+
|
|
|
+ saveSetting = areaSetting;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ AreaSetting tempSetting = new();
|
|
|
+ if (saveSetting.id != null)
|
|
|
+ {
|
|
|
+ var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
|
|
|
+ if (respSetting.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
|
|
|
+ tempSetting = json.ToObject<AreaSetting>();
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(tempFile.id, new PartitionKey("AreaSetting"));
|
|
|
+ }
|
|
|
+
|
|
|
+ tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
|
|
|
+ }
|
|
|
+
|
|
|
+ //if (tempSetting.id != null)
|
|
|
+ //{
|
|
|
+ // if (tempSetting.id.Equals(saveSetting.id))
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting")); //直接替换以前的数据
|
|
|
+ // else
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
|
|
|
+ //}
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, repeatAbilityId, repeatAbilityTaskId });
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 区域列表
|
|
|
/// </summary>
|