using AutoMapper;
using DMS.Application.DTOs;
using DMS.Application.Interfaces;
using DMS.Core.Interfaces;
namespace DMS.Application.Services;
///
/// 历史记录应用服务实现类,负责处理变量历史记录相关的业务逻辑。
///
public class HistoryAppService : IHistoryAppService
{
private readonly IRepositoryManager _repoManager;
private readonly IMapper _mapper;
///
/// 构造函数,注入仓储管理器和AutoMapper。
///
/// 仓储管理器实例。
/// AutoMapper实例。
public HistoryAppService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
_mapper = mapper;
}
///
/// 异步获取指定变量的历史记录。
///
/// 变量ID
/// 变量历史记录列表
public async Task> GetVariableHistoriesAsync(int variableId)
{
var histories = await _repoManager.VariableHistories.GetByVariableIdAsync(variableId);
return _mapper.Map>(histories);
}
///
/// 异步获取指定变量的历史记录,支持条数限制和时间范围筛选。
///
/// 变量ID
/// 返回记录的最大数量,null表示无限制
/// 开始时间,null表示无限制
/// 结束时间,null表示无限制
/// 变量历史记录列表
public async Task> GetVariableHistoriesAsync(int variableId, int? limit = null, DateTime? startTime = null, DateTime? endTime = null)
{
var histories = await _repoManager.VariableHistories.GetByVariableIdAsync(variableId, limit, startTime, endTime);
return _mapper.Map>(histories);
}
///
/// 异步获取所有变量的历史记录。
///
/// 所有变量历史记录列表
public async Task> GetAllVariableHistoriesAsync()
{
var histories = await _repoManager.VariableHistories.GetAllAsync();
return _mapper.Map>(histories);
}
///
/// 异步获取所有变量的历史记录,支持条数限制和时间范围筛选。
///
/// 返回记录的最大数量,null表示无限制
/// 开始时间,null表示无限制
/// 结束时间,null表示无限制
/// 所有变量历史记录列表
public async Task> GetAllVariableHistoriesAsync(int? limit = null, DateTime? startTime = null, DateTime? endTime = null)
{
var histories = await _repoManager.VariableHistories.GetAllAsync(limit, startTime, endTime);
return _mapper.Map>(histories);
}
}