zhangqian
2023-10-31 4c8632271199b4acd4277f64d8ed42461ef4e1b6
修复
6个文件已修改
108 ■■■■ 已修改文件
main.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
middleware/user.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/user.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/user.proto 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/user/user.pb.go 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/lru.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go
@@ -50,8 +50,8 @@
    middleware.InitUserConn()
    v1.InitCodeServiceConn()
    middleware.InitRefreshUserManager(5, 3, 3600)
    middleware.RunRefreshUser() ///定时对活跃用户更新用户详情
    middleware.InitRefreshUserManager(1, 1, 300) //todo zq 暂时改短
    middleware.RunRefreshUser()                  ///定时对活跃用户更新用户详情
    logx.Error(server.ListenAndServe().Error())
}
middleware/user.go
@@ -7,7 +7,6 @@
    "aps_crm/pkg/logx"
    "aps_crm/proto/user"
    "context"
    "fmt"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"
    "strings"
@@ -76,7 +75,7 @@
        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{
@@ -86,10 +85,9 @@
            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
model/user.go
@@ -26,7 +26,7 @@
        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:"-"`
    }
@@ -292,7 +292,7 @@
    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()
@@ -303,7 +303,7 @@
    } 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
proto/user.proto
@@ -15,6 +15,7 @@
  int32 usertype = 3;
  string nickname = 4;
  repeated string sub_user_ids = 5;
  bool sub_user_queried = 6;
}
message UserRequest {
proto/user/user.pb.go
@@ -25,11 +25,12 @@
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields
    Uuid       string   `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`
    Username   string   `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
    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"`
    Uuid           string   `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`
    Username       string   `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
    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() {
@@ -97,6 +98,13 @@
        return x.SubUserIds
    }
    return nil
}
func (x *User) GetSubUserQueried() bool {
    if x != nil {
        return x.SubUserQueried
    }
    return false
}
type UserRequest struct {
@@ -339,7 +347,7 @@
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,
@@ -348,36 +356,39 @@
    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 (
service/lru.go
@@ -16,7 +16,7 @@
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 {
@@ -28,8 +28,8 @@
            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
            }