using AlibabaCloud.SDK.Vod20170321; using Coravel.Invocable; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http.Json; using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using UserCenter.Model.Enum; using VideoAnalysisCore.Common; using VideoAnalysisCore.Model; using VideoAnalysisCore.Model.Dto; using VideoAnalysisCore.Model.蓝鲸智库; using Yitter.IdGenerator; namespace VideoAnalysisCore.Job { /// /// [蓝鲸智库] 查找文件包未处理的视频 /// public class NodePackageJob : IInvocable { /// /// 每个扫描文件包每次取出{20}个 /// private readonly int TopLength = 20; private readonly Repository nodePackageInfoDB; private readonly Repository attachmentsDB; private readonly Repository videoTaskDB; public NodePackageJob(Repository videoTaskDB, Repository nodePackageInfoDB, Repository videotaskDB) { this.attachmentsDB = videoTaskDB; this.nodePackageInfoDB = nodePackageInfoDB; this.videoTaskDB = videotaskDB; } public async Task Invoke() { Console.WriteLine($"{DateTime.Now} 执行=>文件包任务"); var taskArr = await nodePackageInfoDB.AsQueryable() .Where(s => s.SuccessTime == null) .ToArrayAsync(); var videoIdArr = await videoTaskDB.AsQueryable() .Where(s => s.EndTime != null) .Select(s => s.TagId) .ToArrayAsync(); var postData = new List(); foreach (var item in taskArr) { if (videoIdArr.Contains(item.VideoCode)) { postData.Add(item); item.SuccessTime = DateTime.Now; } } Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 已完成任务回调 数量{postData.Count}"); if (postData.Count() == 0) return; //var responseMessage = await new HttpClient() // .PostAsJsonAsync(AppCommon.Config.Subsystem.蓝鲸智库.APIUrl + "/api/callback/platform/videosAnalyze", postData); foreach (var item in taskArr) { HttpResponseMessage responseMessage = null; try { var postUrl = !string.IsNullOrWhiteSpace(item.CallBackUrl) ? item.CallBackUrl : AppCommon.Config.Subsystem.蓝鲸智库.APIUrl + "/api/callback/platform/videosAnalyze"; responseMessage = await new HttpClient() .PostAsJsonAsync(postUrl, postData); if (responseMessage.IsSuccessStatusCode) { var res = await responseMessage.Content.ReadAsStringAsync(); Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调结果 {res}"); await nodePackageInfoDB.AsUpdateable(postData) .UpdateColumns(it => new { it.SuccessTime }) .ExecuteCommandAsync(); } else { var res = await responseMessage.Content.ReadAsStringAsync(); Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage.StatusCode} {res}"); } } catch (Exception ex) { var res = await responseMessage?.Content?.ReadAsStringAsync()??string.Empty; Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage.StatusCode} {res}"); Console.WriteLine(ex); } await Task.Delay(1000); } } } }