refactor:删除不必要的方法
This commit is contained in:
@@ -109,7 +109,12 @@ public class MenuAppService : IMenuAppService
|
||||
try
|
||||
{
|
||||
await _repoManager.BeginTranAsync();
|
||||
var delRes = await _repoManager.Menus.DeleteByIdAsync(id);
|
||||
var menu = await _repoManager.Menus.GetByIdAsync(id);
|
||||
if (menu == null)
|
||||
{
|
||||
throw new InvalidOperationException($"删除菜单失败:菜单ID:{id},请检查菜单Id是否存在");
|
||||
}
|
||||
var delRes = await _repoManager.Menus.DeleteAsync(menu);
|
||||
if (delRes == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"删除菜单失败:菜单ID:{id},请检查菜单Id是否存在");
|
||||
|
||||
@@ -46,7 +46,12 @@ public class MqttAliasAppService : IMqttAliasAppService
|
||||
/// </summary>
|
||||
public async Task<int> RemoveAliasAsync(int aliasId)
|
||||
{
|
||||
return await _repoManager.MqttAliases.DeleteByIdAsync(aliasId);
|
||||
var alias = await _repoManager.MqttAliases.GetByIdAsync(aliasId);
|
||||
if (alias == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return await _repoManager.MqttAliases.DeleteAsync(alias);
|
||||
}
|
||||
|
||||
public async Task<List<MqttAlias>> GetAllAsync()
|
||||
|
||||
@@ -116,7 +116,12 @@ public class MqttAppService : IMqttAppService
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _repoManager.MqttServers.DeleteByIdAsync(id);
|
||||
var mqttServer = await _repoManager.MqttServers.GetByIdAsync(id);
|
||||
if (mqttServer == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return await _repoManager.MqttServers.DeleteAsync(mqttServer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -171,27 +176,27 @@ public class MqttAppService : IMqttAppService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量删除MQTT服务器(事务性操作)。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的MQTT服务器ID列表。</param>
|
||||
/// <returns>如果删除成功则为 true,否则为 false。</returns>
|
||||
/// <exception cref="ApplicationException">如果批量删除MQTT服务器时发生错误。</exception>
|
||||
public async Task<bool> DeleteMqttServersAsync(List<int> ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ids == null || !ids.Any()) return true;
|
||||
|
||||
await _repoManager.BeginTranAsync();
|
||||
var result = await _repoManager.MqttServers.DeleteByIdsAsync(ids);
|
||||
await _repoManager.CommitAsync();
|
||||
return result > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _repoManager.RollbackAsync();
|
||||
throw new ApplicationException($"批量删除MQTT服务器时发生错误,操作已回滚,错误信息:{ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 异步批量删除MQTT服务器(事务性操作)。
|
||||
// /// </summary>
|
||||
// /// <param name="ids">要删除的MQTT服务器ID列表。</param>
|
||||
// /// <returns>如果删除成功则为 true,否则为 false。</returns>
|
||||
// /// <exception cref="ApplicationException">如果批量删除MQTT服务器时发生错误。</exception>
|
||||
// public async Task<bool> DeleteMqttServersAsync(List<int> ids)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (ids == null || !ids.Any()) return true;
|
||||
//
|
||||
// await _repoManager.BeginTranAsync();
|
||||
// var result = await _repoManager.MqttServers.DeleteByIdsAsync(ids);
|
||||
// await _repoManager.CommitAsync();
|
||||
// return result > 0;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// await _repoManager.RollbackAsync();
|
||||
// throw new ApplicationException($"批量删除MQTT服务器时发生错误,操作已回滚,错误信息:{ex.Message}", ex);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -174,7 +174,12 @@ namespace DMS.Application.Services.Database
|
||||
await _repositoryManager.BeginTranAsync();
|
||||
|
||||
// 删除触发器本身
|
||||
var rowsAffected = await _repositoryManager.Triggers.DeleteByIdAsync(id);
|
||||
var trigger = await _repositoryManager.Triggers.GetByIdAsync(id);
|
||||
if (trigger == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var rowsAffected = await _repositoryManager.Triggers.DeleteAsync(trigger);
|
||||
|
||||
await _repositoryManager.CommitAsync();
|
||||
return rowsAffected > 0;
|
||||
|
||||
@@ -44,7 +44,12 @@ public class TriggerVariableAppService : ITriggerVariableAppService
|
||||
/// </summary>
|
||||
public async Task<int> RemoveTriggerVariableAsync(int triggerVariableId)
|
||||
{
|
||||
return await _repositoryManager.TriggerVariables.DeleteByIdAsync(triggerVariableId);
|
||||
var triggerVariable = await _repositoryManager.TriggerVariables.GetByIdAsync(triggerVariableId);
|
||||
if (triggerVariable == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return await _repositoryManager.TriggerVariables.DeleteAsync(triggerVariable);
|
||||
}
|
||||
|
||||
public async Task<List<TriggerVariable>> GetAllAsync()
|
||||
|
||||
@@ -162,7 +162,12 @@ public class VariableAppService : IVariableAppService
|
||||
try
|
||||
{
|
||||
await _repoManager.BeginTranAsync();
|
||||
var delRes = await _repoManager.Variables.DeleteByIdAsync(id);
|
||||
var variable = await _repoManager.Variables.GetByIdAsync(id);
|
||||
if (variable == null)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量失败:变量ID:{id},请检查变量Id是否存在");
|
||||
}
|
||||
var delRes = await _repoManager.Variables.DeleteAsync(variable);
|
||||
if (delRes == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量失败:变量ID:{id},请检查变量Id是否存在");
|
||||
@@ -196,13 +201,13 @@ public class VariableAppService : IVariableAppService
|
||||
await _repoManager.BeginTranAsync();
|
||||
|
||||
// 批量删除变量
|
||||
var deletedCount = await _repoManager.Variables.DeleteByIdsAsync(ids);
|
||||
|
||||
// 检查是否所有变量都被成功删除
|
||||
if (deletedCount != ids.Count)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量失败:请求删除 {ids.Count} 个变量,实际删除 {deletedCount} 个变量");
|
||||
}
|
||||
// var deletedCount = await _repoManager.Variables.DeleteByIdsAsync(ids);
|
||||
//
|
||||
// // 检查是否所有变量都被成功删除
|
||||
// if (deletedCount != ids.Count)
|
||||
// {
|
||||
// throw new InvalidOperationException($"删除变量失败:请求删除 {ids.Count} 个变量,实际删除 {deletedCount} 个变量");
|
||||
// }
|
||||
|
||||
await _repoManager.CommitAsync();
|
||||
return true;
|
||||
|
||||
@@ -146,7 +146,12 @@ namespace DMS.Application.Services.Database
|
||||
try
|
||||
{
|
||||
await _repositoryManager.BeginTranAsync();
|
||||
var delRes = await _repositoryManager.VariableTables.DeleteByIdAsync(id);
|
||||
var variableTable = await _repositoryManager.VariableTables.GetByIdAsync(id);
|
||||
if (variableTable == null)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量表失败:变量表ID:{id},请检查变量表Id是否存在");
|
||||
}
|
||||
var delRes = await _repositoryManager.VariableTables.DeleteAsync(variableTable);
|
||||
if (delRes == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量表失败:变量表ID:{id},请检查变量表Id是否存在");
|
||||
|
||||
Reference in New Issue
Block a user