track/src/TrackCenter.Repository/Repositories/WarningTaskRepository.cs
zzh dabb9a4edb refactor: slim ProviderService upsert APIs and clarify failure tips
Remove debug APIs and transport scan Hangfire; move Upsert to Order/Upsert*; keep original response shapes and put result+reason only in exception messages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 21:12:56 +08:00

157 lines
5.7 KiB
C#

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<WarningNotifyTaskEntity>, IWarningTaskRepository, ITransientDependency
{
#region 预警通知任务
public Task<List<WarningNotifyTaskEntity>> ScanNotifyTaskAsync(DateTime? startDateTime = null)
{
return Context.Queryable<WarningNotifyTaskEntity>()
.Where(x => x.IsClosed == false)
.WhereIF(startDateTime.HasValue, x => startDateTime!.Value <= x.CreateTime)
.ToListAsync();
}
public Task<List<WarningNotifyTaskEntity>> GetWarningNotifyTaskAsync(Expression<Func<WarningNotifyTaskEntity, bool>> expression)
{
return Context.Queryable<WarningNotifyTaskEntity>()
.Where(expression)
.ToListAsync();
}
public Task<List<T>> GetWarningNotifyTaskAsync<T>(Expression<Func<WarningNotifyTaskEntity, bool>> expression, Expression<Func<WarningNotifyTaskEntity, T>> select)
{
return Context.Queryable<WarningNotifyTaskEntity>()
.Where(expression)
.Select(select)
.ToListAsync();
}
public async Task<bool> AddWarningNotifyTaskAsync(WarningNotifyTaskEntity entity)
{
return await Context.Insertable(entity).ExecuteCommandAsync() > 0;
}
public Task<int> BulkInsertWarningNotifyTaskAsync(List<WarningNotifyTaskEntity> entities)
{
return Context.Insertable(entities)
.ExecuteCommandAsync();
}
public Task<int> CloseWarningNotifyTaskAsync(Expression<Func<WarningNotifyTaskEntity, bool>> expression)
{
return Context.Updateable<WarningNotifyTaskEntity>()
.Where(expression)
.SetColumns(x => x.IsClosed, true)
.SetColumns(x => x.UpdateTime, DateTime.Now)
.ExecuteCommandAsync();
}
public Task<bool> CloseWarningNotifyTaskAsync(WarningNotifyTaskEntity entity)
{
if (entity.IsClosed) return Task.FromResult(false);
return Context.Updateable(entity)
.SetColumns(x => x.IsClosed, true)
.ExecuteCommandHasChangeAsync();
}
#endregion
#region 回传预警_重试推送任务
public Task<List<ReturnWarningRetryPushTaskEntity>> ScanReturnWarningRetryPushTaskAsync()
{
return Context.Queryable<ReturnWarningRetryPushTaskEntity>()
.Where(x => x.IsClosed == false)
.ToListAsync();
}
public Task<List<ReturnWarningRetryPushTaskEntity>> GetReturnWarningRetryPushTaskAsync(Expression<Func<ReturnWarningRetryPushTaskEntity, bool>> expression)
{
return Context.Queryable<ReturnWarningRetryPushTaskEntity>()
.Where(expression)
.ToListAsync();
}
public async Task<bool> AddReturnWarningRetryPushTaskAsync(ReturnWarningRetryPushTaskEntity entity)
{
return await Context.Insertable(entity)
.ExecuteCommandAsync() > 0;
}
public Task<int> BulkInsertReturnWarningRetryPushTaskAsync(List<ReturnWarningRetryPushTaskEntity> entities)
{
return Context.Insertable(entities)
.ExecuteCommandAsync();
}
public Task<int> CloseReturnWarningRetryPushTaskAsync(Expression<Func<ReturnWarningRetryPushTaskEntity, bool>> expression)
{
return Context.Updateable<ReturnWarningRetryPushTaskEntity>()
.Where(expression)
.SetColumns(x => x.IsClosed, true)
.ExecuteCommandAsync();
}
public Task<bool> CloseReturnWarningRetryPushTaskAsync(ReturnWarningRetryPushTaskEntity entity)
{
if (entity.IsClosed) return Task.FromResult(false);
return Context.Updateable(entity)
.SetColumns(x => x.IsClosed, true)
.ExecuteCommandHasChangeAsync();
}
#endregion
#region 运输预警_预警明细生成任务
public Task<List<TransportWarningDetailsGenerateTaskEntity>> GetTransportWarningDetailsGenerateTaskAsync(Expression<Func<TransportWarningDetailsGenerateTaskEntity, bool>> expression)
{
return Context.Queryable<TransportWarningDetailsGenerateTaskEntity>()
.Where(expression)
.ToListAsync();
}
public async Task<bool> AddTransportWarningDetailsGenerateTaskAsync(TransportWarningDetailsGenerateTaskEntity entity)
{
return await Context.Insertable(entity)
.ExecuteCommandAsync() > 0;
}
public Task<int> BulkInsertTransportWarningDetailsGenerateTaskAsync(List<TransportWarningDetailsGenerateTaskEntity> entities)
{
return Context.Insertable(entities)
.ExecuteCommandAsync();
}
public Task<int> BulkUpdateTransportWarningDetailsGenerateTaskAsync(List<TransportWarningDetailsGenerateTaskEntity> entities)
{
return Context.Updateable(entities)
.ExecuteCommandAsync();
}
public Task<int> CloseTransportWarningDetailsGenerateTaskAsync(Expression<Func<TransportWarningDetailsGenerateTaskEntity, bool>> expression)
{
return Context.Updateable<TransportWarningDetailsGenerateTaskEntity>()
.Where(expression)
.SetColumns(x => x.IsClosed, true)
.SetColumns(x => x.UpdateTime, DateTime.Now)
.ExecuteCommandAsync();
}
public Task<bool> CloseTransportWarningDetailsGenerateTaskAsync(TransportWarningDetailsGenerateTaskEntity entity)
{
if (entity.IsClosed) return Task.FromResult(false);
return Context.Updateable(entity)
.SetColumns(x => x.IsClosed, true)
.ExecuteCommandHasChangeAsync();
}
#endregion
}