bugfix:修复Mqtt服务器详情页变量值不更新的问题,修复修改Mqtt别名后台不更新的问题,重新调整了别名的架构
This commit is contained in:
@@ -222,42 +222,36 @@ namespace DMS.WPF.ViewModels
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var item in resMqttAliaes)
|
||||
|
||||
int counter = 0;
|
||||
foreach (var mqttAliasItem in resMqttAliaes)
|
||||
{
|
||||
foreach (var selectItem in selectedMqttAliaes)
|
||||
{
|
||||
if (item.Id == selectItem.Id)
|
||||
if (mqttAliasItem.Id == selectItem.Id)
|
||||
{
|
||||
selectItem.Alias = item.Alias;
|
||||
selectItem.Alias = mqttAliasItem.Alias;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 保存更改到数据服务
|
||||
var result = await _wpfDataService.MqttAliasDataService.UpdateMqttAlias(mqttAliasItem);
|
||||
if (result)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//var newAlias = dialogResult.Trim();
|
||||
|
||||
//if (string.IsNullOrEmpty(newAlias))
|
||||
//{
|
||||
// _notificationService.ShowWarn("发送名称不能为空。");
|
||||
// return;
|
||||
//}
|
||||
|
||||
//// 更新变量的发送名称
|
||||
//variableAlias.Alias = newAlias;
|
||||
|
||||
// 保存更改到数据服务
|
||||
// var result = await _wpfDataService.UpdateMqttServer(CurrentMqtt);
|
||||
//
|
||||
// if (result)
|
||||
// {
|
||||
// _notificationService.ShowSuccess($"变量 '{variableAlias.Variable.Name}' 的发送名称已更新为 '{newAlias}'");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _notificationService.ShowError("更新发送名称失败。");
|
||||
// // 如果更新失败,恢复原来的值
|
||||
// variableAlias.Alias = oldAlias;
|
||||
// }
|
||||
if (counter>0)
|
||||
{
|
||||
_notificationService.ShowSuccess($"成功修改发送名称:{counter}个");
|
||||
}
|
||||
else
|
||||
{
|
||||
_notificationService.ShowError("更新发送名称失败。");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -627,48 +627,14 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
// 为每个变量分配MQTT别名
|
||||
foreach (var editedVariableMqtt in editedVariableMqtts)
|
||||
{
|
||||
await _mqttAliasAppService.AssignAliasAsync(
|
||||
editedVariableMqtt.VariableId,
|
||||
selectedMqtt.Id,
|
||||
editedVariableMqtt.Alias);
|
||||
|
||||
totalAffectedCount++;
|
||||
|
||||
// 更新内存中的 Variable 对象
|
||||
var originalVariable = validVariables.FirstOrDefault(v => v.Id == editedVariableMqtt.VariableId);
|
||||
if (originalVariable == null)
|
||||
var mqttAliasItem = await _wpfDataService.MqttAliasDataService.AssignAliasAsync(editedVariableMqtt);
|
||||
if (mqttAliasItem is not null)
|
||||
{
|
||||
continue;
|
||||
totalAffectedCount++;
|
||||
}
|
||||
|
||||
|
||||
if (originalVariable.MqttAliases == null)
|
||||
{
|
||||
originalVariable.MqttAliases = new();
|
||||
}
|
||||
|
||||
// 检查是否已存在该变量与该MQTT服务器的关联
|
||||
var existingVariableMqtt
|
||||
= originalVariable.MqttAliases.FirstOrDefault(vm => vm.MqttServerId == selectedMqtt.Id);
|
||||
|
||||
if (existingVariableMqtt == null)
|
||||
{
|
||||
// 如果不存在,则添加新的关联
|
||||
var variableMqtt = new MqttAliasItem
|
||||
{
|
||||
VariableId = originalVariable.Id,
|
||||
MqttServerId = selectedMqtt.Id,
|
||||
Alias = editedVariableMqtt.Alias,
|
||||
MqttServer = selectedMqtt,
|
||||
Variable = originalVariable
|
||||
};
|
||||
originalVariable.MqttAliases.Add(variableMqtt);
|
||||
selectedMqtt.VariableAliases.Add(variableMqtt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果存在,则更新别名
|
||||
existingVariableMqtt.Alias = editedVariableMqtt.Alias;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalAffectedCount > 0)
|
||||
|
||||
Reference in New Issue
Block a user