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} Invoke=>文件包任务");
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} Invoke=>文件包任务 已完成任务回调 数量{postData.Count}");
if (postData.Count() == 0)
return;
var responseMessage = await new HttpClient()
.PostAsJsonAsync(AppCommon.Config.Subsystem.蓝鲸智库.APIUrl + "/api/callback/platform/videosAnalyze", postData);
if (responseMessage.IsSuccessStatusCode)
{
var res = await responseMessage.Content.ReadAsStringAsync();
Console.WriteLine($"{DateTime.Now} Invoke=>文件包任务 回调结果 {res}");
await nodePackageInfoDB.AsUpdateable(postData)
.UpdateColumns(it => new { it.SuccessTime })
.ExecuteCommandAsync();
}
}
}
}