2025-07-21 14:35:17 +08:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using DMS.Application.Interfaces;
|
2025-09-16 12:29:09 +08:00
|
|
|
|
using DMS.Application.Interfaces.Database;
|
2025-09-06 16:12:30 +08:00
|
|
|
|
using DMS.Core.Interfaces;
|
2025-10-06 17:25:05 +08:00
|
|
|
|
using DMS.Core.Models;
|
2025-07-21 14:35:17 +08:00
|
|
|
|
|
2025-09-16 12:29:09 +08:00
|
|
|
|
namespace DMS.Application.Services.Database;
|
2025-07-21 14:35:17 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-09-06 16:12:30 +08:00
|
|
|
|
/// IMqttAliasAppService 的实现,负责管理变量与MQTT服务器的别名关联。
|
2025-07-21 14:35:17 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MqttAliasAppService : IMqttAliasAppService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepositoryManager _repoManager;
|
2025-10-18 17:18:09 +08:00
|
|
|
|
private readonly IAppStorageService _appStorageService;
|
2025-07-21 14:35:17 +08:00
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// <summary>
|
2025-09-06 16:12:30 +08:00
|
|
|
|
/// 构造函数。
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// </summary>
|
2025-10-18 17:18:09 +08:00
|
|
|
|
public MqttAliasAppService(IRepositoryManager repoManager,IAppStorageService appStorageService, IMapper mapper)
|
2025-07-21 14:35:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
_repoManager = repoManager;
|
2025-10-18 17:18:09 +08:00
|
|
|
|
_appStorageService = appStorageService;
|
2025-07-21 14:35:17 +08:00
|
|
|
|
_mapper = mapper;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// <summary>
|
2025-09-06 16:12:30 +08:00
|
|
|
|
/// 异步为变量分配或更新一个MQTT别名。
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// </summary>
|
2025-10-11 18:07:01 +08:00
|
|
|
|
public async Task<MqttAlias> AssignAliasAsync(MqttAlias mqttAlias)
|
2025-07-21 14:35:17 +08:00
|
|
|
|
{
|
2025-10-11 18:07:01 +08:00
|
|
|
|
return await _repoManager.MqttAliases.AddAsync(mqttAlias);
|
2025-07-21 14:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// <summary>
|
2025-09-06 16:12:30 +08:00
|
|
|
|
/// 异步更新一个已存在的MQTT别名。
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// </summary>
|
2025-10-11 18:07:01 +08:00
|
|
|
|
public async Task<int> UpdateAliasAsync(MqttAlias mqttAlias)
|
2025-07-21 14:35:17 +08:00
|
|
|
|
{
|
2025-10-11 18:07:01 +08:00
|
|
|
|
return await _repoManager.MqttAliases.UpdateAsync(mqttAlias);
|
2025-07-21 14:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// <summary>
|
2025-09-06 16:12:30 +08:00
|
|
|
|
/// 异步移除一个MQTT别名关联。
|
2025-07-24 20:02:08 +08:00
|
|
|
|
/// </summary>
|
2025-10-11 18:07:01 +08:00
|
|
|
|
public async Task<int> RemoveAliasAsync(int aliasId)
|
|
|
|
|
|
{
|
2025-10-21 13:01:27 +08:00
|
|
|
|
var alias = await _repoManager.MqttAliases.GetByIdAsync(aliasId);
|
|
|
|
|
|
if (alias == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
return await _repoManager.MqttAliases.DeleteAsync(alias);
|
2025-10-11 18:07:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<MqttAlias>> GetAllAsync()
|
2025-07-21 14:35:17 +08:00
|
|
|
|
{
|
2025-10-11 18:07:01 +08:00
|
|
|
|
var mqttAliases = await _repoManager.MqttAliases.GetAllAsync();
|
|
|
|
|
|
|
|
|
|
|
|
return mqttAliases;
|
2025-07-21 14:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|