refactor:修复仓储接口和实现中的DeleteAsync方法问题 │

1. 为IBaseRepository接口添加DeleteByIdsAsync方法定义
 2. 为所有仓储实现类添加DeleteByIdsAsync方法实现
 3. 修复DeviceAppService中deviceId未定义的问题
 4. 修复DeviceManagementService中DeleteDeviceByIdAsync方法不存在的问题
 5. 修复所有仓储类中DeleteAsync(List<T>)方法实现不正确的问题
 6. 修复Email相关仓储类中Deleteable方法参数错误的问题"
This commit is contained in:
2025-10-21 12:27:45 +08:00
parent b980f989d8
commit 6872631933
20 changed files with 243 additions and 60 deletions

View File

@@ -34,7 +34,8 @@ public class DeviceAppService : IDeviceAppService
/// </summary>
/// <param name="id">设备ID。</param>
/// <returns>设备数据传输对象。</returns>
public async Task<Device> GetDeviceByIdAsync(int id) {
public async Task<Device> GetDeviceByIdAsync(int id)
{
var device = await _repoManager.Devices.GetByIdAsync(id);
return device;
}
@@ -81,8 +82,10 @@ public class DeviceAppService : IDeviceAppService
dto.VariableTable = await _repoManager.VariableTables.AddAsync(dto.VariableTable);
if (dto.VariableTable == null || dto.VariableTable.Id == 0)
{
throw new InvalidOperationException($"添加设备变量表失败,设备:{dto.Device.Name},变量表:{dto?.VariableTable?.Name}");
throw new InvalidOperationException(
$"添加设备变量表失败,设备:{dto.Device.Name},变量表:{dto?.VariableTable?.Name}");
}
dto.VariableTable.Device = dto.Device;
// 假设有设备菜单
@@ -127,13 +130,14 @@ public class DeviceAppService : IDeviceAppService
}
_mapper.Map(device, existingDevice);
int res=await _repoManager.Devices.UpdateAsync(existingDevice);
var menu=await _repoManager.Menus.GetMenuByTargetIdAsync(MenuType.DeviceMenu, device.Id);
int res = await _repoManager.Devices.UpdateAsync(existingDevice);
var menu = await _repoManager.Menus.GetMenuByTargetIdAsync(MenuType.DeviceMenu, device.Id);
if (menu != null)
{
menu.Header = device.Name;
await _repoManager.Menus.UpdateAsync(menu);
await _repoManager.Menus.UpdateAsync(menu);
}
await _repoManager.CommitAsync();
return res;
}
@@ -157,13 +161,14 @@ public class DeviceAppService : IDeviceAppService
throw new InvalidOperationException($"删除设备失败设备ID:{device.Id}请检查设备Id是否存在");
}
// 删除关联的变量
await _repoManager.Variables.DeleteByVariableTableIdAsync(device.Id);
// 删除关联的变量表
await _repoManager.VariableTables.DeleteAsync(device.VariableTables);
// 删除关联的变量
await _repoManager.Variables.DeleteByVariableTableIdAsync(deviceId);
// 删除关联的菜单树
await _repoManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.DeviceMenu,deviceId);
await _repoManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.DeviceMenu, device.Id);
await _repoManager.CommitAsync();
return true;
@@ -174,7 +179,6 @@ public class DeviceAppService : IDeviceAppService
// 可以在此记录日志
throw new ApplicationException($"删除设备时发生错误,操作已回滚,错误信息:{ex.Message}", ex);
}
}
/// <summary>