|
@@ -23,6 +23,10 @@ using System.Text;
|
|
|
using Azure.Storage.Sas;
|
|
|
using Azure.Storage.Blobs.Specialized;
|
|
|
using Azure;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
|
|
|
namespace TEAMModeBI.Controllers.BISchool
|
|
|
{
|
|
@@ -35,14 +39,18 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
private readonly Option _option;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly IConfiguration _configuration;
|
|
|
+ private readonly NotificationService _notificationService;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
|
|
|
- public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration)
|
|
|
+ public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration,NotificationService notificationService, AzureServiceBusFactory serviceBus)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_dingDing = dingDing;
|
|
|
_azureStorage = azureStorage;
|
|
|
_option = option?.Value;
|
|
|
_configuration = configuration;
|
|
|
+ _notificationService = notificationService;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -148,8 +156,10 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("standardName", out JsonElement standardName)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("institution", out JsonElement institution)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement _tmdid)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("tmdName", out JsonElement _tmdName)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("oldstandard", out JsonElement oldstandard)) return BadRequest();
|
|
|
-
|
|
|
+
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
//查询新的是否存在
|
|
|
await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c where c.standard='{standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
|
|
@@ -190,14 +200,7 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(item.blob))
|
|
|
{
|
|
|
- //string _oldurl = item.blob; //要复制文件的位置
|
|
|
item.blob = item.blob.Replace($"{oldstandard}", $"{standard}");
|
|
|
- //string _newurl = item.blob; //文件目标位置
|
|
|
- //var blobcc = _azureStorage.GetBlobContainerClient("teammodelos"); //获取blob连接地址
|
|
|
- ////int index = $"{_oldurl}".IndexOf("/", 0); //第一次出现的位置
|
|
|
- //string oldUrl = $"{_oldurl}".IndexOf("/", 0) == 0 ? oldUrl = $"{_oldurl}".Substring(1) : oldUrl = $"{_oldurl}"; //判定指定位置是否出现指定字符,出现则删除,不出现直接使用地址
|
|
|
- //var urlSaS = _azureStorage.GetBlobSAS($"teammodelos", oldUrl, BlobSasPermissions.Read | BlobSasPermissions.List); // 取得容器sas和有效期
|
|
|
- //blobcc.GetBlobClient($"{_newurl}").SyncCopyFromUri(new Uri(urlSaS));//执行复制操作
|
|
|
};
|
|
|
|
|
|
item.standard = $"{standard}";
|
|
@@ -226,14 +229,7 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty($"{rnode.link}"))
|
|
|
{
|
|
|
- //string _oldurl = rnode.link; //要复制文件的位置
|
|
|
rnode.link = rnode.link.Replace($"{oldstandard}", $"{standard}");
|
|
|
- //string _newurl = rnode.link; //文件目标位置
|
|
|
- //var blobcc = _azureStorage.GetBlobContainerClient($"{rnode.cntr}"); //获取blob连接地址
|
|
|
- ////int index = $"{_oldurl}".IndexOf("/", 0); //第一次出现的位置
|
|
|
- //string oldUrl = $"{_oldurl}".IndexOf("/", 0) == 0 ? oldUrl = $"{_oldurl}".Substring(1) : oldUrl = $"{_oldurl}"; //判定指定位置是否出现指定字符,出现则删除,不出现直接使用地址
|
|
|
- //var urlSaS = _azureStorage.GetBlobSAS($"{rnode.cntr}", oldUrl, BlobSasPermissions.Read | BlobSasPermissions.List); // 取得容器sas和有效期
|
|
|
- ////blobcc.GetBlobClient($"{_newurl}").SyncCopyFromUri(new Uri(urlSaS));//执行复制操作
|
|
|
}
|
|
|
rnodes.Add(rnode);
|
|
|
}
|
|
@@ -257,30 +253,52 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
await Task.WhenAll(abilityTasks);
|
|
|
}
|
|
|
|
|
|
- Area area = null ;
|
|
|
-
|
|
|
- //查询要复制的区级信息
|
|
|
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c where c.standard='{oldstandard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
|
|
|
- {
|
|
|
-
|
|
|
- area = item ;
|
|
|
- }
|
|
|
- if (area != null)
|
|
|
+ //政策文件
|
|
|
+ StandardFile standardFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<StandardFile>($"{_tmdid}", new PartitionKey($"StandardFile"));
|
|
|
+ standardFile.standard = $"{standard}";
|
|
|
+ standardFile.id = areaId;
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
|
|
|
+
|
|
|
+ //区域配置
|
|
|
+ AreaSetting areaSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>($"{_tmdid}", new PartitionKey($"AreaSetting"));
|
|
|
+ areaSetting.accessConfig = null;
|
|
|
+ areaSetting.id = areaId;
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
|
|
|
+
|
|
|
+ //分区键
|
|
|
+ string code = "copyAbility-mark";
|
|
|
+
|
|
|
+ //执行复制操作
|
|
|
+ BatchCopyFile batchCopyFile = new BatchCopyFile();
|
|
|
+ batchCopyFile.blobCntr = "teammodelos";
|
|
|
+ batchCopyFile.oldFileName = $"{oldstandard}";
|
|
|
+ batchCopyFile.newFileName = $"{standard}";
|
|
|
+ batchCopyFile.tmdid = $"{_tmdid}";
|
|
|
+ batchCopyFile.tmdIds = new List<string> { $"{ _tmdid}" };
|
|
|
+ batchCopyFile.codeKey = code;
|
|
|
+ batchCopyFile.tmdName = $"{_tmdName}";
|
|
|
+ var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
|
|
|
+ messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
|
|
|
+ var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);
|
|
|
+
|
|
|
+ //发送消息实体
|
|
|
+ Notification notification = new Notification
|
|
|
{
|
|
|
- //政策文件
|
|
|
- StandardFile standardFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<StandardFile>(area.id, new PartitionKey($"StandardFile"));
|
|
|
- standardFile.standard = $"{standard}";
|
|
|
- standardFile.id = areaId;
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
|
|
|
-
|
|
|
- //区域配置
|
|
|
- AreaSetting areaSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey($"AreaSetting"));
|
|
|
- areaSetting.accessConfig = null;
|
|
|
- areaSetting.id = areaId;
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
|
|
|
- }
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{_option.Location}:private",
|
|
|
+ to = new List<string> {$"{ _tmdid}"},
|
|
|
+ label = $"{code}_start",
|
|
|
+ body = new { location = _option.Location, biz = code, tmdid = $"{_tmdid}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
|
|
|
- await BarchCopyFile("teammodelos", $"{oldstandard}", $"{standard}");
|
|
|
+ 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); //站内发送消息
|
|
|
|
|
|
return Ok(new { state = 200, abilitie = abilities1.Count, abilitieTasksCount = abilityTasks1.Count});
|
|
|
}
|
|
@@ -292,7 +310,7 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 测试复制Blob中的文件
|
|
|
+ /// 测试复制Blob中的文件 批量创区接口测试完成后删除
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
@@ -325,7 +343,11 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 批量复制文件接口 批量创区接口测试完成后删除
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("copybolbFile")]
|
|
|
public async Task<IActionResult> TestCopyBolbFile(JsonElement jsonElement)
|
|
@@ -337,39 +359,15 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
List<string> errmess = new List<string>();
|
|
|
List<string> fils = new List<string>();
|
|
|
List<Task<Response<BlobCopyInfo>>> file_list = new List<Task<Response<BlobCopyInfo>>>();
|
|
|
- var client = _azureStorage.GetBlobContainerClient($"{_cntr}");
|
|
|
+ var client = _azureStorage.GetBlobContainerClient($"{_cntr}");//获取地址
|
|
|
await foreach (BlobItem item in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"yxpt/{_oldstandard}/"))
|
|
|
{
|
|
|
fils.Add(item.Name);
|
|
|
-
|
|
|
- var blobcc = _azureStorage.GetBlobContainerClient($"teammodelos"); //获取地址
|
|
|
- string[] oldurl = $"{item.Name}".Split($"{_oldstandard}");
|
|
|
-
|
|
|
- string newurl = null;
|
|
|
- if (oldurl.Length == 2)
|
|
|
- {
|
|
|
- newurl = $"{oldurl[0]}{_newstandard}{oldurl[1]}";
|
|
|
- }
|
|
|
- else if (oldurl.Length > 2)
|
|
|
- {
|
|
|
- StringBuilder stringBuilder = new StringBuilder();
|
|
|
- stringBuilder.Append(oldurl[0]);
|
|
|
- stringBuilder.Append($"/{_newstandard}");
|
|
|
- for (int i = 1; i < oldurl.Length; i++)
|
|
|
- {
|
|
|
- stringBuilder.Append(oldurl[i]);
|
|
|
- }
|
|
|
- newurl = stringBuilder.ToString();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errmess.Add(item.Name);
|
|
|
- }
|
|
|
+ string oldurl1 = $"{item.Name}".Replace($"/{_oldstandard}/", $"/{_newstandard}/");
|
|
|
var urlSaS = _azureStorage.GetBlobSAS($"{_cntr}", item.Name, BlobSasPermissions.Read | BlobSasPermissions.List); // 取得容器sas 和有效期
|
|
|
|
|
|
- //blobcc.GetBlobClient($"{newurl}").SyncCopyFromUri(new Uri(urlSaS));
|
|
|
- file_list.Add(blobcc.GetBlobClient($"{newurl}").SyncCopyFromUriAsync(new Uri(urlSaS)));
|
|
|
- //file_list.Add
|
|
|
+ client.GetBlobClient(oldurl1).SyncCopyFromUri(new Uri(urlSaS));
|
|
|
+ //file_list.Add(blobcc.GetBlobClient($"{oldurl1}").SyncCopyFromUriAsync(new Uri(urlSaS)));
|
|
|
}
|
|
|
|
|
|
if (file_list.Count <= 256)
|
|
@@ -386,34 +384,12 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //var bolobcc = _azureStorage.GetBlobContainerClient($"{_cntr}"); //获取地址
|
|
|
-
|
|
|
- //string oldUrl = $"{_oldfile}";
|
|
|
- //var urlSaS = _azureStorage.GetBlobSAS($"{_cntr}", oldUrl, BlobSasPermissions.All); // 取得容器sas 和有效期
|
|
|
- ////var urlSaS = $"{bolobcc.Uri}/{_oldfile}";
|
|
|
- //BlobCopyFromUriOptions blobCopyFromUriOptions = new BlobCopyFromUriOptions();
|
|
|
- //blobCopyFromUriOptions.ShouldSealDestination = true;
|
|
|
- //var response = bolobcc.GetBlobClient($"{_newfile}").StartCopyFromUri(new Uri(urlSaS),blobCopyFromUriOptions);
|
|
|
- ////var response = bolobcc.GetBlobClient($"{_newfile}").SyncCopyFromUri(new Uri(urlSaS));
|
|
|
- ////var response = await bolobcc.GetBlobClient($"{_newfile}").SyncCopyFromUriAsync(new Uri(urlSaS));
|
|
|
-
|
|
|
return Ok(new { fils.Count, fils });
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 批量复制文件夹
|
|
|
+ /// 批量复制文件夹方法 批量创区接口测试完成后删除
|
|
|
/// </summary>
|
|
|
/// <param name="_cntr"></param>
|
|
|
/// <param name="_oldstandard"></param>
|
|
@@ -423,35 +399,14 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
{
|
|
|
List<string> errmess = new List<string>();
|
|
|
List<Task<Response<BlobCopyInfo>>> file_list = new List<Task<Response<BlobCopyInfo>>>();
|
|
|
- var client = _azureStorage.GetBlobContainerClient($"{_cntr}");
|
|
|
+ var client = _azureStorage.GetBlobContainerClient($"{_cntr}"); //获取地址
|
|
|
await foreach (BlobItem item in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"yxpt/{_oldstandard}/"))
|
|
|
{
|
|
|
- var blobcc = _azureStorage.GetBlobContainerClient($"teammodelos"); //获取地址
|
|
|
- string[] oldurl = $"{item.Name}".Split($"{_oldstandard}");
|
|
|
-
|
|
|
- string newurl = null;
|
|
|
- if (oldurl.Length == 2)
|
|
|
- {
|
|
|
- newurl = $"{oldurl[0]}{_newstandard}{oldurl[1]}";
|
|
|
- }
|
|
|
- else if (oldurl.Length > 2)
|
|
|
- {
|
|
|
- StringBuilder stringBuilder = new StringBuilder();
|
|
|
- stringBuilder.Append(oldurl[0]);
|
|
|
- stringBuilder.Append($"/{_newstandard}");
|
|
|
- for (int i = 1; i < oldurl.Length; i++)
|
|
|
- {
|
|
|
- stringBuilder.Append(oldurl[i]);
|
|
|
- }
|
|
|
- newurl = stringBuilder.ToString();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errmess.Add(item.Name);
|
|
|
- }//yxpt/standard6/jyzx/002ea332-0d1f-717c-0589-5f54c3c5ef4a/3 各班分数等级占比分析.mp4
|
|
|
+ string oldurl1 = $"{item.Name}".Replace($"/{_oldstandard}/", $"/{_newstandard}/");
|
|
|
+ //yxpt/standard6/jyzx/002ea332-0d1f-717c-0589-5f54c3c5ef4a/3 各班分数等级占比分析.mp4
|
|
|
var urlSaS = _azureStorage.GetBlobSAS($"{_cntr}", item.Name, BlobSasPermissions.Read | BlobSasPermissions.List); // 取得容器sas 和有效期
|
|
|
- //blobcc.GetBlobClient($"{newurl}").SyncCopyFromUri(new Uri(urlSaS));
|
|
|
- file_list.Add(blobcc.GetBlobClient($"{newurl}").SyncCopyFromUriAsync(new Uri(urlSaS)));
|
|
|
+ //client.GetBlobClient($"{newurl}").SyncCopyFromUri(new Uri(urlSaS));
|
|
|
+ file_list.Add(client.GetBlobClient($"{oldurl1}").SyncCopyFromUriAsync(new Uri(urlSaS)));
|
|
|
}
|
|
|
|
|
|
if (file_list.Count <= 256)
|