departmentcache

pull/249/head
wangchuxiao 3 years ago
parent 6d91f766e7
commit 1531db0a35

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
rocksCache "Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -112,8 +113,12 @@ func (s *organizationServer) CreateDepartment(ctx context.Context, req *rpc.Crea
resp := &rpc.CreateDepartmentResp{DepartmentInfo: &open_im_sdk.Department{}}
utils.CopyStructFields(resp.DepartmentInfo, createdDepartment)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
@ -169,11 +174,15 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda
utils.CopyStructFields(&department, req.DepartmentInfo)
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
if err := imdb.UpdateDepartment(&department, nil); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg, department)
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
resp := &rpc.UpdateDepartmentResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
@ -182,12 +191,24 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda
func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
departmentList, err := imdb.GetSubDepartmentList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
var departmentList []db.Department
var err error
if req.DepartmentID == "-1" {
departmentList, err = rocksCache.GetAllDepartmentsFromCache()
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
} else {
departmentList, err = imdb.GetSubDepartmentList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
}
log.Debug(req.OperationID, "GetSubDepartmentList ", req.DepartmentID, departmentList)
resp := &rpc.GetSubDepartmentResp{}
for _, v := range departmentList {
@ -224,6 +245,12 @@ func (s *organizationServer) DeleteDepartment(ctx context.Context, req *rpc.Dele
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "DeleteDepartment ", req.DepartmentID)
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
resp := &rpc.DeleteDepartmentResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
@ -353,7 +380,9 @@ func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rp
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "UpdateOrganizationUser ", departmentMember)
if err := rocksCache.DelAllDepartmentMembersFromCache(); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
resp := &rpc.CreateDepartmentMemberResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
@ -477,11 +506,22 @@ func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rp
func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
departmentMemberList, err := imdb.GetDepartmentMemberList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
var departmentMemberList []db.DepartmentMember
var err error
if req.DepartmentID == "-1" {
departmentMemberList, err = rocksCache.GetAllDepartmentMembersFromCache()
if err != nil {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
} else {
departmentMemberList, err = imdb.GetDepartmentMemberList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
}
log.Debug(req.OperationID, "GetDepartmentMemberList ", departmentMemberList)

@ -253,7 +253,7 @@ func DelAllFriendsInfoFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
}
func GetAllDepartmentsFromCache() ([]*db.Department, error) {
func GetAllDepartmentsFromCache() ([]db.Department, error) {
getAllDepartments := func() (string, error) {
departmentList, err := imdb.GetSubDepartmentList("-1")
if err != nil {
@ -266,7 +266,7 @@ func GetAllDepartmentsFromCache() ([]*db.Department, error) {
if err != nil {
return nil, utils.Wrap(err, "")
}
var allDepartments []*db.Department
var allDepartments []db.Department
err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments)
return allDepartments, utils.Wrap(err, "")
}
@ -275,7 +275,7 @@ func DelAllDepartmentsFromCache() error {
return db.DB.Rc.TagAsDeleted(allDepartmentCache)
}
func GetAllDepartmentMembersFromCache() ([]*db.DepartmentMember, error) {
func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) {
getAllDepartmentMembers := func() (string, error) {
departmentMembers, err := imdb.GetDepartmentMemberList("-1")
if err != nil {
@ -288,7 +288,7 @@ func GetAllDepartmentMembersFromCache() ([]*db.DepartmentMember, error) {
if err != nil {
return nil, utils.Wrap(err, "")
}
var allDepartmentMembers []*db.DepartmentMember
var allDepartmentMembers []db.DepartmentMember
err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers)
return allDepartmentMembers, utils.Wrap(err, "")
}

Loading…
Cancel
Save