mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
mongo
This commit is contained in:
parent
e7b95892ff
commit
6d20eddd43
@ -7,6 +7,7 @@ import (
|
||||
"Open_IM/internal/api/friend"
|
||||
"Open_IM/internal/api/group"
|
||||
"Open_IM/internal/api/manage"
|
||||
"Open_IM/internal/api/office"
|
||||
apiThird "Open_IM/internal/api/third"
|
||||
"Open_IM/internal/api/user"
|
||||
"Open_IM/pkg/common/log"
|
||||
@ -106,7 +107,23 @@ func main() {
|
||||
conversationGroup.POST("/set_conversation", conversation.SetConversation)
|
||||
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
||||
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
||||
|
||||
// Deprecated
|
||||
conversationGroup.POST("/set_receive_message_opt", conversation.SetReceiveMessageOpt) //1
|
||||
conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt) //1
|
||||
conversationGroup.POST("/get_all_conversation_message_opt", conversation.GetAllConversationMessageOpt) //1
|
||||
}
|
||||
// office
|
||||
officeGroup := r.Group("/office")
|
||||
{
|
||||
officeGroup.POST("/get_user_tags", office.GetUserTags)
|
||||
officeGroup.POST("/create_tag", office.CreateTag)
|
||||
officeGroup.POST("/delete_tag", office.DeleteTag)
|
||||
officeGroup.POST("/set_tag", office.SetTag)
|
||||
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
|
||||
officeGroup.POST("/get_send_tag_log", office.GetSendTagLogs)
|
||||
}
|
||||
|
||||
apiThird.MinioInit()
|
||||
log.NewPrivateLog("api")
|
||||
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||
|
@ -1,6 +1,6 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_admin_cms
|
||||
BINARY_NAME=open_im_office
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
23
cmd/rpc/open_im_office/Makefile
Normal file
23
cmd/rpc/open_im_office/Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=office
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
install:
|
||||
make build
|
||||
mv ${BINARY_NAME} ${BIN_DIR}
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
13
cmd/rpc/open_im_office/main.go
Normal file
13
cmd/rpc/open_im_office/main.go
Normal file
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpc "Open_IM/internal/rpc/office"
|
||||
"flag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11100, "rpc listening port")
|
||||
flag.Parse()
|
||||
rpcServer := rpc.NewOfficeServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
@ -201,3 +201,18 @@ func SetRecvMsgOpt(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func SetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func GetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func GetAllConversationMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
189
internal/api/office/tag.go
Normal file
189
internal/api/office/tag.go
Normal file
@ -0,0 +1,189 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
apistruct "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUserTags(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetUserTagsReq
|
||||
resp apistruct.GetUserTagsResp
|
||||
reqPb pbOffice.GetUserTagsReq
|
||||
respPb *pbOffice.GetUserTagsResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserTags(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserTags rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Data.Tags = respPb.Tags
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CreateTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.CreateTagReq
|
||||
resp apistruct.CreateTagResp
|
||||
reqPb pbOffice.CreateTagReq
|
||||
respPb *pbOffice.CreateTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.CreateTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func DeleteTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.DeleteTagReq
|
||||
resp apistruct.DeleteTagResp
|
||||
reqPb pbOffice.DeleteTagReq
|
||||
respPb *pbOffice.DeleteTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.DeleteTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SetTagReq
|
||||
resp apistruct.SetTagResp
|
||||
reqPb pbOffice.SetTagReq
|
||||
respPb *pbOffice.SetTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SetTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SendMsg2Tag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SendMsg2TagReq
|
||||
resp apistruct.SendMsg2TagResp
|
||||
reqPb pbOffice.SendMsg2TagReq
|
||||
respPb *pbOffice.SendMsg2TagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SendMsg2Tag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetSendTagLogs(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SendMsg2TagReq
|
||||
resp apistruct.SendMsg2TagResp
|
||||
reqPb pbOffice.SendMsg2TagReq
|
||||
respPb *pbOffice.SendMsg2TagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SendMsg2Tag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
@ -33,8 +33,15 @@ func MinioUploadFile(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
switch req.FileType {
|
||||
// videoType upload snapShot
|
||||
case constant.VideoType:
|
||||
snapShotFile, err := c.FormFile("snapShot")
|
||||
if err != nil {
|
||||
|
20
internal/rpc/msg/tag_notification.go
Normal file
20
internal/rpc/msg/tag_notification.go
Normal file
@ -0,0 +1,20 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
)
|
||||
|
||||
func SetTagNotification(operationID, sendID, recvID, content string, contentType int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", sendID, recvID, content, contentType)
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.UserMsgType
|
||||
n.OperationID = operationID
|
||||
n.Content = []byte(content)
|
||||
Notification(&n)
|
||||
}
|
163
internal/rpc/office/office.go
Normal file
163
internal/rpc/office/office.go
Normal file
@ -0,0 +1,163 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type officeServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewOfficeServer(port int) *officeServer {
|
||||
log.NewPrivateLog("officeServer")
|
||||
return &officeServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *officeServer) Run() {
|
||||
log.NewInfo("0", "officeServer rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbOffice.RegisterOfficeServiceServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "message cms rpc success")
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserTags(_ context.Context, req *pbOffice.GetUserTagsReq) (resp *pbOffice.GetUserTagsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req ", req.String())
|
||||
resp = &pbOffice.GetUserTagsResp{
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
Tags: []*pbOffice.Tag{},
|
||||
}
|
||||
tags, err := db.DB.GetUserTags(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(resp.Tags, tags); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
for _, v := range resp.Tags {
|
||||
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) CreateTag(_ context.Context, req *pbOffice.CreateTagReq) (resp *pbOffice.CreateTagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "CreateTag req", req.String())
|
||||
resp = &pbOffice.CreateTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.CreateTag(req.UserID, req.TagName, req.UserIDList); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) DeleteTag(_ context.Context, req *pbOffice.DeleteTagReq) (resp *pbOffice.DeleteTagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.DeleteTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.DeleteTag(req.UserID, req.TagID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteTag failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) SetTag(_ context.Context, req *pbOffice.SetTagReq) (resp *pbOffice.SetTagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SetTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.SetTag(req.UserID, req.TagID, req.NewName, req.ReduceUserIDList, req.ReduceUserIDList); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetTag failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagReq) (resp *pbOffice.SendMsg2TagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SendMsg2TagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
userIDList, err := db.DB.GetUserIDListByTagID(req.SendID, req.TagID)
|
||||
for _, userID := range userIDList {
|
||||
msg.SetTagNotification(req.OperationID, req.SendID, userID, req.Content, req.ContentType)
|
||||
}
|
||||
if err := db.DB.SaveTagSendLog(req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SaveTagSendLog failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (s *officeServer) GetTagSendLogs(_ context.Context, req *pbOffice.GetTagSendLogsReq) (resp *pbOffice.GetTagSendLogsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetTagSendLogsResp{
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
}
|
||||
tagSendLogs, err := db.DB.GetTagSendLogs(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTagSendLogs", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
}
|
||||
if err := utils.CopyStructFields(resp.TagSendLogs, tagSendLogs); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Pagination = &pbCommon.ResponsePagination{
|
||||
CurrentPage: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
@ -13,8 +13,8 @@ type MiniostorageCredentialResp struct {
|
||||
}
|
||||
|
||||
type MinioUploadFileReq struct {
|
||||
OperationID string `form:"operationID"`
|
||||
FileType int `form:"fileType"`
|
||||
OperationID string `form:"operationID" binding:"required"`
|
||||
FileType int `form:"fileType" binding:"required"`
|
||||
}
|
||||
|
||||
type MinioUploadFileResp struct {
|
||||
|
46
pkg/base_info/office_struct.go
Normal file
46
pkg/base_info/office_struct.go
Normal file
@ -0,0 +1,46 @@
|
||||
package base_info
|
||||
|
||||
import pbOffice "Open_IM/pkg/proto/office"
|
||||
|
||||
type GetUserTagsReq struct {
|
||||
pbOffice.GetUserTagsReq
|
||||
}
|
||||
|
||||
type GetUserTagsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tags []*pbOffice.Tag `json:"tags"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateTagReq struct {
|
||||
pbOffice.CreateTagReq
|
||||
}
|
||||
|
||||
type CreateTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteTagReq struct {
|
||||
pbOffice.DeleteTagReq
|
||||
}
|
||||
|
||||
type DeleteTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SetTagReq struct {
|
||||
pbOffice.SetTagReq
|
||||
}
|
||||
|
||||
type SetTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SendMsg2TagReq struct {
|
||||
pbOffice.SendMsg2TagReq
|
||||
}
|
||||
|
||||
type SendMsg2TagResp struct {
|
||||
CommResp
|
||||
}
|
@ -103,6 +103,7 @@ type config struct {
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
|
@ -5,12 +5,14 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
officePb "Open_IM/pkg/proto/office"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogo/protobuf/sortkeys"
|
||||
"math/rand"
|
||||
|
||||
//"github.com/garyburd/redigo/redis"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@ -22,6 +24,8 @@ import (
|
||||
|
||||
const cChat = "msg"
|
||||
const cGroup = "group"
|
||||
const cTag = "tag"
|
||||
const cSendLog = "sendLog"
|
||||
const singleGocMsgNum = 5000
|
||||
|
||||
type MsgInfo struct {
|
||||
@ -430,9 +434,135 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error {
|
||||
//return nil
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
TagID string `bson:"tagID"`
|
||||
TagName string `bson:"tagName"`
|
||||
UserList []string `bson:"userList"`
|
||||
}
|
||||
|
||||
type TagsStruct struct {
|
||||
Uid string `bson:"uid"`
|
||||
Tags map[string]Tag `bson:"tags"`
|
||||
}
|
||||
|
||||
type TagSendLogStruct struct {
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserTags(userID string) ([]Tag, error) {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
var tagStruct TagsStruct
|
||||
var tags []Tag
|
||||
_ = c.FindOne(ctx, bson.M{"uid": userID}).Decode(&tagStruct)
|
||||
for _, v := range tagStruct.Tags {
|
||||
tags = append(tags, v)
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (d *DataBases) CreateTag(userID, tagName string, userList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := Tag{
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
UserList: userList,
|
||||
}
|
||||
_, err := c.InsertOne(ctx, TagsStruct{
|
||||
Uid: userID,
|
||||
Tags: map[string]Tag{tagID: tag},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) DeleteTag(userID, tagID string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_, err := c.DeleteOne(ctx, bson.M{"uid": userID, "tags": bson.M{"$unset": tagID}})
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserList []string, reduceUserIDList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_, err := c.UpdateOne(ctx, bson.M{"uid": userID, "tags": tagID}, bson.M{"tagName": newName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.InsertOne(ctx, bson.M{"uid": userID, "tags": bson.M{tagID: ""}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//_, err = c.InsertOne(ctx)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserIDListByTagID(userID, tagID string) ([]string, error) {
|
||||
var tagIDList []string
|
||||
var tagStruct TagsStruct
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_ = c.FindOne(ctx, bson.M{"uid": userID}).Decode(&tagStruct)
|
||||
for k, tag := range tagStruct.Tags {
|
||||
if k == tagID {
|
||||
tagIDList = tag.UserList
|
||||
}
|
||||
}
|
||||
return tagIDList, nil
|
||||
}
|
||||
|
||||
type TagSendLog struct {
|
||||
TagID string `bson:"tagID"`
|
||||
SendID string `bson:"sendID"`
|
||||
SenderPlatformID int32 `bson:"senderPlatformID"`
|
||||
Content string `bson:"content"`
|
||||
ContentType int32 `bson:"contentType"`
|
||||
SendTime int64 `bson:"sendTime"`
|
||||
UserList []string `bson:"userList"`
|
||||
}
|
||||
|
||||
func (d *DataBases) SaveTagSendLog(sendReq *officePb.SendMsg2TagReq) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
||||
tagSendLog := TagSendLog{
|
||||
TagID: sendReq.TagID,
|
||||
SendID: sendReq.SendID,
|
||||
SenderPlatformID: sendReq.SenderPlatformID,
|
||||
Content: sendReq.Content,
|
||||
ContentType: sendReq.ContentType,
|
||||
SendTime: time.Now().Unix(),
|
||||
}
|
||||
_, err := c.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32) ([]*TagSendLog, error) {
|
||||
var tagSendLogs []*TagSendLog
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
||||
cursor, err := c.Find(ctx, bson.M{"sendID": userID})
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
err = cursor.Decode(&tagSendLogs)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
return tagSendLogs, nil
|
||||
}
|
||||
|
||||
func generateTagID(tagName, userID string) string {
|
||||
return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()))
|
||||
}
|
||||
|
||||
func getCurrentTimestampByMill() int64 {
|
||||
return time.Now().UnixNano() / 1e6
|
||||
}
|
||||
|
||||
func getSeqUid(uid string, seq uint32) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
return indexGen(uid, seqSuffix)
|
||||
|
@ -74,6 +74,19 @@ func GetUserByUserID(userID string) (*db.User, error) {
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func GetUserNameByUserID(userID string) (string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var userName string
|
||||
err = dbConn.Table("users").Select("name").Where("user_id=?", userID).Find(&userName).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return userName, nil
|
||||
}
|
||||
|
||||
func UpdateUserInfo(user db.User) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
|
1183
pkg/proto/office/office.pb.go
Normal file
1183
pkg/proto/office/office.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
108
pkg/proto/office/office.proto
Normal file
108
pkg/proto/office/office.proto
Normal file
@ -0,0 +1,108 @@
|
||||
syntax = "proto3";
|
||||
import "Open_IM/pkg/proto/sdk_ws/ws.proto";
|
||||
option go_package = "./office;office";
|
||||
package office;
|
||||
|
||||
message CommonResp{
|
||||
int32 errCode = 1;
|
||||
string errMsg = 2;
|
||||
}
|
||||
|
||||
message TagUser {
|
||||
string userID = 1;
|
||||
string userName = 2;
|
||||
}
|
||||
|
||||
message Tag {
|
||||
string tagID = 1;
|
||||
string tagName = 2;
|
||||
repeated TagUser userList = 3;
|
||||
}
|
||||
|
||||
message GetUserTagsReq{
|
||||
string userID = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message GetUserTagsResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated Tag tags = 2;
|
||||
}
|
||||
|
||||
message CreateTagReq {
|
||||
string tagName = 1;
|
||||
string userID = 2;
|
||||
repeated string userIDList = 3;
|
||||
string operationID = 4;
|
||||
}
|
||||
|
||||
message CreateTagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message DeleteTagReq {
|
||||
string userID = 1;
|
||||
string tagID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message DeleteTagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message SetTagReq {
|
||||
string userID = 1;
|
||||
string tagID = 2;
|
||||
string newName = 3;
|
||||
repeated string increaseUserIDList = 4;
|
||||
repeated string reduceUserIDList = 5;
|
||||
string operationID = 6;
|
||||
}
|
||||
|
||||
message SetTagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message SendMsg2TagReq {
|
||||
string tagID = 1;
|
||||
string sendID = 2;
|
||||
int32 senderPlatformID = 3;
|
||||
string content = 4;
|
||||
int32 contentType = 5;
|
||||
string operationID = 6;
|
||||
}
|
||||
|
||||
message SendMsg2TagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetTagSendLogsReq {
|
||||
server_api_params.RequestPagination Pagination = 1;
|
||||
string userID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message TagSendLog {
|
||||
string tagID = 1;
|
||||
string tagName = 2;
|
||||
int32 contentType = 3;
|
||||
string content = 4;
|
||||
int64 sendTime = 5;
|
||||
repeated string userList = 6;
|
||||
}
|
||||
|
||||
message GetTagSendLogsResp {
|
||||
CommonResp commonResp = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
repeated TagSendLog tagSendLogs = 3;
|
||||
}
|
||||
|
||||
service OfficeService {
|
||||
rpc GetUserTags(GetUserTagsReq) returns(GetUserTagsResp);
|
||||
rpc CreateTag(CreateTagReq) returns(CreateTagResp);
|
||||
rpc DeleteTag(DeleteTagReq) returns(DeleteTagResp);
|
||||
rpc SetTag(SetTagReq) returns(SetTagResp);
|
||||
rpc SendMsg2Tag(SendMsg2TagReq) returns(SendMsg2TagResp);
|
||||
rpc GetTagSendLogs(GetTagSendLogsReq) returns(GetTagSendLogsResp);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ service_port_name=(
|
||||
openImAdminCmsPort
|
||||
openImMessageCmsPort
|
||||
openImStatisticsPort
|
||||
openImOfficePort
|
||||
)
|
||||
switch=$(cat $config_path | grep demoswitch |awk -F '[:]' '{print $NF}')
|
||||
for i in ${service_port_name[*]}; do
|
||||
|
@ -48,6 +48,7 @@ service_source_root=(
|
||||
../cmd/rpc/open_im_admin_cms/
|
||||
../cmd/rpc/open_im_message_cms/
|
||||
../cmd/rpc/open_im_statistics/
|
||||
../cmd/rpc/open_im_office/
|
||||
${msg_gateway_source_root}
|
||||
${msg_transfer_source_root}
|
||||
${msg_source_root}
|
||||
@ -68,6 +69,7 @@ service_names=(
|
||||
open_im_admin_cms
|
||||
open_im_message_cms
|
||||
open_im_statistics
|
||||
open_im_office
|
||||
${msg_gateway_name}
|
||||
${msg_transfer_name}
|
||||
${msg_name}
|
||||
|
@ -17,6 +17,7 @@ service_filename=(
|
||||
open_im_admin_cms
|
||||
open_im_message_cms
|
||||
open_im_statistics
|
||||
open_im_office
|
||||
${msg_name}
|
||||
)
|
||||
|
||||
@ -34,6 +35,7 @@ service_port_name=(
|
||||
openImMessageCmsPort
|
||||
openImStatisticsPort
|
||||
openImOfflineMessagePort
|
||||
openImOfficePort
|
||||
)
|
||||
|
||||
for ((i = 0; i < ${#service_filename[*]}; i++)); do
|
||||
|
Loading…
x
Reference in New Issue
Block a user