using System.Linq.Expressions; using TrackCenter.Domain.Aggregates.WarningAggregate; using TrackCenter.Domain.Aggregates.WarningAggregate.Return; using TrackCenter.Domain.Aggregates.WarningAggregate.Transport; namespace TrackCenter.Repository.Repositories; public class WarningTaskRepository : BasicRepository, IWarningTaskRepository, ITransientDependency { #region 预警通知任务 public Task> ScanNotifyTaskAsync(DateTime? startDateTime = null) { return Context.Queryable() .Where(x => x.IsClosed == false) .WhereIF(startDateTime.HasValue, x => startDateTime!.Value <= x.CreateTime) .ToListAsync(); } public Task> GetWarningNotifyTaskAsync(Expression> expression) { return Context.Queryable() .Where(expression) .ToListAsync(); } public Task> GetWarningNotifyTaskAsync(Expression> expression, Expression> select) { return Context.Queryable() .Where(expression) .Select(select) .ToListAsync(); } public async Task AddWarningNotifyTaskAsync(WarningNotifyTaskEntity entity) { return await Context.Insertable(entity).ExecuteCommandAsync() > 0; } public Task BulkInsertWarningNotifyTaskAsync(List entities) { return Context.Insertable(entities) .ExecuteCommandAsync(); } public Task CloseWarningNotifyTaskAsync(Expression> expression) { return Context.Updateable() .Where(expression) .SetColumns(x => x.IsClosed, true) .SetColumns(x => x.UpdateTime, DateTime.Now) .ExecuteCommandAsync(); } public Task CloseWarningNotifyTaskAsync(WarningNotifyTaskEntity entity) { if (entity.IsClosed) return Task.FromResult(false); return Context.Updateable(entity) .SetColumns(x => x.IsClosed, true) .ExecuteCommandHasChangeAsync(); } #endregion #region 回传预警_重试推送任务 public Task> ScanReturnWarningRetryPushTaskAsync() { return Context.Queryable() .Where(x => x.IsClosed == false) .ToListAsync(); } public Task> GetReturnWarningRetryPushTaskAsync(Expression> expression) { return Context.Queryable() .Where(expression) .ToListAsync(); } public async Task AddReturnWarningRetryPushTaskAsync(ReturnWarningRetryPushTaskEntity entity) { return await Context.Insertable(entity) .ExecuteCommandAsync() > 0; } public Task BulkInsertReturnWarningRetryPushTaskAsync(List entities) { return Context.Insertable(entities) .ExecuteCommandAsync(); } public Task CloseReturnWarningRetryPushTaskAsync(Expression> expression) { return Context.Updateable() .Where(expression) .SetColumns(x => x.IsClosed, true) .ExecuteCommandAsync(); } public Task CloseReturnWarningRetryPushTaskAsync(ReturnWarningRetryPushTaskEntity entity) { if (entity.IsClosed) return Task.FromResult(false); return Context.Updateable(entity) .SetColumns(x => x.IsClosed, true) .ExecuteCommandHasChangeAsync(); } #endregion #region 运输预警_预警明细生成任务 public Task> GetTransportWarningDetailsGenerateTaskAsync(Expression> expression) { return Context.Queryable() .Where(expression) .ToListAsync(); } public async Task AddTransportWarningDetailsGenerateTaskAsync(TransportWarningDetailsGenerateTaskEntity entity) { return await Context.Insertable(entity) .ExecuteCommandAsync() > 0; } public Task BulkInsertTransportWarningDetailsGenerateTaskAsync(List entities) { return Context.Insertable(entities) .ExecuteCommandAsync(); } public Task BulkUpdateTransportWarningDetailsGenerateTaskAsync(List entities) { return Context.Updateable(entities) .ExecuteCommandAsync(); } public Task CloseTransportWarningDetailsGenerateTaskAsync(Expression> expression) { return Context.Updateable() .Where(expression) .SetColumns(x => x.IsClosed, true) .SetColumns(x => x.UpdateTime, DateTime.Now) .ExecuteCommandAsync(); } public Task CloseTransportWarningDetailsGenerateTaskAsync(TransportWarningDetailsGenerateTaskEntity entity) { if (entity.IsClosed) return Task.FromResult(false); return Context.Updateable(entity) .SetColumns(x => x.IsClosed, true) .ExecuteCommandHasChangeAsync(); } #endregion }