You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

  1. package service
  2. import (
  3. "errors"
  4. "gin-vue-admin/global"
  5. "gin-vue-admin/model"
  6. )
  7. // @title DeleteBaseMenu
  8. // @description 删除基础路由
  9. // @auth (2020/04/05 20:22)
  10. // @param id float64
  11. // @return err error
  12. func DeleteBaseMenu(id float64) (err error) {
  13. err = global.GVA_DB.Where("parent_id = ?", id).First(&model.SysBaseMenu{}).Error
  14. if err != nil {
  15. var menu model.SysBaseMenu
  16. db := global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Delete(&menu)
  17. if len(menu.SysAuthoritys) > 0 {
  18. err = db.Association("SysAuthoritys").Delete(menu.SysAuthoritys).Error
  19. } else {
  20. err = db.Error
  21. }
  22. } else {
  23. return errors.New("此菜单存在子菜单不可删除")
  24. }
  25. return err
  26. }
  27. // @title UpdateBaseMenu
  28. // @description 更新路由
  29. // @auth (2020/04/05 20:22)
  30. // @param menu model.SysBaseMenu
  31. // @return err error
  32. func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
  33. upDateMap := make(map[string]interface{})
  34. upDateMap["parent_id"] = menu.ParentId
  35. upDateMap["path"] = menu.Path
  36. upDateMap["name"] = menu.Name
  37. upDateMap["hidden"] = menu.Hidden
  38. upDateMap["component"] = menu.Component
  39. upDateMap["title"] = menu.Title
  40. upDateMap["icon"] = menu.Icon
  41. upDateMap["sort"] = menu.Sort
  42. err = global.GVA_DB.Where("id = ?", menu.ID).Find(&model.SysBaseMenu{}).Updates(upDateMap).Error
  43. global.GVA_LOG.Debug("菜单修改时候,关联菜单err:%v", err)
  44. return err
  45. }
  46. // @title GetBaseMenuById
  47. // @description get current menus, 返回当前选中menu
  48. // @auth (2020/04/05 20:22)
  49. // @param id float64
  50. // @return err error
  51. func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) {
  52. err = global.GVA_DB.Where("id = ?", id).First(&menu).Error
  53. return
  54. }