修改历史记录功能(未完成)
This commit is contained in:
@@ -9,6 +9,7 @@ public class VariableHistoryDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public int VariableId { get; set; }
|
||||
public string VariableName { get; set; }
|
||||
public string Value { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
41
DMS.Application/Interfaces/IHistoryAppService.cs
Normal file
41
DMS.Application/Interfaces/IHistoryAppService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using DMS.Application.DTOs;
|
||||
|
||||
namespace DMS.Application.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// 定义历史记录管理相关的应用服务操作。
|
||||
/// </summary>
|
||||
public interface IHistoryAppService
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的历史记录。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID</param>
|
||||
/// <returns>变量历史记录列表</returns>
|
||||
Task<List<VariableHistoryDto>> GetVariableHistoriesAsync(int variableId);
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的历史记录,支持条数限制和时间范围筛选。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID</param>
|
||||
/// <param name="limit">返回记录的最大数量,null表示无限制</param>
|
||||
/// <param name="startTime">开始时间,null表示无限制</param>
|
||||
/// <param name="endTime">结束时间,null表示无限制</param>
|
||||
/// <returns>变量历史记录列表</returns>
|
||||
Task<List<VariableHistoryDto>> GetVariableHistoriesAsync(int variableId, int? limit = null, DateTime? startTime = null, DateTime? endTime = null);
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有变量的历史记录。
|
||||
/// </summary>
|
||||
/// <returns>所有变量历史记录列表</returns>
|
||||
Task<List<VariableHistoryDto>> GetAllVariableHistoriesAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有变量的历史记录,支持条数限制和时间范围筛选。
|
||||
/// </summary>
|
||||
/// <param name="limit">返回记录的最大数量,null表示无限制</param>
|
||||
/// <param name="startTime">开始时间,null表示无限制</param>
|
||||
/// <param name="endTime">结束时间,null表示无限制</param>
|
||||
/// <returns>所有变量历史记录列表</returns>
|
||||
Task<List<VariableHistoryDto>> GetAllVariableHistoriesAsync(int? limit = null, DateTime? startTime = null, DateTime? endTime = null);
|
||||
}
|
||||
@@ -70,11 +70,4 @@ public interface IVariableAppService
|
||||
/// <param name="variableToCheck">要检查的变量。</param>
|
||||
/// <returns>如果变量已存在则返回该变量,否则返回null。</returns>
|
||||
Task<VariableDto?> FindExistingVariableAsync(VariableDto variableToCheck);
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的历史记录。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID</param>
|
||||
/// <returns>变量历史记录列表</returns>
|
||||
Task<List<VariableHistoryDto>> GetVariableHistoriesAsync(int variableId);
|
||||
}
|
||||
@@ -40,7 +40,9 @@ public class MappingProfile : Profile
|
||||
.ReverseMap();
|
||||
|
||||
// VariableHistory 映射
|
||||
CreateMap<VariableHistory, VariableHistoryDto>().ReverseMap();
|
||||
CreateMap<VariableHistory, VariableHistoryDto>()
|
||||
.ForMember(dest => dest.VariableName, opt => opt.MapFrom(src => src.Variable.Name))
|
||||
.ReverseMap();
|
||||
|
||||
// MenuBean 映射
|
||||
CreateMap<MenuBean, MenuBeanDto>().ReverseMap();
|
||||
|
||||
@@ -41,6 +41,13 @@ public class AppDataStorageService : IAppDataStorageService
|
||||
/// 安全字典,用于存储所有MQTT变量别名的数据
|
||||
/// </summary>
|
||||
public ConcurrentDictionary<int, VariableMqttAliasDto> VariableMqttAliases { get; } = new();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 安全字典,用于存储所有历史记录
|
||||
/// </summary>
|
||||
public ConcurrentDictionary<int, VariableHistoryDto> VariableHistories { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 安全字典,用于存储所有日志数据
|
||||
|
||||
74
DMS.Application/Services/HistoryAppService.cs
Normal file
74
DMS.Application/Services/HistoryAppService.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using AutoMapper;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Application.Interfaces;
|
||||
using DMS.Core.Interfaces;
|
||||
|
||||
namespace DMS.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 历史记录应用服务实现类,负责处理变量历史记录相关的业务逻辑。
|
||||
/// </summary>
|
||||
public class HistoryAppService : IHistoryAppService
|
||||
{
|
||||
private readonly IRepositoryManager _repoManager;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数,注入仓储管理器和AutoMapper。
|
||||
/// </summary>
|
||||
/// <param name="repoManager">仓储管理器实例。</param>
|
||||
/// <param name="mapper">AutoMapper实例。</param>
|
||||
public HistoryAppService(IRepositoryManager repoManager, IMapper mapper)
|
||||
{
|
||||
_repoManager = repoManager;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的历史记录。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID</param>
|
||||
/// <returns>变量历史记录列表</returns>
|
||||
public async Task<List<VariableHistoryDto>> GetVariableHistoriesAsync(int variableId)
|
||||
{
|
||||
var histories = await _repoManager.VariableHistories.GetByVariableIdAsync(variableId);
|
||||
return _mapper.Map<List<VariableHistoryDto>>(histories);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的历史记录,支持条数限制和时间范围筛选。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID</param>
|
||||
/// <param name="limit">返回记录的最大数量,null表示无限制</param>
|
||||
/// <param name="startTime">开始时间,null表示无限制</param>
|
||||
/// <param name="endTime">结束时间,null表示无限制</param>
|
||||
/// <returns>变量历史记录列表</returns>
|
||||
public async Task<List<VariableHistoryDto>> 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<List<VariableHistoryDto>>(histories);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有变量的历史记录。
|
||||
/// </summary>
|
||||
/// <returns>所有变量历史记录列表</returns>
|
||||
public async Task<List<VariableHistoryDto>> GetAllVariableHistoriesAsync()
|
||||
{
|
||||
var histories = await _repoManager.VariableHistories.GetAllAsync();
|
||||
return _mapper.Map<List<VariableHistoryDto>>(histories);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有变量的历史记录,支持条数限制和时间范围筛选。
|
||||
/// </summary>
|
||||
/// <param name="limit">返回记录的最大数量,null表示无限制</param>
|
||||
/// <param name="startTime">开始时间,null表示无限制</param>
|
||||
/// <param name="endTime">结束时间,null表示无限制</param>
|
||||
/// <returns>所有变量历史记录列表</returns>
|
||||
public async Task<List<VariableHistoryDto>> GetAllVariableHistoriesAsync(int? limit = null, DateTime? startTime = null, DateTime? endTime = null)
|
||||
{
|
||||
var histories = await _repoManager.VariableHistories.GetAllAsync(limit, startTime, endTime);
|
||||
return _mapper.Map<List<VariableHistoryDto>>(histories);
|
||||
}
|
||||
}
|
||||
@@ -285,15 +285,4 @@ public class VariableAppService : IVariableAppService
|
||||
// 如果找到了匹配的变量,返回第一个(也是唯一一个)
|
||||
return existingVariables.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的历史记录。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID</param>
|
||||
/// <returns>变量历史记录列表</returns>
|
||||
public async Task<List<VariableHistoryDto>> GetVariableHistoriesAsync(int variableId)
|
||||
{
|
||||
var histories = await _repoManager.VariableHistories.GetByVariableIdAsync(variableId);
|
||||
return _mapper.Map<List<VariableHistoryDto>>(histories);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user