优化文件结构
This commit is contained in:
parent
27b4b1f57a
commit
ae6e5ce836
|
|
@ -1,4 +1,4 @@
|
||||||
namespace VideoAnalysisRazor.Resources;
|
namespace Learn.VideoAnalysis.Components.Resources;
|
||||||
|
|
||||||
|
|
||||||
internal class I18n
|
internal class I18n
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ namespace Learn.VideoAnalysis.Controllers.Dto
|
||||||
/// 任务类型
|
/// 任务类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TaskTypeEnum? Type { get; set; }
|
public TaskTypeEnum? Type { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 学科类型
|
||||||
|
/// </summary>
|
||||||
|
public SubjectEnum? Subject { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,17 @@ namespace Learn.VideoAnalysis.Controllers
|
||||||
return Ok(Enum.GetValues(type).Cast<object>()
|
return Ok(Enum.GetValues(type).Cast<object>()
|
||||||
.Select(s => new { Text = s.ToString(), Value = (int)s }));
|
.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,7 +8,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using VideoAnalysisCore.Job;
|
using VideoAnalysisCore.Job;
|
||||||
|
|
||||||
namespace VideoAnalysisCore.Common
|
namespace Learn.VideoAnalysis.Expand
|
||||||
{
|
{
|
||||||
public static class CoravelExpand
|
public static class CoravelExpand
|
||||||
{
|
{
|
||||||
|
|
@ -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 Microsoft.Extensions.Options;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
@ -11,13 +10,14 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using VideoAnalysisCore.Common;
|
using VideoAnalysisCore.Common;
|
||||||
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
namespace VideoAnalysisCore.Common
|
namespace Learn.VideoAnalysis.Expand
|
||||||
{
|
{
|
||||||
public static class SqlSugarExpand
|
public static class SqlSugarExpand
|
||||||
{
|
{
|
||||||
public static bool ShowSQL = false;
|
public static bool ShowSQL = false;
|
||||||
public static void InitSqlSugar( this IServiceCollection services)
|
public static void InitSqlSugar(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
#region SqlSugar注入
|
#region SqlSugar注入
|
||||||
var dbList = new List<IocConfig>() {
|
var dbList = new List<IocConfig>() {
|
||||||
|
|
@ -31,9 +31,9 @@ namespace VideoAnalysisCore.Common
|
||||||
};
|
};
|
||||||
dbList.AddRange(AppCommon.Config.OtherDBArr.Select(s => new IocConfig()
|
dbList.AddRange(AppCommon.Config.OtherDBArr.Select(s => new IocConfig()
|
||||||
{
|
{
|
||||||
ConfigId=s.ConfigId,
|
ConfigId = s.ConfigId,
|
||||||
ConnectionString=s.ConnectionString,
|
ConnectionString = s.ConnectionString,
|
||||||
DbType=s.SqlType,
|
DbType = s.SqlType,
|
||||||
IsAutoCloseConnection = true
|
IsAutoCloseConnection = true
|
||||||
}));
|
}));
|
||||||
services.AddSingleton(typeof(Repository<>));
|
services.AddSingleton(typeof(Repository<>));
|
||||||
|
|
@ -79,10 +79,10 @@ namespace VideoAnalysisCore.Common
|
||||||
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
||||||
{
|
{
|
||||||
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||||
//if (id == null || (long)id == 0)
|
if (id == null || (long)id == 0)
|
||||||
// entityInfo.SetValue(YitIdHelper.NextId());
|
entityInfo.SetValue(YitIdHelper.NextId());
|
||||||
}
|
}
|
||||||
if (entityInfo.PropertyName == "CreateTime")
|
if (entityInfo.PropertyName == "CreateTime" && entityInfo.EntityValue is null)
|
||||||
entityInfo.SetValue(DateTime.Now);
|
entityInfo.SetValue(DateTime.Now);
|
||||||
}
|
}
|
||||||
if (entityInfo.OperationType == DataFilterType.UpdateByObject)
|
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;
|
||||||
global using VideoAnalysisCore.Model.Dto;
|
global using VideoAnalysisCore.Model.Dto;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ using VideoAnalysisCore.AICore.GPT.ChatGPT;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using VideoAnalysisCore.AICore.GPT.DeepSeek;
|
using VideoAnalysisCore.AICore.GPT.DeepSeek;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Learn.VideoAnalysis.Expand;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -85,6 +86,7 @@ namespace Learn.VideoAnalysis
|
||||||
|
|
||||||
builder.Services.AddAntDesign();
|
builder.Services.AddAntDesign();
|
||||||
builder.Services.AddMapster();
|
builder.Services.AddMapster();
|
||||||
|
builder.Services.AddCorsExpand();
|
||||||
|
|
||||||
|
|
||||||
builder.Services.Configure<ProSettings>(builder.Configuration.GetSection("ProSettings"));
|
builder.Services.Configure<ProSettings>(builder.Configuration.GetSection("ProSettings"));
|
||||||
|
|
@ -125,6 +127,8 @@ namespace Learn.VideoAnalysis
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.UseCorsExpand();
|
||||||
|
|
||||||
//×Ô¶¨Òå Ó¦ÓÃ
|
//×Ô¶¨Òå Ó¦ÓÃ
|
||||||
SqlSugarExpand.InitDB();
|
SqlSugarExpand.InitDB();
|
||||||
CoravelExpand.Run(app.Services);
|
CoravelExpand.Run(app.Services);
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,8 @@ namespace VideoAnalysisCore.Common
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Console.WriteLine("初始化 redis");
|
Console.WriteLine("初始化 redis");
|
||||||
Redis.Serialize = obj => System.Text.Json.JsonSerializer.Serialize(obj);
|
Redis.Serialize = obj => JsonSerializer.Serialize(obj);
|
||||||
Redis.Deserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
|
Redis.Deserialize = (json, type) => JsonSerializer.Deserialize(json, type);
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Thread.Sleep(1000 * 10);
|
Thread.Sleep(1000 * 10);
|
||||||
|
|
@ -108,11 +108,19 @@ namespace VideoAnalysisCore.Common
|
||||||
/// <param name="taskId"></param>
|
/// <param name="taskId"></param>
|
||||||
public static void SetTaskGPTCached(object taskId, object? data)
|
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)
|
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>
|
/// <summary>
|
||||||
/// 获取任务进度
|
/// 获取任务进度
|
||||||
|
|
@ -152,8 +160,8 @@ namespace VideoAnalysisCore.Common
|
||||||
|
|
||||||
Redis.HMSet(RedisExpandKey.Task(taskId), "StartTime", startTime);
|
Redis.HMSet(RedisExpandKey.Task(taskId), "StartTime", startTime);
|
||||||
|
|
||||||
if(!SubscribeList.ContainsKey(@enum))
|
if (!SubscribeList.ContainsKey(@enum))
|
||||||
throw new Exception(@enum+" 未实现");
|
throw new Exception(@enum + " 未实现");
|
||||||
|
|
||||||
SubscribeList[@enum].Invoke(taskId.ToString());
|
SubscribeList[@enum].Invoke(taskId.ToString());
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +169,7 @@ namespace VideoAnalysisCore.Common
|
||||||
public static async Task TaskEnd(string task)
|
public static async Task TaskEnd(string task)
|
||||||
{
|
{
|
||||||
var tId = long.Parse(task);
|
var tId = long.Parse(task);
|
||||||
var gptRes = (await RedisExpand.Redis
|
var gptRes = (await Redis
|
||||||
.HMGetAsync<TaskRes>(RedisExpandKey.Task(task), "ChatAnalysis")).FirstOrDefault();
|
.HMGetAsync<TaskRes>(RedisExpandKey.Task(task), "ChatAnalysis")).FirstOrDefault();
|
||||||
if (gptRes is null)
|
if (gptRes is null)
|
||||||
throw new Exception("未能读取到GPT处理结果");
|
throw new Exception("未能读取到GPT处理结果");
|
||||||
|
|
@ -175,7 +183,7 @@ namespace VideoAnalysisCore.Common
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
taskData.ChatAnalysis =JsonSerializer.Serialize(gptRes);
|
taskData.ChatAnalysis = JsonSerializer.Serialize(gptRes);
|
||||||
taskData.ChatAnalysisScore = gptRes?.Assessment?.Merit?.Sum(s => s.Score) ?? 0;
|
taskData.ChatAnalysisScore = gptRes?.Assessment?.Merit?.Sum(s => s.Score) ?? 0;
|
||||||
taskData.ErrorMessage = string.Empty;
|
taskData.ErrorMessage = string.Empty;
|
||||||
taskData.LastEnum = RedisChannelEnum.EndTask;
|
taskData.LastEnum = RedisChannelEnum.EndTask;
|
||||||
|
|
@ -324,7 +332,7 @@ namespace VideoAnalysisCore.Common
|
||||||
Console.WriteLine(ex.StackTrace);
|
Console.WriteLine(ex.StackTrace);
|
||||||
Console.WriteLine("==============================================");
|
Console.WriteLine("==============================================");
|
||||||
Thread.Sleep(1000);
|
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());
|
await SetTaskErrorMessage(tID, errArr.First());
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using VideoAnalysisCore.Common;
|
using VideoAnalysisCore.Common;
|
||||||
using VideoAnalysisCore.Model;
|
using VideoAnalysisCore.Model;
|
||||||
|
using VideoAnalysisCore.Model.Dto;
|
||||||
using VideoAnalysisCore.Model.蓝鲸智库;
|
using VideoAnalysisCore.Model.蓝鲸智库;
|
||||||
|
|
||||||
namespace VideoAnalysisCore.Job
|
namespace VideoAnalysisCore.Job
|
||||||
|
|
@ -17,10 +19,12 @@ namespace VideoAnalysisCore.Job
|
||||||
{
|
{
|
||||||
private readonly Repository<NodeSubscription> nodesubscriptionDB;
|
private readonly Repository<NodeSubscription> nodesubscriptionDB;
|
||||||
private readonly Repository<Attachments> attachmentsDB;
|
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.attachmentsDB = videoTaskDB;
|
||||||
this.nodesubscriptionDB = nodesubscriptionDB;
|
this.nodesubscriptionDB = nodesubscriptionDB;
|
||||||
|
this.videotaskDB = videotaskDB;
|
||||||
}
|
}
|
||||||
public async Task Invoke()
|
public async Task Invoke()
|
||||||
{
|
{
|
||||||
|
|
@ -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("绑定学科")]
|
[DisplayName("绑定学科")]
|
||||||
public TaskTypeEnum TaskType { get; set; }
|
public TaskTypeEnum TaskType { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 学科
|
||||||
|
/// </summary>
|
||||||
|
public SubjectEnum Subject { get; set; }
|
||||||
|
/// <summary>
|
||||||
/// 是否启用
|
/// 是否启用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DisplayName("是否启用")]
|
[DisplayName("是否启用")]
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace VideoAnalysisCore.Model
|
||||||
/// 任务id
|
/// 任务id
|
||||||
/// <para>视频音频文件地址都使用taskID能获取</para>
|
/// <para>视频音频文件地址都使用taskID能获取</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 媒体路径
|
/// 媒体路径
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue