using VideoAnalysisCore.Common;
using Microsoft.AspNetCore.Mvc;
using System.Reflection;
using MapsterMapper;
using Mapster;
using VideoAnalysisCore.AICore.SherpaOnnx;
using UserCenter.Model.Enum;
using VideoAnalysisCore.AICore.GPT.ChatGPT;
using VideoAnalysisCore.AICore.GPT;
using System.Text.Json;
using Microsoft.AspNetCore.Authorization;
using VideoAnalysisCore.Model.Enum;
using FFmpeg.NET.Services;
using static FFmpeg.NET.MetaData;
using static System.Runtime.InteropServices.JavaScript.JSType;
using Yitter.IdGenerator;
using VideoAnalysisCore.AICore.GPT.Dto;
namespace Learn.VideoAnalysis.Controllers
{
///
/// 蓝鲸字库接口
///
[ApiController]
[Route("LJZK/[action]")]
public class LJZK_Controller : ControllerBase
{
private readonly ILogger _logger;
private readonly IMapper mp;
private readonly Repository nodesubscriptionDB;
private readonly Repository videoTaskDB;
private readonly Repository videoKonwPointDB;
private readonly Repository nodePackageInfoDB;
private readonly IBserGPT chatGPT;
public LJZK_Controller(ILogger logger,
IMapper mp, IBserGPT chatGPT, Repository nodesubscriptionDB,
Repository videoTaskDB = null, Repository videoKonwPointDB = null
, Repository nodePackageInfoDB = null)
{
_logger = logger;
this.mp = mp;
this.chatGPT = chatGPT;
this.nodesubscriptionDB = nodesubscriptionDB;
this.videoTaskDB = videoTaskDB;
this.videoKonwPointDB = videoKonwPointDB;
this.nodePackageInfoDB = nodePackageInfoDB;
}
///
/// 蓝鲸智库_添加文件节点监控
///
/// 请求体
///
[HttpPost(Name = "NodeSubscription")]
public async Task NodeSubscription(NodeMonitoringReq req)
{
if (req is null || req.NodeId == 0)
return BadRequest("无效的提交数据");
if (nodesubscriptionDB.IsAny(s => s.NodeId == req.NodeId))
return BadRequest("重复添加了节点监控任务" + req.NodeId);
var res = await nodesubscriptionDB.InsertReturnEntityAsync(new NodeSubscription()
{
NodeId = req.NodeId,
TaskType = req.Type ?? default,
Subject = req.Subject ?? default,
});
return Ok(res);
}
///
/// 蓝鲸智库_文件包订阅
///
/// 请求体
///
[HttpPost(Name = "NodePackage")]
public async Task NodePackage(NodePackageReq req)
{
Console.WriteLine($"{DateTime.Now} 文件包订阅请求 req=" + JsonSerializer.Serialize(req));
if (req.AnalyzeItems is null || req.AnalyzeItems.Count() == 0)
return BadRequest("无效视频列表数据");
var videos = new List(req.AnalyzeItems.Count);
var nodePackages = new List(req.AnalyzeItems.Count);
var videoIdArr = videoTaskDB.AsQueryable().Select(v => v.TagId).Distinct().ToArray();
foreach (var s in req.AnalyzeItems)
{
var np = new NodePackageInfo()
{
VideoCode = s.VideoCode,
AttachmentsInfoType = s.AttachmentsInfoType,
MaterialId = s.MaterialId,
StructurePageContentId = s.StructurePageContentId,
VideoName = s.VideoName,
NodeId = req.NodeId,
TaskType = req.TaskType,
SubjectType = req.SubjectType,
};
nodePackages.Add(np);
if (videoIdArr.Contains(s.VideoCode))
continue;
videos.Add(new VideoTask()
{
Id = YitIdHelper.NextId(),
ComeFrom = "127.0.0.1",
ApiToken = "",
Type = req.TaskType,
Subject = req.SubjectType,
TagId = s.VideoCode,
MediaUrl =string.Empty,
MediaName = s.VideoName
});
}
await nodePackageInfoDB.InsertRangeAsync(nodePackages);
await videoTaskDB.InsertRangeAsync(videos);
if (videos is null || videos.Count == 0)
return Ok();
var ids = videos.Select(s => s.Id).ToArray();
RedisExpand.JoinQueue(ids);
return Ok();
}
///
/// 获取任务类型
///
///
[HttpGet(Name = "TaskTypList")]
public IActionResult TaskType()
{
Type type = typeof(TaskTypeEnum);
return Ok(Enum.GetValues(type).Cast