新增作废菜单接口

This commit is contained in:
pangwenpeng 2024-05-30 18:06:01 +08:00
parent 8721251475
commit aab080cf19
2 changed files with 69 additions and 9 deletions

View File

@ -57,13 +57,13 @@ namespace langguanApi.Controllers
/// <summary> /// <summary>
/// 删除菜单 /// 删除菜单
/// </summary> /// </summary>
/// <param name="ids"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
[HttpDelete("remove")] [HttpDelete("DeleteMenu")]
public async Task<IActionResult> Remove(IEnumerable<string> ids) public async Task<IActionResult> DeleteMenu(string id)
{ {
await _menuService.BatchRemoveAsync(ids); var result = await _menuService.DeleteMenu(id);
return Ok(new ApiResult()); return Ok(result);
} }
} }
} }

View File

@ -49,11 +49,37 @@ namespace langguanApi.Service
} }
return new ApiResult { code = 0, msg = "保存菜单信息成功", data = true }; return new ApiResult { code = 0, msg = "保存菜单信息成功", data = true };
} }
/// <summary>
/// 更改菜单
/// </summary>
/// <param name="menu">菜单实体类</param>
/// <returns></returns>
public async Task<ApiResult> UpdateMenu(UpdateMenuDto menu) public async Task<ApiResult> UpdateMenu(UpdateMenuDto menu)
{ {
var entity = menu.Adapt<Menu>(); try
await base.UpdateAsync(entity.Id, entity); {
return new ApiResult(); if (string.IsNullOrEmpty(menu.Id))
{
return new ApiResult() { code = 0, data = false, msg = "更新菜单失败Id不能为空" };
}
var entity = menu.Adapt<Menu>();
await base.UpdateAsync(entity.Id, entity);
}
catch (Exception ex)
{
_logger.LogError($"修改菜单出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(menu)}," +
$"请求接口:'api/Menu/UpdateMenu'" +
$"异常信息:{ex.Message}," +
$"异常位置:{ex.StackTrace}"
);
return new ApiResult { code = 1, msg = "保存菜单失败", data = false };
}
finally
{
_logger.LogInformation($"修改菜单参数menu:{Newtonsoft.Json.JsonConvert.SerializeObject(menu)}");
}
return new ApiResult() { code = 0, data = true, msg = "更新菜单成功" };
} }
/// <summary> /// <summary>
/// 获取菜单树 /// 获取菜单树
@ -147,5 +173,39 @@ namespace langguanApi.Service
} }
return list; return list;
} }
/// <summary>
/// 作废菜单
/// </summary>
/// <param name="id">当前菜单id</param>
/// <returns></returns>
public async Task<ApiResult> DeleteMenu(string id)
{
try
{
var entity = await base.GetAsync(id);
if (entity == null)
{
return new ApiResult() { code = 0, data = false, msg = "删除菜单失败Id不存在" };
}
entity.IsDelete = true;
await base.UpdateAsync(id, entity);
}
catch (Exception ex)
{
_logger.LogError($"删除菜单出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(id)}," +
$"请求接口:'api/Menu/DeleteMenu'" +
$"异常信息:{ex.Message}," +
$"异常位置:{ex.StackTrace}"
);
return new ApiResult { code = 1, msg = "删除菜单失败", data = false };
}
finally
{
_logger.LogInformation($"删除菜单参数menuId:{id}");
}
return new ApiResult() { code = 0, data = true, msg = "删除菜单成功" };
}
} }
} }