优化文件结构
This commit is contained in:
parent
27b4b1f57a
commit
ae6e5ce836
|
|
@ -1,4 +1,4 @@
|
|||
namespace VideoAnalysisRazor.Resources;
|
||||
namespace Learn.VideoAnalysis.Components.Resources;
|
||||
|
||||
|
||||
internal class I18n
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ namespace Learn.VideoAnalysis.Controllers.Dto
|
|||
/// 任务类型
|
||||
/// </summary>
|
||||
public TaskTypeEnum? Type { get; set; }
|
||||
/// <summary>
|
||||
/// 学科类型
|
||||
/// </summary>
|
||||
public SubjectEnum? Subject { get; set; }
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -64,6 +64,17 @@ namespace Learn.VideoAnalysis.Controllers
|
|||
return Ok(Enum.GetValues(type).Cast<object>()
|
||||
.Select(s => new { Text = s.ToString(), Value = (int)s }));
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取学科类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(Name = "SubjectList")]
|
||||
public IActionResult Subject()
|
||||
{
|
||||
Type type = typeof(SubjectEnum);
|
||||
return Ok(Enum.GetValues(type).Cast<object>()
|
||||
.Select(s => new { Text = s.ToString(), Value = (int)s }));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using VideoAnalysisCore.Job;
|
||||
|
||||
namespace VideoAnalysisCore.Common
|
||||
namespace Learn.VideoAnalysis.Expand
|
||||
{
|
||||
public static class CoravelExpand
|
||||
{
|
||||
public static int MyProperty { get; set; }
|
||||
public static void Init(IServiceCollection service)
|
||||
public static void Init(IServiceCollection service)
|
||||
{
|
||||
|
||||
service.AddScheduler();
|
||||
|
|
@ -24,7 +24,7 @@ namespace VideoAnalysisCore.Common
|
|||
provider.UseScheduler(scheduler =>
|
||||
{
|
||||
//每5分钟执行一次 未处理视频扫描
|
||||
scheduler.Schedule<NodeSubscriptionJob>().EveryFiveMinutes();
|
||||
scheduler.Schedule<NodeSubscriptionJob>().EveryFiveMinutes();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Learn.VideoAnalysis.Expand
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class CorsExpand
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加跨域拓展
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static void AddCorsExpand(this IServiceCollection services)
|
||||
{
|
||||
services.AddCors(c =>
|
||||
{
|
||||
c.AddPolicy("All", policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 使用跨域
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
public static void UseCorsExpand(this WebApplication app)
|
||||
{
|
||||
app.UseCors("All");
|
||||
// 获取配置文件中的允许跨域的地址
|
||||
app.UseCors(options =>
|
||||
{
|
||||
options.WithOrigins("*") // 允许跨域请求的地址
|
||||
.AllowAnyHeader() // 允许的请求标头
|
||||
.AllowAnyMethod(); // 允许跨域请求的类型 (GET,POST等)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MySqlConnector;
|
||||
using SqlSugar;
|
||||
|
|
@ -11,13 +10,14 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using VideoAnalysisCore.Common;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace VideoAnalysisCore.Common
|
||||
namespace Learn.VideoAnalysis.Expand
|
||||
{
|
||||
public static class SqlSugarExpand
|
||||
{
|
||||
public static bool ShowSQL = false;
|
||||
public static void InitSqlSugar( this IServiceCollection services)
|
||||
public static void InitSqlSugar(this IServiceCollection services)
|
||||
{
|
||||
#region SqlSugar注入
|
||||
var dbList = new List<IocConfig>() {
|
||||
|
|
@ -31,9 +31,9 @@ namespace VideoAnalysisCore.Common
|
|||
};
|
||||
dbList.AddRange(AppCommon.Config.OtherDBArr.Select(s => new IocConfig()
|
||||
{
|
||||
ConfigId=s.ConfigId,
|
||||
ConnectionString=s.ConnectionString,
|
||||
DbType=s.SqlType,
|
||||
ConfigId = s.ConfigId,
|
||||
ConnectionString = s.ConnectionString,
|
||||
DbType = s.SqlType,
|
||||
IsAutoCloseConnection = true
|
||||
}));
|
||||
services.AddSingleton(typeof(Repository<>));
|
||||
|
|
@ -79,10 +79,10 @@ namespace VideoAnalysisCore.Common
|
|||
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
||||
{
|
||||
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||
//if (id == null || (long)id == 0)
|
||||
// entityInfo.SetValue(YitIdHelper.NextId());
|
||||
if (id == null || (long)id == 0)
|
||||
entityInfo.SetValue(YitIdHelper.NextId());
|
||||
}
|
||||
if (entityInfo.PropertyName == "CreateTime")
|
||||
if (entityInfo.PropertyName == "CreateTime" && entityInfo.EntityValue is null)
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
if (entityInfo.OperationType == DataFilterType.UpdateByObject)
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
global using VideoAnalysisRazor.Resources;
|
||||
global using AntDesign;
|
||||
global using AntDesign;
|
||||
|
||||
global using VideoAnalysisCore.Model;
|
||||
global using VideoAnalysisCore.Model.Dto;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using VideoAnalysisCore.AICore.GPT.ChatGPT;
|
|||
using Microsoft.Extensions.FileProviders;
|
||||
using VideoAnalysisCore.AICore.GPT.DeepSeek;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Learn.VideoAnalysis.Expand;
|
||||
|
||||
|
||||
|
||||
|
|
@ -85,6 +86,7 @@ namespace Learn.VideoAnalysis
|
|||
|
||||
builder.Services.AddAntDesign();
|
||||
builder.Services.AddMapster();
|
||||
builder.Services.AddCorsExpand();
|
||||
|
||||
|
||||
builder.Services.Configure<ProSettings>(builder.Configuration.GetSection("ProSettings"));
|
||||
|
|
@ -125,6 +127,8 @@ namespace Learn.VideoAnalysis
|
|||
|
||||
app.MapControllers();
|
||||
|
||||
app.UseCorsExpand();
|
||||
|
||||
//×Ô¶¨Òå Ó¦ÓÃ
|
||||
SqlSugarExpand.InitDB();
|
||||
CoravelExpand.Run(app.Services);
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ namespace VideoAnalysisCore.Common
|
|||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("初始化 redis");
|
||||
Redis.Serialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
|
||||
Redis.Deserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
|
||||
Redis.Serialize = obj => JsonSerializer.Serialize(obj);
|
||||
Redis.Deserialize = (json, type) => JsonSerializer.Deserialize(json, type);
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(1000 * 10);
|
||||
|
|
@ -108,11 +108,19 @@ namespace VideoAnalysisCore.Common
|
|||
/// <param name="taskId"></param>
|
||||
public static void SetTaskGPTCached(object taskId, object? data)
|
||||
{
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId)+":Res_" + DateTime.Now.ToString("yyyy/MM/dd_HH/mm/ss"), data, 3600 * 24);
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId) + ":Res_" + DateTime.Now.ToString("yyyy/MM/dd_HH/mm/ss"), data, 3600 * 24);
|
||||
}
|
||||
public static void SetTaskGPTReqCached(object taskId, object? data)
|
||||
{
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId)+":Req_"+ DateTime.Now.ToString("yyyy/MM/dd_HH/mm/ss"), data, 3600*24);
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId) + ":Req_" + DateTime.Now.ToString("yyyy/MM/dd_HH/mm/ss"), data, 3600 * 24);
|
||||
}
|
||||
/// <summary>
|
||||
/// 加入到消费队列
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
public static void JoinQueue(params long[] taskId)
|
||||
{
|
||||
Redis.LPush(RedisExpandKey.ChannelKey, taskId);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取任务进度
|
||||
|
|
@ -152,8 +160,8 @@ namespace VideoAnalysisCore.Common
|
|||
|
||||
Redis.HMSet(RedisExpandKey.Task(taskId), "StartTime", startTime);
|
||||
|
||||
if(!SubscribeList.ContainsKey(@enum))
|
||||
throw new Exception(@enum+" 未实现");
|
||||
if (!SubscribeList.ContainsKey(@enum))
|
||||
throw new Exception(@enum + " 未实现");
|
||||
|
||||
SubscribeList[@enum].Invoke(taskId.ToString());
|
||||
}
|
||||
|
|
@ -161,7 +169,7 @@ namespace VideoAnalysisCore.Common
|
|||
public static async Task TaskEnd(string task)
|
||||
{
|
||||
var tId = long.Parse(task);
|
||||
var gptRes = (await RedisExpand.Redis
|
||||
var gptRes = (await Redis
|
||||
.HMGetAsync<TaskRes>(RedisExpandKey.Task(task), "ChatAnalysis")).FirstOrDefault();
|
||||
if (gptRes is null)
|
||||
throw new Exception("未能读取到GPT处理结果");
|
||||
|
|
@ -169,13 +177,13 @@ namespace VideoAnalysisCore.Common
|
|||
var taskData = await DbScoped.SugarScope.Queryable<VideoTask>()
|
||||
.FirstAsync(s => s.Id == tId);
|
||||
if (taskData.Captions == "[]")
|
||||
taskData.Captions = (await Redis.HMGetAsync(RedisExpandKey.Task(task), "Captions")).First();
|
||||
taskData.Captions = (await Redis.HMGetAsync(RedisExpandKey.Task(task), "Captions")).First();
|
||||
if (taskData.Speaker == "[]")
|
||||
taskData.Speaker = (await Redis.HMGetAsync(RedisExpandKey.Task(task), "Speaker")).First();
|
||||
|
||||
|
||||
|
||||
taskData.ChatAnalysis =JsonSerializer.Serialize(gptRes);
|
||||
taskData.ChatAnalysis = JsonSerializer.Serialize(gptRes);
|
||||
taskData.ChatAnalysisScore = gptRes?.Assessment?.Merit?.Sum(s => s.Score) ?? 0;
|
||||
taskData.ErrorMessage = string.Empty;
|
||||
taskData.LastEnum = RedisChannelEnum.EndTask;
|
||||
|
|
@ -239,7 +247,7 @@ namespace VideoAnalysisCore.Common
|
|||
public static async Task ReceivingTaskAsync()
|
||||
{
|
||||
var oldTask = await Redis.GetAsync(RedisExpandKey.IDTask);
|
||||
if (!string.IsNullOrEmpty(oldTask))
|
||||
if (!string.IsNullOrEmpty(oldTask))
|
||||
{
|
||||
var lastEnum = (await Redis.HMGetAsync<RedisChannelEnum>(RedisExpandKey.Task(oldTask), "LastEnum")).FirstOrDefault();
|
||||
await SetTaskErrorMessage(long.Parse(oldTask), null);
|
||||
|
|
@ -268,7 +276,7 @@ namespace VideoAnalysisCore.Common
|
|||
public static async Task<bool> SetTaskErrorMessage(long taskID, Exception? ex)
|
||||
{
|
||||
var error = string.Empty;
|
||||
if (ex != null)
|
||||
if (ex != null)
|
||||
{
|
||||
//执行任务时出现异常
|
||||
error = ex.Message + ex.StackTrace;
|
||||
|
|
@ -282,7 +290,7 @@ namespace VideoAnalysisCore.Common
|
|||
}
|
||||
|
||||
Redis.HMSet(RedisExpandKey.Task(taskID), "ErrorMessage", error);
|
||||
|
||||
|
||||
return await DbScoped.SugarScope.Updateable<VideoTask>()
|
||||
.SetColumns(it => it.ErrorMessage == error)//SetColumns是可以叠加的 写2个就2个字段赋值
|
||||
.Where(it => it.Id == taskID)
|
||||
|
|
@ -313,7 +321,7 @@ namespace VideoAnalysisCore.Common
|
|||
.SetColumns(it => it.LastEnum == key)
|
||||
.Where(it => it.Id == tID)
|
||||
.ExecuteCommandAsync();
|
||||
await action(taskId);
|
||||
await action(taskId);
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -324,7 +332,7 @@ namespace VideoAnalysisCore.Common
|
|||
Console.WriteLine(ex.StackTrace);
|
||||
Console.WriteLine("==============================================");
|
||||
Thread.Sleep(1000);
|
||||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId );
|
||||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId);
|
||||
}
|
||||
}
|
||||
await SetTaskErrorMessage(tID, errArr.First());
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VideoAnalysisCore.Common;
|
||||
using VideoAnalysisCore.Model;
|
||||
using VideoAnalysisCore.Model.Dto;
|
||||
using VideoAnalysisCore.Model.蓝鲸智库;
|
||||
|
||||
namespace VideoAnalysisCore.Job
|
||||
|
|
@ -17,17 +19,19 @@ namespace VideoAnalysisCore.Job
|
|||
{
|
||||
private readonly Repository<NodeSubscription> nodesubscriptionDB;
|
||||
private readonly Repository<Attachments> attachmentsDB;
|
||||
public NodeSubscriptionJob(Repository<Attachments> videoTaskDB, Repository<NodeSubscription> nodesubscriptionDB)
|
||||
private readonly Repository<VideoTask> videotaskDB;
|
||||
public NodeSubscriptionJob(Repository<Attachments> videoTaskDB, Repository<NodeSubscription> nodesubscriptionDB, Repository<VideoTask> videotaskDB)
|
||||
{
|
||||
this.attachmentsDB = videoTaskDB;
|
||||
this.nodesubscriptionDB = nodesubscriptionDB;
|
||||
this.videotaskDB = videotaskDB;
|
||||
}
|
||||
public async Task Invoke()
|
||||
{
|
||||
Console.WriteLine($"{DateTime.Now} Invoke=>{this.GetType().FullName}");
|
||||
|
||||
var tasks = await nodesubscriptionDB.GetListAsync(s => s.Enable);
|
||||
foreach (var item in tasks)
|
||||
var tasks = await nodesubscriptionDB.GetListAsync(s => s.Enable);
|
||||
foreach (var item in tasks)
|
||||
{
|
||||
var fileNodeId = item.NodeId;
|
||||
var data = attachmentsDB.Context.Ado
|
||||
|
|
@ -61,6 +65,22 @@ namespace VideoAnalysisCore.Job
|
|||
)
|
||||
""");
|
||||
|
||||
var videos = data.Select(s => new VideoTask()
|
||||
{
|
||||
ComeFrom = "127.0.0.1",
|
||||
ApiToken = "",
|
||||
Type = item.TaskType,
|
||||
Subject = item.Subject,
|
||||
Tag = string.Empty,
|
||||
TagId = s.VideoCode,
|
||||
MediaUrl = s.Url,
|
||||
MediaName = s.Name
|
||||
}).ToArray();
|
||||
|
||||
//入库
|
||||
await videotaskDB.InsertRangeAsync(videos);
|
||||
var ids = videos.Select(s => s.Id).ToArray();
|
||||
RedisExpand.JoinQueue(ids);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ namespace VideoAnalysisCore.Model
|
|||
[DisplayName("绑定学科")]
|
||||
public TaskTypeEnum TaskType { get; set; }
|
||||
/// <summary>
|
||||
/// 学科
|
||||
/// </summary>
|
||||
public SubjectEnum Subject { get; set; }
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
[DisplayName("是否启用")]
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace VideoAnalysisCore.Model
|
|||
/// 任务id
|
||||
/// <para>视频音频文件地址都使用taskID能获取</para>
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 媒体路径
|
||||
|
|
|
|||
Loading…
Reference in New Issue