99 lines
3.2 KiB
C#
99 lines
3.2 KiB
C#
using AntDesign;
|
|
using AntDesign.TableModels;
|
|
using Microsoft.AspNetCore.Components;
|
|
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!;
|
|
|
|
|
|
IEnumerable<VideoTaskDto> _selectedRows = [];
|
|
ITable _table;
|
|
|
|
List<VideoTaskDto> _dataSource = null;
|
|
RefAsync<int> _total = 0;
|
|
|
|
bool tableLoading = false;
|
|
|
|
/// <summary>
|
|
/// 重试
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
async void ReStart(VideoTaskDto query)
|
|
{
|
|
var lastEnum = (await RedisExpand.Redis.HMGetAsync<RedisChannelEnum>(RedisExpandKey.Task(query.Id), "LastEnum")).FirstOrDefault() ;
|
|
RedisExpand.InsertChannel(lastEnum, query.Id);
|
|
}
|
|
/// <summary>
|
|
/// 分页 查询 筛选 时
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
async void OnChange(QueryModel<VideoTaskDto> 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>()
|
|
.ToPageListAsync(query.PageIndex - 1, query.PageSize, _total);
|
|
|
|
foreach (var item in _dataSource)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.ErrorMessage) || item.LastEnum == RedisChannelEnum.EndTask)
|
|
continue;
|
|
item.Progress = RedisExpand.Redis.HMGet<double>(RedisExpandKey.Task(item.Id), "Progress").FirstOrDefault();
|
|
}
|
|
|
|
tableLoading = false;
|
|
StateHasChanged();
|
|
|
|
}
|
|
private static System.Timers.Timer _timer;
|
|
public void StartTimer(Object source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
if (_dataSource is null)
|
|
return;
|
|
foreach (var item in _dataSource)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.ErrorMessage) || item.LastEnum == RedisChannelEnum.EndTask)
|
|
continue;
|
|
item.Progress = RedisExpand.Redis.HMGet<double>(RedisExpandKey.Task(item.Id), "Progress").FirstOrDefault();
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
protected override void OnInitialized()
|
|
{
|
|
_timer = new System.Timers.Timer(2000);
|
|
_timer.Elapsed += StartTimer;
|
|
_timer.Enabled = true;
|
|
}
|
|
|
|
private async Task<bool> Comfirm(string message)
|
|
{
|
|
return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes;
|
|
}
|
|
|
|
}
|
|
|
|
}
|