| | |
| | | middleware.InitUserConn() |
| | | v1.InitCodeServiceConn() |
| | | |
| | | middleware.InitRefreshUserManager(5, 3, 3600) |
| | | middleware.InitRefreshUserManager(1, 1, 300) //todo zq 暂时改短 |
| | | middleware.RunRefreshUser() ///定时对活跃用户更新用户详情 |
| | | |
| | | logx.Error(server.ListenAndServe().Error()) |
| | |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/proto/user" |
| | | "context" |
| | | "fmt" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | | "strings" |
| | |
| | | return |
| | | } |
| | | |
| | | fmt.Printf("Synced: %v, Message: %s", r.List, r.Message) |
| | | logx.Infof("Synced: %v, Message: %s", r.List, r.Message) |
| | | |
| | | for _, member := range r.List { |
| | | userRecord := model.User{ |
| | |
| | | NickName: member.Nickname, |
| | | } |
| | | if member.SubUserIds != nil { |
| | | subUserIds := strings.Join(member.SubUserIds, ",") |
| | | userRecord.SubUserIds = &subUserIds |
| | | userRecord.SubUserIds = strings.Join(member.SubUserIds, ",") |
| | | } |
| | | err = model.NewUserSearch(nil).Upsert(userRecord) |
| | | err = model.NewUserSearch(nil).Upsert(userRecord, member.SubUserQueried) |
| | | if err != nil { |
| | | logx.Errorf("sync user error: %v", err.Error()) |
| | | continue |
| | |
| | | MenuIds []uint `json:"menuIds" gorm:"-"` // 菜单ID列表 |
| | | AuthorityId uint `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID |
| | | Authority Authority `json:"authority" gorm:"foreignKey:AuthorityId"` |
| | | SubUserIds *string `json:"subUserIds" gorm:"sub_user_ids"` //下属员工用户id,用逗号分开 |
| | | SubUserIds string `json:"subUserIds" gorm:"sub_user_ids"` //下属员工用户id,用逗号分开 |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *UserSearch) Upsert(record User) error { |
| | | func (slf *UserSearch) Upsert(record User, SubUserQueried bool) error { |
| | | |
| | | var db = slf.SetId(record.UUID).build() |
| | | old, err := slf.First() |
| | |
| | | } else if old.Username != record.Username || |
| | | old.UserType != record.UserType || |
| | | old.NickName != record.NickName || |
| | | record.SubUserIds != nil && old.SubUserIds != record.SubUserIds { |
| | | SubUserQueried && old.SubUserIds != record.SubUserIds { |
| | | old.Username = record.Username |
| | | old.UserType = record.UserType |
| | | old.NickName = record.NickName |
| | |
| | | int32 usertype = 3; |
| | | string nickname = 4; |
| | | repeated string sub_user_ids = 5; |
| | | bool sub_user_queried = 6; |
| | | } |
| | | |
| | | message UserRequest { |
| | |
| | | Usertype int32 `protobuf:"varint,3,opt,name=usertype,proto3" json:"usertype,omitempty"` |
| | | Nickname string `protobuf:"bytes,4,opt,name=nickname,proto3" json:"nickname,omitempty"` |
| | | SubUserIds []string `protobuf:"bytes,5,rep,name=sub_user_ids,json=subUserIds,proto3" json:"sub_user_ids,omitempty"` |
| | | SubUserQueried bool `protobuf:"varint,6,opt,name=sub_user_queried,json=subUserQueried,proto3" json:"sub_user_queried,omitempty"` |
| | | } |
| | | |
| | | func (x *User) Reset() { |
| | |
| | | return x.SubUserIds |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (x *User) GetSubUserQueried() bool { |
| | | if x != nil { |
| | | return x.SubUserQueried |
| | | } |
| | | return false |
| | | } |
| | | |
| | | type UserRequest struct { |
| | |
| | | |
| | | var file_user_proto_rawDesc = []byte{ |
| | | 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x75, 0x73, |
| | | 0x65, 0x72, 0x22, 0x90, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x75, |
| | | 0x65, 0x72, 0x22, 0xba, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x75, |
| | | 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, |
| | | 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, |
| | | 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x75, |
| | |
| | | 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x6e, |
| | | 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, |
| | | 0x69, 0x64, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x75, 0x62, 0x55, 0x73, |
| | | 0x65, 0x72, 0x49, 0x64, 0x73, 0x22, 0x2f, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, |
| | | 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, |
| | | 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, |
| | | 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, 0x72, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, |
| | | 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, |
| | | 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, |
| | | 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, |
| | | 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, |
| | | 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, |
| | | 0x4c, 0x69, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x04, 0x20, |
| | | 0x01, 0x28, 0x03, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x22, 0x48, 0x0a, 0x0c, 0x43, 0x68, |
| | | 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x70, |
| | | 0x69, 0x50, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x70, 0x69, |
| | | 0x50, 0x61, 0x74, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x79, |
| | | 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, |
| | | 0x54, 0x79, 0x70, 0x65, 0x22, 0x55, 0x0a, 0x0d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, |
| | | 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, |
| | | 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, |
| | | 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, |
| | | 0x61, 0x67, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, |
| | | 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x7a, 0x0a, 0x0b, 0x55, |
| | | 0x73, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x08, 0x53, 0x79, |
| | | 0x6e, 0x63, 0x55, 0x73, 0x65, 0x72, 0x12, 0x11, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, |
| | | 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, |
| | | 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, |
| | | 0x0d, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x6e, 0x75, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x12, |
| | | 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, |
| | | 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, |
| | | 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x75, 0x73, 0x65, |
| | | 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, |
| | | 0x65, 0x72, 0x49, 0x64, 0x73, 0x12, 0x28, 0x0a, 0x10, 0x73, 0x75, 0x62, 0x5f, 0x75, 0x73, 0x65, |
| | | 0x72, 0x5f, 0x71, 0x75, 0x65, 0x72, 0x69, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, |
| | | 0x0e, 0x73, 0x75, 0x62, 0x55, 0x73, 0x65, 0x72, 0x51, 0x75, 0x65, 0x72, 0x69, 0x65, 0x64, 0x22, |
| | | 0x2f, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, |
| | | 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, |
| | | 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, |
| | | 0x22, 0x72, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, |
| | | 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, |
| | | 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, |
| | | 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, |
| | | 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x75, |
| | | 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x14, |
| | | 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x74, |
| | | 0x6f, 0x74, 0x61, 0x6c, 0x22, 0x48, 0x0a, 0x0c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, |
| | | 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x70, 0x69, 0x50, 0x61, 0x74, 0x68, 0x18, |
| | | 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x70, 0x69, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1e, |
| | | 0x0a, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, |
| | | 0x28, 0x05, 0x52, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x22, 0x55, |
| | | 0x0a, 0x0d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, |
| | | 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, |
| | | 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, |
| | | 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x16, 0x0a, |
| | | 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, |
| | | 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x7a, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x72, |
| | | 0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x08, 0x53, 0x79, 0x6e, 0x63, 0x55, 0x73, 0x65, 0x72, |
| | | 0x12, 0x11, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, |
| | | 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, |
| | | 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x4d, |
| | | 0x65, 0x6e, 0x75, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, |
| | | 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x75, |
| | | 0x73, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, |
| | | 0x65, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, |
| | | 0x74, 0x6f, 0x33, |
| | | } |
| | | |
| | | var ( |
| | |
| | | |
| | | func init() { |
| | | //make cache with 5 minutes TTL and 100 max keys |
| | | userCache = expirable.NewLRU[string, *UserBaseInfo](100, nil, time.Minute*5) |
| | | userCache = expirable.NewLRU[string, *UserBaseInfo](100, nil, time.Minute*1) //todo zq 暂时改成 1分钟 |
| | | } |
| | | |
| | | func GetUserBaseCache(adminUserId string) *UserBaseInfo { |
| | |
| | | return nil |
| | | } |
| | | var subIds []int |
| | | if userRecord.SubUserIds != nil && *userRecord.SubUserIds != "" { |
| | | subIds, _, err = userService.UUID2CrmUserId(strings.Split(*userRecord.SubUserIds, ",")) |
| | | if userRecord.SubUserIds != "" { |
| | | subIds, _, err = userService.UUID2CrmUserId(strings.Split(userRecord.SubUserIds, ",")) |
| | | if err != nil { |
| | | return nil |
| | | } |