183 lines
6.0 KiB
C#
183 lines
6.0 KiB
C#
using AntDesign;
|
|
using AntDesign.TableModels;
|
|
using FFmpeg.NET.Services;
|
|
using Learn.VideoAnalysis.Controllers.Dto;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
|
using SqlSugar;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
using VideoAnalysisCore.Common;
|
|
using VideoAnalysisCore.Enum;
|
|
using VideoAnalysisCore.Model;
|
|
using VideoAnalysisCore.Model.Dto;
|
|
|
|
namespace Learn.VideoAnalysis.Components.Pages
|
|
{
|
|
public partial class VideoTaskPage : ComponentBase
|
|
{
|
|
|
|
[Inject] private ConfirmService ComfirmService { get; set; } = default!;
|
|
[Inject] private Repository<VideoTask> taskDB { get; set; } = default!;
|
|
|
|
|
|
[Inject] private INotificationService _notice { get; set; } = default!;
|
|
IEnumerable<VideoTaskDto> _selectedRows = [];
|
|
ITable _table;
|
|
|
|
List<VideoTaskDto> _dataSource = null;
|
|
RefAsync<int> _total = 0;
|
|
|
|
bool modalShow = false;
|
|
|
|
bool tableLoading = false;
|
|
private VideoTaskDto selectData;
|
|
private bool rowRestartLoading = false;
|
|
private VideoTaskDto reStartTask ;
|
|
|
|
static TextValue[] SelectDataSource =
|
|
Enum.GetValues(typeof(RedisChannelEnum))
|
|
.Cast<RedisChannelEnum>()
|
|
.Select(s => new TextValue(s.ToString(), (int)s))
|
|
.ToArray();
|
|
int selectEnum = 1;
|
|
int selectDefaultValue =1;
|
|
|
|
/// <summary>
|
|
/// 点击重试
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
async void ReStartClick(VideoTaskDto query)
|
|
{
|
|
selectDefaultValue =
|
|
(await RedisExpand.Redis.HMGetAsync<int>(RedisExpandKey.Task(query.Id), "LastEnum")).FirstOrDefault();
|
|
selectEnum = selectDefaultValue;
|
|
reStartTask = query;
|
|
modalShow = true;
|
|
}
|
|
/// <summary>
|
|
/// 重试
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
async void ReStart()
|
|
{
|
|
await RedisExpand.SetTaskErrorMessage(reStartTask.Id, null);
|
|
RedisExpand.InsertChannel((RedisChannelEnum)selectEnum, reStartTask.Id);
|
|
modalShow = false;
|
|
}
|
|
private QueryModel<VideoTaskDto> lastQuery = null;
|
|
/// <summary>
|
|
/// 分页 查询 筛选 时
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="changed"></param>
|
|
async void ShowErrorTask(MouseEventArgs e)
|
|
{
|
|
_dataSource = await taskDB.AsQueryable()
|
|
.Where(s => s.ErrorMessage != null && s.ErrorMessage != string.Empty)
|
|
.Select<VideoTaskDto>()
|
|
.ToListAsync();
|
|
_total = _dataSource.Count();
|
|
tableLoading = false;
|
|
StateHasChanged();
|
|
|
|
}
|
|
/// <summary>
|
|
/// 分页 查询 筛选 时
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="changed"></param>
|
|
async void OnChange(QueryModel<VideoTaskDto> query)
|
|
{
|
|
lastQuery = query;
|
|
tableLoading = true;
|
|
List<IConditionalModel> where = default!;
|
|
if (query.FilterModel != null && ((query.FilterModel?.Count() ?? 0) > 0))
|
|
{
|
|
where = query.ToSqlSugerWhere();
|
|
}
|
|
_dataSource = await taskDB.AsQueryable()
|
|
.Where(where)
|
|
.Select<VideoTaskDto>()
|
|
.OrderByDescending(s => s.Id)
|
|
.ToPageListAsync(query.PageIndex , query.PageSize, _total);
|
|
|
|
tableLoading = false;
|
|
StateHasChanged();
|
|
|
|
}
|
|
/// <summary>
|
|
/// 刷新数据
|
|
/// </summary>
|
|
/// <param name="rowData"></param>
|
|
public void RowRload(RowData<VideoTaskDto> rowData)
|
|
{
|
|
rowRestartLoading = true;
|
|
var item = rowData.Data;
|
|
if (item is null)
|
|
return;
|
|
var data = RedisExpand.Redis.HMGet<string>(RedisExpandKey.Task(item.Id),
|
|
"Progress", "LastEnum", "StartTime", "ErrorMessage");
|
|
item.Progress = float.Parse(data[0]);
|
|
item.LastEnum = data[1].ToEnum<RedisChannelEnum>() ?? default;
|
|
item.StartTimeDic = System.Text.Json.JsonSerializer.Deserialize<Dictionary<RedisChannelEnum, DateTime>>(data[2]) ?? null;
|
|
item.ErrorMessage = data[3];
|
|
rowRestartLoading = false;
|
|
StateHasChanged();
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string RowST(RowData<VideoTaskDto> rowData, RedisChannelEnum e)
|
|
{
|
|
var dic = rowData.Data.StartTimeDic;
|
|
if (dic is null || !dic.ContainsKey(e))
|
|
return "--";
|
|
return dic[e].ToString();
|
|
}
|
|
private string RowSTStatus(RowData<VideoTaskDto> rowData)
|
|
{
|
|
var dic = rowData.Data.StartTimeDic;
|
|
if (dic is null)
|
|
return "wait";
|
|
if (!string.IsNullOrEmpty(rowData.Data.ErrorMessage))
|
|
return "error";
|
|
if (dic.ContainsKey(RedisChannelEnum.EndTask))
|
|
return "finish";
|
|
return "wait";
|
|
}
|
|
private int RowSTIndex(RowData<VideoTaskDto> rowData)
|
|
{
|
|
return (int)rowData.Data.LastEnum;
|
|
}
|
|
private void OnExpand(RowData<VideoTaskDto> rowData)
|
|
{
|
|
RowRload(rowData);
|
|
}
|
|
/// <summary>
|
|
/// 在渲染页面之后
|
|
/// </summary>
|
|
/// <param name="firstRender"></param>
|
|
/// <returns></returns>
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
protected override void OnInitialized()
|
|
{
|
|
}
|
|
|
|
private async Task<bool> Comfirm(string message)
|
|
{
|
|
return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes;
|
|
}
|
|
|
|
}
|
|
|
|
}
|