|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package organization
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
chat "Open_IM/internal/rpc/msg"
|
|
|
|
|
"Open_IM/pkg/common/config"
|
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
@ -8,16 +9,16 @@ import (
|
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
|
"Open_IM/pkg/common/token_verify"
|
|
|
|
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
|
|
|
|
"Open_IM/pkg/proto/auth"
|
|
|
|
|
rpc "Open_IM/pkg/proto/organization"
|
|
|
|
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"context"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
"net"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type organizationServer struct {
|
|
|
|
@ -97,6 +98,7 @@ 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)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -120,6 +122,7 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda
|
|
|
|
|
|
|
|
|
|
resp := &rpc.UpdateDepartmentResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -137,6 +140,16 @@ func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetS
|
|
|
|
|
v1 := open_im_sdk.Department{}
|
|
|
|
|
utils.CopyStructFields(&v1, v)
|
|
|
|
|
log.Debug(req.OperationID, "src ", v, "dst ", v1)
|
|
|
|
|
err, v1.MemberNum = imdb.GetDepartmentMemberNum(v1.DepartmentID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error(req.OperationID, "GetDepartmentMemberNum failed ", err.Error(), v1.DepartmentID)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
err, v1.SubDepartmentNum = imdb.GetSubDepartmentNum(v1.DepartmentID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error(req.OperationID, "GetSubDepartmentNum failed ", err.Error(), v1.DepartmentID)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
resp.DepartmentList = append(resp.DepartmentList, &v1)
|
|
|
|
|
}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
@ -159,10 +172,29 @@ func (s *organizationServer) DeleteDepartment(ctx context.Context, req *rpc.Dele
|
|
|
|
|
log.Debug(req.OperationID, "DeleteDepartment ", req.DepartmentID)
|
|
|
|
|
resp := &rpc.DeleteDepartmentResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rpc.CreateOrganizationUserReq) (*rpc.CreateOrganizationUserResp, error) {
|
|
|
|
|
authReq := &pbAuth.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
|
|
|
|
|
utils.CopyStructFields(authReq.UserInfo, req.OrganizationUser)
|
|
|
|
|
authReq.OperationID = req.OperationID
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
|
|
|
|
client := pbAuth.NewAuthClient(etcdConn)
|
|
|
|
|
|
|
|
|
|
reply, err := client.UserRegister(context.Background(), authReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errMsg := "UserRegister failed " + err.Error()
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
|
|
|
|
}
|
|
|
|
|
if reply.CommonResp.ErrCode != 0 {
|
|
|
|
|
errMsg := "UserRegister failed " + reply.CommonResp.ErrMsg
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
|
|
|
|
if !token_verify.IsManagerUserID(req.OpUserID) {
|
|
|
|
|
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
|
|
|
@ -173,7 +205,7 @@ func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rp
|
|
|
|
|
utils.CopyStructFields(&organizationUser, req.OrganizationUser)
|
|
|
|
|
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth))
|
|
|
|
|
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser)
|
|
|
|
|
err := imdb.CreateOrganizationUser(&organizationUser)
|
|
|
|
|
err = imdb.CreateOrganizationUser(&organizationUser)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errMsg := req.OperationID + " " + "CreateOrganizationUser failed " + err.Error()
|
|
|
|
|
log.Error(req.OperationID, errMsg, organizationUser)
|
|
|
|
@ -182,10 +214,29 @@ func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rp
|
|
|
|
|
log.Debug(req.OperationID, "CreateOrganizationUser ", organizationUser)
|
|
|
|
|
resp := &rpc.CreateOrganizationUserResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rpc.UpdateOrganizationUserReq) (*rpc.UpdateOrganizationUserResp, error) {
|
|
|
|
|
authReq := &pbAuth.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
|
|
|
|
|
utils.CopyStructFields(authReq.UserInfo, req.OrganizationUser)
|
|
|
|
|
authReq.OperationID = req.OperationID
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
|
|
|
|
client := pbAuth.NewAuthClient(etcdConn)
|
|
|
|
|
|
|
|
|
|
reply, err := client.UserRegister(context.Background(), authReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errMsg := "UserRegister failed " + err.Error()
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
|
|
|
|
}
|
|
|
|
|
if reply.CommonResp.ErrCode != 0 {
|
|
|
|
|
errMsg := "UserRegister failed " + reply.CommonResp.ErrMsg
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
|
|
|
|
if !token_verify.IsManagerUserID(req.OpUserID) {
|
|
|
|
|
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
|
|
|
@ -200,7 +251,7 @@ func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser)
|
|
|
|
|
err := imdb.UpdateOrganizationUser(&organizationUser, nil)
|
|
|
|
|
err = imdb.UpdateOrganizationUser(&organizationUser, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errMsg := req.OperationID + " " + "CreateOrganizationUser failed " + err.Error()
|
|
|
|
|
log.Error(req.OperationID, errMsg, organizationUser)
|
|
|
|
@ -209,6 +260,7 @@ func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rp
|
|
|
|
|
log.Debug(req.OperationID, "UpdateOrganizationUser ", organizationUser)
|
|
|
|
|
resp := &rpc.UpdateOrganizationUserResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -240,6 +292,7 @@ func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rp
|
|
|
|
|
|
|
|
|
|
resp := &rpc.CreateDepartmentMemberResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -298,6 +351,7 @@ func (s *organizationServer) UpdateUserInDepartment(ctx context.Context, req *rp
|
|
|
|
|
}
|
|
|
|
|
resp := &rpc.UpdateUserInDepartmentResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -318,6 +372,7 @@ func (s *organizationServer) DeleteUserInDepartment(ctx context.Context, req *rp
|
|
|
|
|
log.Debug(req.OperationID, "DeleteUserInDepartment success ", req.DepartmentID, req.UserID)
|
|
|
|
|
resp := &rpc.DeleteUserInDepartmentResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -337,6 +392,7 @@ func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rp
|
|
|
|
|
log.Debug(req.OperationID, "DeleteOrganizationUser success ", req.UserID)
|
|
|
|
|
resp := &rpc.DeleteOrganizationUserResp{}
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
|
|
|
|
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|