package controllers import ( "ERP_storage/Nats/NatsServer" powerlibs "git.baozhida.cn/ERP_libs/Power" "github.com/beego/beego/v2/adapter/orm" ) // 检查角色是否与User一致,不存在则添加 func CheckPowerUniformity() { o := orm.NewOrm() // 也可以直接使用 Model 结构体作为表名 powerDao := powerlibs.NewPower(o) userPowerList, _ := NatsServer.Read_Power_List_All() powerList, _ := powerDao.Read_Power_List("", 0, 9999) if len(userPowerList) == len(powerList) { return } powerMap := make(map[string]string) for _, r := range powerList { powerMap[r.T_id] = r.T_name } for _, r := range userPowerList { _, ok := powerMap[r.T_id] if !ok { p := powerlibs.Power{ T_id: r.T_id, T_name: r.T_name, } if r.T_menu == "*" { p.T_menu = "*" } powerDao.Add_Power(p) } } }