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; using VideoAnalysisCore.Model; using VideoAnalysisCore.Controllers.Dto; namespace VideoAnalysisCore.Controllers { /// /// 蓝鲸字库接口 /// [ApiController] [Route("LJZK/[action]")] public class LJZK_Controller : ControllerBase { 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( IMapper mp, IBserGPT chatGPT, Repository nodesubscriptionDB, Repository videoTaskDB = null, Repository videoKonwPointDB = null , Repository nodePackageInfoDB = null) { 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")] [NonAction, Obsolete] 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 (s.AttachmentsInfoType == AttachmentsInfoType.PPT) continue; 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, PPTVideoCode = req.AnalyzeItems //获取ppt videoCode .FirstOrDefault(x => x.AttachmentsInfoType == AttachmentsInfoType.PPT && s.StructurePageContentId == x.StructurePageContentId) ?.VideoCode, }); } 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() .Select(s => new { Text = s.ToString(), Value = (int)s })); } /// /// 获取学科类型 /// /// [HttpGet(Name = "SubjectList")] public IActionResult Subject() { Type type = typeof(SubjectEnum); return Ok(Enum.GetValues(type).Cast() .Select(s => new { Text = s.ToString(), Value = (int)s })); } /// /// 获取视频知识点片段taskId/tagId二选一 /// /// /// 自定义id /// [HttpGet(Name = "TaskKnowInfo")] public async Task TaskKnowInfo(long taskId, string? tagId) { if (taskId == 0 && string.IsNullOrEmpty(tagId)) return BadRequest(); var task = await videoTaskDB.AsQueryable() .WhereIF(taskId != 0, s => s.Id == taskId) .WhereIF(!string.IsNullOrEmpty(tagId), s => s.TagId == tagId) .FirstAsync(); if (task is null) return BadRequest("无效任务"); var konwArr = await videoKonwPointDB.AsQueryable() .Where(s => s.VideoTaskId == task.Id) .ToArrayAsync(); if (konwArr is null || konwArr.Length == 0) return BadRequest("无效任务"); return Ok(new TaskKnowRes() { TagId = task.TagId, Status = task.LastEnum, VideoTaskId = task.Id, KnowBlockArr = konwArr .GroupBy(s => s.StartTime) .Select(s => new TaskKnowBlock() { Id = s.First().Id, Content = s.First().Content, StartTime = s.First().StartTime, EndTime = s.First().EndTime, Theme = s.First().Theme, Know = s.Select(x => new TaskKnowInfo() { Id = x.Id, KnowPoint = x.KnowPoint, KnowPointId = x.KnowPointId }).ToArray() }).ToArray() }); } } }