parent
2e3bb941b0
commit
a92dd54354
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,25 +0,0 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_cms_api
|
||||
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
|
||||
|
@ -1,30 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/cms_api"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := cmsapi.NewGinRouter()
|
||||
router.Use(utils.CorsHandler())
|
||||
defaultPorts := config.Config.CmsApi.GinPort
|
||||
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10006 as port")
|
||||
flag.Parse()
|
||||
address := "0.0.0.0:" + strconv.Itoa(*ginPort)
|
||||
if config.Config.Api.ListenIP != "" {
|
||||
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
|
||||
}
|
||||
address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort)
|
||||
fmt.Println("start cms api server, address: ", address, ", OpenIM version: ", constant.CurrentVersion, "\n")
|
||||
router.Run(address)
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_admin_cms
|
||||
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
|
@ -1,26 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpcMessageCMS "Open_IM/internal/rpc/admin_cms"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defaultPorts := config.Config.RpcPort.OpenImAdminCmsPort
|
||||
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
|
||||
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AdminCmsPrometheusPort[0], "adminCMSPrometheusPort default listen port")
|
||||
flag.Parse()
|
||||
fmt.Println("start cms rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
|
||||
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
|
||||
go func() {
|
||||
err := promePkg.StartPromeSrv(*prometheusPort)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
rpcServer.Run()
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_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
|
@ -1,26 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpc "Open_IM/internal/rpc/office"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defaultPorts := config.Config.RpcPort.OpenImOfficePort
|
||||
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
|
||||
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.OfficePrometheusPort[0], "officePrometheusPort default listen port")
|
||||
flag.Parse()
|
||||
fmt.Println("start office rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
|
||||
rpcServer := rpc.NewOfficeServer(*rpcPort)
|
||||
go func() {
|
||||
err := promePkg.StartPromeSrv(*prometheusPort)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
rpcServer.Run()
|
||||
}
|
@ -0,0 +1,359 @@
|
||||
|
||||
notification:
|
||||
groupCreated:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "create group title" # xx create the group
|
||||
desc: "create group desc"
|
||||
ext: "create group ext"
|
||||
defaultTips:
|
||||
tips: "create the group" # xx create the group
|
||||
|
||||
groupInfoSet:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupInfoSet title"
|
||||
desc: "groupInfoSet desc"
|
||||
ext: "groupInfoSet ext"
|
||||
defaultTips:
|
||||
tips: "modified the group profile" # group info changed by xx
|
||||
|
||||
joinGroupApplication:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "joinGroupApplication title"
|
||||
desc: "joinGroupApplication desc"
|
||||
ext: "joinGroupApplication ext"
|
||||
defaultTips:
|
||||
tips: "apply to join the group" # group info changed by xx
|
||||
|
||||
memberQuit:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "memberQuit title"
|
||||
desc: "memberQuit desc"
|
||||
ext: "memberQuit ext"
|
||||
defaultTips:
|
||||
tips: "quit group msg" # group info changed by xx
|
||||
|
||||
groupApplicationAccepted:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupApplicationAccepted title"
|
||||
desc: "groupApplicationAccepted desc"
|
||||
ext: "groupApplicationAccepted ext"
|
||||
defaultTips:
|
||||
tips: "was allowed to join the group" # group info changed by xx
|
||||
|
||||
groupApplicationRejected:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: " title"
|
||||
desc: " desc"
|
||||
ext: " ext"
|
||||
defaultTips:
|
||||
tips: "was rejected into the group" # group info changed by xx
|
||||
|
||||
groupOwnerTransferred:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupOwnerTransferred title"
|
||||
desc: "groupOwnerTransferred desc"
|
||||
ext: "groupOwnerTransferred ext"
|
||||
defaultTips:
|
||||
tips: "become a new group owner" # group info changed by xx
|
||||
|
||||
memberKicked:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "memberKicked title"
|
||||
desc: "memberKicked desc"
|
||||
ext: "memberKicked ext"
|
||||
defaultTips:
|
||||
tips: "was kicked out of the group" # group info changed by xx
|
||||
|
||||
memberInvited:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "memberInvited title"
|
||||
desc: "memberInvited desc"
|
||||
ext: "memberInvited ext"
|
||||
defaultTips:
|
||||
tips: "was invited into the group" # group info changed by xx
|
||||
|
||||
memberEnter:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "memberEnter title"
|
||||
desc: "memberEnter desc"
|
||||
ext: "memberEnter ext"
|
||||
defaultTips:
|
||||
tips: "entered the group" # group info changed by xx
|
||||
|
||||
groupDismissed:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupDismissed title"
|
||||
desc: "groupDismissed desc"
|
||||
ext: "groupDismissed ext"
|
||||
defaultTips:
|
||||
tips: "group dismissed"
|
||||
|
||||
|
||||
groupMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMuted title"
|
||||
desc: "groupMuted desc"
|
||||
ext: "groupMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Muted"
|
||||
|
||||
groupCancelMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupCancelMuted title"
|
||||
desc: "groupCancelMuted desc"
|
||||
ext: "groupCancelMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Cancel Muted"
|
||||
|
||||
|
||||
groupMemberMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberMuted title"
|
||||
desc: "groupMemberMuted desc"
|
||||
ext: "groupMemberMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Member Muted"
|
||||
|
||||
groupMemberCancelMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberCancelMuted title"
|
||||
desc: "groupMemberCancelMuted desc"
|
||||
ext: "groupMemberCancelMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Member Cancel Muted"
|
||||
|
||||
groupMemberInfoSet:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberInfoSet title"
|
||||
desc: "groupMemberInfoSet desc"
|
||||
ext: "groupMemberInfoSet ext"
|
||||
defaultTips:
|
||||
tips: "group member info set"
|
||||
|
||||
|
||||
|
||||
#############################friend#################################
|
||||
|
||||
friendApplicationAdded:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "Somebody applies to add you as a friend"
|
||||
desc: "Somebody applies to add you as a friend"
|
||||
ext: "Somebody applies to add you as a friend"
|
||||
defaultTips:
|
||||
tips: "I applies to add you as a friend" #
|
||||
|
||||
friendApplicationApproved:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "Someone applies to add your friend application"
|
||||
desc: "Someone applies to add your friend application"
|
||||
ext: "Someone applies to add your friend application"
|
||||
defaultTips:
|
||||
tips: "I applies to add your friend application" #
|
||||
|
||||
|
||||
friendApplicationRejected:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "Someone rejected your friend application"
|
||||
desc: "Someone rejected your friend application"
|
||||
ext: "Someone rejected your friend application"
|
||||
defaultTips:
|
||||
tips: "I rejected your friend application" #
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
friendAdded:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "We have become friends"
|
||||
desc: "We have become friends"
|
||||
ext: "We have become friends"
|
||||
defaultTips:
|
||||
tips: "We have become friends" #
|
||||
|
||||
|
||||
|
||||
friendDeleted:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "deleted a friend"
|
||||
desc: "deleted a friend"
|
||||
ext: "deleted a friend"
|
||||
defaultTips:
|
||||
tips: "deleted a friend" #
|
||||
|
||||
|
||||
friendRemarkSet:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "Your friend's profile has been changed"
|
||||
desc: "Your friend's profile has been changed"
|
||||
ext: "Your friend's profile has been changed"
|
||||
defaultTips:
|
||||
tips: "Your friend's profile has been changed" #
|
||||
|
||||
|
||||
|
||||
blackAdded:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "blocked a user"
|
||||
desc: "blocked a user"
|
||||
ext: "blocked a user"
|
||||
defaultTips:
|
||||
tips: "blocked a user" #
|
||||
|
||||
|
||||
blackDeleted:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "Remove a blocked user"
|
||||
desc: "Remove a blocked user"
|
||||
ext: "Remove a blocked user"
|
||||
defaultTips:
|
||||
tips: "Remove a blocked user"
|
||||
|
||||
friendInfoUpdated:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "friend info updated"
|
||||
desc: "friend info updated"
|
||||
ext: "friend info updated"
|
||||
defaultTips:
|
||||
tips: "friend info updated"
|
||||
|
||||
|
||||
#####################user#########################
|
||||
userInfoUpdated:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "Remove a blocked user"
|
||||
desc: "Remove a blocked user"
|
||||
ext: "Remove a blocked user"
|
||||
defaultTips:
|
||||
tips: "remove a blocked user"
|
||||
|
||||
#####################conversation#########################
|
||||
conversationOptUpdate:
|
||||
conversation:
|
||||
reliabilityLevel: 1
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "conversation opt update"
|
||||
desc: "conversation opt update"
|
||||
ext: "conversation opt update"
|
||||
defaultTips:
|
||||
tips: "conversation opt update"
|
||||
|
||||
conversationSetPrivate:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "burn after reading"
|
||||
desc: "burn after reading"
|
||||
ext: "burn after reading"
|
||||
defaultTips:
|
||||
openTips: "burn after reading was opened"
|
||||
closeTips: "burn after reading was closed"
|
||||
|
@ -1,20 +0,0 @@
|
||||
FROM ubuntu
|
||||
|
||||
# 设置固定的项目路径
|
||||
ENV WORKDIR /Open-IM-Server
|
||||
ENV CMDDIR $WORKDIR/cmd
|
||||
ENV CONFIG_NAME $WORKDIR/config/config.yaml
|
||||
|
||||
|
||||
# 将可执行文件复制到目标目录
|
||||
ADD ./open_im_admin_cms $WORKDIR/cmd/main
|
||||
|
||||
# 创建用于挂载的几个目录,添加可执行权限
|
||||
RUN mkdir $WORKDIR/logs $WORKDIR/config $WORKDIR/script && \
|
||||
chmod +x $WORKDIR/cmd/main
|
||||
|
||||
VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config", "/Open-IM-Server/script"]
|
||||
|
||||
|
||||
WORKDIR $CMDDIR
|
||||
CMD ./main
|
@ -1,43 +0,0 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: admin-cms-deployment
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: admin-cms # 选择这个指定标签执行
|
||||
replicas: 1 # 运行pod数量
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: admin-cms # 标签
|
||||
spec:
|
||||
containers:
|
||||
- name: admin-cms
|
||||
image: openim/admin_cms:v2.3.4
|
||||
# imagePullPolicy: Always #每次启动都重新拉取镜像
|
||||
ports:
|
||||
- containerPort: 10200
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /Open-IM-Server/config
|
||||
readOnly: true
|
||||
- name: usualConfig
|
||||
mountPath: /Open-IM-Server/config
|
||||
readOnly: true
|
||||
env:
|
||||
- name: CONFIG_NAME
|
||||
value: "/Open-IM-Server"
|
||||
- name: USUAL_CONFIG_NAME
|
||||
value: "/Open-IM-Server"
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: openim-config
|
||||
- name: usualConfig
|
||||
configMap:
|
||||
name: openim-usualConfig
|
||||
strategy: #更新策略
|
||||
type: RollingUpdate # 滚动更新
|
||||
|
@ -1,18 +0,0 @@
|
||||
FROM ubuntu
|
||||
|
||||
# 设置固定的项目路径
|
||||
ENV WORKDIR /Open-IM-Server
|
||||
ENV CMDDIR $WORKDIR/cmd
|
||||
ENV CONFIG_NAME $WORKDIR/config/config.yaml
|
||||
|
||||
# 将可执行文件复制到目标目录
|
||||
ADD ./open_im_cms_api $WORKDIR/cmd/main
|
||||
|
||||
# 创建用于挂载的几个目录,添加可执行权限
|
||||
RUN mkdir $WORKDIR/logs $WORKDIR/config $WORKDIR/script && \
|
||||
chmod +x $WORKDIR/cmd/main
|
||||
|
||||
VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config","/Open-IM-Server/script"]
|
||||
|
||||
WORKDIR $CMDDIR
|
||||
CMD ./main
|
@ -1,56 +0,0 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: cms-api-deployment
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: cms-api # 选择这个指定标签执行
|
||||
replicas: 1 # 运行pod数量
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: cms-api # 标签
|
||||
spec:
|
||||
containers:
|
||||
- name: cms-api
|
||||
image: openim/cms_api:v2.3.4
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10006
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /Open-IM-Server/config
|
||||
readOnly: true
|
||||
- name: usualConfig
|
||||
mountPath: /Open-IM-Server/config
|
||||
readOnly: true
|
||||
env:
|
||||
- name: CONFIG_NAME
|
||||
value: "/Open-IM-Server"
|
||||
- name: USUAL_CONFIG_NAME
|
||||
value: "/Open-IM-Server"
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: openim-config
|
||||
- name: usualConfig
|
||||
configMap:
|
||||
name: openim-usualConfig
|
||||
strategy: #更新策略
|
||||
type: RollingUpdate # 滚动更新
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: cms-api
|
||||
spec:
|
||||
ports:
|
||||
- name: cms-api-port
|
||||
protocol: TCP
|
||||
port: 10006
|
||||
targetPort: 10006
|
||||
selector:
|
||||
app: cms-api
|
||||
type: NodePort
|
@ -1,42 +0,0 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: office-deployment
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: office # 选择这个指定标签执行
|
||||
replicas: 1 # 运行pod数量
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: office # 标签
|
||||
spec:
|
||||
containers:
|
||||
- name: office
|
||||
image: openim/office:v2.3.4
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10210
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /Open-IM-Server/config
|
||||
readOnly: true
|
||||
- name: usualConfig
|
||||
mountPath: /Open-IM-Server/config
|
||||
readOnly: true
|
||||
env:
|
||||
- name: CONFIG_NAME
|
||||
value: "/Open-IM-Server"
|
||||
- name: USUAL_CONFIG_NAME
|
||||
value: "/Open-IM-Server"
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: openim-config
|
||||
- name: usualConfig
|
||||
configMap:
|
||||
name: openim-usualConfig
|
||||
strategy: #更新策略
|
||||
type: RollingUpdate # 滚动更新
|
@ -1,20 +0,0 @@
|
||||
FROM ubuntu
|
||||
|
||||
# 设置固定的项目路径
|
||||
ENV WORKDIR /Open-IM-Server
|
||||
ENV CMDDIR $WORKDIR/cmd
|
||||
ENV CONFIG_NAME $WORKDIR/config/config.yaml
|
||||
|
||||
|
||||
# 将可执行文件复制到目标目录
|
||||
ADD ./open_im_office $WORKDIR/cmd/main
|
||||
|
||||
# 创建用于挂载的几个目录,添加可执行权限
|
||||
RUN mkdir $WORKDIR/logs $WORKDIR/config $WORKDIR/script && \
|
||||
chmod +x $WORKDIR/cmd/main
|
||||
|
||||
VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config","/Open-IM-Server/script"]
|
||||
|
||||
|
||||
WORKDIR $CMDDIR
|
||||
CMD ./main
|
@ -1,450 +0,0 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Summary 获取用户标签信息
|
||||
// @Description 用户获取自己的所有的标签
|
||||
// @Tags 标签
|
||||
// @ID GetUserTags
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetUserTagsReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetUserTagsResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/get_user_tags [post]
|
||||
func GetUserTags(c *gin.Context) {
|
||||
var (
|
||||
req api.GetUserTagsReq
|
||||
resp api.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
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
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())
|
||||
}
|
||||
if respPb.Tags != nil {
|
||||
resp.Data.Tags = respPb.Tags
|
||||
} else {
|
||||
resp.Data.Tags = []*pbOffice.Tag{}
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 创建标签
|
||||
// @Description 创建标签
|
||||
// @Tags 标签
|
||||
// @ID CreateTag
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.CreateTagReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.CreateTagResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/create_tag [post]
|
||||
func CreateTag(c *gin.Context) {
|
||||
var (
|
||||
req api.CreateTagReq
|
||||
resp api.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())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// @Summary 删除标签
|
||||
// @Description 根据标签ID创建标签
|
||||
// @Tags 标签
|
||||
// @ID DeleteTag
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.DeleteTagReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.DeleteTagResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/delete_tag [post]
|
||||
func DeleteTag(c *gin.Context) {
|
||||
var (
|
||||
req api.DeleteTagReq
|
||||
resp api.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())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// @Summary 修改标签
|
||||
// @Description 根据标签ID修改标签用户列表, 名称
|
||||
// @Tags 标签
|
||||
// @ID SetTag
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.SetTagReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.SetTagResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/set_tag [post]
|
||||
func SetTag(c *gin.Context) {
|
||||
var (
|
||||
req api.SetTagReq
|
||||
resp api.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())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// @Summary 发送标签消息
|
||||
// @Description 对标签用户发送消息
|
||||
// @Tags 标签
|
||||
// @ID SendMsg2Tag
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.SendMsg2TagReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.SendMsg2TagResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/send_msg_to_tag [post]
|
||||
func SendMsg2Tag(c *gin.Context) {
|
||||
var (
|
||||
req api.SendMsg2TagReq
|
||||
resp api.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())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.SendID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// @Summary 获取发送历史记录
|
||||
// @Description 分页获取发送历史记录
|
||||
// @Tags 标签
|
||||
// @ID GetTagSendLogs
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetTagSendLogsReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetTagSendLogsResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/get_send_tag_log [post]
|
||||
func GetTagSendLogs(c *gin.Context) {
|
||||
var (
|
||||
req api.GetTagSendLogsReq
|
||||
resp api.GetTagSendLogsResp
|
||||
reqPb pbOffice.GetTagSendLogsReq
|
||||
respPb *pbOffice.GetTagSendLogsResp
|
||||
)
|
||||
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
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
maxSizeOption := grpc.MaxCallRecvMsgSize(1024 * 1024 * 20)
|
||||
respPb, err := client.GetTagSendLogs(context.Background(), &reqPb, maxSizeOption)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTagSendLogs failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetTagSendLogs rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
if respPb.TagSendLogs != nil {
|
||||
resp.Data.Logs = respPb.TagSendLogs
|
||||
} else {
|
||||
resp.Data.Logs = []*pbOffice.TagSendLog{}
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 获取该用户的标签信息
|
||||
// @Description 通过标签id获取该用户的标签信息
|
||||
// @Tags 标签
|
||||
// @ID GetUserTagByID
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetUserTagByIDReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetUserTagByIDResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/get_user_tag_by_id [post]
|
||||
func GetUserTagByID(c *gin.Context) {
|
||||
var (
|
||||
req api.GetUserTagByIDReq
|
||||
resp api.GetUserTagByIDResp
|
||||
reqPb pbOffice.GetUserTagByIDReq
|
||||
respPb *pbOffice.GetUserTagByIDResp
|
||||
)
|
||||
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
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.TagID = req.TagID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserTagByID(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTagByID 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.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Data.Tag = respPb.Tag
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
@ -1,670 +0,0 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Summary 创建一条工作圈
|
||||
// @Description 用户创建一条工作圈
|
||||
// @Tags 工作圈
|
||||
// @ID CreateOneWorkMoment
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.CreateOneWorkMomentReq true "请求 atUserList likeUserList permissionGroupList permissionUserList 字段中userName可以不填"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.CreateOneWorkMomentResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/create_one_work_moment [post]
|
||||
func CreateOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req api.CreateOneWorkMomentReq
|
||||
resp api.CreateOneWorkMomentResp
|
||||
reqPb pbOffice.CreateOneWorkMomentReq
|
||||
respPb *pbOffice.CreateOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
reqPb.WorkMoment.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.CreateOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CreateOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.CommResp = api.CommResp{
|
||||
ErrCode: respPb.CommonResp.ErrCode,
|
||||
ErrMsg: respPb.CommonResp.ErrMsg,
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 删除一条工作圈
|
||||
// @Description 根据用户工作圈ID删除一条工作圈
|
||||
// @Tags 工作圈
|
||||
// @ID DeleteOneWorkMoment
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.DeleteOneWorkMomentReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.DeleteOneWorkMomentResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/delete_one_work_moment [post]
|
||||
func DeleteOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req api.DeleteOneWorkMomentReq
|
||||
resp api.DeleteOneWorkMomentResp
|
||||
reqPb pbOffice.DeleteOneWorkMomentReq
|
||||
respPb *pbOffice.DeleteOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.DeleteOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "DeleteOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 点赞一条工作圈
|
||||
// @Description 工作圈ID点赞一条工作圈
|
||||
// @Tags 工作圈
|
||||
// @ID LikeOneWorkMoment
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.LikeOneWorkMomentReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.LikeOneWorkMomentResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/like_one_work_moment [post]
|
||||
func LikeOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req api.LikeOneWorkMomentReq
|
||||
resp api.LikeOneWorkMomentResp
|
||||
reqPb pbOffice.LikeOneWorkMomentReq
|
||||
respPb *pbOffice.LikeOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.LikeOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "LikeOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 评论一条工作圈
|
||||
// @Description 评论一条工作圈
|
||||
// @Tags 工作圈
|
||||
// @ID CommentOneWorkMoment
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.CommentOneWorkMomentReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.CommentOneWorkMomentResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/comment_one_work_moment [post]
|
||||
func CommentOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req api.CommentOneWorkMomentReq
|
||||
resp api.CommentOneWorkMomentResp
|
||||
reqPb pbOffice.CommentOneWorkMomentReq
|
||||
respPb *pbOffice.CommentOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.CommentOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CommentOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CommentOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 删除一条评论
|
||||
// @Description 删除一条评论
|
||||
// @Tags 工作圈
|
||||
// @ID DeleteComment
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.DeleteCommentReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.DeleteCommentResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/delete_comment [post]
|
||||
func DeleteComment(c *gin.Context) {
|
||||
var (
|
||||
req api.DeleteCommentReq
|
||||
resp api.DeleteCommentResp
|
||||
reqPb pbOffice.DeleteCommentReq
|
||||
respPb *pbOffice.DeleteCommentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.DeleteComment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteComment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "DeleteComment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 通过ID获取工作圈
|
||||
// @Description 通过ID获取工作圈
|
||||
// @Tags 工作圈
|
||||
// @ID GetWorkMomentByID
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetWorkMomentByIDReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetWorkMomentByIDResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/get_work_moment_by_id [post]
|
||||
func GetWorkMomentByID(c *gin.Context) {
|
||||
var (
|
||||
req api.GetWorkMomentByIDReq
|
||||
resp api.GetWorkMomentByIDResp
|
||||
reqPb pbOffice.GetWorkMomentByIDReq
|
||||
respPb *pbOffice.GetWorkMomentByIDResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.OpUserID = userID
|
||||
reqPb.WorkMomentID = req.WorkMomentID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetWorkMomentByID(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserWorkMoments rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Data.WorkMoment = &api.WorkMoment{LikeUserList: []*api.WorkMomentUser{}, Comments: []*api.Comment{},
|
||||
AtUserList: []*api.WorkMomentUser{}, PermissionUserList: []*api.WorkMomentUser{}}
|
||||
if err := utils.CopyStructFields(&resp.Data.WorkMoment, respPb.WorkMoment); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 查询用户工作圈
|
||||
// @Description 查询用户工作圈
|
||||
// @Tags 工作圈
|
||||
// @ID GetUserWorkMoments
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetUserWorkMomentsReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetUserWorkMomentsResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/get_user_work_moments [post]
|
||||
func GetUserWorkMoments(c *gin.Context) {
|
||||
var (
|
||||
req api.GetUserWorkMomentsReq
|
||||
resp api.GetUserWorkMomentsResp
|
||||
reqPb pbOffice.GetUserWorkMomentsReq
|
||||
respPb *pbOffice.GetUserWorkMomentsResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var opUserID string
|
||||
ok, opUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
reqPb.OpUserID = opUserID
|
||||
reqPb.UserID = req.UserID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserWorkMoments(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserWorkMoments rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.Data.WorkMoments = []*api.WorkMoment{}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
for _, v := range respPb.WorkMoments {
|
||||
workMoment := api.WorkMoment{
|
||||
WorkMomentID: v.WorkMomentID,
|
||||
UserID: v.UserID,
|
||||
Content: v.Content,
|
||||
FaceURL: v.FaceURL,
|
||||
UserName: v.UserName,
|
||||
CreateTime: v.CreateTime,
|
||||
Comments: make([]*api.Comment, len(v.Comments)),
|
||||
LikeUserList: make([]*api.WorkMomentUser, len(v.LikeUserList)),
|
||||
AtUserList: make([]*api.WorkMomentUser, len(v.AtUserList)),
|
||||
PermissionUserList: make([]*api.WorkMomentUser, len(v.PermissionUserList)),
|
||||
Permission: v.Permission,
|
||||
}
|
||||
for i, comment := range v.Comments {
|
||||
workMoment.Comments[i] = &api.Comment{
|
||||
UserID: comment.UserID,
|
||||
UserName: comment.UserName,
|
||||
ReplyUserID: comment.ReplyUserID,
|
||||
ReplyUserName: comment.ReplyUserName,
|
||||
ContentID: comment.ContentID,
|
||||
Content: comment.Content,
|
||||
CreateTime: comment.CreateTime,
|
||||
}
|
||||
}
|
||||
for i, likeUser := range v.LikeUserList {
|
||||
workMoment.LikeUserList[i] = &api.WorkMomentUser{
|
||||
UserID: likeUser.UserID,
|
||||
UserName: likeUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, atUser := range v.AtUserList {
|
||||
workMoment.AtUserList[i] = &api.WorkMomentUser{
|
||||
UserID: atUser.UserID,
|
||||
UserName: atUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, permissionUser := range v.PermissionUserList {
|
||||
workMoment.PermissionUserList[i] = &api.WorkMomentUser{
|
||||
UserID: permissionUser.UserID,
|
||||
UserName: permissionUser.UserName,
|
||||
}
|
||||
}
|
||||
resp.Data.WorkMoments = append(resp.Data.WorkMoments, &workMoment)
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 查询自己大工作圈页面
|
||||
// @Description 查询用户工作圈页面
|
||||
// @Tags 工作圈
|
||||
// @ID GetUserFriendWorkMoments
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetUserFriendWorkMomentsReq true "请求"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetUserFriendWorkMomentsResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /office/get_user_friend_work_moments [post]
|
||||
func GetUserFriendWorkMoments(c *gin.Context) {
|
||||
var (
|
||||
req api.GetUserFriendWorkMomentsReq
|
||||
resp api.GetUserFriendWorkMomentsResp
|
||||
reqPb pbOffice.GetUserFriendWorkMomentsReq
|
||||
respPb *pbOffice.GetUserFriendWorkMomentsResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserFriendWorkMoments(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserFriendWorkMoments rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
//if err := utils.CopyStructFields(&resp.Map.WorkMoments, respPb.WorkMoments); err != nil {
|
||||
// log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
//}
|
||||
resp.Data.WorkMoments = []*api.WorkMoment{}
|
||||
for _, v := range respPb.WorkMoments {
|
||||
workMoment := api.WorkMoment{
|
||||
WorkMomentID: v.WorkMomentID,
|
||||
UserID: v.UserID,
|
||||
Content: v.Content,
|
||||
FaceURL: v.FaceURL,
|
||||
UserName: v.UserName,
|
||||
CreateTime: v.CreateTime,
|
||||
Comments: make([]*api.Comment, len(v.Comments)),
|
||||
LikeUserList: make([]*api.WorkMomentUser, len(v.LikeUserList)),
|
||||
AtUserList: make([]*api.WorkMomentUser, len(v.AtUserList)),
|
||||
PermissionUserList: make([]*api.WorkMomentUser, len(v.PermissionUserList)),
|
||||
Permission: v.Permission,
|
||||
}
|
||||
for i, comment := range v.Comments {
|
||||
workMoment.Comments[i] = &api.Comment{
|
||||
UserID: comment.UserID,
|
||||
UserName: comment.UserName,
|
||||
ReplyUserID: comment.ReplyUserID,
|
||||
ReplyUserName: comment.ReplyUserName,
|
||||
ContentID: comment.ContentID,
|
||||
Content: comment.Content,
|
||||
CreateTime: comment.CreateTime,
|
||||
}
|
||||
}
|
||||
for i, likeUser := range v.LikeUserList {
|
||||
workMoment.LikeUserList[i] = &api.WorkMomentUser{
|
||||
UserID: likeUser.UserID,
|
||||
UserName: likeUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, atUser := range v.AtUserList {
|
||||
workMoment.AtUserList[i] = &api.WorkMomentUser{
|
||||
UserID: atUser.UserID,
|
||||
UserName: atUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, permissionUser := range v.PermissionUserList {
|
||||
workMoment.PermissionUserList[i] = &api.WorkMomentUser{
|
||||
UserID: permissionUser.UserID,
|
||||
UserName: permissionUser.UserName,
|
||||
}
|
||||
}
|
||||
resp.Data.WorkMoments = append(resp.Data.WorkMoments, &workMoment)
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetUserWorkMomentsLevel(c *gin.Context) {
|
||||
var (
|
||||
req api.SetUserWorkMomentsLevelReq
|
||||
resp api.SetUserWorkMomentsLevelResp
|
||||
reqPb pbOffice.SetUserWorkMomentsLevelReq
|
||||
respPb *pbOffice.SetUserWorkMomentsLevelResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
var userID string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SetUserWorkMomentsLevel(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetUserWorkMomentsLevel rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "SetUserWorkMomentsLevel rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
apiStruct "Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbAdmin "Open_IM/pkg/proto/admin_cms"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
|
||||
url2 "net/url"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var (
|
||||
minioClient *minio.Client
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
operationID := utils.OperationIDGenerator()
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio config: ", config.Config.Credential.Minio)
|
||||
var initUrl string
|
||||
if config.Config.Credential.Minio.EndpointInnerEnable {
|
||||
initUrl = config.Config.Credential.Minio.EndpointInner
|
||||
} else {
|
||||
initUrl = config.Config.Credential.Minio.Endpoint
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "use initUrl: ", initUrl)
|
||||
minioUrl, err := url2.Parse(initUrl)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||
return
|
||||
}
|
||||
opts := &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""),
|
||||
}
|
||||
if minioUrl.Scheme == "http" {
|
||||
opts.Secure = false
|
||||
} else if minioUrl.Scheme == "https" {
|
||||
opts.Secure = true
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "Parse ok ", config.Config.Credential.Minio)
|
||||
minioClient, err = minio.New(minioUrl.Host, opts)
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "new ok ", config.Config.Credential.Minio)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "init minio client failed", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func GetUserToken(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.GetUserTokenRequest
|
||||
resp apiStruct.GetUserTokenResponse
|
||||
reqPb pbAdmin.GetUserTokenReq
|
||||
respPb *pbAdmin.GetUserTokenResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.UserID = req.UserID
|
||||
reqPb.PlatformID = req.PlatFormID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.GetUserToken(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.Token = respPb.Token
|
||||
resp.ExpTime = respPb.ExpTime
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
// register
|
||||
func AdminLogin(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.AdminLoginRequest
|
||||
resp apiStruct.AdminLoginResponse
|
||||
reqPb pbAdmin.AdminLoginReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.Secret = req.Secret
|
||||
reqPb.AdminID = req.AdminName
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.AdminLogin(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.FaceURL = respPb.FaceURL
|
||||
resp.UserName = respPb.UserName
|
||||
resp.Token = respPb.Token
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbAdmin "Open_IM/pkg/proto/admin_cms"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetUserFriends(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetFriendsReq
|
||||
resp cms_struct.GetFriendsResp
|
||||
reqPb pbAdmin.GetUserFriendsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{}
|
||||
utils.CopyStructFields(&reqPb.Pagination, req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.UserID = req.UserID
|
||||
reqPb.FriendUserName = req.FriendUserName
|
||||
reqPb.FriendUserID = req.FriendUserID
|
||||
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.GetUserFriends(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.FriendInfoList {
|
||||
friend := &cms_struct.FriendInfo{}
|
||||
utils.CopyStructFields(friend, v)
|
||||
friend.Nickname = v.FriendUser.Nickname
|
||||
friend.UserID = v.FriendUser.UserID
|
||||
resp.FriendInfoList = append(resp.FriendInfoList, friend)
|
||||
}
|
||||
resp.FriendNums = respPb.FriendNums
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
common "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetGroups(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetGroupsRequest
|
||||
resp cms_struct.GetGroupsResponse
|
||||
reqPb pbGroup.GetGroupsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.Pagination = &common.RequestPagination{}
|
||||
utils.CopyStructFields(&reqPb.Pagination, req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
reqPb.GroupID = req.GroupID
|
||||
reqPb.GroupName = req.GroupName
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.GetGroups(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.CMSGroups {
|
||||
groupResp := cms_struct.GroupResponse{}
|
||||
utils.CopyStructFields(&groupResp, v.GroupInfo)
|
||||
groupResp.GroupOwnerName = v.GroupOwnerUserName
|
||||
groupResp.GroupOwnerID = v.GroupOwnerUserID
|
||||
resp.Groups = append(resp.Groups, groupResp)
|
||||
}
|
||||
resp.GroupNums = int(respPb.GroupNum)
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
func GetGroupMembers(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetGroupMembersRequest
|
||||
reqPb pbGroup.GetGroupMembersCMSReq
|
||||
resp cms_struct.GetGroupMembersResponse
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.Pagination = &common.RequestPagination{
|
||||
PageNumber: int32(req.PageNumber),
|
||||
ShowNumber: int32(req.ShowNumber),
|
||||
}
|
||||
reqPb.GroupID = req.GroupID
|
||||
reqPb.UserName = req.UserName
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.GetGroupMembersCMS(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS failed:", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ResponsePagination = cms_struct.ResponsePagination{
|
||||
CurrentPage: int(respPb.Pagination.CurrentPage),
|
||||
ShowNumber: int(respPb.Pagination.ShowNumber),
|
||||
}
|
||||
resp.MemberNums = int(respPb.MemberNums)
|
||||
for _, groupMember := range respPb.Members {
|
||||
memberResp := cms_struct.GroupMemberResponse{}
|
||||
utils.CopyStructFields(&memberResp, groupMember)
|
||||
resp.GroupMembers = append(resp.GroupMembers, memberResp)
|
||||
}
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package messageCMS
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbAdminCMS "Open_IM/pkg/proto/admin_cms"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetChatLogs(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetChatLogsReq
|
||||
resp cms_struct.GetChatLogsResp
|
||||
reqPb pbAdminCMS.GetChatLogsReq
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: int32(req.PageNumber),
|
||||
ShowNumber: int32(req.ShowNumber),
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, &req)
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdminCMS.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.GetChatLogs(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.ChatLogs {
|
||||
chatLog := cms_struct.ChatLog{}
|
||||
utils.CopyStructFields(&chatLog, v)
|
||||
resp.ChatLogs = append(resp.ChatLogs, &chatLog)
|
||||
}
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
resp.ChatLogsNum = int(respPb.ChatLogsNum)
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package cmsapi
|
||||
|
||||
import (
|
||||
"Open_IM/internal/cms_api/admin"
|
||||
"Open_IM/internal/cms_api/friend"
|
||||
"Open_IM/internal/cms_api/group"
|
||||
messageCMS "Open_IM/internal/cms_api/message_cms"
|
||||
"Open_IM/internal/cms_api/middleware"
|
||||
"Open_IM/internal/cms_api/statistics"
|
||||
"Open_IM/internal/cms_api/user"
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NewGinRouter() *gin.Engine {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
baseRouter := gin.New()
|
||||
baseRouter.Use(gin.Recovery())
|
||||
baseRouter.Use(middleware.CorsHandler())
|
||||
if config.Config.Prometheus.Enable {
|
||||
baseRouter.GET("/metrics", promePkg.PrometheusHandler())
|
||||
}
|
||||
router := baseRouter.Group("/cms")
|
||||
adminRouterGroup := router.Group("/admin")
|
||||
{
|
||||
adminRouterGroup.POST("/login", admin.AdminLogin)
|
||||
adminRouterGroup.Use(middleware.JWTAuth())
|
||||
adminRouterGroup.POST("/get_user_token", admin.GetUserToken)
|
||||
}
|
||||
r2 := router.Group("")
|
||||
r2.Use(middleware.JWTAuth())
|
||||
statisticsRouterGroup := r2.Group("/statistics")
|
||||
{
|
||||
statisticsRouterGroup.POST("/get_messages_statistics", statistics.GetMessagesStatistics)
|
||||
statisticsRouterGroup.POST("/get_user_statistics", statistics.GetUserStatistics)
|
||||
statisticsRouterGroup.POST("/get_group_statistics", statistics.GetGroupStatistics)
|
||||
statisticsRouterGroup.POST("/get_active_user", statistics.GetActiveUser)
|
||||
statisticsRouterGroup.POST("/get_active_group", statistics.GetActiveGroup)
|
||||
}
|
||||
groupRouterGroup := r2.Group("/group")
|
||||
{
|
||||
groupRouterGroup.POST("/get_groups", group.GetGroups)
|
||||
groupRouterGroup.POST("/get_group_members", group.GetGroupMembers)
|
||||
}
|
||||
userRouterGroup := r2.Group("/user")
|
||||
{
|
||||
userRouterGroup.POST("/get_user_id_by_email_phone", user.GetUserIDByEmailAndPhoneNumber)
|
||||
}
|
||||
messageCMSRouterGroup := r2.Group("/message")
|
||||
{
|
||||
messageCMSRouterGroup.POST("/get_chat_logs", messageCMS.GetChatLogs)
|
||||
}
|
||||
friendCMSRouterGroup := r2.Group("/friend")
|
||||
{
|
||||
friendCMSRouterGroup.POST("/get_friends", friend.GetUserFriends)
|
||||
}
|
||||
|
||||
return baseRouter
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
admin "Open_IM/pkg/proto/admin_cms"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetMessagesStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetMessageStatisticsRequest
|
||||
resp cms_struct.GetMessageStatisticsResponse
|
||||
reqPb admin.GetMessageStatisticsReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
utils.CopyStructFields(&reqPb.StatisticsReq, &req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := admin.NewAdminCMSClient(etcdConn)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
|
||||
defer cancel()
|
||||
respPb, err := client.GetMessageStatistics(ctx, &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetMessageStatistics failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp.GroupMessageNum = int(respPb.GroupMessageNum)
|
||||
resp.PrivateMessageNum = int(respPb.PrivateMessageNum)
|
||||
for _, v := range respPb.PrivateMessageNumList {
|
||||
resp.PrivateMessageNumList = append(resp.PrivateMessageNumList, struct {
|
||||
Date string "json:\"date\""
|
||||
MessageNum int "json:\"messageNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
MessageNum: int(v.Num),
|
||||
})
|
||||
}
|
||||
for _, v := range respPb.GroupMessageNumList {
|
||||
resp.GroupMessageNumList = append(resp.GroupMessageNumList, struct {
|
||||
Date string "json:\"date\""
|
||||
MessageNum int "json:\"messageNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
MessageNum: int(v.Num),
|
||||
})
|
||||
}
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
func GetUserStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetUserStatisticsRequest
|
||||
resp cms_struct.GetUserStatisticsResponse
|
||||
reqPb admin.GetUserStatisticsReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
utils.CopyStructFields(&reqPb.StatisticsReq, &req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := admin.NewAdminCMSClient(etcdConn)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
|
||||
defer cancel()
|
||||
respPb, err := client.GetUserStatistics(ctx, &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserStatistics failed", err.Error(), reqPb.String())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ActiveUserNum = int(respPb.ActiveUserNum)
|
||||
resp.IncreaseUserNum = int(respPb.IncreaseUserNum)
|
||||
resp.TotalUserNum = int(respPb.TotalUserNum)
|
||||
for _, v := range respPb.ActiveUserNumList {
|
||||
resp.ActiveUserNumList = append(resp.ActiveUserNumList, struct {
|
||||
Date string "json:\"date\""
|
||||
ActiveUserNum int "json:\"activeUserNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
ActiveUserNum: int(v.Num),
|
||||
})
|
||||
}
|
||||
for _, v := range respPb.IncreaseUserNumList {
|
||||
resp.IncreaseUserNumList = append(resp.IncreaseUserNumList, struct {
|
||||
Date string "json:\"date\""
|
||||
IncreaseUserNum int "json:\"increaseUserNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
IncreaseUserNum: int(v.Num),
|
||||
})
|
||||
}
|
||||
for _, v := range respPb.TotalUserNumList {
|
||||
resp.TotalUserNumList = append(resp.TotalUserNumList, struct {
|
||||
Date string "json:\"date\""
|
||||
TotalUserNum int "json:\"totalUserNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
TotalUserNum: int(v.Num),
|
||||
})
|
||||
}
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
func GetGroupStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetGroupStatisticsRequest
|
||||
resp cms_struct.GetGroupStatisticsResponse
|
||||
reqPb admin.GetGroupStatisticsReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
utils.CopyStructFields(&reqPb.StatisticsReq, &req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := admin.NewAdminCMSClient(etcdConn)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
|
||||
defer cancel()
|
||||
respPb, err := client.GetGroupStatistics(ctx, &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
// utils.CopyStructFields(&resp, respPb)
|
||||
resp.IncreaseGroupNum = int(respPb.GetIncreaseGroupNum())
|
||||
resp.TotalGroupNum = int(respPb.GetTotalGroupNum())
|
||||
for _, v := range respPb.IncreaseGroupNumList {
|
||||
resp.IncreaseGroupNumList = append(resp.IncreaseGroupNumList,
|
||||
struct {
|
||||
Date string "json:\"date\""
|
||||
IncreaseGroupNum int "json:\"increaseGroupNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
IncreaseGroupNum: int(v.Num),
|
||||
})
|
||||
}
|
||||
for _, v := range respPb.TotalGroupNumList {
|
||||
resp.TotalGroupNumList = append(resp.TotalGroupNumList,
|
||||
struct {
|
||||
Date string "json:\"date\""
|
||||
TotalGroupNum int "json:\"totalGroupNum\""
|
||||
}{
|
||||
Date: v.Date,
|
||||
TotalGroupNum: int(v.Num),
|
||||
})
|
||||
|
||||
}
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
func GetActiveUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetActiveUserRequest
|
||||
resp cms_struct.GetActiveUserResponse
|
||||
reqPb admin.GetActiveUserReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
utils.CopyStructFields(&reqPb.StatisticsReq, req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := admin.NewAdminCMSClient(etcdConn)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
|
||||
defer cancel()
|
||||
respPb, err := client.GetActiveUser(ctx, &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveUser failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&resp.ActiveUserList, respPb.Users)
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
func GetActiveGroup(c *gin.Context) {
|
||||
var (
|
||||
req cms_struct.GetActiveGroupRequest
|
||||
resp cms_struct.GetActiveGroupResponse
|
||||
reqPb admin.GetActiveGroupReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = utils.OperationIDGenerator()
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
utils.CopyStructFields(&reqPb.StatisticsReq, req)
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := admin.NewAdminCMSClient(etcdConn)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*100)
|
||||
defer cancel()
|
||||
respPb, err := client.GetActiveGroup(ctx, &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveGroup failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
for _, group := range respPb.Groups {
|
||||
resp.ActiveGroupList = append(resp.ActiveGroupList, struct {
|
||||
GroupName string "json:\"groupName\""
|
||||
GroupId string "json:\"groupID\""
|
||||
MessageNum int "json:\"messageNum\""
|
||||
}{
|
||||
GroupName: group.GroupName,
|
||||
GroupId: group.GroupId,
|
||||
MessageNum: int(group.MessageNum),
|
||||
})
|
||||
}
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/cms_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbAdminCms "Open_IM/pkg/proto/admin_cms"
|
||||
common "Open_IM/pkg/proto/sdkws"
|
||||
pb "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetUserIDByEmailAndPhoneNumber(c *gin.Context) {
|
||||
var (
|
||||
req cmsstruct.GetUserIDByEmailAndPhoneNumberRequest
|
||||
resp cmsstruct.GetUserIDByEmailAndPhoneNumberResponse
|
||||
reqPb pbAdminCms.GetUserIDByEmailAndPhoneNumberReq
|
||||
respPb *pbAdminCms.GetUserIDByEmailAndPhoneNumberResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Email = req.Email
|
||||
reqPb.PhoneNumber = req.PhoneNumber
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdminCms.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.GetUserIDByEmailAndPhoneNumber(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.UserIDList = respPb.UserIDList
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -1,541 +0,0 @@
|
||||
package admincms
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/controller"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/proto/admincms"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
|
||||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type adminCMSServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
adminCMSInterface controller.AdminCMSInterface
|
||||
groupInterface controller.GroupInterface
|
||||
userInterface controller.UserInterface
|
||||
chatLogInterface controller.ChatLogInterface
|
||||
|
||||
AuthInterface controller.AuthController
|
||||
}
|
||||
|
||||
func NewAdminCMSServer(port int) *adminCMSServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
admin := &adminCMSServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
||||
etcdSchema: config.Config.Zookeeper.Schema,
|
||||
etcdAddr: config.Config.Zookeeper.ZkAddr,
|
||||
}
|
||||
var mysql relation.Mysql
|
||||
var redis cache.RedisClient
|
||||
mysql.InitConn()
|
||||
redis.InitRedis()
|
||||
admin.userInterface = controller.NewUserController(mysql.GormConn())
|
||||
admin.groupInterface = controller.NewGroupInterface(mysql.GormConn(), redis.GetClient(), nil)
|
||||
admin.adminCMSInterface = controller.NewAdminCMSController(mysql.GormConn())
|
||||
admin.chatLogInterface = controller.NewChatLogController(mysql.GormConn())
|
||||
return admin
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) Run() {
|
||||
log.NewInfo("0", "AdminCMS rpc start ")
|
||||
listenIP := ""
|
||||
if config.Config.ListenIP == "" {
|
||||
listenIP = "0.0.0.0"
|
||||
} else {
|
||||
listenIP = config.Config.ListenIP
|
||||
}
|
||||
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", address, listener)
|
||||
defer listener.Close()
|
||||
var grpcOpts []grpc.ServerOption
|
||||
if config.Config.Prometheus.Enable {
|
||||
promePkg.NewGrpcRequestCounter()
|
||||
promePkg.NewGrpcRequestFailedCounter()
|
||||
promePkg.NewGrpcRequestSuccessCounter()
|
||||
grpcOpts = append(grpcOpts, []grpc.ServerOption{
|
||||
// grpc.UnaryInterceptor(promePkg.UnaryServerInterceptorProme),
|
||||
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
|
||||
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
|
||||
}...)
|
||||
}
|
||||
srv := grpc.NewServer(grpcOpts...)
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
admincms.RegisterAdminCMSServer(srv, s)
|
||||
zkClient, err := openKeeper.NewClient(config.Config)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "message cms rpc success")
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) AdminLogin(ctx context.Context, req *admincms.AdminLoginReq) (*admincms.AdminLoginResp, error) {
|
||||
resp := &admincms.AdminLoginResp{}
|
||||
for i, adminID := range config.Config.Manager.AppManagerUid {
|
||||
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
||||
token, err := s.AuthInterface.CreateToken(ctx, adminID, constant.LinuxPlatformID)
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
log.NewInfo(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||
resp.Token = token
|
||||
break
|
||||
}
|
||||
}
|
||||
if resp.Token == "" {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "failed")
|
||||
return nil, constant.ErrInternalServer
|
||||
}
|
||||
admin, err := s.userInterface.Take(ctx, req.AdminID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.UserName = admin.Nickname
|
||||
resp.FaceURL = admin.FaceURL
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetUserToken(ctx context.Context, req *pbAdminCMS.GetUserTokenReq) (*pbAdminCMS.GetUserTokenResp, error) {
|
||||
token, expTime, err := tokenverify.CreateToken(req.UserID, int(req.PlatformID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbAdminCMS.GetUserTokenResp{Token: token, ExpTime: expTime}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetChatLogs(ctx context.Context, req *pbAdminCMS.GetChatLogsReq) (*pbAdminCMS.GetChatLogsResp, error) {
|
||||
chatLog := relationTb.ChatLog{
|
||||
Content: req.Content,
|
||||
ContentType: req.ContentType,
|
||||
SessionType: req.SessionType,
|
||||
RecvID: req.RecvID,
|
||||
SendID: req.SendID,
|
||||
}
|
||||
if req.SendTime != "" {
|
||||
sendTime, err := utils.TimeStringToTime(req.SendTime)
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "time string parse error", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
chatLog.SendTime = sendTime
|
||||
}
|
||||
num, chatLogs, err := s.chatLogInterface.GetChatLog(&chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber, []int32{
|
||||
constant.Text,
|
||||
constant.Picture,
|
||||
constant.Voice,
|
||||
constant.Video,
|
||||
constant.File,
|
||||
constant.AtText,
|
||||
constant.Merger,
|
||||
constant.Card,
|
||||
constant.Location,
|
||||
constant.Custom,
|
||||
constant.Revoke,
|
||||
constant.Quote,
|
||||
constant.AdvancedText,
|
||||
constant.AdvancedRevoke,
|
||||
constant.CustomNotTriggerConversation,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbAdminCMS.GetChatLogsResp{}
|
||||
resp.ChatLogsNum = int32(num)
|
||||
for _, chatLog := range chatLogs {
|
||||
pbChatLog := &pbAdminCMS.ChatLog{}
|
||||
utils.CopyStructFields(pbChatLog, chatLog)
|
||||
pbChatLog.SendTime = chatLog.SendTime.Unix()
|
||||
pbChatLog.CreateTime = chatLog.CreateTime.Unix()
|
||||
if chatLog.SenderNickname == "" {
|
||||
sendUser, err := s.userInterface.Take(ctx, chatLog.SendID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbChatLog.SenderNickname = sendUser.Nickname
|
||||
}
|
||||
switch chatLog.SessionType {
|
||||
case constant.SingleChatType:
|
||||
recvUser, err := s.userInterface.Take(ctx, chatLog.RecvID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbChatLog.SenderNickname = recvUser.Nickname
|
||||
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
group, err := s.groupInterface.TakeGroup(ctx, chatLog.RecvID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbChatLog.RecvID = group.GroupID
|
||||
pbChatLog.GroupName = group.GroupName
|
||||
}
|
||||
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetActiveGroup(_ context.Context, req *pbAdminCMS.GetActiveGroupReq) (*pbAdminCMS.GetActiveGroupResp, error) {
|
||||
resp := &pbAdminCMS.GetActiveGroupResp{}
|
||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
activeGroups, err := s.adminCMSInterface.GetActiveGroups(fromTime, toTime, 12)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, activeGroup := range activeGroups {
|
||||
resp.Groups = append(resp.Groups,
|
||||
&pbAdminCMS.GroupResp{
|
||||
GroupName: activeGroup.Name,
|
||||
GroupID: activeGroup.ID,
|
||||
MessageNum: int32(activeGroup.MessageNum),
|
||||
})
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetActiveUser(ctx context.Context, req *pbAdminCMS.GetActiveUserReq) (*pbAdminCMS.GetActiveUserResp, error) {
|
||||
resp := &pbAdminCMS.GetActiveUserResp{}
|
||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
activeUsers, err := s.adminCMSInterface.GetActiveUsers(fromTime, toTime, 12)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, activeUser := range activeUsers {
|
||||
resp.Users = append(resp.Users,
|
||||
&pbAdminCMS.UserResp{
|
||||
UserID: activeUser.ID,
|
||||
NickName: activeUser.Name,
|
||||
MessageNum: int32(activeUser.MessageNum),
|
||||
},
|
||||
)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func ParseTimeFromTo(from, to string) (time.Time, time.Time, error) {
|
||||
var fromTime time.Time
|
||||
var toTime time.Time
|
||||
fromTime, err := utils.TimeStringToTime(from)
|
||||
if err != nil {
|
||||
return fromTime, toTime, err
|
||||
}
|
||||
toTime, err = utils.TimeStringToTime(to)
|
||||
if err != nil {
|
||||
return fromTime, toTime, err
|
||||
}
|
||||
return fromTime, toTime, nil
|
||||
}
|
||||
|
||||
func isInOneMonth(from, to time.Time) bool {
|
||||
return from.Month() == to.Month() && from.Year() == to.Year()
|
||||
}
|
||||
|
||||
func GetRangeDate(from, to time.Time) [][2]time.Time {
|
||||
interval := to.Sub(from)
|
||||
var times [][2]time.Time
|
||||
switch {
|
||||
// today
|
||||
case interval == 0:
|
||||
times = append(times, [2]time.Time{
|
||||
from, from.Add(time.Hour * 24),
|
||||
})
|
||||
// days
|
||||
case isInOneMonth(from, to):
|
||||
for i := 0; ; i++ {
|
||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
||||
if toTime.After(to.Add(time.Hour * 24)) {
|
||||
break
|
||||
}
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
}
|
||||
// month
|
||||
case !isInOneMonth(from, to):
|
||||
if to.Sub(from) < time.Hour*24*30 {
|
||||
for i := 0; ; i++ {
|
||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
||||
if toTime.After(to.Add(time.Hour * 24)) {
|
||||
break
|
||||
}
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
for i := 0; ; i++ {
|
||||
if i == 0 {
|
||||
fromTime := from
|
||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
} else {
|
||||
fromTime := getFirstDateOfNextNMonth(from, i)
|
||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
||||
if toTime.After(to) {
|
||||
toTime = to
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
break
|
||||
}
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return times
|
||||
}
|
||||
|
||||
func getFirstDateOfNextNMonth(currentTime time.Time, n int) time.Time {
|
||||
lastOfMonth := time.Date(currentTime.Year(), currentTime.Month(), 1, 0, 0, 0, 0, currentTime.Location()).AddDate(0, n, 0)
|
||||
return lastOfMonth
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetGroupStatistics(ctx context.Context, req *pbAdminCMS.GetGroupStatisticsReq) (*pbAdminCMS.GetGroupStatisticsResp, error) {
|
||||
resp := &pbAdminCMS.GetGroupStatisticsResp{}
|
||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
increaseGroupNum, err := s.adminCMSInterface.GetIncreaseGroupNum(fromTime, toTime.Add(time.Hour*24))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
totalGroupNum, err := s.adminCMSInterface.GetTotalGroupNum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.IncreaseGroupNum = int32(increaseGroupNum)
|
||||
resp.TotalGroupNum = int32(totalGroupNum)
|
||||
times := GetRangeDate(fromTime, toTime)
|
||||
wg := &sync.WaitGroup{}
|
||||
resp.IncreaseGroupNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
resp.TotalGroupNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
wg.Add(len(times))
|
||||
for i, v := range times {
|
||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
||||
defer wg.Done()
|
||||
num, err := s.adminCMSInterface.GetIncreaseGroupNum(v[0], v[1])
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.IncreaseGroupNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
num, err = s.adminCMSInterface.GetGroupNum(v[1])
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.TotalGroupNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
}(wg, i, v)
|
||||
}
|
||||
wg.Wait()
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetMessageStatistics(ctx context.Context, req *pbAdminCMS.GetMessageStatisticsReq) (*pbAdminCMS.GetMessageStatisticsResp, error) {
|
||||
resp := &pbAdminCMS.GetMessageStatisticsResp{}
|
||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
||||
log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "times: ", fromTime, toTime)
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
privateMessageNum, err := s.adminCMSInterface.GetSingleChatMessageNum(fromTime, toTime.Add(time.Hour*24))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupMessageNum, err := s.adminCMSInterface.GetGroupMessageNum(fromTime, toTime.Add(time.Hour*24))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), privateMessageNum, groupMessageNum)
|
||||
resp.PrivateMessageNum = int32(privateMessageNum)
|
||||
resp.GroupMessageNum = int32(groupMessageNum)
|
||||
times := GetRangeDate(fromTime, toTime)
|
||||
resp.GroupMessageNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
resp.PrivateMessageNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(len(times))
|
||||
for i, v := range times {
|
||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
||||
defer wg.Done()
|
||||
num, err := s.adminCMSInterface.GetSingleChatMessageNum(v[0], v[1])
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.PrivateMessageNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
num, err = s.adminCMSInterface.GetGroupMessageNum(v[0], v[1])
|
||||
if err != nil {
|
||||
log.NewError(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.GroupMessageNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
}(wg, i, v)
|
||||
}
|
||||
wg.Wait()
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetUserStatistics(_ context.Context, req *pbAdminCMS.GetUserStatisticsReq) (*pbAdminCMS.GetUserStatisticsResp, error) {
|
||||
resp := &pbAdminCMS.GetUserStatisticsResp{}
|
||||
fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
activeUserNum, err := s.adminCMSInterface.GetActiveUserNum(fromTime, toTime.Add(time.Hour*24))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
increaseUserNum, err := s.adminCMSInterface.GetIncreaseUserNum(fromTime, toTime.Add(time.Hour*24))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
totalUserNum, err := s.adminCMSInterface.GetTotalUserNum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.ActiveUserNum = int32(activeUserNum)
|
||||
resp.TotalUserNum = int32(totalUserNum)
|
||||
resp.IncreaseUserNum = int32(increaseUserNum)
|
||||
times := GetRangeDate(fromTime, toTime)
|
||||
resp.TotalUserNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
resp.ActiveUserNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
resp.IncreaseUserNumList = make([]*pbAdminCMS.DateNumList, len(times), len(times))
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(len(times))
|
||||
for i, v := range times {
|
||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
||||
defer wg.Done()
|
||||
num, err := s.adminCMSInterface.GetActiveUserNum(v[0], v[1])
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.ActiveUserNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
|
||||
num, err = s.adminCMSInterface.GetTotalUserNumByDate(v[1])
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNumByDate", v, err.Error())
|
||||
}
|
||||
resp.TotalUserNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
num, err = s.adminCMSInterface.GetIncreaseUserNum(v[0], v[1])
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseUserNum", v, err.Error())
|
||||
}
|
||||
resp.IncreaseUserNumList[index] = &pbAdminCMS.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Num: int32(num),
|
||||
}
|
||||
}(wg, i, v)
|
||||
}
|
||||
wg.Wait()
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetUserFriends(ctx context.Context, req *pbAdminCMS.GetUserFriendsReq) (*pbAdminCMS.GetUserFriendsResp, error) {
|
||||
resp := &pbAdminCMS.GetUserFriendsResp{}
|
||||
var friendList []*relation.FriendUser
|
||||
var err error
|
||||
if req.FriendUserID != "" {
|
||||
friend, err := s.adminCMSInterface.GetFriendByIDCMS(req.UserID, req.FriendUserID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
friendList = append(friendList, friend)
|
||||
resp.FriendNums = 1
|
||||
} else {
|
||||
var count int64
|
||||
friendList, count, err = s.adminCMSInterface.GetUserFriendsCMS(req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.FriendNums = int32(count)
|
||||
}
|
||||
for _, v := range friendList {
|
||||
friendInfo := &common.FriendInfo{}
|
||||
userInfo := &common.UserInfo{UserID: v.FriendUserID, Nickname: v.Nickname}
|
||||
utils.CopyStructFields(friendInfo, v)
|
||||
friendInfo.FriendUser = userInfo
|
||||
resp.FriendInfoList = append(resp.FriendInfoList, friendInfo)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetUserIDByEmailAndPhoneNumber(ctx context.Context, req *pbAdminCMS.GetUserIDByEmailAndPhoneNumberReq) (*pbAdminCMS.GetUserIDByEmailAndPhoneNumberResp, error) {
|
||||
resp := &pbAdminCMS.GetUserIDByEmailAndPhoneNumberResp{}
|
||||
userIDList, err := s.userInterface.GetUserIDsByEmailAndID(req.PhoneNumber, req.Email)
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
resp.UserIDList = userIDList
|
||||
return resp, nil
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func TagSendMessage(operationID string, user *im_mysql_model.User, recvID, content string, senderPlatformID int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", user.UserID, recvID, content)
|
||||
var req pbChat.SendMsgReq
|
||||
var msgData pbCommon.MsgData
|
||||
msgData.SendID = user.UserID
|
||||
msgData.RecvID = recvID
|
||||
msgData.ContentType = constant.Custom
|
||||
msgData.SessionType = constant.SingleChatType
|
||||
msgData.MsgFrom = constant.UserMsgType
|
||||
msgData.Content = []byte(content)
|
||||
msgData.SenderFaceURL = user.FaceURL
|
||||
msgData.SenderNickname = user.Nickname
|
||||
msgData.Options = map[string]bool{}
|
||||
msgData.Options[constant.IsSenderConversationUpdate] = false
|
||||
msgData.Options[constant.IsSenderNotificationPush] = false
|
||||
msgData.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
|
||||
msgData.SenderPlatformID = senderPlatformID
|
||||
req.MsgData = &msgData
|
||||
req.OperationID = operationID
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, operationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return
|
||||
}
|
||||
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
respPb, err := client.SendMsg(context.Background(), &req)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send msg failed", err.Error())
|
||||
return
|
||||
}
|
||||
if respPb.ErrCode != 0 {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send tag msg failed ", respPb)
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
sdk "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func WorkMomentSendNotification(operationID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), recvID, notificationMsg)
|
||||
WorkMomentNotification(operationID, recvID, recvID, notificationMsg)
|
||||
}
|
||||
|
||||
func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message) {
|
||||
var tips sdk.TipsComm
|
||||
var err error
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
n := &NotificationMsg{
|
||||
SendID: sendID,
|
||||
RecvID: recvID,
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.WorkMomentNotification,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: operationID,
|
||||
}
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "proto.Marshal failed")
|
||||
return
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), string(n.Content))
|
||||
Notification(n)
|
||||
}
|
@ -1,734 +0,0 @@
|
||||
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/db/mongo"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/getcdv3"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type officeServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
ch chan tagSendStruct
|
||||
}
|
||||
|
||||
func NewOfficeServer(port int) *officeServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
ch := make(chan tagSendStruct, 100000)
|
||||
return &officeServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfficeName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
ch: ch,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *officeServer) Run() {
|
||||
log.NewInfo("0", "officeServer rpc start ")
|
||||
listenIP := ""
|
||||
if config.Config.ListenIP == "" {
|
||||
listenIP = "0.0.0.0"
|
||||
} else {
|
||||
listenIP = config.Config.ListenIP
|
||||
}
|
||||
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", address, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
recvSize := 1024 * 1024 * 30
|
||||
sendSize := 1024 * 1024 * 30
|
||||
var grpcOpts = []grpc.ServerOption{
|
||||
grpc.MaxRecvMsgSize(recvSize),
|
||||
grpc.MaxSendMsgSize(sendSize),
|
||||
}
|
||||
if config.Config.Prometheus.Enable {
|
||||
promePkg.NewGrpcRequestCounter()
|
||||
promePkg.NewGrpcRequestFailedCounter()
|
||||
promePkg.NewGrpcRequestSuccessCounter()
|
||||
grpcOpts = append(grpcOpts, []grpc.ServerOption{
|
||||
// grpc.UnaryInterceptor(promePkg.UnaryServerInterceptorProme),
|
||||
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
|
||||
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
|
||||
}...)
|
||||
}
|
||||
srv := grpc.NewServer(grpcOpts...)
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbOffice.RegisterOfficeServiceServer(srv, s)
|
||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
||||
if config.Config.RpcRegisterIP == "" {
|
||||
rpcRegisterIP, err = utils.GetLocalIP()
|
||||
if err != nil {
|
||||
log.Error("", "GetLocalIP failed ", err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
panic(utils.Wrap(err, "register office module rpc to etcd err"))
|
||||
}
|
||||
go s.sendTagMsgRoutine()
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "message cms rpc success")
|
||||
}
|
||||
|
||||
type tagSendStruct struct {
|
||||
operationID string
|
||||
user *imdb.User
|
||||
userID string
|
||||
content string
|
||||
senderPlatformID int32
|
||||
}
|
||||
|
||||
func (s *officeServer) sendTagMsgRoutine() {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "start")
|
||||
for {
|
||||
select {
|
||||
case v := <-s.ch:
|
||||
msg.TagSendMessage(v.operationID, v.user, v.userID, v.content, v.senderPlatformID)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "tags: ", tags)
|
||||
for _, v := range tags {
|
||||
tag := &pbOffice.Tag{
|
||||
TagID: v.TagID,
|
||||
TagName: v.TagName,
|
||||
}
|
||||
for _, userID := range v.UserList {
|
||||
UserName, err := im_mysql_model.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
tag.UserList = append(tag.UserList, &pbOffice.TagUser{
|
||||
UserID: userID,
|
||||
UserName: UserName,
|
||||
})
|
||||
}
|
||||
resp.Tags = append(resp.Tags, tag)
|
||||
}
|
||||
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())
|
||||
userIDList := utils.RemoveRepeatedStringInList(req.UserIDList)
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
||||
resp = &pbOffice.CreateTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.CreateTag(req.UserID, req.TagName, 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{}}
|
||||
increaseUserIDList := utils.RemoveRepeatedStringInList(req.IncreaseUserIDList)
|
||||
reduceUserIDList := utils.RemoveRepeatedStringInList(req.ReduceUserIDList)
|
||||
if err := db.DB.SetTag(req.UserID, req.TagID, req.NewName, increaseUserIDList, reduceUserIDList); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetTag failed", increaseUserIDList, reduceUserIDList, 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) 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{}}
|
||||
var tagUserIDList []string
|
||||
for _, tagID := range req.TagList {
|
||||
userIDList, err := db.DB.GetUserIDListByTagID(req.SendID, tagID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserIDListByTagID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
tagUserIDList = append(tagUserIDList, userIDList...)
|
||||
}
|
||||
var groupUserIDList []string
|
||||
for _, groupID := range req.GroupList {
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
resp.CommonResp.ErrCode = constant.ErrInternal.ErrCode
|
||||
resp.CommonResp.ErrMsg = errMsg
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
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, "GetGroupMemberIDListFromCache rpc call failed ", err.Error(), req.String())
|
||||
resp.CommonResp.ErrCode = constant.ErrServer.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
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
|
||||
userIDList = append(userIDList, tagUserIDList...)
|
||||
userIDList = append(userIDList, groupUserIDList...)
|
||||
userIDList = append(userIDList, req.UserList...)
|
||||
userIDList = utils.RemoveRepeatedStringInList(userIDList)
|
||||
for i, userID := range userIDList {
|
||||
if userID == req.SendID || userID == "" {
|
||||
userIDList = append(userIDList[:i], userIDList[i+1:]...)
|
||||
}
|
||||
}
|
||||
if unsafe.Sizeof(userIDList) > 1024*1024 {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "size", unsafe.Sizeof(userIDList))
|
||||
resp.CommonResp.ErrMsg = constant.ErrSendLimit.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrSendLimit.ErrCode
|
||||
return
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "total userIDList result: ", userIDList)
|
||||
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 successUserIDList []string
|
||||
for _, userID := range userIDList {
|
||||
t := tagSendStruct{
|
||||
operationID: req.OperationID,
|
||||
user: user,
|
||||
userID: userID,
|
||||
content: req.Content,
|
||||
senderPlatformID: req.SenderPlatformID,
|
||||
}
|
||||
select {
|
||||
case s.ch <- t:
|
||||
log.NewDebug(t.operationID, utils.GetSelfFuncName(), "msg: ", t, "send success")
|
||||
successUserIDList = append(successUserIDList, userID)
|
||||
// if channel is full, return grpc req
|
||||
case <-time.After(1 * time.Second):
|
||||
log.NewError(t.operationID, utils.GetSelfFuncName(), s.ch, "channel is full")
|
||||
resp.CommonResp.ErrCode = constant.ErrSendLimit.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrSendLimit.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
var tagSendLogs mongoDB.TagSendLog
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(successUserIDList))
|
||||
var lock sync.Mutex
|
||||
for _, userID := range successUserIDList {
|
||||
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(), userID)
|
||||
return
|
||||
}
|
||||
lock.Lock()
|
||||
tagSendLogs.UserList = append(tagSendLogs.UserList, mongoDB.TagUser{
|
||||
UserID: userID,
|
||||
UserName: userName,
|
||||
})
|
||||
lock.Unlock()
|
||||
}(userID)
|
||||
}
|
||||
wg.Wait()
|
||||
tagSendLogs.SendID = req.SendID
|
||||
tagSendLogs.Content = req.Content
|
||||
tagSendLogs.SenderPlatformID = req.SenderPlatformID
|
||||
tagSendLogs.SendTime = time.Now().Unix()
|
||||
if err := db.DB.SaveTagSendLog(&tagSendLogs); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SaveTagSendLog failed", tagSendLogs, err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
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{},
|
||||
Pagination: &pbCommon.ResponsePagination{
|
||||
CurrentPage: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
},
|
||||
TagSendLogs: []*pbOffice.TagSendLog{},
|
||||
}
|
||||
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
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.TagSendLogs, tagSendLogs); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserTagByID(_ context.Context, req *pbOffice.GetUserTagByIDReq) (resp *pbOffice.GetUserTagByIDResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetUserTagByIDResp{
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
Tag: &pbOffice.Tag{},
|
||||
}
|
||||
tag, err := db.DB.GetTagByID(req.UserID, req.TagID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTagByID failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
for _, userID := range tag.UserList {
|
||||
userName, err := im_mysql_model.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
resp.Tag.UserList = append(resp.Tag.UserList, &pbOffice.TagUser{
|
||||
UserID: userID,
|
||||
UserName: userName,
|
||||
})
|
||||
}
|
||||
resp.Tag.TagID = tag.TagID
|
||||
resp.Tag.TagName = tag.TagName
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.CreateOneWorkMomentReq) (resp *pbOffice.CreateOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.CreateOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
workMoment := mongoDB.WorkMoment{
|
||||
Comments: []*mongoDB.Comment{},
|
||||
LikeUserList: []*mongoDB.WorkMomentUser{},
|
||||
PermissionUserList: []*mongoDB.WorkMomentUser{},
|
||||
}
|
||||
createUser, err := imdb.GetUserByUserID(req.WorkMoment.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&workMoment, req.WorkMoment); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
workMoment.UserName = createUser.Nickname
|
||||
workMoment.FaceURL = createUser.FaceURL
|
||||
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
|
||||
workMoment.PermissionUserList = []*mongoDB.WorkMomentUser{}
|
||||
for _, userID := range workMoment.PermissionUserIDList {
|
||||
userName, err := imdb.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
workMoment.PermissionUserList = append(workMoment.PermissionUserList, &mongoDB.WorkMomentUser{
|
||||
UserID: userID,
|
||||
UserName: userName,
|
||||
})
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
|
||||
err = db.DB.CreateOneWorkMoment(&workMoment)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CreateOneWorkMoment", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// send notification to at users
|
||||
for _, atUser := range req.WorkMoment.AtUserList {
|
||||
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
|
||||
NotificationMsgType: constant.WorkMomentAtUserNotification,
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: workMoment.UserID,
|
||||
FaceURL: createUser.FaceURL,
|
||||
UserName: createUser.Nickname,
|
||||
CreateTime: workMoment.CreateTime,
|
||||
}
|
||||
msg.WorkMomentSendNotification(req.OperationID, atUser.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) DeleteComment(_ context.Context, req *pbOffice.DeleteCommentReq) (resp *pbOffice.DeleteCommentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.DeleteCommentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
err = db.DB.DeleteComment(req.WorkMomentID, req.ContentID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetWorkMomentByID 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
|
||||
}
|
||||
|
||||
// count and distinct permission users
|
||||
func (s *officeServer) getPermissionUserIDList(operationID string, groupList []*pbOffice.PermissionGroup, userList []*pbOffice.WorkMomentUser) []string {
|
||||
var permissionUserIDList []string
|
||||
for _, group := range groupList {
|
||||
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(group.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", group, err.Error())
|
||||
continue
|
||||
}
|
||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "groupMemberIDList: ", groupMemberIDList)
|
||||
permissionUserIDList = append(permissionUserIDList, groupMemberIDList...)
|
||||
}
|
||||
var userIDList []string
|
||||
for _, user := range userList {
|
||||
userIDList = append(userIDList, user.UserID)
|
||||
}
|
||||
permissionUserIDList = append(permissionUserIDList, userIDList...)
|
||||
permissionUserIDList = utils.RemoveRepeatedStringInList(permissionUserIDList)
|
||||
return permissionUserIDList
|
||||
}
|
||||
|
||||
func (s *officeServer) DeleteOneWorkMoment(_ context.Context, req *pbOffice.DeleteOneWorkMomentReq) (resp *pbOffice.DeleteOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.DeleteOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
workMoment, err := db.DB.GetWorkMomentByID(req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetWorkMomentByID failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment", workMoment)
|
||||
if workMoment.UserID != req.UserID {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoment.UserID != req.WorkMomentID, delete failed", workMoment, req.WorkMomentID)
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
err = db.DB.DeleteOneWorkMoment(req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteOneWorkMoment", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func isUserCanSeeWorkMoment(userID string, workMoment mongoDB.WorkMoment) bool {
|
||||
if userID != workMoment.UserID {
|
||||
switch workMoment.Permission {
|
||||
case constant.WorkMomentPublic:
|
||||
return true
|
||||
case constant.WorkMomentPrivate:
|
||||
return false
|
||||
case constant.WorkMomentPermissionCanSee:
|
||||
return utils.IsContain(userID, workMoment.PermissionUserIDList)
|
||||
case constant.WorkMomentPermissionCantSee:
|
||||
return !utils.IsContain(userID, workMoment.PermissionUserIDList)
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOneWorkMomentReq) (resp *pbOffice.LikeOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.LikeOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
user, err := imdb.GetUserByUserID(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
workMoment, like, err := db.DB.LikeOneWorkMoment(req.UserID, user.Nickname, req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
|
||||
NotificationMsgType: constant.WorkMomentLikeNotification,
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: user.UserID,
|
||||
FaceURL: user.FaceURL,
|
||||
UserName: user.Nickname,
|
||||
CreateTime: int32(time.Now().Unix()),
|
||||
}
|
||||
// send notification
|
||||
if like && workMoment.UserID != req.UserID {
|
||||
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.CommentOneWorkMomentReq) (resp *pbOffice.CommentOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.CommentOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
commentUser, err := imdb.GetUserByUserID(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID commentUserName failed", req.UserID, err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
var replyUserName string
|
||||
if req.ReplyUserID != "" {
|
||||
replyUserName, err = imdb.GetUserNameByUserID(req.ReplyUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID get replyUserName failed", req.ReplyUserID, err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
comment := &mongoDB.Comment{
|
||||
UserID: req.UserID,
|
||||
UserName: commentUser.Nickname,
|
||||
ReplyUserID: req.ReplyUserID,
|
||||
ReplyUserName: replyUserName,
|
||||
Content: req.Content,
|
||||
CreateTime: int32(time.Now().Unix()),
|
||||
}
|
||||
workMoment, err := db.DB.CommentOneWorkMoment(comment, req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CommentOneWorkMoment failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
|
||||
NotificationMsgType: constant.WorkMomentCommentNotification,
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: commentUser.UserID,
|
||||
FaceURL: commentUser.FaceURL,
|
||||
UserName: commentUser.Nickname,
|
||||
ReplyUserID: comment.ReplyUserID,
|
||||
ReplyUserName: comment.ReplyUserName,
|
||||
ContentID: comment.ContentID,
|
||||
Content: comment.Content,
|
||||
CreateTime: comment.CreateTime,
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "msg: ", *workMomentNotificationMsg)
|
||||
if req.UserID != workMoment.UserID {
|
||||
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
if req.ReplyUserID != "" && req.ReplyUserID != workMoment.UserID && req.ReplyUserID != req.UserID {
|
||||
msg.WorkMomentSendNotification(req.OperationID, req.ReplyUserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetWorkMomentByID(_ context.Context, req *pbOffice.GetWorkMomentByIDReq) (resp *pbOffice.GetWorkMomentByIDResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetWorkMomentByIDResp{
|
||||
WorkMoment: &pbOffice.WorkMoment{},
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
}
|
||||
workMoment, err := db.DB.GetWorkMomentByID(req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetWorkMomentByID failed", err.Error())
|
||||
return resp, nil
|
||||
}
|
||||
canSee := isUserCanSeeWorkMoment(req.OpUserID, *workMoment)
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), canSee, req.OpUserID, *workMoment)
|
||||
if !canSee {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoments not access to user", canSee, workMoment, req.OpUserID)
|
||||
}
|
||||
|
||||
if err := utils.CopyStructFields(resp.WorkMoment, workMoment); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
user, err := imdb.GetUserByUserID(workMoment.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID failed", err.Error())
|
||||
}
|
||||
if user != nil {
|
||||
resp.WorkMoment.FaceURL = user.FaceURL
|
||||
resp.WorkMoment.UserName = user.Nickname
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserWorkMoments(_ context.Context, req *pbOffice.GetUserWorkMomentsReq) (resp *pbOffice.GetUserWorkMomentsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetUserWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
|
||||
resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}
|
||||
var workMoments []mongoDB.WorkMoment
|
||||
if req.UserID == req.OpUserID {
|
||||
workMoments, err = db.DB.GetUserSelfWorkMoments(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
} else {
|
||||
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}
|
||||
return resp, nil
|
||||
}
|
||||
workMoments, err = db.DB.GetUserWorkMoments(req.OpUserID, req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber, friendIDList)
|
||||
}
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.WorkMoments, workMoments); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
for _, v := range resp.WorkMoments {
|
||||
user, err := imdb.GetUserByUserID(v.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
if user != nil {
|
||||
v.UserName = user.Nickname
|
||||
v.FaceURL = user.FaceURL
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserFriendWorkMoments(_ context.Context, req *pbOffice.GetUserFriendWorkMomentsReq) (resp *pbOffice.GetUserFriendWorkMomentsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetUserFriendWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
|
||||
resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}
|
||||
var friendIDList []string
|
||||
if config.Config.WorkMoment.OnlyFriendCanSee {
|
||||
friendIDList, err = rocksCache.GetFriendIDListFromCache(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
workMoments, err := db.DB.GetUserFriendWorkMoments(req.Pagination.ShowNumber, req.Pagination.PageNumber, req.UserID, friendIDList)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.WorkMoments, workMoments); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
for _, v := range resp.WorkMoments {
|
||||
user, err := rocksCache.GetUserInfoFromCache(v.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
if user != nil {
|
||||
v.UserName = user.Nickname
|
||||
v.FaceURL = user.FaceURL
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) SetUserWorkMomentsLevel(_ context.Context, req *pbOffice.SetUserWorkMomentsLevelReq) (resp *pbOffice.SetUserWorkMomentsLevelResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SetUserWorkMomentsLevelResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.SetUserWorkMomentsLevel(req.UserID, req.Level); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetUserWorkMomentsLevel failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) ChangeWorkMomentPermission(_ context.Context, req *pbOffice.ChangeWorkMomentPermissionReq) (resp *pbOffice.ChangeWorkMomentPermissionResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.ChangeWorkMomentPermissionResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package apistruct
|
||||
|
||||
import (
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
)
|
||||
|
||||
type GetUserTagsReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTagsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tags []*pbOffice.Tag `json:"tags"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateTagReq struct {
|
||||
TagName string `json:"tagName" binding:"required"` // tag名称
|
||||
UserIDList []string `json:"userIDList" binding:"required"` // 用户ID列表
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type CreateTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteTagReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type DeleteTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SetTagReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
NewName string `json:"newName"`
|
||||
IncreaseUserIDList []string `json:"increaseUserIDList"`
|
||||
ReduceUserIDList []string `json:"reduceUserIDList"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SetTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SendMsg2TagReq struct {
|
||||
TagList []string `json:"tagList"`
|
||||
UserList []string `json:"userList"`
|
||||
GroupList []string `json:"groupList"`
|
||||
|
||||
SenderPlatformID int32 `json:"senderPlatformID" binding:"required"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SendMsg2TagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetTagSendLogsReq struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int32 `json:"showNumber" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetTagSendLogsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Logs []*pbOffice.TagSendLog `json:"logs"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserTagByIDReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTagByIDResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tag *pbOffice.Tag `json:"tag"`
|
||||
} `json:"data"`
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
package apistruct
|
||||
|
||||
import "Open_IM/pkg/proto/office"
|
||||
|
||||
type CreateOneWorkMomentReq struct {
|
||||
office.CreateOneWorkMomentReq
|
||||
}
|
||||
|
||||
type CreateOneWorkMomentResp struct {
|
||||
CommResp
|
||||
Data struct{} `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteOneWorkMomentReq struct {
|
||||
WorkMomentID string `json:"workMomentID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type DeleteOneWorkMomentResp struct {
|
||||
CommResp
|
||||
Data struct{} `json:"data"`
|
||||
}
|
||||
|
||||
type LikeOneWorkMomentReq struct {
|
||||
WorkMomentID string `json:"workMomentID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type LikeOneWorkMomentResp struct {
|
||||
CommResp
|
||||
Data struct{} `json:"data"`
|
||||
}
|
||||
|
||||
type CommentOneWorkMomentReq struct {
|
||||
WorkMomentID string `json:"workMomentID" binding:"required"`
|
||||
ReplyUserID string `json:"replyUserID"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type CommentOneWorkMomentResp struct {
|
||||
CommResp
|
||||
Data struct{} `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteCommentReq struct {
|
||||
WorkMomentID string `json:"workMomentID" binding:"required"`
|
||||
ContentID string `json:"contentID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type DeleteCommentResp struct {
|
||||
CommResp
|
||||
Data struct{} `json:"data"`
|
||||
}
|
||||
|
||||
type WorkMomentsUserCommonReq struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int32 `json:"showNumber" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetWorkMomentByIDReq struct {
|
||||
WorkMomentID string `json:"workMomentID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type WorkMoment struct {
|
||||
WorkMomentID string `json:"workMomentID"`
|
||||
UserID string `json:"userID"`
|
||||
Content string `json:"content"`
|
||||
LikeUserList []*WorkMomentUser `json:"likeUsers"`
|
||||
Comments []*Comment `json:"comments"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
UserName string `json:"userName"`
|
||||
AtUserList []*WorkMomentUser `json:"atUsers"`
|
||||
PermissionUserList []*WorkMomentUser `json:"permissionUsers"`
|
||||
CreateTime int32 `json:"createTime"`
|
||||
Permission int32 `json:"permission"`
|
||||
}
|
||||
|
||||
type WorkMomentUser struct {
|
||||
UserID string `json:"userID"`
|
||||
UserName string `json:"userName"`
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
UserID string `json:"userID"`
|
||||
UserName string `json:"userName"`
|
||||
ReplyUserID string `json:"replyUserID"`
|
||||
ReplyUserName string `json:"replyUserName"`
|
||||
ContentID string `json:"contentID"`
|
||||
Content string `json:"content"`
|
||||
CreateTime int32 `json:"createTime"`
|
||||
}
|
||||
|
||||
type GetWorkMomentByIDResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
WorkMoment *WorkMoment `json:"workMoment"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserWorkMomentsReq struct {
|
||||
WorkMomentsUserCommonReq
|
||||
UserID string `json:"userID"`
|
||||
}
|
||||
|
||||
type GetUserWorkMomentsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
WorkMoments []*WorkMoment `json:"workMoments"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserFriendWorkMomentsReq struct {
|
||||
WorkMomentsUserCommonReq
|
||||
}
|
||||
|
||||
type GetUserFriendWorkMomentsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
WorkMoments []*WorkMoment `json:"workMoments"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type SetUserWorkMomentsLevelReq struct {
|
||||
office.SetUserWorkMomentsLevelReq
|
||||
}
|
||||
|
||||
type SetUserWorkMomentsLevelResp struct {
|
||||
CommResp
|
||||
Data struct{} `json:"data"`
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/api_struct"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
type AdminLoginRequest struct {
|
||||
AdminName string `json:"adminID" binding:"required"`
|
||||
Secret string `json:"secret" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type AdminLoginResponse struct {
|
||||
Token string `json:"token"`
|
||||
UserName string `json:"userName"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
}
|
||||
|
||||
type GetUserTokenRequest struct {
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
PlatFormID int32 `json:"platformID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTokenResponse struct {
|
||||
Token string `json:"token"`
|
||||
ExpTime int64 `json:"expTime"`
|
||||
}
|
||||
|
||||
type AddUserRegisterAddFriendIDListRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
}
|
||||
|
||||
type AddUserRegisterAddFriendIDListResponse struct {
|
||||
}
|
||||
|
||||
type ReduceUserRegisterAddFriendIDListRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
Operation int32 `json:"operation"`
|
||||
}
|
||||
|
||||
type ReduceUserRegisterAddFriendIDListResponse struct {
|
||||
}
|
||||
|
||||
type GetUserRegisterAddFriendIDListRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
apistruct.RequestPagination
|
||||
}
|
||||
|
||||
type GetUserRegisterAddFriendIDListResponse struct {
|
||||
Users []*sdkws.UserInfo `json:"users"`
|
||||
apistruct.ResponsePagination
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
type RequestPagination struct {
|
||||
PageNumber int `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int `json:"showNumber" binding:"required"`
|
||||
}
|
||||
|
||||
type ResponsePagination struct {
|
||||
CurrentPage int `json:"currentPage"`
|
||||
ShowNumber int `json:"showNumber"`
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
type GetFriendsReq struct {
|
||||
OperationID string `json:"operationID"`
|
||||
UserID string `json:"userID"`
|
||||
FriendUserName string `json:"friendUserName"`
|
||||
FriendUserID string `json:"friendUserID"`
|
||||
RequestPagination
|
||||
}
|
||||
|
||||
type FriendInfo struct {
|
||||
OwnerUserID string `json:"ownerUserID"`
|
||||
Remark string `json:"remark"`
|
||||
CreateTime uint32 `json:"createTime"`
|
||||
UserID string `json:"userID"`
|
||||
Nickname string `json:"nickName"`
|
||||
AddSource int32 `json:"addSource"`
|
||||
OperatorUserID string `json:"operatorUserID"`
|
||||
}
|
||||
|
||||
type GetFriendsResp struct {
|
||||
ResponsePagination
|
||||
FriendInfoList []*FriendInfo `json:"friendInfoList"`
|
||||
FriendNums int32 `json:"friendNums"`
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
type GroupResponse struct {
|
||||
GroupOwnerName string `json:"GroupOwnerName"`
|
||||
GroupOwnerID string `json:"GroupOwnerID"`
|
||||
GroupID string `json:"groupID"`
|
||||
GroupName string `json:"groupName"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
OwnerUserID string `json:"ownerUserID"`
|
||||
CreateTime uint32 `json:"createTime"`
|
||||
MemberCount uint32 `json:"memberCount"`
|
||||
Ex string `json:"ex"`
|
||||
Status int32 `json:"status"`
|
||||
CreatorUserID string `json:"creatorUserID"`
|
||||
GroupType int32 `json:"groupType"`
|
||||
NeedVerification int32 `json:"needVerification"`
|
||||
LookMemberInfo int32 `json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `json:"applyMemberFriend"`
|
||||
NotificationUpdateTime uint32 `json:"notificationUpdateTime"`
|
||||
NotificationUserID string `json:"notificationUserID"`
|
||||
}
|
||||
|
||||
type GetGroupsRequest struct {
|
||||
RequestPagination
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID"`
|
||||
GroupName string `json:"groupName"`
|
||||
}
|
||||
|
||||
type GetGroupsResponse struct {
|
||||
Groups []GroupResponse `json:"groups"`
|
||||
GroupNums int `json:"groupNums"`
|
||||
ResponsePagination
|
||||
}
|
||||
|
||||
type GetGroupMembersRequest struct {
|
||||
GroupID string `form:"groupID" binding:"required"`
|
||||
UserName string `form:"userName"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
RequestPagination
|
||||
}
|
||||
|
||||
type GroupMemberResponse struct {
|
||||
GroupID string `json:"groupID"`
|
||||
UserID string `json:"userID"`
|
||||
RoleLevel int32 `json:"roleLevel"`
|
||||
JoinTime int32 `json:"joinTime"`
|
||||
Nickname string `json:"nickname"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
AppMangerLevel int32 `json:"appMangerLevel"` //if >0
|
||||
JoinSource int32 `json:"joinSource"`
|
||||
OperatorUserID string `json:"operatorUserID"`
|
||||
Ex string `json:"ex"`
|
||||
MuteEndTime uint32 `json:"muteEndTime"`
|
||||
InviterUserID string `json:"inviterUserID"`
|
||||
}
|
||||
|
||||
type GetGroupMembersResponse struct {
|
||||
GroupMembers []GroupMemberResponse `json:"groupMembers"`
|
||||
ResponsePagination
|
||||
MemberNums int `json:"memberNums"`
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
import (
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
type GetChatLogsReq struct {
|
||||
SessionType int `json:"sessionType"`
|
||||
ContentType int `json:"contentType"`
|
||||
Content string `json:"content"`
|
||||
SendID string `json:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
GroupID string `json:"groupID"`
|
||||
SendTime string `json:"sendTime"`
|
||||
RequestPagination
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
type ChatLog struct {
|
||||
SendID string `json:"sendID,omitempty"`
|
||||
RecvID string `json:"recvID,omitempty"`
|
||||
GroupID string `json:"groupID,omitempty"`
|
||||
ClientMsgID string `json:"clientMsgID,omitempty"`
|
||||
ServerMsgID string `json:"serverMsgID,omitempty"`
|
||||
SenderPlatformID int32 `json:"senderPlatformID,omitempty"`
|
||||
SenderNickname string `json:"senderNickname,omitempty"`
|
||||
SenderFaceURL string `json:"senderFaceURL,omitempty"`
|
||||
SessionType int32 `json:"sessionType,omitempty"`
|
||||
MsgFrom int32 `json:"msgFrom,omitempty"`
|
||||
ContentType int32 `json:"contentType,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Seq uint32 `json:"seq,omitempty"`
|
||||
SendTime int64 `json:"sendTime,omitempty"`
|
||||
CreateTime int64 `json:"createTime,omitempty"`
|
||||
Status int32 `json:"status,omitempty"`
|
||||
Options map[string]bool `json:"options,omitempty"`
|
||||
OfflinePushInfo *pbCommon.OfflinePushInfo `json:"offlinePushInfo,omitempty"`
|
||||
AtUserIDList []string `json:"atUserIDList,omitempty"`
|
||||
MsgDataList []byte `json:"msgDataList,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
}
|
||||
|
||||
type GetChatLogsResp struct {
|
||||
ChatLogs []*ChatLog `json:"chatLogs"`
|
||||
ChatLogsNum int `json:"logNums"`
|
||||
ResponsePagination
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
type GetStatisticsRequest struct {
|
||||
From string `json:"from" binding:"required"`
|
||||
To string `json:"to" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetMessageStatisticsRequest struct {
|
||||
GetStatisticsRequest
|
||||
}
|
||||
|
||||
type GetMessageStatisticsResponse struct {
|
||||
PrivateMessageNum int `json:"privateMessageNum"`
|
||||
GroupMessageNum int `json:"groupMessageNum"`
|
||||
PrivateMessageNumList []struct {
|
||||
Date string `json:"date"`
|
||||
MessageNum int `json:"messageNum"`
|
||||
} `json:"privateMessageNumList"`
|
||||
GroupMessageNumList []struct {
|
||||
Date string `json:"date"`
|
||||
MessageNum int `json:"messageNum"`
|
||||
} `json:"groupMessageNumList"`
|
||||
}
|
||||
|
||||
type GetUserStatisticsRequest struct {
|
||||
GetStatisticsRequest
|
||||
}
|
||||
|
||||
type GetUserStatisticsResponse struct {
|
||||
IncreaseUserNum int `json:"increaseUserNum"`
|
||||
ActiveUserNum int `json:"activeUserNum"`
|
||||
TotalUserNum int `json:"totalUserNum"`
|
||||
IncreaseUserNumList []struct {
|
||||
Date string `json:"date"`
|
||||
IncreaseUserNum int `json:"increaseUserNum"`
|
||||
} `json:"increaseUserNumList"`
|
||||
ActiveUserNumList []struct {
|
||||
Date string `json:"date"`
|
||||
ActiveUserNum int `json:"activeUserNum"`
|
||||
} `json:"activeUserNumList"`
|
||||
TotalUserNumList []struct {
|
||||
Date string `json:"date"`
|
||||
TotalUserNum int `json:"totalUserNum"`
|
||||
} `json:"totalUserNumList"`
|
||||
}
|
||||
|
||||
type GetGroupStatisticsRequest struct {
|
||||
GetStatisticsRequest
|
||||
}
|
||||
|
||||
// 群聊统计
|
||||
type GetGroupStatisticsResponse struct {
|
||||
IncreaseGroupNum int `json:"increaseGroupNum"`
|
||||
TotalGroupNum int `json:"totalGroupNum"`
|
||||
IncreaseGroupNumList []struct {
|
||||
Date string `json:"date"`
|
||||
IncreaseGroupNum int `json:"increaseGroupNum"`
|
||||
} `json:"increaseGroupNumList"`
|
||||
TotalGroupNumList []struct {
|
||||
Date string `json:"date"`
|
||||
TotalGroupNum int `json:"totalGroupNum"`
|
||||
} `json:"totalGroupNumList"`
|
||||
}
|
||||
|
||||
type GetActiveUserRequest struct {
|
||||
GetStatisticsRequest
|
||||
// RequestPagination
|
||||
}
|
||||
|
||||
type GetActiveUserResponse struct {
|
||||
ActiveUserList []struct {
|
||||
NickName string `json:"nickName"`
|
||||
UserId string `json:"userID"`
|
||||
MessageNum int `json:"messageNum"`
|
||||
} `json:"activeUserList"`
|
||||
}
|
||||
|
||||
type GetActiveGroupRequest struct {
|
||||
GetStatisticsRequest
|
||||
// RequestPagination
|
||||
}
|
||||
|
||||
type GetActiveGroupResponse struct {
|
||||
ActiveGroupList []struct {
|
||||
GroupName string `json:"groupName"`
|
||||
GroupId string `json:"groupID"`
|
||||
MessageNum int `json:"messageNum"`
|
||||
} `json:"activeGroupList"`
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package cmsstruct
|
||||
|
||||
type UserResponse struct {
|
||||
FaceURL string `json:"faceURL"`
|
||||
Nickname string `json:"nickName"`
|
||||
UserID string `json:"userID"`
|
||||
CreateTime string `json:"createTime,omitempty"`
|
||||
CreateIp string `json:"createIp,omitempty"`
|
||||
LastLoginTime string `json:"lastLoginTime,omitempty"`
|
||||
LastLoginIp string `json:"lastLoginIP,omitempty"`
|
||||
LoginTimes int32 `json:"loginTimes"`
|
||||
LoginLimit int32 `json:"loginLimit"`
|
||||
IsBlock bool `json:"isBlock"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Email string `json:"email"`
|
||||
Birth string `json:"birth"`
|
||||
Gender int `json:"gender"`
|
||||
}
|
||||
|
||||
type AddUserRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
PhoneNumber string `json:"phoneNumber" binding:"required"`
|
||||
UserId string `json:"userID" binding:"required"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
Email string `json:"email"`
|
||||
Birth string `json:"birth"`
|
||||
Gender string `json:"gender"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
}
|
||||
|
||||
type AddUserResponse struct {
|
||||
}
|
||||
|
||||
type BlockUser struct {
|
||||
UserResponse
|
||||
BeginDisableTime string `json:"beginDisableTime"`
|
||||
EndDisableTime string `json:"endDisableTime"`
|
||||
}
|
||||
|
||||
type BlockUserRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
EndDisableTime string `json:"endDisableTime" binding:"required"`
|
||||
}
|
||||
|
||||
type BlockUserResponse struct {
|
||||
}
|
||||
|
||||
type UnblockUserRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
}
|
||||
|
||||
type UnBlockUserResponse struct {
|
||||
}
|
||||
|
||||
type GetBlockUsersRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
RequestPagination
|
||||
}
|
||||
|
||||
type GetBlockUsersResponse struct {
|
||||
BlockUsers []BlockUser `json:"blockUsers"`
|
||||
ResponsePagination
|
||||
UserNums int32 `json:"userNums"`
|
||||
}
|
||||
|
||||
type GetUserIDByEmailAndPhoneNumberRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type GetUserIDByEmailAndPhoneNumberResponse struct {
|
||||
UserIDList []string `json:"userIDList"`
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AdminCMSInterface interface {
|
||||
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalUserNum() (num int64, err error)
|
||||
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalGroupNum() (num int64, err error)
|
||||
GetGroupNum(to time.Time) (num int64, err error)
|
||||
GetActiveGroups(from, to time.Time, limit int) (activeGroups []*relation.ActiveGroup, err error)
|
||||
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
|
||||
}
|
||||
|
||||
type AdminCMSController struct {
|
||||
database AdminCMSDatabaseInterface
|
||||
}
|
||||
|
||||
func NewAdminCMSController(db *gorm.DB) AdminCMSInterface {
|
||||
adminCMSController := &AdminCMSController{
|
||||
database: newAdminCMSDatabase(db),
|
||||
}
|
||||
return adminCMSController
|
||||
}
|
||||
|
||||
func newAdminCMSDatabase(db *gorm.DB) AdminCMSDatabaseInterface {
|
||||
return &AdminCMSDatabase{Statistics: relation.NewStatistics(db)}
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetActiveUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetIncreaseUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetTotalUserNum() (num int64, err error) {
|
||||
return admin.database.GetTotalUserNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||
return admin.database.GetTotalUserNumByDate(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.GetSingleChatMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetGroupMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetIncreaseGroupNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetTotalGroupNum() (num int64, err error) {
|
||||
return admin.database.GetTotalGroupNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetGroupNum(to time.Time) (num int64, err error) {
|
||||
return admin.database.GetGroupNum(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
|
||||
return admin.database.GetActiveGroups(from, to, limit)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
|
||||
return admin.database.GetActiveUsers(from, to, limit)
|
||||
}
|
||||
|
||||
type AdminCMSDatabaseInterface interface {
|
||||
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalUserNum() (num int64, err error)
|
||||
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalGroupNum() (num int64, err error)
|
||||
GetGroupNum(to time.Time) (num int64, err error)
|
||||
GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error)
|
||||
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
|
||||
}
|
||||
|
||||
type AdminCMSDatabase struct {
|
||||
Statistics *relation.Statistics
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetActiveUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetIncreaseUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetTotalUserNum() (num int64, err error) {
|
||||
return admin.Statistics.GetTotalUserNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetTotalUserNumByDate(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetSingleChatMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetGroupMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetIncreaseGroupNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetTotalGroupNum() (num int64, err error) {
|
||||
return admin.Statistics.GetTotalGroupNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetGroupNum(to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetGroupNum(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
|
||||
return admin.Statistics.GetActiveGroups(from, to, limit)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
|
||||
return admin.Statistics.GetActiveUsers(from, to, limit)
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
type Mysql struct {
|
||||
gormConn *gorm.DB
|
||||
}
|
||||
|
||||
func (m *Mysql) GormConn() *gorm.DB {
|
||||
return m.gormConn
|
||||
}
|
||||
|
||||
func (m *Mysql) SetGormConn(gormConn *gorm.DB) {
|
||||
m.gormConn = gormConn
|
||||
}
|
||||
|
||||
func (m *Mysql) InitConn() *Mysql {
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
|
||||
var db *gorm.DB
|
||||
db, err := gorm.Open(mysql.Open(dsn), nil)
|
||||
if err != nil {
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
db, err = gorm.Open(mysql.Open(dsn), nil)
|
||||
if err != nil {
|
||||
panic(err.Error() + " open failed " + dsn)
|
||||
}
|
||||
}
|
||||
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
|
||||
err = db.Exec(sql).Error
|
||||
if err != nil {
|
||||
panic(err.Error() + " Exec failed:" + sql)
|
||||
}
|
||||
dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||
newLogger := logger.New(
|
||||
Writer{},
|
||||
logger.Config{
|
||||
SlowThreshold: time.Duration(config.Config.Mysql.SlowThreshold) * time.Millisecond, // Slow SQL threshold
|
||||
LogLevel: logger.LogLevel(config.Config.Mysql.LogLevel), // Log level
|
||||
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||||
Colorful: true, // Disable color
|
||||
},
|
||||
)
|
||||
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: newLogger,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error() + " Open failed " + dsn)
|
||||
}
|
||||
sqlDB, err := db.DB()
|
||||
if err != nil {
|
||||
panic(err.Error() + " DB.DB() failed ")
|
||||
}
|
||||
sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime))
|
||||
sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
|
||||
sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
|
||||
if db == nil {
|
||||
panic("db is nil")
|
||||
}
|
||||
m.SetGormConn(db)
|
||||
return m
|
||||
}
|
||||
|
||||
//models := []interface{}{&Friend{}, &FriendRequest{}, &Group{}, &GroupMember{}, &GroupRequest{},
|
||||
// &User{}, &Black{}, &ChatLog{}, &Conversation{}, &AppVersion{}}
|
||||
|
||||
func (m *Mysql) AutoMigrateModel(model interface{}) error {
|
||||
err := m.gormConn.AutoMigrate(model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.gormConn.Set("gorm:table_options", "CHARSET=utf8")
|
||||
m.gormConn.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
_ = m.gormConn.Migrator().CreateTable(model)
|
||||
return nil
|
||||
}
|
||||
|
||||
type Writer struct{}
|
||||
|
||||
func (w Writer) Printf(format string, args ...interface{}) {
|
||||
fmt.Printf(format, args...)
|
||||
}
|
||||
|
||||
func getDBConn(db *gorm.DB, tx []any) *gorm.DB {
|
||||
if len(tx) > 0 {
|
||||
if txDB, ok := tx[0].(*gorm.DB); ok {
|
||||
return txDB
|
||||
}
|
||||
}
|
||||
return db
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Statistics struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewStatistics(db *gorm.DB) *Statistics {
|
||||
return &Statistics{DB: db}
|
||||
}
|
||||
|
||||
func (s *Statistics) getUserModel() *gorm.DB {
|
||||
return s.DB.Model(&User{})
|
||||
}
|
||||
|
||||
func (s *Statistics) getChatLogModel() *gorm.DB {
|
||||
return s.DB.Model(&ChatLog{})
|
||||
}
|
||||
|
||||
func (s *Statistics) getGroupModel() *gorm.DB {
|
||||
return s.DB.Model(&Group{})
|
||||
}
|
||||
|
||||
func (s *Statistics) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||
err = s.getChatLogModel().Select("count(distinct(send_id))").Where("send_time >= ? and send_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||
err = s.getUserModel().Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetTotalUserNum() (num int64, err error) {
|
||||
err = s.getUserModel().Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||
err = s.getUserModel().Where("create_time <= ?", to).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||
err = s.getChatLogModel().Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||
err = s.getChatLogModel().Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||
err = s.getGroupModel().Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetTotalGroupNum() (num int64, err error) {
|
||||
err = s.getGroupModel().Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetGroupNum(to time.Time) (num int64, err error) {
|
||||
err = s.getGroupModel().Where("create_time <= ?", to).Count(&num).Error
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetActiveGroups(from, to time.Time, limit int) ([]*ActiveGroup, error) {
|
||||
var activeGroups []*ActiveGroup
|
||||
err := s.getChatLogModel().Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
for _, activeGroup := range activeGroups {
|
||||
group := Group{
|
||||
GroupID: activeGroup.ID,
|
||||
}
|
||||
s.getGroupModel().Where("group_id= ? ", group.GroupID).Find(&group)
|
||||
activeGroup.Name = group.GroupName
|
||||
}
|
||||
return activeGroups, err
|
||||
}
|
||||
|
||||
func (s *Statistics) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*ActiveUser, err error) {
|
||||
err = s.getChatLogModel().Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.SingleChatType, constant.GroupChatType, constant.SuperGroupChatType}).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
for _, activeUser := range activeUsers {
|
||||
user := User{
|
||||
UserID: activeUser.ID,
|
||||
}
|
||||
err = s.getUserModel().Select("user_id, name").Find(&user).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
activeUser.Name = user.Nickname
|
||||
activeUser.ID = user.UserID
|
||||
}
|
||||
return activeUsers, err
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package unrelation
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
CTag = "tag"
|
||||
CSendLog = "send_log"
|
||||
)
|
||||
|
||||
type TagModel struct {
|
||||
UserID string `bson:"user_id"`
|
||||
TagID string `bson:"tag_id"`
|
||||
TagName string `bson:"tag_name"`
|
||||
UserList []string `bson:"user_list"`
|
||||
}
|
||||
|
||||
func (TagModel) TableName() string {
|
||||
return CTag
|
||||
}
|
||||
|
||||
type TagSendLogModel struct {
|
||||
UserList []CommonUserModel `bson:"tag_list"`
|
||||
SendID string `bson:"send_id"`
|
||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||
Content string `bson:"content"`
|
||||
SendTime int64 `bson:"send_time"`
|
||||
}
|
||||
|
||||
func (TagSendLogModel) TableName() string {
|
||||
return CSendLog
|
||||
}
|
||||
|
||||
type TagModelInterface interface {
|
||||
GetUserTags(ctx context.Context, userID string) ([]TagModel, error)
|
||||
CreateTag(ctx context.Context, userID, tagName string, userList []string) error
|
||||
GetTagByID(ctx context.Context, userID, tagID string) (TagModel, error)
|
||||
DeleteTag(ctx context.Context, userID, tagID string) error
|
||||
SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error
|
||||
GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error)
|
||||
SaveTagSendLog(ctx context.Context, tagSendLog *TagSendLogModel) error
|
||||
GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]TagSendLogModel, error)
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package unrelation
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
CWorkMoment = "work_moment"
|
||||
)
|
||||
|
||||
type WorkMoment struct {
|
||||
WorkMomentID string `bson:"work_moment_id"`
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
FaceURL string `bson:"face_url"`
|
||||
Content string `bson:"content"`
|
||||
LikeUserList []*CommonUserModel `bson:"like_user_list"`
|
||||
AtUserList []*CommonUserModel `bson:"at_user_list"`
|
||||
PermissionUserList []*CommonUserModel `bson:"permission_user_list"`
|
||||
Comments []*CommonUserModel `bson:"comments"`
|
||||
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
||||
Permission int32 `bson:"permission"`
|
||||
CreateTime int32 `bson:"create_time"`
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
UserID string `bson:"user_id" json:"user_id"`
|
||||
UserName string `bson:"user_name" json:"user_name"`
|
||||
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
||||
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
||||
ContentID string `bson:"content_id" json:"content_id"`
|
||||
Content string `bson:"content" json:"content"`
|
||||
CreateTime int32 `bson:"create_time" json:"create_time"`
|
||||
}
|
||||
|
||||
func (WorkMoment) TableName() string {
|
||||
return CWorkMoment
|
||||
}
|
||||
|
||||
type WorkMomentModelInterface interface {
|
||||
CreateOneWorkMoment(ctx context.Context, workMoment *WorkMoment) error
|
||||
DeleteOneWorkMoment(ctx context.Context, workMomentID string) error
|
||||
DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error
|
||||
GetWorkMomentByID(ctx context.Context, workMomentID string) (*WorkMoment, error)
|
||||
LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*WorkMoment, bool, error)
|
||||
CommentOneWorkMoment(ctx context.Context, comment *Comment, workMomentID string) (*WorkMoment, error)
|
||||
GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]*WorkMoment, error)
|
||||
GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]*WorkMoment, error)
|
||||
GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]*WorkMoment, error)
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TagMongoDriver struct {
|
||||
mgoDB *mongo.Database
|
||||
TagCollection *mongo.Collection
|
||||
TagSendLogCollection *mongo.Collection
|
||||
}
|
||||
|
||||
func NewTagMongoDriver(mgoDB *mongo.Database) *TagMongoDriver {
|
||||
return &TagMongoDriver{mgoDB: mgoDB, TagCollection: mgoDB.Collection(unrelation.CTag), TagSendLogCollection: mgoDB.Collection(unrelation.CSendLog)}
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) generateTagID(tagName, userID string) string {
|
||||
return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()) + time.Now().String())
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetUserTags(ctx context.Context, userID string) ([]unrelation.TagModel, error) {
|
||||
var tags []unrelation.TagModel
|
||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
}
|
||||
if err = cursor.All(ctx, &tags); err != nil {
|
||||
return tags, err
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := unrelation.TagModel{
|
||||
UserID: userID,
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
UserList: userList,
|
||||
}
|
||||
_, err := db.TagCollection.InsertOne(ctx, tag)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetTagByID(ctx context.Context, userID, tagID string) (unrelation.TagModel, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) DeleteTag(ctx context.Context, userID, tagID string) error {
|
||||
_, err := db.TagCollection.DeleteOne(ctx, bson.M{"user_id": userID, "tag_id": tagID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
var tag unrelation.TagModel
|
||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||
return err
|
||||
}
|
||||
if newName != "" {
|
||||
_, err := db.TagCollection.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"tag_name": newName}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
||||
tag.UserList = utils.RemoveRepeatedStringInList(tag.UserList)
|
||||
for _, v := range reduceUserIDList {
|
||||
for i2, v2 := range tag.UserList {
|
||||
if v == v2 {
|
||||
tag.UserList[i2] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
var newUserList []string
|
||||
for _, v := range tag.UserList {
|
||||
if v != "" {
|
||||
newUserList = append(newUserList, v)
|
||||
}
|
||||
}
|
||||
_, err := db.TagCollection.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"user_list": newUserList}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag.UserList, err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) SaveTagSendLog(ctx context.Context, tagSendLog *unrelation.TagSendLogModel) error {
|
||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.TagSendLogModel, error) {
|
||||
var tagSendLogs []unrelation.TagSendLogModel
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
||||
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
err = cursor.All(ctx, &tagSendLogs)
|
||||
return tagSendLogs, err
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WorkMomentMongoDriver struct {
|
||||
mgoDB *mongo.Database
|
||||
WorkMomentCollection *mongo.Collection
|
||||
}
|
||||
|
||||
func NewWorkMomentMongoDriver(mgoDB *mongo.Database) *WorkMomentMongoDriver {
|
||||
return &WorkMomentMongoDriver{mgoDB: mgoDB, WorkMomentCollection: mgoDB.Collection(unrelation.CWorkMoment)}
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) generateWorkMomentID(userID string) string {
|
||||
return utils.Md5(userID + strconv.Itoa(rand.Int()) + time.Now().String())
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) generateWorkMomentCommentID(workMomentID string) string {
|
||||
return utils.Md5(workMomentID + strconv.Itoa(rand.Int()) + time.Now().String())
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *unrelation.WorkMoment) error {
|
||||
workMomentID := db.generateWorkMomentID(workMoment.UserID)
|
||||
workMoment.WorkMomentID = workMomentID
|
||||
workMoment.CreateTime = int32(time.Now().Unix())
|
||||
_, err := db.WorkMomentCollection.InsertOne(ctx, workMoment)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) DeleteOneWorkMoment(ctx context.Context, workMomentID string) error {
|
||||
_, err := db.WorkMomentCollection.DeleteOne(ctx, bson.M{"work_moment_id": workMomentID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error {
|
||||
_, err := db.WorkMomentCollection.UpdateOne(ctx, bson.D{{"work_moment_id", workMomentID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", opUserID}},
|
||||
bson.D{{"comments", bson.M{"$elemMatch": bson.M{"user_id": opUserID}}}},
|
||||
},
|
||||
}}, bson.M{"$pull": bson.M{"comments": bson.M{"content_id": contentID}}})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetWorkMomentByID(ctx context.Context, workMomentID string) (*unrelation.WorkMoment, error) {
|
||||
workMoment := &unrelation.WorkMoment{}
|
||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*unrelation.WorkMoment, bool, error) {
|
||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
var isAlreadyLike bool
|
||||
for i, user := range workMoment.LikeUserList {
|
||||
if likeUserID == user.UserID {
|
||||
isAlreadyLike = true
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList[0:i], workMoment.LikeUserList[i+1:]...)
|
||||
}
|
||||
}
|
||||
if !isAlreadyLike {
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &unrelation.CommonUserModel{UserID: likeUserID, UserName: userName})
|
||||
}
|
||||
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
||||
return workMoment, !isAlreadyLike, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) CommentOneWorkMoment(ctx context.Context, comment *unrelation.Comment, workMomentID string) (unrelation.WorkMoment, error) {
|
||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||
var workMoment unrelation.WorkMoment
|
||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
||||
{"user_id", userID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {"permission_user_id_list", bson.D{{"$nin", bson.A{opUserID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {"permission_user_id_list", bson.D{{"$in", bson.A{opUserID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||
}},
|
||||
}, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
var filter bson.D
|
||||
permissionFilter := bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {"permission_user_id_list", bson.D{{"$nin", bson.A{userID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {"permission_user_id_list", bson.D{{"$in", bson.A{userID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||
}}}
|
||||
if config.Config.WorkMoment.OnlyFriendCanSee {
|
||||
filter = bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", userID}}, //self
|
||||
bson.D{{"$and", bson.A{permissionFilter, bson.D{{"user_id", bson.D{{"$in", friendIDList}}}}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
filter = bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", userID}}, //self
|
||||
permissionFilter,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
result, err := db.WorkMomentCollection.Find(ctx, filter, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, err
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,175 +0,0 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "Open_IM/pkg/proto/admincms;admincms";
|
||||
import "Open-IM-Server/pkg/proto/sdkws/ws.proto";
|
||||
package admincms;
|
||||
|
||||
message AdminLoginReq {
|
||||
string adminID = 2;
|
||||
string secret = 3;
|
||||
}
|
||||
|
||||
message AdminLoginResp {
|
||||
string token = 1;
|
||||
string userName = 2;
|
||||
string faceURL = 3;
|
||||
}
|
||||
|
||||
message GetChatLogsReq {
|
||||
string content = 1;
|
||||
string sendID = 2;
|
||||
string recvID = 3;
|
||||
string sendTime = 4;
|
||||
int32 sessionType = 5;
|
||||
int32 contentType = 6;
|
||||
sdkws.RequestPagination pagination = 7;
|
||||
}
|
||||
|
||||
message ChatLog {
|
||||
string serverMsgID = 1;
|
||||
string clientMsgID = 2;
|
||||
string sendID = 3;
|
||||
string recvID = 4;
|
||||
string groupID = 5;
|
||||
string recvNickname = 6;
|
||||
int32 senderPlatformID = 7;
|
||||
string senderNickname = 8;
|
||||
string senderFaceURL = 9;
|
||||
string groupName = 10;
|
||||
int32 sessionType = 11;
|
||||
int32 msgFrom = 12;
|
||||
int32 contentType = 13;
|
||||
string content = 14;
|
||||
int32 status = 15;
|
||||
int64 sendTime = 16;
|
||||
int64 createTime = 17;
|
||||
string ex = 18;
|
||||
}
|
||||
|
||||
message GetChatLogsResp {
|
||||
repeated ChatLog chatLogs = 1;
|
||||
int32 chatLogsNum = 2;
|
||||
}
|
||||
|
||||
|
||||
message StatisticsReq {
|
||||
string from = 1;
|
||||
string to = 2;
|
||||
}
|
||||
|
||||
message GetActiveUserReq{
|
||||
StatisticsReq statisticsReq = 1;
|
||||
}
|
||||
|
||||
message UserResp{
|
||||
string nickName = 1;
|
||||
string userID = 2;
|
||||
int32 messageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveUserResp {
|
||||
repeated UserResp Users = 1;
|
||||
}
|
||||
|
||||
message GetActiveGroupReq{
|
||||
StatisticsReq statisticsReq = 1;
|
||||
}
|
||||
|
||||
message GroupResp {
|
||||
string GroupName = 1;
|
||||
string GroupID = 2;
|
||||
int32 MessageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveGroupResp {
|
||||
repeated GroupResp Groups = 1;
|
||||
}
|
||||
|
||||
message DateNumList {
|
||||
string Date = 1;
|
||||
int32 Num = 2;
|
||||
}
|
||||
|
||||
|
||||
message GetMessageStatisticsReq {
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
}
|
||||
|
||||
|
||||
message GetMessageStatisticsResp {
|
||||
int32 PrivateMessageNum = 1;
|
||||
int32 GroupMessageNum = 2;
|
||||
repeated DateNumList PrivateMessageNumList = 3;
|
||||
repeated DateNumList GroupMessageNumList = 4;
|
||||
}
|
||||
|
||||
message GetGroupStatisticsReq {
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
}
|
||||
|
||||
|
||||
message GetGroupStatisticsResp {
|
||||
int32 IncreaseGroupNum = 1;
|
||||
int32 TotalGroupNum = 2;
|
||||
repeated DateNumList IncreaseGroupNumList = 3;
|
||||
repeated DateNumList TotalGroupNumList = 4;
|
||||
}
|
||||
|
||||
message GetUserStatisticsReq {
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message GetUserStatisticsResp {
|
||||
int32 IncreaseUserNum = 1;
|
||||
int32 ActiveUserNum = 2;
|
||||
int32 TotalUserNum = 3;
|
||||
repeated DateNumList IncreaseUserNumList = 4;
|
||||
repeated DateNumList ActiveUserNumList = 5;
|
||||
repeated DateNumList TotalUserNumList = 6;
|
||||
}
|
||||
|
||||
|
||||
message GetUserFriendsReq {
|
||||
string operationID = 1;
|
||||
string userID = 2;
|
||||
string friendUserID = 3;
|
||||
string friendUserName = 4;
|
||||
sdkws.RequestPagination pagination = 5;
|
||||
}
|
||||
|
||||
message GetUserFriendsResp {
|
||||
repeated sdkws.FriendInfo friendInfoList = 2;
|
||||
int32 friendNums = 3;
|
||||
}
|
||||
|
||||
message GetUserIDByEmailAndPhoneNumberReq{
|
||||
string email = 2;
|
||||
string phoneNumber = 3;
|
||||
}
|
||||
|
||||
message GetUserIDByEmailAndPhoneNumberResp{
|
||||
repeated string userIDList = 1;
|
||||
}
|
||||
|
||||
message GetUserTokenReq {
|
||||
string userID = 1;
|
||||
int32 platformID = 2;
|
||||
}
|
||||
|
||||
message GetUserTokenResp {
|
||||
string token = 1;
|
||||
int64 expTime = 2;
|
||||
}
|
||||
|
||||
service adminCMS {
|
||||
rpc AdminLogin(AdminLoginReq) returns(AdminLoginResp);
|
||||
rpc GetChatLogs(GetChatLogsReq) returns(GetChatLogsResp);
|
||||
rpc GetActiveUser(GetActiveUserReq) returns(GetActiveUserResp);
|
||||
rpc GetActiveGroup(GetActiveGroupReq) returns(GetActiveGroupResp);
|
||||
rpc GetMessageStatistics(GetMessageStatisticsReq) returns(GetMessageStatisticsResp);
|
||||
rpc GetGroupStatistics(GetGroupStatisticsReq) returns(GetGroupStatisticsResp);
|
||||
rpc GetUserStatistics(GetUserStatisticsReq) returns(GetUserStatisticsResp);
|
||||
rpc GetUserFriends(GetUserFriendsReq) returns(GetUserFriendsResp);
|
||||
rpc GetUserIDByEmailAndPhoneNumber(GetUserIDByEmailAndPhoneNumberReq) returns(GetUserIDByEmailAndPhoneNumberResp);
|
||||
rpc GetUserToken(GetUserTokenReq) returns(GetUserTokenResp);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,303 +0,0 @@
|
||||
syntax = "proto3";
|
||||
import "Open-IM-Server/pkg/proto/sdkws/ws.proto";
|
||||
option go_package = "Open_IM/pkg/proto/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 {
|
||||
repeated string tagList = 1;
|
||||
repeated string UserList = 2;
|
||||
repeated string GroupList = 3;
|
||||
string sendID = 4;
|
||||
int32 senderPlatformID = 5;
|
||||
string content = 6;
|
||||
string operationID = 7;
|
||||
}
|
||||
|
||||
message SendMsg2TagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetTagSendLogsReq {
|
||||
sdkws.RequestPagination Pagination = 1;
|
||||
string userID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message TagSendLog {
|
||||
repeated TagUser userList = 1;
|
||||
string content = 2;
|
||||
int64 sendTime = 3;
|
||||
}
|
||||
|
||||
message GetTagSendLogsResp {
|
||||
CommonResp commonResp = 1;
|
||||
sdkws.ResponsePagination Pagination = 2;
|
||||
repeated TagSendLog tagSendLogs = 3;
|
||||
}
|
||||
|
||||
message GetUserTagByIDReq {
|
||||
string userID = 1;
|
||||
string tagID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message GetUserTagByIDResp {
|
||||
CommonResp commonResp = 1;
|
||||
Tag tag = 2;
|
||||
}
|
||||
|
||||
/// WorkMoment
|
||||
|
||||
message LikeUser {
|
||||
string userID = 1;
|
||||
string userName = 2;
|
||||
}
|
||||
|
||||
message NotificationUser {
|
||||
string userID = 1;
|
||||
string userName = 2;
|
||||
}
|
||||
|
||||
message Comment {
|
||||
string userID = 1;
|
||||
string userName = 2;
|
||||
string faceURL = 3;
|
||||
string replyUserID = 4;
|
||||
string replyUserName = 5;
|
||||
string contentID = 6;
|
||||
string content = 7;
|
||||
int32 createTime = 8;
|
||||
}
|
||||
|
||||
message PermissionGroup {
|
||||
string groupName = 1;
|
||||
string groupID = 2;
|
||||
}
|
||||
|
||||
message WorkMomentUser {
|
||||
string userID = 1;
|
||||
string userName = 2;
|
||||
}
|
||||
|
||||
message WorkMoment {
|
||||
string workMomentID = 1;
|
||||
string userID = 2;
|
||||
string userName = 3;
|
||||
string faceURL = 4;
|
||||
string content = 5;
|
||||
repeated WorkMomentUser likeUserList = 6;
|
||||
repeated Comment comments = 7;
|
||||
int32 permission = 8;
|
||||
repeated WorkMomentUser permissionUserList = 9;
|
||||
repeated PermissionGroup permissionGroupList = 10;
|
||||
repeated WorkMomentUser atUserList = 11;
|
||||
int32 createTime = 12;
|
||||
}
|
||||
|
||||
message CreateOneWorkMomentReq {
|
||||
WorkMoment workMoment = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message CreateOneWorkMomentResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message DeleteOneWorkMomentReq {
|
||||
string workMomentID = 1;
|
||||
string userID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message DeleteOneWorkMomentResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message LikeOneWorkMomentReq {
|
||||
string userID = 1;
|
||||
string WorkMomentID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message LikeOneWorkMomentResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message CommentOneWorkMomentReq {
|
||||
string userID = 1;
|
||||
string workMomentID = 2;
|
||||
string replyUserID = 3;
|
||||
string content = 4;
|
||||
string operationID = 5;
|
||||
}
|
||||
|
||||
message CommentOneWorkMomentResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message DeleteCommentReq {
|
||||
string workMomentID = 1;
|
||||
string contentID = 2;
|
||||
string opUserID = 3;
|
||||
string operationID = 4;
|
||||
}
|
||||
|
||||
message DeleteCommentResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetWorkMomentByIDReq {
|
||||
string workMomentID = 1;
|
||||
string opUserID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message GetWorkMomentByIDResp {
|
||||
CommonResp commonResp = 1;
|
||||
WorkMoment workMoment = 2;
|
||||
}
|
||||
|
||||
message ChangeWorkMomentPermissionReq {
|
||||
string workMomentID = 1;
|
||||
string opUserID = 2;
|
||||
int32 permission = 3;
|
||||
repeated string permissionUserIDList = 4;
|
||||
string operationID = 5;
|
||||
}
|
||||
|
||||
message ChangeWorkMomentPermissionResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetUserWorkMomentsReq {
|
||||
string userID = 1;
|
||||
string opUserID = 2;
|
||||
sdkws.RequestPagination Pagination = 3;
|
||||
string operationID = 4;
|
||||
}
|
||||
|
||||
message GetUserWorkMomentsResp {
|
||||
CommonResp commonResp = 1;
|
||||
repeated WorkMoment workMoments = 2;
|
||||
sdkws.ResponsePagination Pagination = 3;
|
||||
}
|
||||
|
||||
message GetUserFriendWorkMomentsReq {
|
||||
string userID = 1;
|
||||
sdkws.RequestPagination Pagination = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message GetUserFriendWorkMomentsResp {
|
||||
CommonResp commonResp = 1;
|
||||
repeated WorkMoment workMoments = 2;
|
||||
sdkws.ResponsePagination Pagination = 3;
|
||||
}
|
||||
|
||||
message WorkMomentNotificationMsg {
|
||||
int32 notificationMsgType = 1;
|
||||
string replyUserName = 2;
|
||||
string replyUserID = 3;
|
||||
string content = 4;
|
||||
string contentID = 5;
|
||||
string workMomentID = 6;
|
||||
string userID = 7;
|
||||
string userName = 8;
|
||||
string faceURL = 9;
|
||||
string workMomentContent = 10;
|
||||
int32 createTime = 11;
|
||||
}
|
||||
|
||||
message SetUserWorkMomentsLevelReq {
|
||||
string userID = 1;
|
||||
int32 level = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message SetUserWorkMomentsLevelResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
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);
|
||||
rpc GetUserTagByID(GetUserTagByIDReq) returns(GetUserTagByIDResp);
|
||||
|
||||
rpc CreateOneWorkMoment(CreateOneWorkMomentReq) returns(CreateOneWorkMomentResp);
|
||||
rpc DeleteOneWorkMoment(DeleteOneWorkMomentReq) returns(DeleteOneWorkMomentResp);
|
||||
rpc LikeOneWorkMoment(LikeOneWorkMomentReq) returns(LikeOneWorkMomentResp);
|
||||
rpc CommentOneWorkMoment(CommentOneWorkMomentReq) returns(CommentOneWorkMomentResp);
|
||||
rpc DeleteComment(DeleteCommentReq) returns(DeleteCommentResp);
|
||||
rpc GetWorkMomentByID(GetWorkMomentByIDReq) returns(GetWorkMomentByIDResp);
|
||||
rpc ChangeWorkMomentPermission(ChangeWorkMomentPermissionReq) returns(ChangeWorkMomentPermissionResp);
|
||||
/// user self
|
||||
rpc GetUserWorkMoments(GetUserWorkMomentsReq) returns(GetUserWorkMomentsResp);
|
||||
/// users friend
|
||||
rpc GetUserFriendWorkMoments(GetUserFriendWorkMomentsReq) returns(GetUserFriendWorkMomentsResp);
|
||||
rpc SetUserWorkMomentsLevel(SetUserWorkMomentsLevelReq) returns(SetUserWorkMomentsLevelResp);
|
||||
}
|
||||
|
@ -1,22 +1,14 @@
|
||||
SET ROOT=%cd%
|
||||
mkdir %ROOT%\..\bin\
|
||||
cd ..\cmd\open_im_api\ && go build -ldflags="-w -s" && move open_im_api.exe %ROOT%\..\bin\
|
||||
cd ..\..\cmd\open_im_cms_api\ && go build -ldflags="-w -s" && move open_im_cms_api.exe %ROOT%\..\bin\
|
||||
cd ..\..\cmd\open_im_demo\ && go build -ldflags="-w -s" && move open_im_demo.exe %ROOT%\..\bin\
|
||||
cd ..\..\cmd\open_im_msg_gateway\ && go build -ldflags="-w -s" && move open_im_msg_gateway.exe %ROOT%\..\bin\
|
||||
cd ..\..\cmd\open_im_msg_transfer\ && go build -ldflags="-w -s" && move open_im_msg_transfer.exe %ROOT%\..\bin\
|
||||
cd ..\..\cmd\open_im_push\ && go build -ldflags="-w -s" && move open_im_push.exe %ROOT%\..\bin\
|
||||
cd ..\..\cmd\rpc\open_im_admin_cms\&& go build -ldflags="-w -s" && move open_im_admin_cms.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_auth\&& go build -ldflags="-w -s" && move open_im_auth.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_cache\&& go build -ldflags="-w -s" && move open_im_cache.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_conversation\&& go build -ldflags="-w -s" && move open_im_conversation.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_friend\&& go build -ldflags="-w -s" && move open_im_friend.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_group\&& go build -ldflags="-w -s" && move open_im_group.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_message_cms\&& go build -ldflags="-w -s" && move open_im_message_cms.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_msg\&& go build -ldflags="-w -s" && move open_im_msg.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_office\&& go build -ldflags="-w -s" && move open_im_office.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_organization\&& go build -ldflags="-w -s" && move open_im_organization.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_statistics\&& go build -ldflags="-w -s" && move open_im_statistics.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\rpc\open_im_user\&& go build -ldflags="-w -s" && move open_im_user.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\Open-IM-SDK-Core\ws_wrapper\cmd\&& go build -ldflags="-w -s" open_im_sdk_server.go && move open_im_sdk_server.exe %ROOT%\..\bin\
|
||||
cd ..\..\..\cmd\Open-IM-SDK-Core\ws_wrapper\cmd\&& go build -ldflags="-w -s" sdkws_server.go && move sdkws_server.exe %ROOT%\..\bin\
|
||||
cd %ROOT%
|
@ -1,22 +1,15 @@
|
||||
SET ROOT=%cd%
|
||||
cd %ROOT%\..\bin\
|
||||
start cmd /C .\open_im_api.exe -port 10002
|
||||
start cmd /C .\open_im_cms_api.exe -port 10006
|
||||
start cmd /C .\open_im_user.exe -port 10110
|
||||
start cmd /C .\open_im_friend.exe -port 10120
|
||||
start cmd /C .\open_im_group.exe -port 10150
|
||||
start cmd /C .\open_im_auth.exe -port 10160
|
||||
start cmd /C .\open_im_admin_cms.exe -port 10200
|
||||
start cmd /C .\open_im_message_cms.exe -port 10190
|
||||
start cmd /C .\open_im_statistics.exe -port 10180
|
||||
start cmd /C .\open_im_msg.exe -port 10130
|
||||
start cmd /C .\open_im_office.exe -port 10210
|
||||
start cmd /C .\open_im_organization.exe -port 10220
|
||||
start cmd /C .\open_im_conversation.exe -port 10230
|
||||
start cmd /C .\open_im_cache.exe -port 10240
|
||||
start cmd /C .\open_im_push.exe -port 10170
|
||||
start cmd /C .\open_im_msg_transfer.exe
|
||||
start cmd /C .\open_im_sdk_server.exe -openIM_api_port 10002 -openIM_ws_port 10001 -sdkws_port 10003 -openIM_log_level 6
|
||||
start cmd /C .\sdkws_server.exe -openIM_api_port 10002 -openIM_ws_port 10001 -sdkws_port 10003 -openIM_log_level 6
|
||||
start cmd /C .\open_im_msg_gateway.exe -rpc_port 10140 -ws_port 10001
|
||||
start cmd /C .\open_im_demo.exe -port 10004
|
||||
cd %ROOT%
|
Loading…
Reference in new issue