Skip to content

Commit

Permalink
sys_base_menu.go: fix table name "sys_base_menus" specified more than…
Browse files Browse the repository at this point in the history
… once (SQLSTATE 42712) (#1704)
  • Loading branch information
crazyrunsnail authored Apr 11, 2024
1 parent 032910f commit f9974a8
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions server/service/system/sys_base_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,33 @@ var BaseMenuServiceApp = new(BaseMenuService)
func (baseMenuService *BaseMenuService) DeleteBaseMenu(id int) (err error) {
err = global.GVA_DB.Preload("MenuBtn").Preload("Parameters").Where("parent_id = ?", id).First(&system.SysBaseMenu{}).Error
if err != nil {
var menu system.SysBaseMenu
db := global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Delete(&menu)
err = global.GVA_DB.Delete(&system.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error
err = global.GVA_DB.Delete(&system.SysBaseMenuBtn{}, "sys_base_menu_id = ?", id).Error
err = global.GVA_DB.Delete(&system.SysAuthorityBtn{}, "sys_menu_id = ?", id).Error
if err != nil {
return err
}
if len(menu.SysAuthoritys) > 0 {
err = global.GVA_DB.Model(&menu).Association("SysAuthoritys").Delete(&menu.SysAuthoritys)
} else {
err = db.Error
global.GVA_DB.Transaction(func(tx *gorm.DB) error {
var menu system.SysBaseMenu
err = global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Error
if err != nil {
return
return err
}
}
global.GVA_DB.Delete((&menu))
err = global.GVA_DB.Delete(&system.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error
if err != nil {
return err
}
err = global.GVA_DB.Delete(&system.SysBaseMenuBtn{}, "sys_base_menu_id = ?", id).Error
if err != nil {
return err
}
err = global.GVA_DB.Delete(&system.SysAuthorityBtn{}, "sys_menu_id = ?", id).Error
if err != nil {
return err
}
if len(menu.SysAuthoritys) > 0 {
err = global.GVA_DB.Model(&menu).Association("SysAuthoritys").Delete(&menu.SysAuthoritys)
}
if err != nil {
return err
}
return nil
})
} else {
return errors.New("此菜单存在子菜单不可删除")
}
Expand Down

0 comments on commit f9974a8

Please sign in to comment.