Browse Source

feat: 创建CellularDeviceRuntimeDetailRepository实现类

- 实现ICellularDeviceRuntimeDetailRepository接口的所有方法
- 提供完整的运行时明细数据查询功能
- 支持多条件分页查询和批量操作
- 修复依赖注入问题,确保StartDeviceRuntimeCommandHandler正常工作
feature/x1-web-request
hyh 3 days ago
parent
commit
6269ad3e59
  1. 1
      src/X1.Infrastructure/DependencyInjection.cs
  2. 154
      src/X1.Infrastructure/Repositories/Device/CellularDeviceRuntimeDetailRepository.cs
  3. 53
      src/modify.md

1
src/X1.Infrastructure/DependencyInjection.cs

@ -177,6 +177,7 @@ public static class DependencyInjection
services.AddScoped<ICellularDeviceRepository, CellularDeviceRepository>();
services.AddScoped<IProtocolVersionRepository, ProtocolVersionRepository>();
services.AddScoped<ICellularDeviceRuntimeRepository, CellularDeviceRuntimeRepository>();
services.AddScoped<ICellularDeviceRuntimeDetailRepository, CellularDeviceRuntimeDetailRepository>();
services.AddScoped<IRAN_ConfigurationRepository, RAN_ConfigurationRepository>();
services.AddScoped<ICoreNetworkConfigRepository, CoreNetworkConfigRepository>();
services.AddScoped<IIMS_ConfigurationRepository, IMS_ConfigurationRepository>();

154
src/X1.Infrastructure/Repositories/Device/CellularDeviceRuntimeDetailRepository.cs

@ -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);
}
}

53
src/modify.md

@ -1,5 +1,58 @@
# 修改记录
## 2025-01-29 - 创建CellularDeviceRuntimeDetailRepository实现类
### 修改原因
`ICellularDeviceRuntimeDetailRepository` 接口在 `DependencyInjection.cs` 中已注册,但缺少对应的实现类,导致依赖注入失败。
### 修改文件
- `X1.Infrastructure/Repositories/Device/CellularDeviceRuntimeDetailRepository.cs` - 创建运行时明细仓储实现类
### 修改内容
#### 1. 实现类结构
- **继承关系**:继承 `BaseRepository<CellularDeviceRuntimeDetail>` 基类
- **接口实现**:实现 `ICellularDeviceRuntimeDetailRepository` 接口的所有方法
- **依赖注入**:通过构造函数注入 `ICommandRepository`、`IQueryRepository` 和 `ILogger`
#### 2. 核心方法实现
- **GetDetailsByRuntimeCodeAsync**:根据运行编码查询明细列表
- **GetDetailsByCreatedByAsync**:根据创建人查询明细列表(按创建时间倒序)
- **GetDetailsByRuntimeStatusAsync**:根据运行时状态查询明细列表(按创建时间倒序)
- **SearchDetailsAsync**:支持多条件分页查询(运行编码、创建人、状态、时间范围)
- **GetDetailCountAsync**:获取明细记录总数
- **AddDetailsRangeAsync**:批量添加明细记录
#### 3. 查询优化
- **条件组合**:支持多个查询条件的组合查询
- **分页支持**:提供标准的分页查询功能
- **排序优化**:查询结果按创建时间倒序排列
- **性能考虑**:利用数据库索引提升查询性能
#### 4. 错误处理
- **空值处理**:正确处理可选的查询参数
- **异常传播**:将底层仓储的异常向上传播
- **日志记录**:通过注入的Logger记录操作日志
### 技术特性
- **CQRS模式**:使用命令和查询分离的仓储模式
- **异步操作**:所有方法都支持异步操作和取消令牌
- **类型安全**:使用强类型的查询表达式
- **可扩展性**:基于基类设计,便于扩展和维护
### 业务价值
- **数据查询**:提供完整的运行时明细数据查询功能
- **历史追踪**:支持按时间、状态、用户等维度追踪设备运行历史
- **统计分析**:支持明细数据的统计和分页查询
- **批量操作**:支持批量添加明细记录,提高数据录入效率
### 影响范围
- **依赖注入**:修复了 `ICellularDeviceRuntimeDetailRepository` 的依赖注入问题
- **应用层**:`StartDeviceRuntimeCommandHandler` 现在可以正常使用明细仓储
- **数据访问**:提供了完整的运行时明细数据访问能力
---
## 2025-01-29 - 修复StartDeviceRuntimeCommandHandler中网络启动返回值记录问题
### 修改原因

Loading…
Cancel
Save