|
@@ -49,11 +49,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
{
|
|
|
public class ActiveTaskTopic
|
|
|
{
|
|
|
- public static ConcurrentQueue<(ScreenshotDto screenshotDto, List<StudentArtResult> studentArts)> concurrentQueue
|
|
|
- = new ConcurrentQueue<(ScreenshotDto screenshotDto, List<StudentArtResult> studentArts)>();
|
|
|
- public static bool busy = false;
|
|
|
+
|
|
|
private readonly int psize = 20;
|
|
|
- public static SpinWait spinWait = new SpinWait(); // 构造SpinWait实例
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
@@ -757,26 +754,11 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
break;
|
|
|
//case bool when element.TryGetProperty("bizType", out JsonElement _bizType) && $"{_bizType}".Equals("ArtStudentPdf"):
|
|
|
// await GenArtStudentPdf(element, msg);
|
|
|
- // break;
|
|
|
+ // break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async Task<List<string>> DoPDFTask((ScreenshotDto screenshotDto, List<StudentArtResult> studentArts) datas) {
|
|
|
- List<string> resUrls = new List<string>();
|
|
|
- try {
|
|
|
- var httpResponse = await _httpClient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/screen/screenshot-pdf",
|
|
|
- datas.screenshotDto
|
|
|
- );
|
|
|
- if (httpResponse.StatusCode == HttpStatusCode.OK)
|
|
|
- {
|
|
|
- JsonElement json_res = await httpResponse.Content.ReadFromJsonAsync<JsonElement>();
|
|
|
- resUrls = json_res.GetProperty("urls").Deserialize<List<string>>();
|
|
|
- await UpdatePdfBlob(datas.studentArts, resUrls);
|
|
|
- }
|
|
|
- } catch {
|
|
|
- }
|
|
|
- return resUrls;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
private async Task GenArtStudentPdf(JsonElement json, string msg) {
|
|
|
try
|
|
@@ -808,7 +790,6 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
{
|
|
|
env = "develop";
|
|
|
}
|
|
|
-
|
|
|
if (urls.Count <= psize)
|
|
|
{
|
|
|
var screenshot = new ScreenshotDto
|
|
@@ -822,7 +803,6 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
pagesize = 5,
|
|
|
env = env
|
|
|
};
|
|
|
- concurrentQueue.Enqueue((screenshot,artResults));
|
|
|
}
|
|
|
else {
|
|
|
int pages = (urls.Count + psize) / psize;
|
|
@@ -840,115 +820,14 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
pagesize = 5,
|
|
|
env = env
|
|
|
};
|
|
|
- concurrentQueue.Enqueue((screenshot, artResults));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- while (true) {
|
|
|
- if (!busy)
|
|
|
- {
|
|
|
- if (concurrentQueue.Count > 0)
|
|
|
- {
|
|
|
-
|
|
|
- if (concurrentQueue.TryDequeue(out (ScreenshotDto screenshotDto, List<StudentArtResult> studentArts) datas))
|
|
|
- {
|
|
|
- busy = true;
|
|
|
- await DoPDFTask(datas);
|
|
|
- busy = false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- else { }
|
|
|
}
|
|
|
-
|
|
|
- //空转一次
|
|
|
- spinWait.SpinOnce();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- if (urls.Count <= psize)
|
|
|
- {
|
|
|
- var screenshot = new ScreenshotDto
|
|
|
- {
|
|
|
- width = 1080,
|
|
|
- height = 1920,
|
|
|
- urls = urls,
|
|
|
- fileNameKey = "pdfpath",
|
|
|
- cnt = $"{_schoolCode}",
|
|
|
- root = "art",
|
|
|
- pagesize = 5,
|
|
|
- env = env
|
|
|
- };
|
|
|
- var st = screenshot.ToJsonString();
|
|
|
- var httpResponse = await _httpClient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/screen/screenshot-pdf",
|
|
|
- screenshot
|
|
|
- );
|
|
|
- if (httpResponse.StatusCode == HttpStatusCode.OK)
|
|
|
- {
|
|
|
- JsonElement json_res = await httpResponse.Content.ReadFromJsonAsync<JsonElement>();
|
|
|
- var resUrls = json_res.GetProperty("urls").Deserialize<List<string>>();
|
|
|
- await UpdatePdfBlob(artResults, resUrls);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int pages = (urls.Count + psize) / psize;
|
|
|
- for (int i = 0; i < pages; i++)
|
|
|
- {
|
|
|
- var lists = urls.Skip((i) * psize).Take(psize).ToList();
|
|
|
- var screenshot = new ScreenshotDto
|
|
|
- {
|
|
|
- width = 1080,
|
|
|
- height = 1920,
|
|
|
- urls = lists,
|
|
|
- fileNameKey = "pdfpath",
|
|
|
- cnt = $"{_schoolCode}",
|
|
|
- root = "art",
|
|
|
- pagesize = 5,
|
|
|
- env = env
|
|
|
- };
|
|
|
- var st = screenshot.ToJsonString();
|
|
|
- var httpResponse = await _httpClient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/screen/screenshot-pdf",
|
|
|
- screenshot
|
|
|
- );
|
|
|
- if (httpResponse.StatusCode == HttpStatusCode.OK)
|
|
|
- {
|
|
|
- JsonElement json_res = await httpResponse.Content.ReadFromJsonAsync<JsonElement>();
|
|
|
- var resUrls = json_res.GetProperty("urls").Deserialize<List<string>>();
|
|
|
- await UpdatePdfBlob(artResults, resUrls);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
await _dingDing.SendBotMsg($"{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
}
|
|
|
}
|
|
|
- //https://teammodeltest.blob.core.chinacloudapi.cn/hbcn/art/e864a924-e644-42dc-87c4-e970e6185065/report/202201001.pdf
|
|
|
- private async Task UpdatePdfBlob(List<StudentArtResult> studentArts, List<string> urls)
|
|
|
- {
|
|
|
- List<Task<ItemResponse<StudentArtResult>>> artResults = new List<Task<ItemResponse<StudentArtResult>>>();
|
|
|
- urls.ForEach(z => {
|
|
|
- var res = studentArts.FindAll(x => z.Contains(x.artId) && z.Contains($"{x.studentId}"));
|
|
|
- if (res.Any())
|
|
|
- {
|
|
|
- if (string.IsNullOrWhiteSpace(res[0].blob))
|
|
|
- {
|
|
|
- res[0].blob = $"art/{res[0].artId}/report/{res[0].studentId}.pdf";
|
|
|
- artResults.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(res[0], res[0].id, new PartitionKey(res[0].code)));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if (artResults.Any())
|
|
|
- {
|
|
|
- await Task.WhenAll(artResults);
|
|
|
- }
|
|
|
- }
|
|
|
private async Task GenOfflineRecordPdf(JsonElement element,string msg) {
|
|
|
try
|
|
|
{
|