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.
74 lines
2.4 KiB
74 lines
2.4 KiB
package service
|
|
|
|
import (
|
|
"errors"
|
|
"gin-vue-admin/global"
|
|
"gin-vue-admin/model"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// @title DeleteBaseMenu
|
|
// @description 删除基础路由
|
|
// @auth (2020/04/05 20:22)
|
|
// @param id float64
|
|
// @return err error
|
|
|
|
func DeleteBaseMenu(id float64) (err error) {
|
|
err = global.GVA_DB.Preload("Parameters").Where("parent_id = ?", id).First(&model.SysBaseMenu{}).Error
|
|
if err != nil {
|
|
var menu model.SysBaseMenu
|
|
db := global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Delete(&menu)
|
|
err = global.GVA_DB.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error
|
|
if len(menu.SysAuthoritys) > 0 {
|
|
err = global.GVA_DB.Model(&menu).Association("SysAuthoritys").Delete(&menu.SysAuthoritys)
|
|
} else {
|
|
err = db.Error
|
|
}
|
|
} else {
|
|
return errors.New("此菜单存在子菜单不可删除")
|
|
}
|
|
return err
|
|
}
|
|
|
|
// @title UpdateBaseMenu
|
|
// @description 更新路由
|
|
// @auth (2020/04/05 20:22)
|
|
// @param menu model.SysBaseMenu
|
|
// @return err errorgetMenu
|
|
|
|
func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
|
|
var oldMenu model.SysBaseMenu
|
|
upDateMap := make(map[string]interface{})
|
|
upDateMap["keep_alive"] = menu.KeepAlive
|
|
upDateMap["default_menu"] = menu.DefaultMenu
|
|
upDateMap["parent_id"] = menu.ParentId
|
|
upDateMap["path"] = menu.Path
|
|
upDateMap["name"] = menu.Name
|
|
upDateMap["hidden"] = menu.Hidden
|
|
upDateMap["component"] = menu.Component
|
|
upDateMap["title"] = menu.Title
|
|
upDateMap["icon"] = menu.Icon
|
|
upDateMap["sort"] = menu.Sort
|
|
|
|
db := global.GVA_DB.Where("id = ?", menu.ID).Find(&oldMenu)
|
|
if oldMenu.Name != menu.Name {
|
|
if !errors.Is(global.GVA_DB.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
|
|
global.GVA_LOG.Debug("存在相同name修改失败")
|
|
return errors.New("存在相同name修改失败")
|
|
}
|
|
}
|
|
err = global.GVA_DB.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error
|
|
err = db.Updates(upDateMap).Error
|
|
return err
|
|
}
|
|
|
|
// @title GetBaseMenuById
|
|
// @description get current menus, 返回当前选中menu
|
|
// @auth (2020/04/05 20:22)
|
|
// @param id float64
|
|
// @return err error
|
|
|
|
func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) {
|
|
err = global.GVA_DB.Preload("Parameters").Where("id = ?", id).First(&menu).Error
|
|
return
|
|
}
|