|
@@ -25,90 +25,13 @@ using Azure.Storage.Sas;
|
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
|
using Azure.Core;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using System.Configuration;
|
|
|
|
|
|
namespace TEAMModelOS.SDK
|
|
|
{
|
|
|
public static class GenPDFService
|
|
|
{
|
|
|
- public static async Task<(PDFGenRedis genRedis, PDFGenQueue genQueue,string msg )> SentTask(AzureRedisFactory _azureRedis, AzureStorageFactory _azureStorage)
|
|
|
- {
|
|
|
- string msg = string.Empty;
|
|
|
- //从尾部弹出元素,队列先进先出
|
|
|
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- var queueValue = await _azureRedis.GetRedisClient(8).ListRightPopAsync("PDFGen:Queue");
|
|
|
- PDFGenRedis genRedis = null;
|
|
|
- PDFGenQueue genQueue = null;
|
|
|
- if (queueValue!=default && queueValue.HasValue)
|
|
|
- {
|
|
|
- genQueue = queueValue.ToString().ToObject<PDFGenQueue>();
|
|
|
- RedisValue redisValue = await _azureRedis.GetRedisClient(8).HashGetAsync($"PDFGen:{genQueue.sessionId}", genQueue.id);
|
|
|
- if (redisValue!=default)
|
|
|
- {
|
|
|
- genRedis = redisValue.ToString().ToObject<PDFGenRedis>();
|
|
|
- //计算等待了多久的时间才开始生成。
|
|
|
- var wait = now- genRedis.join;
|
|
|
- genRedis.wait = wait;
|
|
|
- genRedis.status = 1;
|
|
|
- try
|
|
|
- {
|
|
|
- Uri uri = new Uri(genQueue.pageUrl);
|
|
|
- var query = HttpUtility.ParseQueryString(uri.Query);
|
|
|
- string? url = query["url"];
|
|
|
- if (!string.IsNullOrWhiteSpace(url))
|
|
|
- {
|
|
|
- url= HttpUtility.UrlDecode(url);
|
|
|
- uri = new Uri(url);
|
|
|
- string host = uri.Host;
|
|
|
- var blobServiceClient = _azureStorage.GetBlobServiceClient();
|
|
|
- if (host.Equals(blobServiceClient.Uri.Host))
|
|
|
- {
|
|
|
- // 获取容器名,它是路径的第一个部分
|
|
|
- string containerName = uri.Segments[1].TrimEnd('/');
|
|
|
- // 获取文件的完整同级目录,这是文件路径中除了文件名和扩展名之外的部分
|
|
|
- // 由于文件名是路径的最后一个部分,我们可以通过连接除了最后一个部分之外的所有部分来获取目录路径
|
|
|
- string directoryPath = string.Join("", uri.Segments, 2, uri.Segments.Length - 3);
|
|
|
- string? fileName = Path.GetFileNameWithoutExtension(uri.AbsolutePath);
|
|
|
- string blobPath = $"{directoryPath}{fileName}.pdf";
|
|
|
- var urlSas = _azureStorage.GetBlobSAS(containerName, blobPath, BlobSasPermissions.Write, hour: 1);
|
|
|
- genQueue.blobSas = urlSas.sas;
|
|
|
- genQueue.blobName=blobPath;
|
|
|
- genQueue.cntName=containerName;
|
|
|
- genQueue.blobFullUrl=urlSas.fullUri;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- msg="数据地址与服务提供的站点不一致!";
|
|
|
- genRedis.status=3;
|
|
|
- genRedis.msg = msg;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- msg="数据地址解析异常!";
|
|
|
- genRedis.status=3;
|
|
|
- genRedis.msg = msg;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- msg=$"数据地址处理异常,异常信息:{ex.Message}";
|
|
|
- genRedis.status=3;
|
|
|
- genRedis.msg = ex.Message;
|
|
|
- }
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync($"PDFGen:{genQueue.sessionId}", genQueue.id, genRedis.ToJsonString());
|
|
|
- }
|
|
|
- else {
|
|
|
- msg="队列任务关联数据为空!";
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- msg="队列暂无任务!";
|
|
|
- }
|
|
|
- return (genRedis, genQueue, msg);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -497,6 +420,7 @@ namespace TEAMModelOS.SDK
|
|
|
dbData.url= item.url;
|
|
|
dbData.scope = data.scope;
|
|
|
dbData.owner= data.owner;
|
|
|
+ dbData.env= data.env;
|
|
|
genRedis.Add(dbData);
|
|
|
}
|
|
|
}
|
|
@@ -510,7 +434,8 @@ namespace TEAMModelOS.SDK
|
|
|
name=item.name,
|
|
|
url= item.url,
|
|
|
scope=data.scope,
|
|
|
- owner= data.owner
|
|
|
+ owner= data.owner,
|
|
|
+ env= data.env,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -529,6 +454,7 @@ namespace TEAMModelOS.SDK
|
|
|
sessionId= data.sessionId,
|
|
|
timeout =data.timeout,
|
|
|
name=item.name,
|
|
|
+ env= data.env,
|
|
|
};
|
|
|
//string message = JsonSerializer.Serialize(genQueue);
|
|
|
//从头部压入元素,队列先进先出
|
|
@@ -546,7 +472,7 @@ namespace TEAMModelOS.SDK
|
|
|
}
|
|
|
|
|
|
public static async Task GenArtStudentPdf( AzureRedisFactory _azureRedis, AzureCosmosFactory _azureCosmos,
|
|
|
- CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, AzureStorageFactory _azureStorage, JsonElement json)
|
|
|
+ CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, AzureStorageFactory _azureStorage, IConfiguration _configuration, JsonElement json)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -597,11 +523,11 @@ namespace TEAMModelOS.SDK
|
|
|
// string url = $"{atrUrl}?url={s.fullUri}";
|
|
|
// urls.Add(url);
|
|
|
//});
|
|
|
- string env = "release";
|
|
|
- if (Environment.GetEnvironmentVariable("Option:Location").Contains("Test", StringComparison.CurrentCultureIgnoreCase) ||
|
|
|
- Environment.GetEnvironmentVariable("Option:Location").Contains("Dep", StringComparison.CurrentCultureIgnoreCase))
|
|
|
+ string env = ScreenConstant.env_release;
|
|
|
+ if (_configuration.GetValue<string>("Option:Location").Contains("Test", StringComparison.OrdinalIgnoreCase) ||
|
|
|
+ _configuration.GetValue<string>("Option:Location").Contains("Dep", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
- env = "develop";
|
|
|
+ env = ScreenConstant.env_develop;
|
|
|
}
|
|
|
var addData = await GenPDFService.AddGenPdfQueue(_azureRedis,
|
|
|
new GenPDFData
|
|
@@ -754,6 +680,10 @@ namespace TEAMModelOS.SDK
|
|
|
/// 数据范围
|
|
|
/// </summary>
|
|
|
public string scope { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 环境变量
|
|
|
+ /// </summary>
|
|
|
+ public string env { get; set; }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -771,6 +701,10 @@ namespace TEAMModelOS.SDK
|
|
|
/// </summary>
|
|
|
public class PDFGenQueue
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// 环境变量
|
|
|
+ /// </summary>
|
|
|
+ public string env { get; set;}
|
|
|
/// <summary>
|
|
|
/// 姓名
|
|
|
/// </summary>
|
|
@@ -944,10 +878,15 @@ namespace TEAMModelOS.SDK
|
|
|
public static readonly string error = "error";
|
|
|
public static readonly string offline = "offline";
|
|
|
public static readonly string grant_type = "bookjs_api";
|
|
|
- /// <summary>
|
|
|
- /// 冗余时间
|
|
|
- /// </summary>
|
|
|
- public static readonly long time_excess = 5000;
|
|
|
+
|
|
|
+
|
|
|
+ public static readonly string env_release = "release";
|
|
|
+ public static readonly string env_develop = "develop";
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 冗余时间
|
|
|
+ /// </summary>
|
|
|
+ public static readonly long time_excess = 5000;
|
|
|
}
|
|
|
public enum MessageType {
|
|
|
conn_success,//连接成功
|