Browse Source
- 实现ICellularDeviceRuntimeDetailRepository接口的所有方法 - 提供完整的运行时明细数据查询功能 - 支持多条件分页查询和批量操作 - 修复依赖注入问题,确保StartDeviceRuntimeCommandHandler正常工作feature/x1-web-request
3 changed files with 208 additions and 0 deletions
@ -0,0 +1,154 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Expressions; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using CellularManagement.Domain.Entities.Device; |
||||
|
using CellularManagement.Domain.Repositories.Device; |
||||
|
using CellularManagement.Domain.Repositories.Base; |
||||
|
using CellularManagement.Infrastructure.Repositories.Base; |
||||
|
|
||||
|
namespace CellularManagement.Infrastructure.Repositories.Device; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 蜂窝设备运行时明细仓储实现类
|
||||
|
/// </summary>
|
||||
|
public class CellularDeviceRuntimeDetailRepository : BaseRepository<CellularDeviceRuntimeDetail>, ICellularDeviceRuntimeDetailRepository |
||||
|
{ |
||||
|
private readonly ILogger<CellularDeviceRuntimeDetailRepository> _logger; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 初始化仓储
|
||||
|
/// </summary>
|
||||
|
public CellularDeviceRuntimeDetailRepository( |
||||
|
ICommandRepository<CellularDeviceRuntimeDetail> commandRepository, |
||||
|
IQueryRepository<CellularDeviceRuntimeDetail> queryRepository, |
||||
|
ILogger<CellularDeviceRuntimeDetailRepository> logger) |
||||
|
: base(commandRepository, queryRepository, logger) |
||||
|
{ |
||||
|
_logger = logger; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据运行编码获取运行时明细列表
|
||||
|
/// </summary>
|
||||
|
public async Task<List<CellularDeviceRuntimeDetail>> GetDetailsByRuntimeCodeAsync(string runtimeCode, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var details = await QueryRepository.FindAsync(d => d.RuntimeCode == runtimeCode, cancellationToken: cancellationToken); |
||||
|
return details.ToList(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据创建人获取运行时明细列表
|
||||
|
/// </summary>
|
||||
|
public async Task<List<CellularDeviceRuntimeDetail>> GetDetailsByCreatedByAsync(string createdBy, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var details = await QueryRepository.FindAsync(d => d.CreatedBy == createdBy, cancellationToken: cancellationToken); |
||||
|
return details.OrderByDescending(d => d.CreatedAt).ToList(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据运行时状态获取运行时明细列表
|
||||
|
/// </summary>
|
||||
|
public async Task<List<CellularDeviceRuntimeDetail>> GetDetailsByRuntimeStatusAsync(bool runtimeStatus, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var details = await QueryRepository.FindAsync(d => d.RuntimeStatus == runtimeStatus, cancellationToken: cancellationToken); |
||||
|
return details.OrderByDescending(d => d.CreatedAt).ToList(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 分页查询运行时明细
|
||||
|
/// </summary>
|
||||
|
public async Task<(int TotalCount, List<CellularDeviceRuntimeDetail> Items)> SearchDetailsAsync( |
||||
|
string? runtimeCode = null, |
||||
|
string? createdBy = null, |
||||
|
bool? runtimeStatus = null, |
||||
|
DateTime? startDate = null, |
||||
|
DateTime? endDate = null, |
||||
|
int pageNumber = 1, |
||||
|
int pageSize = 10, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
// 构建查询条件
|
||||
|
Expression<Func<CellularDeviceRuntimeDetail, bool>> predicate = d => true; |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(runtimeCode)) |
||||
|
{ |
||||
|
predicate = d => d.RuntimeCode == runtimeCode; |
||||
|
} |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(createdBy)) |
||||
|
{ |
||||
|
predicate = d => d.CreatedBy == createdBy; |
||||
|
} |
||||
|
|
||||
|
if (runtimeStatus.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.RuntimeStatus == runtimeStatus.Value; |
||||
|
} |
||||
|
|
||||
|
if (startDate.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.CreatedAt >= startDate.Value; |
||||
|
} |
||||
|
|
||||
|
if (endDate.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.CreatedAt <= endDate.Value; |
||||
|
} |
||||
|
|
||||
|
// 组合多个条件
|
||||
|
if (!string.IsNullOrEmpty(runtimeCode) && !string.IsNullOrEmpty(createdBy)) |
||||
|
{ |
||||
|
predicate = d => d.RuntimeCode == runtimeCode && d.CreatedBy == createdBy; |
||||
|
} |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(runtimeCode) && runtimeStatus.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.RuntimeCode == runtimeCode && d.RuntimeStatus == runtimeStatus.Value; |
||||
|
} |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(createdBy) && runtimeStatus.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.CreatedBy == createdBy && d.RuntimeStatus == runtimeStatus.Value; |
||||
|
} |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(runtimeCode) && !string.IsNullOrEmpty(createdBy) && runtimeStatus.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.RuntimeCode == runtimeCode && d.CreatedBy == createdBy && d.RuntimeStatus == runtimeStatus.Value; |
||||
|
} |
||||
|
|
||||
|
if (startDate.HasValue && endDate.HasValue) |
||||
|
{ |
||||
|
predicate = d => d.CreatedAt >= startDate.Value && d.CreatedAt <= endDate.Value; |
||||
|
} |
||||
|
|
||||
|
// 获取分页结果
|
||||
|
var (totalCount, items) = await QueryRepository.GetPagedAsync(predicate, pageNumber, pageSize, cancellationToken: cancellationToken); |
||||
|
|
||||
|
// 按创建时间倒序排列
|
||||
|
var orderedItems = items.OrderByDescending(d => d.CreatedAt).ToList(); |
||||
|
|
||||
|
return (totalCount, orderedItems); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取运行时明细总数
|
||||
|
/// </summary>
|
||||
|
public async Task<int> GetDetailCountAsync(CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var allDetails = await QueryRepository.GetAllAsync(cancellationToken: cancellationToken); |
||||
|
return allDetails.Count(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 批量添加运行时明细
|
||||
|
/// </summary>
|
||||
|
public async Task<IEnumerable<CellularDeviceRuntimeDetail>> AddDetailsRangeAsync(IEnumerable<CellularDeviceRuntimeDetail> details, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await CommandRepository.AddRangeAsync(details, cancellationToken); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue