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 taskDB { get; set; } = default!; [Inject] private INotificationService _notice { get; set; } = default!; IEnumerable _selectedRows = []; ITable _table; List _dataSource = null; RefAsync _total = 0; bool modalShow = false; bool tableLoading = false; private VideoTaskDto selectData; private bool rowRestartLoading = false; private VideoTaskDto reStartTask ; TextValue[] SelectDataSource = Enum.GetValues(typeof(RedisChannelEnum)) .Cast() .Select(s => new TextValue(s.ToString(), (int)s)) .ToArray(); int selectEnum = 1; int selectDefaultValue =1; /// /// 点击重试 /// /// async void ReStartClick(VideoTaskDto query) { selectDefaultValue = (await RedisExpand.Redis.HMGetAsync(RedisExpandKey.Task(query.Id), "LastEnum")).FirstOrDefault(); selectEnum = selectDefaultValue; reStartTask = query; modalShow = true; } /// /// 重试 /// /// async void ReStart() { await RedisExpand.SetTaskErrorMessage(reStartTask.Id, null); RedisExpand.InsertChannel((RedisChannelEnum)selectEnum, reStartTask.Id); modalShow = false; } private QueryModel lastQuery = null; /// /// 分页 查询 筛选 时 /// /// /// async void ShowErrorTask(MouseEventArgs e) { _dataSource = await taskDB.AsQueryable() .Where(s => s.ErrorMessage != null && s.ErrorMessage != string.Empty) .Select() .ToListAsync(); _total = _dataSource.Count(); tableLoading = false; StateHasChanged(); } /// /// 分页 查询 筛选 时 /// /// /// async void OnChange(QueryModel query) { lastQuery = query; tableLoading = true; List where = default!; if (query.FilterModel != null && ((query.FilterModel?.Count() ?? 0) > 0)) { where = query.ToSqlSugerWhere(); } _dataSource = await taskDB.AsQueryable() .Where(where) .Select() .OrderByDescending(s => s.Id) .ToPageListAsync(query.PageIndex - 1, query.PageSize, _total); tableLoading = false; StateHasChanged(); } public void RowRestart(RowData rowData) { rowRestartLoading = true; var item = rowData.Data; if (item is null) return; var data = RedisExpand.Redis.HMGet(RedisExpandKey.Task(item.Id), "Progress", "LastEnum", "StartTime", "ErrorMessage"); item.Progress = float.Parse(data[0]); item.LastEnum = data[1].ToEnum() ?? default; item.StartTimeDic = System.Text.Json.JsonSerializer.Deserialize>(data[2]) ?? null; item.ErrorMessage = data[3]; rowRestartLoading = false; StateHasChanged(); } /// /// /// /// private string RowST(RowData rowData, RedisChannelEnum e) { var dic = rowData.Data.StartTimeDic; if (dic is null || !dic.ContainsKey(e)) return "--"; return dic[e].ToString(); } private string RowSTStatus(RowData 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 rowData) { var dic = rowData.Data.StartTimeDic; if (dic is null) return 0; return (int)dic.LastOrDefault().Key; } private void OnExpand(RowData rowData) { RowRestart(rowData); } /// /// 在渲染页面之后 /// /// /// protected override async Task OnAfterRenderAsync(bool firstRender) { } /// /// 初始化 /// protected override void OnInitialized() { } private async Task Comfirm(string message) { return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes; } } }