package model import ( "time" "gorm.io/gorm" ) type RoleRoute struct { ID string `json:"id" gorm:"column:id; primaryKey;autoIncrement:false"` RoleID string `json:"role_id" gorm:"comment:'角色ID'"` RouteID string `json:"route_id" gorm:"comment:'路由ID'"` CreatedAt time.Time `json:"created_at" gorm:"column:created_at;comment:'创建时间'"` UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at;comment:'修改时间'"` DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at;comment:'删除时间'"` } func (r RoleRoute) TableName() string { return "sys_auth_role_route" } func GetRoleRoute(db *gorm.DB, role_id string, route_id string) (RoleRoute, error) { r := RoleRoute{} err := db.Where("role_id = ? and route_id = ?", role_id, route_id).First(&r).Error if err != nil && err != gorm.ErrRecordNotFound { return r, err } return r, nil } func GetRouteIdsByRoleId(db *gorm.DB, role_id string) ([]string, error) { r := []RoleRoute{} err := db.Where("role_id = ?", role_id).Find(&r).Error if err != nil && err != gorm.ErrRecordNotFound { return nil, err } a := []string{} for _, v := range r { a = append(a, v.RouteID) } return a, nil }