diff --git a/langguanApi/Controllers/MenuController.cs b/langguanApi/Controllers/MenuController.cs index 49cff20..6627b6d 100644 --- a/langguanApi/Controllers/MenuController.cs +++ b/langguanApi/Controllers/MenuController.cs @@ -57,13 +57,13 @@ namespace langguanApi.Controllers /// /// 删除菜单 /// - /// + /// /// - [HttpDelete("remove")] - public async Task Remove(IEnumerable ids) + [HttpDelete("DeleteMenu")] + public async Task DeleteMenu(string id) { - await _menuService.BatchRemoveAsync(ids); - return Ok(new ApiResult()); + var result = await _menuService.DeleteMenu(id); + return Ok(result); } } } diff --git a/langguanApi/Service/MenuService.cs b/langguanApi/Service/MenuService.cs index 0a3fe7f..6da7469 100644 --- a/langguanApi/Service/MenuService.cs +++ b/langguanApi/Service/MenuService.cs @@ -49,11 +49,37 @@ namespace langguanApi.Service } return new ApiResult { code = 0, msg = "保存菜单信息成功", data = true }; } + /// + /// 更改菜单 + /// + /// 菜单实体类 + /// public async Task UpdateMenu(UpdateMenuDto menu) { - var entity = menu.Adapt(); - await base.UpdateAsync(entity.Id, entity); - return new ApiResult(); + try + { + if (string.IsNullOrEmpty(menu.Id)) + { + return new ApiResult() { code = 0, data = false, msg = "更新菜单失败,Id不能为空" }; + } + var entity = menu.Adapt(); + 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 = "更新菜单成功" }; } /// /// 获取菜单树 @@ -83,7 +109,7 @@ namespace langguanApi.Service //筛选数据 if (!string.IsNullOrEmpty(input.key)) { - if (dto.Exists(p => p.Name == input.key) || + if (dto.Exists(p => p.Name == input.key) || dto.Exists(p => p.Children.Exists(c => c.Name == input.key)) || dto.Exists(p => p.ParentName == input.key)) { @@ -147,5 +173,39 @@ namespace langguanApi.Service } return list; } + + /// + /// 作废菜单 + /// + /// 当前菜单id + /// + public async Task 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 = "删除菜单成功" }; + } } }