42 lines
1.5 KiB
Go
42 lines
1.5 KiB
Go
package business
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
datasystem "kra/internal/data/system"
|
|
"kra/internal/modules/surface"
|
|
"kra/pkg/module"
|
|
)
|
|
|
|
func migrateActivationSurface(db *gorm.DB) error {
|
|
if !db.Migrator().HasTable("sys_authorities") {
|
|
return nil
|
|
}
|
|
var roots int64
|
|
if err := db.Table("sys_authorities").Where("authority_id=888 AND deleted_at IS NULL").Count(&roots).Error; err != nil {
|
|
return err
|
|
}
|
|
if roots == 0 {
|
|
return nil
|
|
}
|
|
if db.Migrator().HasTable("sys_base_menus") {
|
|
if err := db.Table("sys_base_menus").Where("name=?", "sw_ChannelActivationList").Update("title", "激活列表").Error; err != nil {
|
|
return err
|
|
}
|
|
}
|
|
apis := surface.APIsForPrefix("/sw/promoteActivePool/", 0)
|
|
if err := datasystem.EnsureAdminSurface(db, module.Surface{APIs: apis}, 888); err != nil {
|
|
return err
|
|
}
|
|
// 申请绑定与流失记录对各级商务开放,升级旧的仅三级菜单授权。
|
|
if db.Migrator().HasTable("sys_authority_menus") && db.Migrator().HasTable("sys_base_menus") {
|
|
if err := db.Exec(`INSERT INTO sys_authority_menus(sys_authority_authority_id,sys_base_menu_id)
|
|
SELECT a.authority_id,m.id FROM sys_authorities a CROSS JOIN sys_base_menus m
|
|
WHERE a.business_level IN (1,2,3) AND a.deleted_at IS NULL AND m.deleted_at IS NULL
|
|
AND m.name IN ('sw_ChannelActivationList','sw_BusMgmt')
|
|
AND NOT EXISTS (SELECT 1 FROM sys_authority_menus x WHERE x.sys_authority_authority_id=a.authority_id AND x.sys_base_menu_id=m.id)`).Error; err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return datasystem.GrantMenuAPIs(db, "sw_ChannelActivationList", apis)
|
|
}
|