按照软件设计文档开始重构代码01
This commit is contained in:
39
DMS.Core/Interfaces/IBaseRepository.cs
Normal file
39
DMS.Core/Interfaces/IBaseRepository.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// 提供泛型数据访问操作的基础仓储接口。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">领域模型的类型。</typeparam>
|
||||
public interface IBaseRepository<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步根据ID获取单个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">实体的主键ID。</param>
|
||||
/// <returns>找到的实体,如果不存在则返回null。</returns>
|
||||
Task<T> GetByIdAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有实体。
|
||||
/// </summary>
|
||||
/// <returns>所有实体的列表。</returns>
|
||||
Task<List<T>> GetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加一个新实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">要添加的实体。</param>
|
||||
Task AddAsync(T entity);
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新一个已存在的实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">要更新的实体。</param>
|
||||
Task UpdateAsync(T entity);
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除的实体的主键ID。</param>
|
||||
Task DeleteAsync(int id);
|
||||
}
|
||||
23
DMS.Core/Interfaces/IDeviceRepository.cs
Normal file
23
DMS.Core/Interfaces/IDeviceRepository.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// 继承自IBaseRepository,提供设备相关的特定数据查询功能。
|
||||
/// </summary>
|
||||
public interface IDeviceRepository : IBaseRepository<Device>
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步获取所有激活的设备,并级联加载其下的变量表和变量。
|
||||
/// 这是后台轮询服务需要的主要数据。
|
||||
/// </summary>
|
||||
/// <returns>包含完整层级结构的激活设备列表。</returns>
|
||||
Task<List<Device>> GetActiveDevicesWithDetailsAsync(ProtocolType protocol);
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据设备ID获取设备及其所有详细信息(变量表、变量、MQTT别名等)。
|
||||
/// </summary>
|
||||
/// <param name="deviceId">设备ID。</param>
|
||||
/// <returns>包含详细信息的设备对象。</returns>
|
||||
Task<Device> GetDeviceWithDetailsAsync(int deviceId);
|
||||
}
|
||||
8
DMS.Core/Interfaces/IMenuRepository.cs
Normal file
8
DMS.Core/Interfaces/IMenuRepository.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IMenuRepository : IBaseRepository<MenuBean>
|
||||
{
|
||||
// 可以添加特定于菜单的查询方法,例如获取所有菜单项
|
||||
}
|
||||
13
DMS.Core/Interfaces/IMqttServerRepository.cs
Normal file
13
DMS.Core/Interfaces/IMqttServerRepository.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IMqttServerRepository : IBaseRepository<MqttServer>
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步获取一个MQTT服务器及其关联的所有变量别名。
|
||||
/// </summary>
|
||||
/// <param name="serverId">MQTT服务器ID。</param>
|
||||
/// <returns>包含变量别名信息的MQTT服务器对象。</returns>
|
||||
Task<MqttServer> GetMqttServerWithVariableAliasesAsync(int serverId);
|
||||
}
|
||||
66
DMS.Core/Interfaces/IRepositoryManager.cs
Normal file
66
DMS.Core/Interfaces/IRepositoryManager.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// 定义了一个仓储管理器,它使用工作单元模式来组合多个仓储操作,以确保事务的原子性。
|
||||
/// 实现了IDisposable,以确保数据库连接等资源能被正确释放。
|
||||
/// </summary>
|
||||
public interface IRepositoryManager : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取设备仓储的实例。
|
||||
/// 所有通过此管理器获取的仓储都共享同一个数据库上下文和事务。
|
||||
/// </summary>
|
||||
IDeviceRepository Devices { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量表仓储的实例。
|
||||
/// </summary>
|
||||
IVariableTableRepository VariableTables { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量仓储的实例。
|
||||
/// </summary>
|
||||
IVariableRepository Variables { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取MQTT服务器仓储的实例。
|
||||
/// </summary>
|
||||
IMqttServerRepository MqttServers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量MQTT别名仓储的实例。
|
||||
/// </summary>
|
||||
IVariableMqttAliasRepository VariableMqttAliases { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单仓储的实例。
|
||||
/// </summary>
|
||||
IMenuRepository Menus { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量历史仓储的实例。
|
||||
/// </summary>
|
||||
IVariableHistoryRepository VariableHistories { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户仓储的实例。
|
||||
/// </summary>
|
||||
IUserRepository Users { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始一个新的数据库事务。
|
||||
/// </summary>
|
||||
void BeginTransaction();
|
||||
|
||||
/// <summary>
|
||||
/// 异步提交当前事务中的所有变更。
|
||||
/// </summary>
|
||||
/// <returns>一个表示异步操作的任务。</returns>
|
||||
Task CommitAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 异步回滚当前事务中的所有变更。
|
||||
/// </summary>
|
||||
/// <returns>一个表示异步操作的任务。</returns>
|
||||
Task RollbackAsync();
|
||||
}
|
||||
13
DMS.Core/Interfaces/IUserRepository.cs
Normal file
13
DMS.Core/Interfaces/IUserRepository.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IUserRepository : IBaseRepository<User>
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步根据用户名获取用户。
|
||||
/// </summary>
|
||||
/// <param name="username">用户名。</param>
|
||||
/// <returns>用户对象,如果不存在则为null。</returns>
|
||||
Task<User> GetByUsernameAsync(string username);
|
||||
}
|
||||
8
DMS.Core/Interfaces/IVariableHistoryRepository.cs
Normal file
8
DMS.Core/Interfaces/IVariableHistoryRepository.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IVariableHistoryRepository : IBaseRepository<VariableHistory>
|
||||
{
|
||||
// 可以添加特定于VariableHistory的查询方法
|
||||
}
|
||||
21
DMS.Core/Interfaces/IVariableMqttAliasRepository.cs
Normal file
21
DMS.Core/Interfaces/IVariableMqttAliasRepository.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IVariableMqttAliasRepository : IBaseRepository<VariableMqttAlias>
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步获取指定变量的所有MQTT别名关联,并加载关联的MQTT服务器信息。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID。</param>
|
||||
/// <returns>指定变量的所有MQTT别名关联列表。</returns>
|
||||
Task<List<VariableMqttAlias>> GetAliasesForVariableAsync(int variableId);
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据变量ID和MQTT服务器ID获取特定的MQTT别名关联。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID。</param>
|
||||
/// <param name="mqttServerId">MQTT服务器ID。</param>
|
||||
/// <returns>匹配的VariableMqttAlias对象,如果不存在则为null。</returns>
|
||||
Task<VariableMqttAlias> GetByVariableAndServerAsync(int variableId, int mqttServerId);
|
||||
}
|
||||
13
DMS.Core/Interfaces/IVariableRepository.cs
Normal file
13
DMS.Core/Interfaces/IVariableRepository.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IVariableRepository : IBaseRepository<Variable>
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步获取一个变量及其关联的所有MQTT别名和对应的MQTT服务器信息。
|
||||
/// </summary>
|
||||
/// <param name="variableId">变量ID。</param>
|
||||
/// <returns>包含别名和服务器信息的变量对象。</returns>
|
||||
Task<Variable> GetVariableWithMqttAliasesAsync(int variableId);
|
||||
}
|
||||
8
DMS.Core/Interfaces/IVariableTableRepository.cs
Normal file
8
DMS.Core/Interfaces/IVariableTableRepository.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces;
|
||||
|
||||
public interface IVariableTableRepository : IBaseRepository<VariableTable>
|
||||
{
|
||||
// 可以添加特定于VariableTable的查询方法
|
||||
}
|
||||
Reference in New Issue
Block a user