| | |
| | | // parseToken 解析token包含的信息 |
| | | claims, err := j.ParseToken(token) |
| | | if err != nil { |
| | | if err == utils.TokenExpired { |
| | | c.Next() |
| | | return |
| | | } |
| | | c.Next() |
| | | ctx.Fail(ecode.JWTDisabled) |
| | | c.Abort() |
| | | return |
| | | } |
| | | userInfo := service.GetUserBaseCache(claims.UserId) |
| | |
| | | SyncUserInfo([]string{claims.UserId}) |
| | | userInfo = service.GetUserBaseCache(claims.UserId) |
| | | } |
| | | if userInfo == nil { |
| | | ctx.Fail(ecode.JWTDisabled) |
| | | c.Abort() |
| | | return |
| | | } |
| | | |
| | | SetActiveTime(claims.UserId) |
| | | |
| | |
| | | intervalRefreshUserMinute: intervalRefreshUserMinute, |
| | | ctx: ctx, |
| | | cancel: cancel, |
| | | Users: map[string]*CurrentActiveUser{}, |
| | | } |
| | | } |
| | | |
| | |
| | | func (slf *UserSearch) UUID2CrmUserId(userIds []string) ([]*IdPair, error) { |
| | | var ( |
| | | records = make([]*IdPair, 0) |
| | | db = slf.build() |
| | | db = slf.Orm.Model(&User{}) |
| | | ) |
| | | |
| | | db = db.Where("uuid in ?", userIds) |
| | | if err := db.Find(&records).Error; err != nil { |
| | | if err := db.Select("user.id, user.uuid").Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find all err: %v", err) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | func GetUserBaseCache(adminUserId string) *UserBaseInfo { |
| | | userCache, ok := userCache.Get(adminUserId) |
| | | cache, ok := userCache.Get(adminUserId) |
| | | if !ok { |
| | | userService := UserService{} |
| | | userRecord, err := userService.GetUserInfo(adminUserId) |
| | | if err != nil { |
| | | return nil |
| | | } |
| | | subIds, _, err := userService.UUID2CrmUserId(strings.Split(userRecord.SubUserIds, ",")) |
| | | subIds = append(subIds, userRecord.ID) |
| | | if err != nil { |
| | | return nil |
| | | var subIds []int |
| | | if len(userRecord.SubUserIds) > 0 { |
| | | subIds, _, err = userService.UUID2CrmUserId(strings.Split(userRecord.SubUserIds, ",")) |
| | | if err != nil { |
| | | return nil |
| | | } |
| | | } |
| | | |
| | | subIds = append(subIds, userRecord.ID) |
| | | |
| | | baseInfo := &UserBaseInfo{ |
| | | UserId: userRecord.ID, |
| | | NickName: userRecord.NickName, |
| | |
| | | SetUserBaseCache(adminUserId, baseInfo) |
| | | return baseInfo |
| | | } |
| | | return userCache |
| | | return cache |
| | | } |
| | | |
| | | func SetUserBaseCache(adminUserId string, user *UserBaseInfo) { |