organization

pull/232/head
wangchuxiao 3 years ago
parent 098dae9640
commit 2534921af9

@ -75,11 +75,15 @@ func joinTestDepartment(operationID, userID, departmentID string) error {
}()
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
client := organizationRpc.NewOrganizationClient(etcdConn)
req := &organizationRpc.CreateDepartmentMemberReq{DepartmentMember: &commonPb.DepartmentMember{
UserID: userID,
DepartmentID: departmentID,
Position: randomPosition(),
}}
req := &organizationRpc.CreateDepartmentMemberReq{
DepartmentMember: &commonPb.DepartmentMember{
UserID: userID,
DepartmentID: departmentID,
Position: randomPosition(),
},
OperationID: operationID,
OpUserID: config.Config.Manager.AppManagerUid[0],
}
resp, err := client.CreateDepartmentMember(context.Background(), req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())

@ -9,14 +9,17 @@ import (
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbCache "Open_IM/pkg/proto/cache"
pbOffice "Open_IM/pkg/proto/office"
pbCommon "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"golang.org/x/net/html/atom"
"google.golang.org/grpc"
"net"
"strconv"
"strings"
"sync"
"time"
)
@ -172,13 +175,27 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
}
var groupUserIDList []string
for _, groupID := range req.GroupList {
userIDList, err := im_mysql_model.GetGroupMemberIDListByGroupID(groupID)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
cacheClient := pbCache.NewCacheClient(etcdConn)
req := pbCache.GetGroupMemberIDListFromCacheReq{
OperationID: req.OperationID,
GroupID: groupID,
}
getGroupMemberIDListFromCacheResp, err := cacheClient.GetGroupMemberIDListFromCache(context.Background(), &req)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", err.Error(), groupID)
continue
log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc call failed ", err.Error(), req.String())
resp.CommonResp.ErrCode = constant.ErrServer.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), userIDList)
groupUserIDList = append(groupUserIDList, userIDList...)
if getGroupMemberIDListFromCacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc logic call failed ", getGroupMemberIDListFromCacheResp.CommonResp.ErrCode)
resp.CommonResp.ErrCode = getGroupMemberIDListFromCacheResp.CommonResp.ErrCode
resp.CommonResp.ErrMsg = getGroupMemberIDListFromCacheResp.CommonResp.ErrMsg
return resp, nil
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), getGroupMemberIDListFromCacheResp.UserIDList)
groupUserIDList = append(groupUserIDList, getGroupMemberIDListFromCacheResp.UserIDList...)
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), groupUserIDList, req.GroupList)
var userIDList []string
@ -195,22 +212,37 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
user, err := imdb.GetUserByUserID(req.SendID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.SendID)
resp.CommonResp.ErrMsg = err.Error()
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
return resp, nil
}
var wg sync.WaitGroup
wg.Add(len(userIDList))
for _, userID := range userIDList {
msg.TagSendMessage(req.OperationID, user, userID, req.Content, req.SenderPlatformID)
go func(userID string) {
defer wg.Done()
msg.TagSendMessage(req.OperationID, user, userID, req.Content, req.SenderPlatformID)
}(userID)
}
wg.Wait()
var tagSendLogs db.TagSendLog
wg.Add(len(userIDList))
for _, userID := range userIDList {
userName, err := im_mysql_model.GetUserNameByUserID(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
continue
}
tagSendLogs.UserList = append(tagSendLogs.UserList, db.TagUser{
UserID: userID,
UserName: userName,
})
go func(userID string) {
defer wg.Done()
userName, err := im_mysql_model.GetUserNameByUserID(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
return
}
tagSendLogs.UserList = append(tagSendLogs.UserList, db.TagUser{
UserID: userID,
UserName: userName,
})
}(userID)
}
wg.Wait()
tagSendLogs.SendID = req.SendID
tagSendLogs.Content = req.Content
tagSendLogs.SenderPlatformID = req.SenderPlatformID

@ -252,7 +252,7 @@ func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department,
var parentID string
dbConn.LogMode(true)
// select * from departments where department_id = (select parent_id from departments where department_id= zx234fd);
err := dbConn.Table("departments").Where("department_id=?", dbConn.Table("departments").Where("department_id=?", departmentID).Pluck("parent_id", parentID)).Error
err := dbConn.Table("departments").Where("department_id=?", dbConn.Table("departments").Where("department_id=?", departmentID).Pluck("parent_id", parentID)).Find(&department).Error
return &department, err
}

Loading…
Cancel
Save