rocks cache

pull/249/head
wangchuxiao 2 years ago
parent 9e0e2fe124
commit b064244907

@ -50,6 +50,7 @@ func main() {
}
address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort)
fmt.Println("start demo api server address: ", address)
go register.OnboardingProcessRoutine()
err := r.Run(address)
if err != nil {
log.Error("", "run failed ", *ginPort, err.Error())

@ -113,6 +113,18 @@ services:
restart: always
command: minio server /data --console-address ':9090'
dtm:
image: yedf/dtm
ports:
- 36789:36789
- 36790:36790
environment:
STORE_DRIVER: mysql
STORE_HOST: localhost
STORE_USER: root
STORE_PASSWORD: ''
STORE_PORT: 3306
open_im_server:
image: openim/open_im_server:v2.2.0
container_name: open_im_server
@ -129,6 +141,7 @@ services:
- redis
- etcd
- minio
- dtm
network_mode: "host"
logging:
driver: json-file

@ -19,20 +19,16 @@ require (
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-playground/validator/v10 v10.11.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2
github.com/golang-jwt/jwt/v4 v4.1.0
github.com/golang/protobuf v1.5.2
github.com/gorilla/websocket v1.4.2
github.com/jinzhu/copier v0.3.4
github.com/jinzhu/gorm v1.9.16
github.com/jinzhu/now v1.1.3 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/strftime v1.0.4 // indirect
github.com/lib/pq v1.2.0 // indirect
github.com/lithammer/shortuuid v3.0.0+incompatible
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/minio/minio-go/v7 v7.0.22
github.com/mitchellh/mapstructure v1.4.2
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
@ -64,6 +60,8 @@ require (
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.3.5
gorm.io/gorm v1.23.8
)
replace github.com/Shopify/sarama => github.com/Shopify/sarama v1.29.0

@ -84,7 +84,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
@ -112,7 +111,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
@ -183,7 +181,6 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.1.0 h1:XUgk2Ex5veyVFVeLm0xhusUTQybEbexJXrvPNOKkSY0=
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@ -256,8 +253,9 @@ github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBef
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI=
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
@ -304,8 +302,6 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECae
github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w=
github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@ -317,8 +313,6 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
@ -718,6 +712,10 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.3.5 h1:iWBTVW/8Ij5AG4e0G/zqzaJblYkBI1VIL1LG2HUGsvY=
gorm.io/driver/mysql v1.3.5/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=

@ -21,6 +21,30 @@ import (
"time"
)
type OnboardingProcessReq struct {
OperationID string
UserID string
NickName string
FaceURL string
PhoneNumber string
Email string
}
var Ch chan OnboardingProcessReq
func init() {
Ch = make(chan OnboardingProcessReq, 1000)
}
func OnboardingProcessRoutine() {
for {
req := <-Ch
go func() {
onboardingProcess(req.OperationID, req.UserID, req.NickName, req.FaceURL, req.PhoneNumber, req.Email)
}()
}
}
func onboardingProcess(operationID, userID, userName, faceURL, phoneNumber, email string) {
log.NewInfo(operationID, utils.GetSelfFuncName(), userName, userID, faceURL)
if err := createOrganizationUser(operationID, userID, userName, phoneNumber, email); err != nil {

@ -108,7 +108,18 @@ func SetPassword(c *gin.Context) {
log.Info(params.OperationID, "end setPassword", account, params.Password)
// demo onboarding
if params.UserID == "" {
onboardingProcess(params.OperationID, userID, params.Nickname, params.FaceURL, params.AreaCode+params.PhoneNumber, params.Email)
select {
case Ch <- OnboardingProcessReq{
OperationID: params.OperationID,
UserID: params.UserID,
NickName: params.Nickname,
FaceURL: params.FaceURL,
PhoneNumber: params.AreaCode + params.PhoneNumber,
Email: params.Email,
}:
case <-time.After(time.Second * 2):
log.NewWarn(params.OperationID, utils.GetSelfFuncName(), "to ch timeOut")
}
}
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken})
return

@ -3,20 +3,16 @@ package cache
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbCache "Open_IM/pkg/proto/cache"
commonPb "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"google.golang.org/grpc"
"net"
"strconv"
"strings"
"sync"
"google.golang.org/grpc"
)
type cacheServer struct {
@ -54,13 +50,6 @@ func (s *cacheServer) Run() {
defer listener.Close()
//grpc server
//to cache
err = SyncDB2Cache()
if err != nil {
log.NewError("", err.Error(), "db to cache failed")
panic(err.Error())
}
srv := grpc.NewServer()
defer srv.GracefulStop()
pbCache.RegisterCacheServer(srv, s)
@ -86,167 +75,10 @@ func (s *cacheServer) Run() {
log.NewInfo("0", "message cms rpc success")
}
func SyncDB2Cache() error {
var err error
log.NewInfo("0", utils.GetSelfFuncName())
userList, err := imdb.GetAllUser()
log.NewDebug("", utils.GetSelfFuncName(), "userList", userList)
if err != nil {
return utils.Wrap(err, "")
}
//err = updateAllUserToCache(userList)
wg := &sync.WaitGroup{}
wg.Add(3)
go func() {
defer wg.Done()
err = updateAllFriendToCache(userList)
}()
go func() {
defer wg.Done()
err = updateAllBlackListToCache(userList)
}()
go func() {
defer wg.Done()
err = updateAllGroupMemberListToCache()
}()
wg.Wait()
return utils.Wrap(err, "")
}
func DelRelationCache() {}
func updateAllUserToCache(userList []db.User) error {
wg := &sync.WaitGroup{}
wg.Add(len(userList))
for _, userInfo := range userList {
go func() {
defer wg.Done()
userInfoPb := &commonPb.UserInfo{
UserID: userInfo.UserID,
Nickname: userInfo.Nickname,
FaceURL: userInfo.FaceURL,
Gender: userInfo.Gender,
PhoneNumber: userInfo.PhoneNumber,
Birth: uint32(userInfo.Birth.Unix()),
Email: userInfo.Email,
Ex: userInfo.Ex,
CreateTime: uint32(userInfo.CreateTime.Unix()),
AppMangerLevel: userInfo.AppMangerLevel,
}
m, err := utils.Pb2Map(userInfoPb)
if err != nil {
log.NewWarn("", utils.GetSelfFuncName(), err.Error())
}
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
}
}()
}
wg.Wait()
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil
}
func updateAllGroupMemberListToCache() error {
log.NewInfo("0", utils.GetSelfFuncName())
groupIDList, err := imdb.GetAllGroupIDList()
if err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error())
panic(err.Error())
}
for _, groupID := range groupIDList {
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
if err != nil {
log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error())
continue
}
if len(groupMemberIDList) > 0 {
if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil {
log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error())
}
}
}
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil
}
func updateAllFriendToCache(userList []db.User) error {
log.NewInfo("0", utils.GetSelfFuncName())
for _, user := range userList {
friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID)
if err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
continue
}
if len(friendIDList) > 0 {
if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID)
}
}
}
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil
}
func updateAllBlackListToCache(userList []db.User) error {
log.NewInfo("0", utils.GetSelfFuncName())
for _, user := range userList {
blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID)
if err != nil {
log.NewWarn("", utils.GetSelfFuncName(), err.Error())
continue
}
if len(blackIDList) > 0 {
if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
}
}
}
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil
}
func (s *cacheServer) GetUserInfoFromCache(_ context.Context, req *pbCache.GetUserInfoFromCacheReq) (resp *pbCache.GetUserInfoFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.GetUserInfoFromCacheResp{
CommonResp: &pbCache.CommonResp{},
}
for _, userID := range req.UserIDList {
userInfo, err := db.DB.GetUserInfoFromCache(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get userInfo from cache failed", err.Error())
continue
}
resp.UserInfoList = append(resp.UserInfoList, userInfo)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *cacheServer) UpdateUserInfoToCache(_ context.Context, req *pbCache.UpdateUserInfoToCacheReq) (resp *pbCache.UpdateUserInfoToCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.UpdateUserInfoToCacheResp{
CommonResp: &pbCache.CommonResp{},
}
for _, userInfo := range req.UserInfoList {
m, err := utils.Pb2Map(userInfo)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), *userInfo)
}
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.GetFriendIDListFromCacheReq) (resp *pbCache.GetFriendIDListFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.GetFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
friendIDList, err := db.DB.GetFriendIDListFromCache(req.UserID)
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
@ -259,36 +91,24 @@ func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.G
return resp, nil
}
func (s *cacheServer) AddFriendToCache(_ context.Context, req *pbCache.AddFriendToCacheReq) (resp *pbCache.AddFriendToCacheResp, err error) {
// this is for dtm call
func (s *cacheServer) DelFriendIDListFromCache(_ context.Context, req *pbCache.DelFriendIDListFromCacheReq) (resp *pbCache.DelFriendIDListFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.AddFriendToCacheResp{CommonResp: &pbCache.CommonResp{}}
if err := db.DB.AddFriendToCache(req.UserID, req.FriendID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
resp = &pbCache.DelFriendIDListFromCacheResp{}
if err := rocksCache.DelFriendIDListFromCache(req.UserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, 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 *cacheServer) ReduceFriendFromCache(_ context.Context, req *pbCache.ReduceFriendFromCacheReq) (resp *pbCache.ReduceFriendFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.ReduceFriendFromCacheResp{CommonResp: &pbCache.CommonResp{}}
if err := db.DB.ReduceFriendToCache(req.UserID, req.FriendID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
return resp, nil
}
func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.GetBlackIDListFromCacheReq) (resp *pbCache.GetBlackIDListFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.GetBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
blackUserIDList, err := db.DB.GetBlackListFromCache(req.UserID)
blackUserIDList, err := rocksCache.GetBlackListFromCache(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
@ -301,29 +121,16 @@ func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.Ge
return resp, nil
}
func (s *cacheServer) AddBlackUserToCache(_ context.Context, req *pbCache.AddBlackUserToCacheReq) (resp *pbCache.AddBlackUserToCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.AddBlackUserToCacheResp{CommonResp: &pbCache.CommonResp{}}
if err := db.DB.AddBlackUserToCache(req.UserID, req.BlackUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), 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 *cacheServer) ReduceBlackUserFromCache(_ context.Context, req *pbCache.ReduceBlackUserFromCacheReq) (resp *pbCache.ReduceBlackUserFromCacheResp, err error) {
func (s *cacheServer) DelBlackIDListFromCache(_ context.Context, req *pbCache.DelBlackIDListFromCacheReq) (resp *pbCache.DelBlackIDListFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.ReduceBlackUserFromCacheResp{CommonResp: &pbCache.CommonResp{}}
if err := db.DB.ReduceBlackUserFromCache(req.UserID, req.BlackUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp = &pbCache.DelBlackIDListFromCacheResp{}
if err := rocksCache.DelBlackIDListFromCache(req.UserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
return resp, nil
}
@ -332,7 +139,7 @@ func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCa
resp = &pbCache.GetGroupMemberIDListFromCacheResp{
CommonResp: &pbCache.CommonResp{},
}
userIDList, err := db.DB.GetGroupMemberIDListFromCache(req.GroupID)
userIDList, err := rocksCache.GetGroupMemberIDListFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListFromCache failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
@ -344,28 +151,15 @@ func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCa
return resp, nil
}
func (s *cacheServer) AddGroupMemberToCache(_ context.Context, req *pbCache.AddGroupMemberToCacheReq) (resp *pbCache.AddGroupMemberToCacheResp, err error) {
func (s *cacheServer) DelGroupMemberIDListFromCache(_ context.Context, req *pbCache.DelGroupMemberIDListFromCacheReq) (resp *pbCache.DelGroupMemberIDListFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.AddGroupMemberToCacheResp{CommonResp: &pbCache.CommonResp{}}
if err := db.DB.AddGroupMemberToCache(req.GroupID, req.UserIDList...); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddGroupMemberToCache failed", err.Error())
resp = &pbCache.DelGroupMemberIDListFromCacheResp{}
if err := rocksCache.DelGroupMemberIDListFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.GroupID, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *cacheServer) ReduceGroupMemberFromCache(_ context.Context, req *pbCache.ReduceGroupMemberFromCacheReq) (resp *pbCache.ReduceGroupMemberFromCacheResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbCache.ReduceGroupMemberFromCacheResp{CommonResp: &pbCache.CommonResp{}}
if err := db.DB.ReduceGroupMemberFromCache(req.GroupID, req.UserIDList...); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ReduceGroupMemberFromCache failed", 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())
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
return resp, nil
}

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
cp "Open_IM/pkg/common/utils"
@ -95,10 +96,10 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
err := imdb.InsertInToUserBlackList(black)
if err != nil {
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
}
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
reqAddBlackUserToCache := &pbCache.AddBlackUserToCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
@ -106,15 +107,16 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.AddBlackUserToCache(context.Background(), reqAddBlackUserToCache)
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
if err != nil {
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc call failed ", err.Error())
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "AddBlackUserToCache rpc call failed"}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc logic call failed ", cacheResp.String())
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
chat.BlackAddedNotification(req)
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
}
@ -208,6 +210,30 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
}
}
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
resp.CommonResp.ErrMsg = errMsg
resp.CommonResp.ErrCode = 500
return &resp, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{UserID: req.FromUserID, OperationID: req.OperationID})
if err != nil {
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
resp.CommonResp.ErrCode = 500
resp.CommonResp.ErrMsg = err.Error()
return &resp, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
resp.CommonResp.ErrCode = 500
resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg
return &resp, nil
}
resp.CommonResp.ErrCode = 0
log.NewInfo(req.OperationID, "ImportFriend rpc ok ", resp.String())
return &resp, nil
@ -267,7 +293,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
// cache rpc
addFriendToCacheReq := &pbCache.AddFriendToCacheReq{OperationID: req.CommID.OperationID}
delFriendIDListFromCacheReq := &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
@ -275,29 +301,26 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
client := pbCache.NewCacheClient(etcdConn)
addFriendToCacheReq.UserID = req.CommID.ToUserID
addFriendToCacheReq.FriendID = req.CommID.FromUserID
respPb, err := client.AddFriendToCache(context.Background(), addFriendToCacheReq)
delFriendIDListFromCacheReq.UserID = req.CommID.ToUserID
respPb, err := client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq)
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String())
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
}
if respPb.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String())
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
}
addFriendToCacheReq.UserID = req.CommID.FromUserID
addFriendToCacheReq.FriendID = req.CommID.ToUserID
respPb, err = client.AddFriendToCache(context.Background(), addFriendToCacheReq)
delFriendIDListFromCacheReq.UserID = req.CommID.FromUserID
respPb, err = client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq)
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String())
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
}
if respPb.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String())
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
}
chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
}
}
@ -327,7 +350,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok")
reduceFriendFromCache := &pbCache.ReduceFriendFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID, FriendID: req.CommID.ToUserID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
@ -335,13 +358,13 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
client := pbCache.NewCacheClient(etcdConn)
respPb, err := client.ReduceFriendFromCache(context.Background(), reduceFriendFromCache)
respPb, err := client.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID})
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache rpc failed", err.Error())
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache rpc failed", err.Error())
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
}
if respPb.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed")
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
}
chat.FriendDeletedNotification(req)
@ -351,13 +374,12 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String())
//Parse token, to find current user information
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
blackListInfo, err := imdb.GetBlackListByUserID(req.CommID.FromUserID)
blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID)
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
@ -366,15 +388,14 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl
var (
userInfoList []*sdkws.PublicUserInfo
)
for _, blackUser := range blackListInfo {
var blackUserInfo sdkws.PublicUserInfo
//Find black user information
us, err := imdb.GetUserByUserID(blackUser.BlockUserID)
for _, userID := range blackIDList {
user, err := rocksCache.GetUserInfoFromCache(userID)
if err != nil {
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), blackUser.BlockUserID)
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), userID)
continue
}
utils.CopyStructFields(&blackUserInfo, us)
var blackUserInfo sdkws.PublicUserInfo
utils.CopyStructFields(&blackUserInfo, user)
userInfoList = append(userInfoList, &blackUserInfo)
}
log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok ", pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList})
@ -391,10 +412,15 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
if err != nil {
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark, err.Error())
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok")
err = rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "DelAllFriendInfoFromCache failed ", req.CommID.FromUserID, err.Error())
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
chat.FriendRemarkSetNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{}}, nil
}
@ -413,7 +439,7 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove
}
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ")
reqReduceBlackUserFromCache := &pbCache.ReduceBlackUserFromCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
@ -422,13 +448,13 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.ReduceBlackUserFromCache(context.Background(), reqReduceBlackUserFromCache)
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
if err != nil {
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc call failed ", err.Error())
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "ReduceBlackUserFromCache rpc call failed"}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc logic call failed ", cacheResp.String())
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.CommonResp.String())
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
chat.BlackDeletedNotification(req)
@ -441,10 +467,13 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
var isInBlacklist = false
err := imdb.CheckBlack(req.CommID.FromUserID, req.CommID.ToUserID)
if err == nil {
blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
return &pbFriend.IsInBlackListResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil
}
var isInBlacklist bool
if utils.IsContain(req.CommID.ToUserID, blackIDList) {
isInBlacklist = true
}
log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok ", pbFriend.IsInBlackListResp{Response: isInBlacklist})
@ -453,16 +482,18 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
log.NewInfo(req.CommID.OperationID, req.String())
var isFriend bool
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.IsFriendResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
_, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
if err == nil {
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
return &pbFriend.IsFriendResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil
}
var isFriend bool
if utils.IsContain(req.CommID.ToUserID, friendIDList) {
isFriend = true
} else {
isFriend = false
}
log.NewInfo(req.CommID.OperationID, pbFriend.IsFriendResp{Response: isFriend})
return &pbFriend.IsFriendResp{Response: isFriend}, nil
@ -474,16 +505,16 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
friends, err := imdb.GetFriendListByUserID(req.CommID.FromUserID)
friendList, err := rocksCache.GetAllFriendsInfoFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed ", err.Error(), req.CommID.FromUserID)
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache failed", err.Error(), req.CommID.FromUserID)
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
var userInfoList []*sdkws.FriendInfo
for _, friendUser := range friends {
for _, friendUser := range friendList {
friendUserInfo := sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
cp.FriendDBCopyOpenIM(&friendUserInfo, &friendUser)
cp.FriendDBCopyOpenIM(&friendUserInfo, friendUser)
log.NewDebug(req.CommID.OperationID, "friends : ", friendUser, "openim friends: ", friendUserInfo)
userInfoList = append(userInfoList, &friendUserInfo)
}

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
@ -159,7 +160,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
return resp, nil
}
utils.CopyStructFields(resp.GroupInfo, group)
resp.GroupInfo.MemberCount, err = imdb.GetGroupMemberNumByGroupID(groupId)
memberCount, err := imdb.GetGroupMemberNumByGroupID(groupId)
resp.GroupInfo.MemberCount = uint32(memberCount)
if err != nil {
log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId)
resp.ErrCode = constant.ErrDB.ErrCode
@ -182,28 +184,6 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
}
if len(okUserIDList) != 0 {
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
UserIDList: okUserIDList,
GroupID: groupId,
OperationID: req.OperationID,
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
if err != nil {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
if req.GroupInfo.GroupType != constant.SuperGroup {
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
@ -227,10 +207,10 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
//group list
joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(req.FromUserID)
joinedGroupList, err := rocksCache.GetJoinedGroupIDListFromCache(req.FromUserID)
if err != nil {
log.NewError(req.OperationID, "GetJoinedGroupIDListByUserID failed ", err.Error(), req.FromUserID)
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetJoinedGroupIDListFromCache failed", err.Error(), req.FromUserID)
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
@ -238,8 +218,14 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
for _, v := range joinedGroupList {
var groupNode open_im_sdk.GroupInfo
num, err := imdb.GetGroupMemberNumByGroupID(v)
owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v)
group, err := imdb.GetGroupInfoByGroupID(v)
groupOwnerID, err2 := rocksCache.GetGroupOwnerFromCache(v)
owner, err2 := rocksCache.GetGroupMemberInfoFromCache(v, groupOwnerID)
//owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v)
group, err := rocksCache.GetGroupInfoFromCache(v)
//group, err := imdb.GetGroupInfoByGroupID(v)
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
utils.CopyStructFields(&groupNode, group)
groupNode.CreateTime = uint32(group.CreateTime.Unix())
@ -416,11 +402,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
}
}
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
UserIDList: okUserIDList,
GroupID: req.GroupID,
OperationID: req.OperationID,
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
@ -428,17 +410,23 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if groupInfo.GroupType != constant.SuperGroup {
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
} else {
go func() {
@ -455,7 +443,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
log.NewInfo(req.OperationID, "GetGroupAllMember, args ", req.String())
var resp pbGroup.GetGroupAllMemberResp
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
//groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
resp.ErrCode = constant.ErrDB.ErrCode
@ -463,18 +452,23 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
return &resp, nil
}
if groupInfo.GroupType != constant.SuperGroup {
memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
memberList, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg
log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID)
return &resp, nil
}
//memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
//if err != nil {
// log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID)
// resp.ErrCode = constant.ErrDB.ErrCode
// resp.ErrMsg = constant.ErrDB.ErrMsg
// return &resp, nil
//}
for _, v := range memberList {
//log.Debug(req.OperationID, v)
var node open_im_sdk.GroupMemberFullInfo
cp.GroupMemberDBCopyOpenIM(&node, &v)
cp.GroupMemberDBCopyOpenIM(&node, v)
//log.Debug(req.OperationID, "db value:", v.MuteEndTime, "seconds: ", v.MuteEndTime.Unix())
//log.Debug(req.OperationID, "cp value: ", node)
resp.MemberList = append(resp.MemberList, &node)
@ -506,7 +500,6 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
} else {
resp.NextSeq = req.NextSeq + int32(len(memberList))
}
resp.ErrCode = 0
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
return &resp, nil
@ -635,11 +628,6 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
}
}
reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
UserIDList: okUserIDList,
GroupID: req.GroupID,
OperationID: req.OperationID,
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
@ -647,16 +635,23 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if groupInfo.GroupType != constant.SuperGroup {
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.MemberKickedNotification(req, okUserIDList)
} else {
go func() {
@ -664,8 +659,8 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
chat.SuperGroupNotification(req.OperationID, v, v)
}
}()
}
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
return &resp, nil
}
@ -674,20 +669,38 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
var resp pbGroup.GetGroupMembersInfoResp
resp.MemberList = []*open_im_sdk.GroupMemberFullInfo{}
//for _, v := range req.MemberList {
// var memberNode open_im_sdk.GroupMemberFullInfo
// memberInfo, err := imdb.GetMemberInfoByID(req.GroupID, v)
// memberNode.UserID = v
// if err != nil {
// log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v)
// continue
// } else {
// utils.CopyStructFields(&memberNode, memberInfo)
// memberNode.JoinTime = int32(memberInfo.JoinTime.Unix())
// resp.MemberList = append(resp.MemberList, &memberNode)
// }
//}
for _, v := range req.MemberList {
var memberNode open_im_sdk.GroupMemberFullInfo
memberInfo, err := imdb.GetMemberInfoByID(req.GroupID, v)
memberNode.UserID = v
if err != nil {
log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v)
continue
} else {
utils.CopyStructFields(&memberNode, memberInfo)
memberNode.JoinTime = int32(memberInfo.JoinTime.Unix())
groupMembers, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg
return &resp, nil
}
for _, member := range groupMembers {
if utils.IsContain(member.UserID, req.MemberList) {
var memberNode open_im_sdk.GroupMemberFullInfo
utils.CopyStructFields(&memberNode, member)
memberNode.JoinTime = int32(member.JoinTime.Unix())
resp.MemberList = append(resp.MemberList, &memberNode)
}
}
resp.ErrCode = 0
log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp.String())
return &resp, nil
@ -730,16 +743,17 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
groupsInfoList := make([]*open_im_sdk.GroupInfo, 0)
for _, groupID := range req.GroupIDList {
groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID)
//groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID)
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(groupID)
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
continue
}
var groupInfo open_im_sdk.GroupInfo
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromMysql)
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromRedis)
//groupInfo.NeedVerification
groupInfo.NeedVerification = groupInfoFromMysql.NeedVerification
groupInfo.NeedVerification = groupInfoFromRedis.NeedVerification
groupsInfoList = append(groupsInfoList, &groupInfo)
}
@ -823,23 +837,36 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
} else {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
}
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{OperationID: req.OperationID, GroupID: req.GroupID, UserIDList: []string{req.FromUserID}}
etcdCacheConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
if etcdCacheConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
if err != nil {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
group, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
if group != nil {
if group.GroupType != constant.SuperGroup {
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
}
}
chat.GroupApplicationAcceptedNotification(req)
chat.MemberEnterNotification(req)
} else if req.HandleResult == constant.GroupResponseRefuse {
@ -872,24 +899,19 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
}
if groupInfo.NeedVerification == constant.Directly {
us, err := imdb.GetUserByUserID(req.OpUserID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
//to group member
groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID}
utils.CopyStructFields(&groupMember, us)
err = imdb.InsertIntoGroupMember(groupMember)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if groupInfo.GroupType != constant.SuperGroup {
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
UserIDList: []string{req.OpUserID},
GroupID: req.GroupID,
OperationID: req.OperationID,
us, err := imdb.GetUserByUserID(req.OpUserID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
//to group member
groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID}
utils.CopyStructFields(&groupMember, us)
err = imdb.InsertIntoGroupMember(groupMember)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
@ -898,20 +920,23 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
log.NewInfo(req.OperationID, "JoinGroup rpc return ")
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
} else {
log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType)
log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType, "not support directly")
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
}
}
@ -926,7 +951,6 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
//
//_, err = imdb.GetGroupMemberListByGroupIDAndRoleLevel(req.GroupID, constant.GroupOwner)
//if err != nil {
// log.NewError(req.OperationID, "GetGroupMemberListByGroupIDAndRoleLevel failed ", err.Error(), req.GroupID, constant.GroupOwner)
@ -994,25 +1018,23 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
}
}
reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
UserIDList: []string{req.OpUserID},
GroupID: req.GroupID,
OperationID: req.OperationID,
}
etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConnCache == nil {
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConnCache)
cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
@ -1105,6 +1127,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
}
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
if changedType != 0 {
chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
@ -1187,8 +1214,10 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
chat.GroupOwnerTransferredNotification(req)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
}
@ -1379,7 +1408,7 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
return resp, http.WrapError(constant.ErrDB)
}
log.NewInfo(req.OperationID, groupMembersCount)
resp.MemberNums = groupMembersCount
resp.MemberNums = int32(groupMembersCount)
for _, groupMember := range groupMembers {
resp.Members = append(resp.Members, &open_im_sdk.GroupMemberFullInfo{
GroupID: req.GroupId,
@ -1443,27 +1472,28 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
}
}
reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
UserIDList: resp.Success,
GroupID: req.GroupId,
OperationID: req.OperationID,
}
etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConnCache == nil {
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrInternal)
return resp, http.WrapError(constant.ErrDB)
}
cacheClient := pbCache.NewCacheClient(etcdConnCache)
cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupId,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return resp, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupId); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupId)
}
chat.MemberKickedNotification(reqKick, resp.Success)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
@ -1504,27 +1534,28 @@ func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGrou
}
}
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
UserIDList: resp.Success,
GroupID: req.GroupId,
OperationID: req.OperationId,
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationId)
if etcdConn == nil {
errMsg := req.OperationId + "getcdv3.GetConn == nil"
log.NewError(req.OperationId, errMsg)
return resp, http.WrapError(constant.ErrInternal)
return resp, http.WrapError(constant.ErrDB)
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupId,
OperationID: req.OperationId,
})
if err != nil {
log.NewError(req.OperationId, "AddGroupMemberToCache rpc call failed ", err.Error())
log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationId, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return resp, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupId); err != nil {
log.NewError(req.OperationId, utils.GetSelfFuncName(), err.Error(), req.GroupId)
}
chat.MemberInvitedNotification(req.OperationId, req.GroupId, req.OpUserId, "admin add you to group", resp.Success)
return resp, nil
@ -1627,6 +1658,28 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
}
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: errMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
}
@ -1672,6 +1725,9 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
@ -1713,6 +1769,9 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
@ -1752,6 +1811,9 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
log.Error(req.OperationID, "OperateGroupStatus failed ", err.Error(), req.GroupID, constant.GroupStatusMuted)
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
@ -1791,6 +1853,9 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
log.Error(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), req.GroupID)
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
@ -1803,7 +1868,6 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
log.Error(req.OperationID, errMsg)
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
groupMemberInfo := db.GroupMember{}
groupMemberInfo.UserID = req.UserID
groupMemberInfo.GroupID = req.GroupID
@ -1824,6 +1888,9 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
log.Error(req.OperationID, errMsg)
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
@ -1856,6 +1923,9 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + ":" + err.Error()
return resp, nil
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
if req.RoleLevel != nil {
switch req.RoleLevel.Value {
case constant.GroupOrdinaryUsers:

@ -182,7 +182,7 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda
func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
err, departmentList := imdb.GetSubDepartmentList(req.DepartmentID)
departmentList, err := imdb.GetSubDepartmentList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
@ -477,7 +477,7 @@ func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rp
func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
err, departmentMemberList := imdb.GetDepartmentMemberList(req.DepartmentID)
departmentMemberList, err := imdb.GetDepartmentMemberList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/db/rocks_cache"
errors "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
@ -112,7 +113,7 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
if len(req.UserIDList) > 0 {
for _, userID := range req.UserIDList {
var userInfo sdkws.UserInfo
user, err := imdb.GetUserByUserID(userID)
user, err := rocksCache.GetUserInfoFromCache(userID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), userID)
continue
@ -401,36 +402,24 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID},
}
RpcResp, err := client.GetFriendList(context.Background(), newReq)
rpcResp, err := client.GetFriendList(context.Background(), newReq)
if err != nil {
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil
}
for _, v := range RpcResp.FriendInfoList {
for _, v := range rpcResp.FriendInfoList {
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID)
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID)
}
if err := rocksCache.DelUserInfoFromCache(user.UserID); err != nil {
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
}
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID)
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID)
if req.UserInfo.FaceURL != "" {
go s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID)
}
//updateUserInfoToCacheReq := &cache.UpdateUserInfoToCacheReq{
// OperationID: req.OperationID,
// UserInfoList: []*sdkws.UserInfo{req.UserInfo},
//}
//cacheEtcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
//cacheClient := cache.NewCacheClient(cacheEtcdConn)
//resp, err := cacheClient.UpdateUserInfoToCache(context.Background(), updateUserInfoToCacheReq)
//if err != nil {
// log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), updateUserInfoToCacheReq.String())
// return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: err.Error()}}, nil
//}
//if resp.CommonResp.ErrCode != 0 {
// log.NewError(req.OperationID, utils.GetSelfFuncName(), resp.String())
// return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: resp.CommonResp.ErrMsg}}, nil
//}
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
}
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) {
@ -456,15 +445,22 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
return &pbUser.SetGlobalRecvMessageOptResp{CommonResp: &pbUser.CommonResp{}}, nil
}
func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string, operationID string, opUserID string) {
joinedGroupIDList, err := imdb.GetJoinedGroupIDListByUserID(userID)
joinedGroupIDList, err := rocksCache.GetJoinedGroupIDListFromCache(userID)
if err != nil {
log.NewWarn(operationID, "GetJoinedGroupIDListByUserID failed ", userID, err.Error())
return
}
for _, v := range joinedGroupIDList {
groupMemberInfo := db.GroupMember{UserID: userID, GroupID: v, FaceURL: faceURL}
imdb.UpdateGroupMemberInfo(groupMemberInfo)
chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID)
for _, groupID := range joinedGroupIDList {
groupMemberInfo := db.GroupMember{UserID: userID, GroupID: groupID, FaceURL: faceURL}
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
continue
}
if err := rocksCache.DelAllGroupMembersInfoFromCache(groupID); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID)
continue
}
chat.GroupMemberInfoSetNotification(operationID, opUserID, groupID, userID)
}
}

@ -9,7 +9,6 @@ import (
pbCommon "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"errors"
"fmt"
go_redis "github.com/go-redis/redis/v8"
@ -18,6 +17,7 @@ import (
"strconv"
"time"
)
const (
accountTempCode = "ACCOUNT_TEMP_CODE"
resetPwdTempCode = "RESET_PWD_TEMP_CODE"
@ -27,17 +27,12 @@ const (
uidPidToken = "UID_PID_TOKEN_STATUS:"
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
getuiToken = "GETUI_TOKEN"
userInfoCache = "USER_INFO_CACHE:"
friendRelationCache = "FRIEND_RELATION_CACHE:"
blackListCache = "BLACK_LIST_CACHE:"
groupCache = "GROUP_CACHE:"
messageCache = "MESSAGE_CACHE:"
SignalCache = "SIGNAL_CACHE:"
SignalListCache = "SIGNAL_LIST_CACHE:"
GlobalMsgRecvOpt = "GLOBAL_MSG_RECV_OPT"
)
//func (d * DataBases)pubMessage(channel, msg string) {
// d.rdb.Publish(context.Background(),channel,msg)
//}
@ -346,84 +341,3 @@ func (d *DataBases) GetGetuiToken() (string, error) {
result := d.rdb.Get(context.Background(), getuiToken)
return result.String(), result.Err()
}
func (d *DataBases) AddFriendToCache(userID string, friendIDList ...string) error {
var IDList []interface{}
for _, id := range friendIDList {
IDList = append(IDList, id)
}
return d.rdb.SAdd(context.Background(), friendRelationCache+userID, IDList...).Err()
}
func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...string) error {
var IDList []interface{}
for _, id := range friendIDList {
IDList = append(IDList, id)
}
return d.rdb.SRem(context.Background(), friendRelationCache+userID, IDList...).Err()
}
func (d *DataBases) GetFriendIDListFromCache(userID string) ([]string, error) {
result := d.rdb.SMembers(context.Background(), friendRelationCache+userID)
return result.Result()
}
func (d *DataBases) AddBlackUserToCache(userID string, blackList ...string) error {
var IDList []interface{}
for _, id := range blackList {
IDList = append(IDList, id)
}
return d.rdb.SAdd(context.Background(), blackListCache+userID, IDList...).Err()
}
func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...string) error {
var IDList []interface{}
for _, id := range blackList {
IDList = append(IDList, id)
}
return d.rdb.SRem(context.Background(), blackListCache+userID, IDList...).Err()
}
func (d *DataBases) GetBlackListFromCache(userID string) ([]string, error) {
result := d.rdb.SMembers(context.Background(), blackListCache+userID)
return result.Result()
}
func (d *DataBases) AddGroupMemberToCache(groupID string, userIDList ...string) error {
var IDList []interface{}
for _, id := range userIDList {
IDList = append(IDList, id)
}
return d.rdb.SAdd(context.Background(), groupCache+groupID, IDList...).Err()
}
func (d *DataBases) ReduceGroupMemberFromCache(groupID string, userIDList ...string) error {
var IDList []interface{}
for _, id := range userIDList {
IDList = append(IDList, id)
}
return d.rdb.SRem(context.Background(), groupCache+groupID, IDList...).Err()
}
func (d *DataBases) GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
result := d.rdb.SMembers(context.Background(), groupCache+groupID)
return result.Result()
}
func (d *DataBases) SetUserInfoToCache(userID string, m map[string]interface{}) error {
return d.rdb.HSet(context.Background(), userInfoCache+userID, m).Err()
}
func (d *DataBases) GetUserInfoFromCache(userID string) (*pbCommon.UserInfo, error) {
result, err := d.rdb.HGetAll(context.Background(), userInfoCache+userID).Result()
bytes, err := json.Marshal(result)
if err != nil {
return nil, err
}
userInfo := &pbCommon.UserInfo{}
if err := proto.Unmarshal(bytes, userInfo); err != nil {
return nil, err
}
err = json.Unmarshal(bytes, userInfo)
return userInfo, err
}

@ -37,7 +37,6 @@ type RedisClient struct {
client *go_redis.Client
cluster *go_redis.ClusterClient
go_redis.UniversalClient
enableCluster bool
}
func key(dbAddress, dbName string) string {
@ -90,16 +89,14 @@ func init() {
if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil {
fmt.Println("work_moment_id", "index create failed", err.Error())
}
if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil {
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
}
if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil {
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
}
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
fmt.Println("tag_id", "index create failed", err.Error())
}
fmt.Println("create index success")
DB.mongoClient = mongoClient
@ -145,14 +142,12 @@ func init() {
}
}
DB.rc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
DB.Rc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
Addr: config.Config.Redis.DBAddress[0],
Password: config.Config.Redis.DBPassWord, // no password set
DB: 0, // use default DB
PoolSize: 100, // 连接池大小
}), rockscache.NewDefaultOptions())
DB.rc.Options.StrongConsistency = true
}
func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error {

@ -7,13 +7,13 @@ import (
"sync"
"time"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type mysqlDB struct {
sync.RWMutex
dbMap map[string]*gorm.DB
db *gorm.DB
}
func initMysqlDB() {
@ -22,13 +22,13 @@ func initMysqlDB() {
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
var db *gorm.DB
var err1 error
db, err := gorm.Open("mysql", dsn)
db, err := gorm.Open(mysql.Open(dsn), nil)
if err != nil {
fmt.Println("0", "Open failed ", err.Error(), dsn)
}
if err != nil {
time.Sleep(time.Duration(30) * time.Second)
db, err1 = gorm.Open("mysql", dsn)
db, err1 = gorm.Open(mysql.Open(dsn), nil)
if err1 != nil {
fmt.Println("0", "Open failed ", err1.Error(), dsn)
panic(err1.Error())
@ -42,11 +42,10 @@ func initMysqlDB() {
fmt.Println("0", "Exec failed ", err.Error(), sql)
panic(err.Error())
}
db.Close()
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)
db, err = gorm.Open("mysql", dsn)
db, err = gorm.Open(mysql.Open(dsn), nil)
if err != nil {
fmt.Println("0", "Open failed ", err.Error(), dsn)
panic(err.Error())
@ -65,103 +64,70 @@ func initMysqlDB() {
db.Set("gorm:table_options", "CHARSET=utf8")
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
if !db.HasTable(&Friend{}) {
if !db.Migrator().HasTable(&Friend{}) {
fmt.Println("CreateTable Friend")
db.CreateTable(&Friend{})
db.Migrator().CreateTable(&Friend{})
}
if !db.HasTable(&FriendRequest{}) {
if !db.Migrator().HasTable(&FriendRequest{}) {
fmt.Println("CreateTable FriendRequest")
db.CreateTable(&FriendRequest{})
db.Migrator().CreateTable(&FriendRequest{})
}
if !db.HasTable(&Group{}) {
if !db.Migrator().HasTable(&Group{}) {
fmt.Println("CreateTable Group")
db.CreateTable(&Group{})
db.Migrator().CreateTable(&Group{})
}
if !db.HasTable(&GroupMember{}) {
if !db.Migrator().HasTable(&GroupMember{}) {
fmt.Println("CreateTable GroupMember")
db.CreateTable(&GroupMember{})
db.Migrator().CreateTable(&GroupMember{})
}
if !db.HasTable(&GroupRequest{}) {
if !db.Migrator().HasTable(&GroupRequest{}) {
fmt.Println("CreateTable GroupRequest")
db.CreateTable(&GroupRequest{})
db.Migrator().CreateTable(&GroupRequest{})
}
if !db.HasTable(&User{}) {
if !db.Migrator().HasTable(&User{}) {
fmt.Println("CreateTable User")
db.CreateTable(&User{})
db.Migrator().CreateTable(&User{})
}
if !db.HasTable(&Black{}) {
if !db.Migrator().HasTable(&Black{}) {
fmt.Println("CreateTable Black")
db.CreateTable(&Black{})
db.Migrator().CreateTable(&Black{})
}
if !db.HasTable(&ChatLog{}) {
if !db.Migrator().HasTable(&ChatLog{}) {
fmt.Println("CreateTable ChatLog")
db.CreateTable(&ChatLog{})
db.Migrator().CreateTable(&ChatLog{})
}
if !db.HasTable(&Register{}) {
if !db.Migrator().HasTable(&Register{}) {
fmt.Println("CreateTable Register")
db.CreateTable(&Register{})
db.Migrator().CreateTable(&Register{})
}
if !db.HasTable(&Conversation{}) {
if !db.Migrator().HasTable(&Conversation{}) {
fmt.Println("CreateTable Conversation")
db.CreateTable(&Conversation{})
db.Migrator().CreateTable(&Conversation{})
}
if !db.HasTable(&Department{}) {
if !db.Migrator().HasTable(&Department{}) {
fmt.Println("CreateTable Department")
db.CreateTable(&Department{})
db.Migrator().CreateTable(&Department{})
}
if !db.HasTable(&OrganizationUser{}) {
if !db.Migrator().HasTable(&OrganizationUser{}) {
fmt.Println("CreateTable OrganizationUser")
db.CreateTable(&OrganizationUser{})
db.Migrator().CreateTable(&OrganizationUser{})
}
if !db.HasTable(&DepartmentMember{}) {
if !db.Migrator().HasTable(&DepartmentMember{}) {
fmt.Println("CreateTable DepartmentMember")
db.CreateTable(&DepartmentMember{})
db.Migrator().CreateTable(&DepartmentMember{})
}
if !db.HasTable(&AppVersion{}) {
if !db.Migrator().HasTable(&AppVersion{}) {
fmt.Println("CreateTable DepartmentMember")
db.CreateTable(&AppVersion{})
db.Migrator().CreateTable(&AppVersion{})
}
DB.MysqlDB.db = db
return
}
func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) {
return m.GormDB(config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
}
func (m *mysqlDB) GormDB(dbAddress, dbName string) (*gorm.DB, error) {
m.Lock()
defer m.Unlock()
k := key(dbAddress, dbName)
if _, ok := m.dbMap[k]; !ok {
if err := m.open(dbAddress, dbName); err != nil {
return nil, err
}
}
return m.dbMap[k], nil
}
func (m *mysqlDB) open(dbAddress, dbName string) error {
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, dbAddress, dbName)
db, err := gorm.Open("mysql", dsn)
if err != nil {
return err
}
db.SingularTable(true)
db.DB().SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
db.DB().SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
db.DB().SetConnMaxLifetime(time.Duration(config.Config.Mysql.DBMaxLifeTime) * time.Second)
if m.dbMap == nil {
m.dbMap = make(map[string]*gorm.DB)
}
k := key(dbAddress, dbName)
m.dbMap[k] = db
return nil
func (m *mysqlDB) DefaultGormDB() *gorm.DB {
return DB.MysqlDB.db
}

@ -7,99 +7,65 @@ import (
)
func SetConversation(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
// if exist, then update record
} else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
//force update
return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat,
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat,
"group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error
}
}
func SetOneConversation(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
}
func PeerUserSetConversation(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
// if exist, then update record
}
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
//force update
return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Update(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Updates(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error
}
func SetRecvMsgOpt(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
// if exist, then update record
} else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
//force update
return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
}
}
func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversations, err
}
dbConn.LogMode(false)
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
return conversations, err
}
func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]db.Conversation, error) {
var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversations, err
}
dbConn.LogMode(false)
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
return conversations, err
}
func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var resultArr []string
err = dbConn.Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error
if err != nil {
return nil, err
}
@ -108,38 +74,21 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str
func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) {
var conversation db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversation, err
}
err = dbConn.Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
return conversation, err
}
func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) {
var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversations, err
}
err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
return conversations, err
}
func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) {
var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversations, err
}
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
return conversations, err
}
func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
return dbConn.Debug().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
}

@ -2,16 +2,12 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
_ "github.com/jinzhu/gorm"
_ "gorm.io/gorm"
)
func GetRegister(account, areaCode, userID string) (*db.Register, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var r db.Register
return &r, dbConn.Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?",
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?",
userID, "", account, account, areaCode).Take(&r).Error
}
@ -23,21 +19,12 @@ func SetPassword(account, password, ex, userID, areaCode string) error {
UserID: userID,
AreaCode: areaCode,
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
return dbConn.Table("registers").Create(&r).Error
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Create(&r).Error
}
func ResetPassword(account, password string) error {
r := db.Register{
Password: password,
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(false)
if err != nil {
return err
}
return dbConn.Table("registers").Where("account = ?", account).Update(&r).Error
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("account = ?", account).Updates(&r).Error
}

@ -6,10 +6,6 @@ import (
)
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
updateTime := int(time.Now().Unix())
app := db.AppVersion{
Version: version,
@ -20,24 +16,19 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
ForceUpdate: forceUpdate,
UpdateLog: updateLog,
}
result := dbConn.Model(db.AppVersion{}).Where("type = ?", appType).Update(map[string]interface{}{"force_update": forceUpdate,
result := db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
err := dbConn.Create(&app).Error
err := db.DB.MysqlDB.DefaultGormDB().Create(&app).Error
return err
}
return nil
}
func GetNewestVersion(appType int) (*db.AppVersion, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
app := db.AppVersion{}
if err != nil {
return &app, err
}
dbConn.LogMode(true)
return &app, dbConn.Model(db.AppVersion{}).First(&app, appType).Error
return &app, db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).First(&app, appType).Error
}

@ -7,13 +7,8 @@ import (
)
func InsertToFriend(toInsertFollow *db.Friend) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
toInsertFollow.CreateTime = time.Now()
err = dbConn.Table("friends").Create(toInsertFollow).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error
if err != nil {
return err
}
@ -21,12 +16,8 @@ func InsertToFriend(toInsertFollow *db.Friend) error {
}
func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Friend, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friend db.Friend
err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
if err != nil {
return nil, err
}
@ -34,15 +25,10 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Frie
}
func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friends []db.Friend
var x db.Friend
x.OwnerUserID = OwnerUserID
err = dbConn.Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
if err != nil {
return nil, err
}
@ -50,12 +36,8 @@ func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) {
}
func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friendIDList []string
err = dbConn.Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error
if err != nil {
return nil, err
}
@ -63,29 +45,9 @@ func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
}
func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
return err
return db.DB.MysqlDB.DefaultGormDB().Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
}
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
return err
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
}
//type Friend struct {
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
// FriendUserID string `gorm:"column:friend_user_id;primaryKey;"`
// Remark string `gorm:"column:remark"`
// CreateTime time.Time `gorm:"column:create_time"`
// AddSource int32 `gorm:"column:add_source"`
// OperatorUserID string `gorm:"column:operator_user_id"`
// Ex string `gorm:"column:ex"`
//}

@ -20,12 +20,8 @@ import (
// who apply to add me
func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var usersInfo []db.FriendRequest
err = dbConn.Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
if err != nil {
return nil, err
}
@ -34,12 +30,8 @@ func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequ
//I apply to add somebody
func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var usersInfo []db.FriendRequest
err = dbConn.Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
if err != nil {
return nil, err
}
@ -48,12 +40,8 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest
//FromUserId apply to add ToUserID
func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friendRequest db.FriendRequest
err = dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
if err != nil {
return nil, err
}
@ -61,23 +49,13 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRe
}
func UpdateFriendApplication(friendRequest *db.FriendRequest) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
friendRequest.CreateTime = time.Now()
return dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?",
friendRequest.FromUserID, friendRequest.ToUserID).Updates(&friendRequest).Error
}
func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if err = dbConn.Table("friend_requests").Create(friendRequest).Error; err == nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error; err == nil {
return nil
}
@ -89,7 +67,7 @@ func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]in
friendRequest.CreateTime = time.Now()
args["create_time"] = friendRequest.CreateTime
u := dbConn.Model(friendRequest).Updates(args)
u := db.DB.MysqlDB.DefaultGormDB().Model(friendRequest).Updates(args)
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
@ -104,7 +82,7 @@ func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]in
if friendRequest.HandleTime.Unix() < 0 {
friendRequest.HandleTime = utils.UnixSecondToTime(0)
}
err = dbConn.Table("friend_requests").Create(friendRequest).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error
if err != nil {
return err
}

@ -22,16 +22,12 @@ import (
//}
func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
toInsertInfo.JoinTime = time.Now()
if toInsertInfo.RoleLevel == 0 {
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
}
toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
err = dbConn.Table("group_members").Create(toInsertInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
if err != nil {
return err
}
@ -39,12 +35,8 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
}
func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMemberList []db.GroupMember
err = dbConn.Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
//err = dbConn.Table("group_members").Where("user_id=?", userID).Take(&groupMemberList).Error
if err != nil {
return nil, err
@ -53,13 +45,8 @@ func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) {
}
func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMemberList []db.GroupMember
err = dbConn.Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
if err != nil {
return nil, err
}
@ -67,13 +54,8 @@ func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) {
}
func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
dbConn.LogMode(false)
var groupMemberIDList []string
err = dbConn.Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
if err != nil {
return nil, err
}
@ -81,12 +63,8 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
}
func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMemberList []db.GroupMember
err = dbConn.Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
if err != nil {
return nil, err
}
@ -94,12 +72,8 @@ func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([
}
func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMember db.GroupMember
err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
if err != nil {
return nil, err
}
@ -107,73 +81,33 @@ func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMemb
}
func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error
if err != nil {
return err
}
return nil
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error
}
func DeleteGroupMemberByGroupID(groupID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error
if err != nil {
return err
}
return nil
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error
}
func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Update(&groupMemberInfo).Error
if err != nil {
return err
}
return nil
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error
}
func UpdateGroupMemberInfoByMap(groupMemberInfo db.GroupMember, m map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
if err != nil {
return err
}
return nil
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
}
func GetOwnerManagerByGroupID(groupID string) ([]db.GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMemberList []db.GroupMember
err = dbConn.Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
if err != nil {
return nil, err
}
return groupMemberList, nil
}
func GetGroupMemberNumByGroupID(groupID string) (uint32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, utils.Wrap(err, "DefaultGormDB failed")
}
var number uint32
err = dbConn.Table("group_members").Where("group_id=?", groupID).Count(&number).Error
func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
var number int64
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error
if err != nil {
return 0, utils.Wrap(err, "")
}
@ -195,12 +129,8 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*db.GroupMember, error) {
}
func IsExistGroupMember(groupID, userID string) bool {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return false
}
var number int32
err = dbConn.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
var number int64
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
if err != nil {
return false
}
@ -270,36 +200,23 @@ func IsGroupOwnerAdmin(groupID, UserID string) bool {
func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]db.GroupMember, error) {
var groupMembers []db.GroupMember
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return groupMembers, err
}
err = dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groupMembers).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
if err != nil {
return nil, err
}
return groupMembers, nil
}
func GetGroupMembersCount(groupId, userName string) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var count int32
if err != nil {
return count, err
}
dbConn.LogMode(false)
if err := dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
func GetGroupMembersCount(groupId, userName string) (int64, error) {
var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
return count, err
}
return count, nil
}
func UpdateGroupMemberInfoDefaultZero(groupMemberInfo db.GroupMember, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
return dbConn.Model(groupMemberInfo).Updates(args).Error
return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
}
//

@ -3,10 +3,9 @@ package im_mysql_model
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/utils"
"errors"
"fmt"
"github.com/jinzhu/gorm"
"gorm.io/gorm"
"time"
)
@ -24,15 +23,11 @@ import (
//}
func InsertIntoGroup(groupInfo db.Group) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if groupInfo.GroupName == "" {
groupInfo.GroupName = "Group Chat"
}
groupInfo.CreateTime = time.Now()
err = dbConn.Table("groups").Create(groupInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Create(groupInfo).Error
if err != nil {
return err
}
@ -40,12 +35,8 @@ func InsertIntoGroup(groupInfo db.Group) error {
}
func GetGroupInfoByGroupID(groupId string) (*db.Group, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, utils.Wrap(err, "")
}
var groupInfo db.Group
err = dbConn.Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error
if err != nil {
return nil, err
}
@ -53,33 +44,18 @@ func GetGroupInfoByGroupID(groupId string) (*db.Group, error) {
}
func SetGroupInfo(groupInfo db.Group) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error
return err
return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error
}
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]db.Group, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var groups []db.Group
if err != nil {
return groups, err
}
err = dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
return groups, err
}
func GetGroups(pageNumber, showNumber int) ([]db.Group, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var groups []db.Group
if err != nil {
return groups, err
}
if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
return groups, err
}
return groups, nil
@ -97,27 +73,18 @@ func OperateGroupStatus(groupId string, groupStatus int32) error {
}
func DeleteGroup(groupId string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
var group db.Group
var groupMembers []db.GroupMember
if err := dbConn.Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
return err
}
if err := dbConn.Table("group_members").Where("group_id=?", groupId).Delete(groupMembers).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Delete(groupMembers).Error; err != nil {
return err
}
return nil
}
func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return "", "", err
}
groupMember := db.GroupMember{
UserID: userId,
GroupID: groupId,
@ -126,10 +93,11 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
RoleLevel: roleLevel,
}
groupMaster := db.GroupMember{}
var err error
switch roleLevel {
case constant.GroupOwner:
err = dbConn.Transaction(func(tx *gorm.DB) error {
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{
err = db.DB.MysqlDB.DefaultGormDB().Transaction(func(tx *gorm.DB) error {
result := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Updates(&db.GroupMember{
RoleLevel: constant.GroupOrdinaryUsers,
})
if result.Error != nil {
@ -139,7 +107,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
result = dbConn.Table("group_members").First(&groupMember).Update(updateInfo)
result = db.DB.MysqlDB.DefaultGormDB().Table("group_members").First(&groupMember).Updates(updateInfo)
if result.Error != nil {
return result.Error
}
@ -150,8 +118,8 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
})
case constant.GroupOrdinaryUsers:
err = dbConn.Transaction(func(tx *gorm.DB) error {
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
err = db.DB.MysqlDB.DefaultGormDB().Transaction(func(tx *gorm.DB) error {
result := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
if result.Error != nil {
return result.Error
}
@ -161,7 +129,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
if groupMaster.UserID == userId {
return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId))
} else {
result = dbConn.Table("group_members").Find(&groupMember).Update(updateInfo)
result = db.DB.MysqlDB.DefaultGormDB().Table("group_members").Find(&groupMember).Updates(updateInfo)
if result.Error != nil {
return result.Error
}
@ -172,64 +140,41 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
return nil
})
}
return "", "", nil
return "", "", err
}
func GetGroupsCountNum(group db.Group) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
var count int32
if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
return 0, err
}
return count, nil
return int32(count), nil
}
func GetGroupById(groupId string) (db.Group, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
group := db.Group{
GroupID: groupId,
}
if err != nil {
return group, err
}
if err := dbConn.Table("groups").Find(&group).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Find(&group).Error; err != nil {
return group, err
}
return group, nil
}
func GetGroupMaster(groupId string) (db.GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
groupMember := db.GroupMember{}
if err != nil {
return groupMember, err
}
if err := dbConn.Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil {
return groupMember, err
}
return groupMember, nil
}
func UpdateGroupInfoDefaultZero(groupID string, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
return dbConn.Table("groups").Where("group_id = ? ", groupID).Update(args).Error
return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id = ? ", groupID).Updates(args).Error
}
func GetAllGroupIDList() ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupIDList []string
err = dbConn.Table("groups").Pluck("group_id", &groupIDList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Pluck("group_id", &groupIDList).Error
return groupIDList, err
}

@ -20,27 +20,18 @@ import (
//}
func UpdateGroupRequest(groupRequest db.GroupRequest) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if groupRequest.HandledTime.Unix() < 0 {
groupRequest.HandledTime = utils.UnixSecondToTime(0)
}
return dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).Error
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
}
func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if toInsertInfo.HandledTime.Unix() < 0 {
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
}
u := dbConn.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Update(&toInsertInfo)
u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
if u.RowsAffected != 0 {
return nil
}
@ -50,7 +41,7 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
}
err = dbConn.Table("group_requests").Create(&toInsertInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
if err != nil {
return err
}
@ -58,12 +49,8 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
}
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupRequest db.GroupRequest
err = dbConn.Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
if err != nil {
return nil, err
}
@ -71,24 +58,12 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest
}
func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error
if err != nil {
return err
}
return nil
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error
}
func GetGroupRequestByGroupID(groupID string) ([]db.GroupRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupRequestList []db.GroupRequest
err = dbConn.Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
if err != nil {
return nil, err
}
@ -119,12 +94,7 @@ func GetGroupApplicationList(userID string) ([]db.GroupRequest, error) {
func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) {
var groupRequestList []db.GroupRequest
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
dbConn.LogMode(false)
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
return groupRequestList, err
}

@ -8,15 +8,10 @@ import (
)
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var chatLogs []db.ChatLog
if err != nil {
return chatLogs, err
}
dbConn.LogMode(false)
db := dbConn.Table("chat_logs").
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
if chatLog.SessionType != 0 {
db = db.Where("session_type = ?", chatLog.SessionType)
}
@ -32,19 +27,14 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
if chatLog.SendTime.Unix() > 0 {
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
err = db.Find(&chatLogs).Error
err := db.Find(&chatLogs).Error
return chatLogs, err
}
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var chatLogs []db.ChatLog
var count int64
if err != nil {
return count, err
}
dbConn.LogMode(false)
db := dbConn.Table("chat_logs").
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
if chatLog.SessionType != 0 {
db = db.Where("session_type = ?", chatLog.SessionType)
@ -63,6 +53,6 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
err = db.Find(&chatLogs).Count(&count).Error
err := db.Find(&chatLogs).Count(&count).Error
return count, err
}

@ -3,175 +3,116 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/utils"
"github.com/jinzhu/gorm"
"gorm.io/gorm"
"time"
)
func CreateDepartment(department *db.Department) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
department.CreateTime = time.Now()
return dbConn.Table("departments").Create(department).Error
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error
}
func GetDepartment(departmentID string) (*db.Department, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var department db.Department
err = dbConn.Table("departments").Where("department_id=?", departmentID).Find(&department).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error
return &department, err
}
func UpdateDepartment(department *db.Department, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if err = dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
return err
}
if args != nil {
return dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
}
return nil
}
func GetSubDepartmentList(departmentID string) (error, []db.Department) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err, nil
}
func GetSubDepartmentList(departmentID string) ([]db.Department, error) {
var departmentList []db.Department
var err error
if departmentID == "-1" {
err = dbConn.Table("departments").Find(&departmentList).Error
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Find(&departmentList).Error
} else {
err = dbConn.Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
}
return err, departmentList
return departmentList, err
}
func DeleteDepartment(departmentID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
var err error
if err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil {
return err
}
if err = dbConn.Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil {
return err
}
if err = dbConn.Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil {
if err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil {
return err
}
return nil
}
func CreateOrganizationUser(organizationUser *db.OrganizationUser) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
organizationUser.CreateTime = time.Now()
return dbConn.Table("organization_users").Create(organizationUser).Error
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error
}
func GetOrganizationUser(userID string) (error, *db.OrganizationUser) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err, nil
}
organizationUser := db.OrganizationUser{}
err = dbConn.Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
return err, &organizationUser
}
func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if err = dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
return err
}
if args != nil {
return dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
}
return nil
}
func CreateDepartmentMember(departmentMember *db.DepartmentMember) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
departmentMember.CreateTime = time.Now()
return dbConn.Table("department_members").Create(departmentMember).Error
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error
}
func GetUserInDepartment(userID string) (error, []db.DepartmentMember) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err, nil
}
var departmentMemberList []db.DepartmentMember
err = dbConn.Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
return err, departmentMemberList
}
func UpdateUserInDepartment(departmentMember *db.DepartmentMember, args map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
if err = dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
if err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
Updates(departmentMember).Error; err != nil {
return err
}
if args != nil {
return dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
Updates(args).Error
}
return nil
}
func DeleteUserInDepartment(departmentID, userID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
return dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error
}
func DeleteUserInAllDepartment(userID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
return dbConn.Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error
}
func DeleteOrganizationUser(OrganizationUserID string) error {
if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil {
return err
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
return dbConn.Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error
}
func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err, nil
}
var departmentMemberList []db.DepartmentMember
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
if err != nil {
return err, nil
}
@ -182,77 +123,54 @@ func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
return err, userIDList
}
func GetDepartmentMemberList(departmentID string) (error, []db.DepartmentMember) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err, nil
}
func GetDepartmentMemberList(departmentID string) ([]db.DepartmentMember, error) {
var departmentMemberList []db.DepartmentMember
var err error
if departmentID == "-1" {
err = dbConn.Table("department_members").Find(&departmentMemberList).Error
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Find(&departmentMemberList).Error
} else {
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
}
if err != nil {
return err, nil
return nil, err
}
return err, departmentMemberList
return departmentMemberList, err
}
func GetAllOrganizationUserID() (error, []string) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err, nil
}
var OrganizationUser db.OrganizationUser
var result []string
return dbConn.Model(&OrganizationUser).Pluck("user_id", &result).Error, result
return db.DB.MysqlDB.DefaultGormDB().Model(&OrganizationUser).Pluck("user_id", &result).Error, result
}
func GetDepartmentMemberNum(departmentID string) (error, uint32) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return utils.Wrap(err, "DefaultGormDB failed"), 0
}
var number uint32
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Count(&number).Error
var number int64
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Count(&number).Error
if err != nil {
return utils.Wrap(err, ""), 0
}
return nil, number
return nil, uint32(number)
}
func GetSubDepartmentNum(departmentID string) (error, uint32) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return utils.Wrap(err, "DefaultGormDB failed"), 0
}
var number uint32
err = dbConn.Table("departments").Where("parent_id=?", departmentID).Count(&number).Error
var number int64
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Count(&number).Error
if err != nil {
return utils.Wrap(err, ""), 0
}
return nil, number
return nil, uint32(number)
}
func SetDepartmentRelatedGroupID(groupID, departmentID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return utils.Wrap(err, "DefaultGormDB failed")
}
department := &db.Department{RelatedGroupID: groupID}
return dbConn.Model(&department).Where("department_id=?", departmentID).Update(department).Error
return db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Updates(department).Error
}
func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, utils.Wrap(err, "DefaultGormDB failed")
}
var groupIDList []string
err = dbConn.Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
return groupIDList, err
}
@ -260,8 +178,7 @@ func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department,
var department db.Department
var parentDepartment db.Department
//var parentID string
dbConn.LogMode(true)
err := dbConn.Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
if err != nil {
return nil, utils.Wrap(err, "")
}
@ -287,21 +204,14 @@ func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList *[]s
}
func GetDepartmentParentIDList(departmentID string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
dbConn := db.DB.MysqlDB.DefaultGormDB()
var parentIDList []string
err = GetDepartmentParent(departmentID, dbConn, &parentIDList)
err := GetDepartmentParent(departmentID, dbConn, &parentIDList)
return parentIDList, err
}
func GetRandomDepartmentID() (string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return "", err
}
department := &db.Department{}
err = dbConn.Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error
return department.DepartmentID, err
}

@ -6,102 +6,57 @@ import (
)
func GetActiveUserNum(from, to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return int32(num), err
}
func GetIncreaseUserNum(from, to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return int32(num), err
}
func GetTotalUserNum() (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Count(&num).Error
return int32(num), err
}
func GetTotalUserNumByDate(to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time <= ?", to).Count(&num).Error
return int32(num), err
}
func GetPrivateMessageNum(from, to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
return int32(num), err
}
func GetGroupMessageNum(from, to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
return int32(num), err
}
func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return int32(num), err
}
func GetTotalGroupNum() (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Count(&num).Error
return int32(num), err
}
func GetGroupNum(to time.Time) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
return num, err
var num int64
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time <= ?", to).Count(&num).Error
return int32(num), err
}
type activeGroup struct {
@ -111,18 +66,13 @@ type activeGroup struct {
}
func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var activeGroups []*activeGroup
if err != nil {
return activeGroups, err
}
dbConn.LogMode(false)
err = dbConn.Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
for _, activeGroup := range activeGroups {
group := db.Group{
GroupID: activeGroup.Id,
}
dbConn.Table("groups").Where("group_id= ? ", group.GroupID).Find(&group)
db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id= ? ", group.GroupID).Find(&group)
activeGroup.Name = group.GroupName
}
return activeGroups, err
@ -135,18 +85,13 @@ type activeUser struct {
}
func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var activeUsers []*activeUser
if err != nil {
return activeUsers, err
}
dbConn.LogMode(false)
err = dbConn.Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
for _, activeUser := range activeUsers {
user := db.User{
UserID: activeUser.Id,
}
dbConn.Table("users").Select("user_id, name").Find(&user)
db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user)
activeUser.Name = user.Nickname
}
return activeUsers, err

@ -7,13 +7,8 @@ import (
)
func InsertInToUserBlackList(black db.Black) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
black.CreateTime = time.Now()
err = dbConn.Table("blacks").Create(black).Error
return err
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
}
//type Black struct {
@ -26,31 +21,18 @@ func InsertInToUserBlackList(black db.Black) error {
//}
func CheckBlack(ownerUserID, blockUserID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
var black db.Black
err = dbConn.Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
return err
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
}
func RemoveBlackList(ownerUserID, blockUserID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error
return utils.Wrap(err, "RemoveBlackList failed")
}
func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var blackListUsersInfo []db.Black
err = dbConn.Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
if err != nil {
return nil, err
}
@ -58,12 +40,8 @@ func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
}
func GetBlackIDListByUserID(ownerUserID string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var blackIDList []string
err = dbConn.Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
if err != nil {
return nil, err
}

@ -7,8 +7,6 @@ import (
"Open_IM/pkg/utils"
"fmt"
"time"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func init() {
@ -37,10 +35,6 @@ func init() {
}
func UserRegister(user db.User) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
user.CreateTime = time.Now()
if user.AppMangerLevel == 0 {
user.AppMangerLevel = constant.AppOrdinaryUsers
@ -48,7 +42,7 @@ func UserRegister(user db.User) error {
if user.Birth.Unix() < 0 {
user.Birth = utils.UnixSecondToTime(0)
}
err = dbConn.Table("users").Create(&user).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
if err != nil {
return err
}
@ -56,31 +50,19 @@ func UserRegister(user db.User) error {
}
func DeleteUser(userID string) (i int64) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0
}
i = dbConn.Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected
i = db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected
return i
}
func GetAllUser() ([]db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var userList []db.User
err = dbConn.Table("users").Find(&userList).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error
return userList, err
}
func GetUserByUserID(userID string) (*db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var user db.User
err = dbConn.Table("users").Where("user_id=?", userID).Take(&user).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error
if err != nil {
return nil, err
}
@ -88,12 +70,8 @@ func GetUserByUserID(userID string) (*db.User, error) {
}
func GetUserNameByUserID(userID string) (string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return "", err
}
var user db.User
err = dbConn.Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
if err != nil {
return "", err
}
@ -101,33 +79,17 @@ func GetUserNameByUserID(userID string) (string, error) {
}
func UpdateUserInfo(user db.User) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
return err
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(&user).Error
}
func UpdateUserInfoByMap(user db.User, m map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
err = dbConn.Table("users").Where("user_id=?", user.UserID).Updates(m).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(m).Error
return err
}
func SelectAllUserID() ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var resultArr []string
err = dbConn.Table("users").Pluck("user_id", &resultArr).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Pluck("user_id", &resultArr).Error
if err != nil {
return nil, err
}
@ -135,14 +97,8 @@ func SelectAllUserID() ([]string, error) {
}
func SelectSomeUserID(userIDList []string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(false)
if err != nil {
return nil, err
}
var resultArr []string
err = dbConn.Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error
if err != nil {
return nil, err
}
@ -150,13 +106,8 @@ func SelectSomeUserID(userIDList []string) ([]string, error) {
}
func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var users []db.User
if err != nil {
return users, err
}
dbConn.LogMode(false)
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
if err != nil {
return users, err
}
@ -164,10 +115,6 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
}
func AddUser(userId, phoneNumber, name string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
user := db.User{
PhoneNumber: phoneNumber,
Birth: time.Now(),
@ -175,17 +122,13 @@ func AddUser(userId, phoneNumber, name string) error {
UserID: userId,
Nickname: name,
}
result := dbConn.Table("users").Create(&user)
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
return result.Error
}
func UserIsBlock(userId string) (bool, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return false, err
}
var user db.BlackList
rows := dbConn.Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
if rows >= 1 {
return true, nil
}
@ -197,10 +140,6 @@ func BlockUser(userId, endDisableTime string) error {
if err != nil || user.UserID == "" {
return err
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
end, err := time.Parse("2006-01-02 15:04:05", endDisableTime)
if err != nil {
return err
@ -209,9 +148,9 @@ func BlockUser(userId, endDisableTime string) error {
return constant.ErrDB
}
var blockUser db.BlackList
dbConn.Table("black_lists").Where("uid=?", userId).First(&blockUser)
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser)
if blockUser.UserId != "" {
dbConn.Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
return nil
}
blockUser = db.BlackList{
@ -219,18 +158,12 @@ func BlockUser(userId, endDisableTime string) error {
BeginDisableTime: time.Now(),
EndDisableTime: end,
}
result := dbConn.Create(&blockUser)
result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser)
return result.Error
}
func UnBlockUser(userId string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
return result.Error
return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error
}
type BlockUserInfo struct {
@ -240,21 +173,17 @@ type BlockUserInfo struct {
}
func GetBlockUserById(userId string) (BlockUserInfo, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var blockUserInfo BlockUserInfo
blockUser := db.BlackList{
UserId: userId,
}
if err != nil {
return blockUserInfo, err
}
if err = dbConn.Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
return blockUserInfo, err
}
user := db.User{
UserID: blockUser.UserId,
}
if err := dbConn.Find(&user).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Find(&user).Error; err != nil {
return blockUserInfo, err
}
blockUserInfo.User.UserID = user.UserID
@ -266,19 +195,14 @@ func GetBlockUserById(userId string) (BlockUserInfo, error) {
}
func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var blockUserInfos []BlockUserInfo
var blockUsers []db.BlackList
if err != nil {
return blockUserInfos, err
}
dbConn.LogMode(false)
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
if err := db.DB.MysqlDB.DefaultGormDB().Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil {
return blockUserInfos, err
}
for _, blockUser := range blockUsers {
var user db.User
if err := dbConn.Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
blockUserInfos = append(blockUserInfos, BlockUserInfo{
User: db.User{
UserID: user.UserID,
@ -294,38 +218,23 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
}
func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var users []db.User
if err != nil {
return users, err
}
dbConn.LogMode(false)
err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
return users, err
}
func GetUsersCount(user db.User) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var count int32
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
return 0, err
}
return count, nil
return int32(count), nil
}
func GetBlockUsersNumCount() (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(false)
var count int32
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Model(&db.BlackList{}).Count(&count).Error; err != nil {
return 0, err
}
return count, nil
return int32(count), nil
}

@ -19,10 +19,6 @@ import (
)
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
chatLog := new(db.ChatLog)
copier.Copy(chatLog, msg.MsgData)
switch msg.MsgData.SessionType {
@ -47,5 +43,5 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime)
chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime)
log.NewDebug("test", "this is ", chatLog)
return dbConn.Table("chat_logs").Create(chatLog).Error
return db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Create(chatLog).Error
}

@ -2,9 +2,7 @@ package im_mysql_msg_model
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/db"
"hash/crc32"
"strconv"
)
func getHashMsgDBAddr(userID string) string {
@ -16,21 +14,3 @@ func getHashMsgTableIndex(userID string) int {
hCode := crc32.ChecksumIEEE([]byte(userID))
return int(hCode % uint32(config.Config.Mysql.DBMsgTableNum))
}
func QueryUserMsgID(userID string) ([]string, error) {
dbAddress, dbTableIndex := getHashMsgDBAddr(userID), getHashMsgTableIndex(userID)
dbTableName := "receive" + strconv.Itoa(dbTableIndex)
dbConn, _ := db.DB.MysqlDB.GormDB(dbAddress, config.Config.Mysql.DBTableName)
var msgID string
var msgIDList []string
rows, _ := dbConn.Raw("select msg_id from ? where user_id = ?", dbTableName, userID).Rows()
defer rows.Close()
for rows.Next() {
rows.Scan(&msgID)
msgIDList = append(msgIDList, msgID)
}
return msgIDList, nil
}

@ -0,0 +1,248 @@
package rocksCache
import (
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"encoding/json"
"strings"
"time"
)
const (
userInfoCache = "USER_INFO_CACHE:"
friendRelationCache = "FRIEND_RELATION_CACHE:"
blackListCache = "BLACK_LIST_CACHE:"
groupCache = "GROUP_CACHE:"
groupInfoCache = "GROUP_INFO_CACHE:"
groupOwnerIDCache = "GROUP_OWNER_ID:"
joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
allDepartmentCache = "ALL_DEPARTMENT_CACHE:"
allDepartmentMemberCache = "ALL_DEPARTMENT_MEMBER_CACHE:"
)
func GetFriendIDListFromCache(userID string) ([]string, error) {
getFriendIDList := func() (string, error) {
friendIDList, err := imdb.GetFriendIDListByUserID(userID)
return strings.Join(friendIDList, ","), err
}
friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second, getFriendIDList)
return strings.Split(friendIDListStr, ","), err
}
func DelFriendIDListFromCache(userID string) error {
err := db.DB.Rc.TagAsDeleted(friendRelationCache + userID)
return err
}
func GetBlackListFromCache(userID string) ([]string, error) {
getBlackIDList := func() (string, error) {
blackIDList, err := imdb.GetBlackIDListByUserID(userID)
return strings.Join(blackIDList, ","), err
}
blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second, getBlackIDList)
return strings.Split(blackIDListStr, ","), err
}
func DelBlackIDListFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(blackListCache + userID)
}
func GetJoinedGroupIDListFromCache(userID string) ([]string, error) {
getJoinedGroupIDList := func() (string, error) {
joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(userID)
return strings.Join(joinedGroupList, ","), err
}
joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second, getJoinedGroupIDList)
return strings.Split(joinedGroupIDListStr, ","), err
}
func DelJoinedGroupIDListFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(joinedGroupListCache + userID)
}
func GetGroupOwnerFromCache(groupID string) (string, error) {
getGroupOwnerIDList := func() (string, error) {
groupOwner, err := imdb.GetGroupOwnerInfoByGroupID(groupID)
if err != nil {
return "", err
}
return groupOwner.UserID, err
}
groupOwnerID, err := db.DB.Rc.Fetch(groupOwnerIDCache+groupID, time.Second, getGroupOwnerIDList)
return groupOwnerID, err
}
func DelGroupOwnerListFromCache(groupID string) error {
return db.DB.Rc.TagAsDeleted(groupOwnerIDCache + groupID)
}
func GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
getGroupMemberIDList := func() (string, error) {
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
return strings.Join(groupMemberIDList, ","), err
}
groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second, getGroupMemberIDList)
return strings.Split(groupIDListStr, ","), err
}
func DelGroupMemberIDListFromCache(userID string) error {
err := db.DB.Rc.TagAsDeleted(groupCache + userID)
return err
}
func GetUserInfoFromCache(userID string) (*db.User, error) {
getUserInfo := func() (string, error) {
userInfo, err := imdb.GetUserByUserID(userID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(userInfo)
return string(bytes), err
}
userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second, getUserInfo)
if err != nil {
return nil, err
}
userInfo := &db.User{}
err = json.Unmarshal([]byte(userInfoStr), userInfo)
return userInfo, err
}
func DelUserInfoFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(userInfoCache + userID)
}
func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error) {
getGroupMemberInfo := func() (string, error) {
groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(groupMemberInfo)
return string(bytes), err
}
groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second, getGroupMemberInfo)
if err != nil {
return nil, err
}
groupMember := &db.GroupMember{}
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
return groupMember, err
}
func DelGroupMemberInfoFromCache(groupID, userID string) error {
return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID)
}
func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error) {
getGroupMemberInfo := func() (string, error) {
groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(groupMembers)
return string(bytes), err
}
groupMembersStr, err := db.DB.Rc.Fetch(groupAllMemberInfoCache+groupID, time.Second, getGroupMemberInfo)
if err != nil {
return nil, err
}
var groupMembers []*db.GroupMember
err = json.Unmarshal([]byte(groupMembersStr), &groupMembers)
return groupMembers, err
}
func DelAllGroupMembersInfoFromCache(groupID string) error {
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
}
func GetGroupInfoFromCache(groupID string) (*db.Group, error) {
getGroupInfo := func() (string, error) {
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(groupInfo)
return string(bytes), err
}
groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second, getGroupInfo)
if err != nil {
return nil, err
}
groupInfo := &db.Group{}
err = json.Unmarshal([]byte(groupInfoStr), groupInfo)
return groupInfo, err
}
func DelGroupInfoFromCache(groupID string) error {
return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID)
}
func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) {
getAllFriendInfo := func() (string, error) {
friendInfoList, err := imdb.GetFriendListByUserID(userID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(friendInfoList)
return string(bytes), err
}
allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second, getAllFriendInfo)
if err != nil {
return nil, err
}
var friendInfoList []*db.Friend
err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList)
return friendInfoList, err
}
func DelAllFriendsInfoFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
}
func GetAllDepartmentsFromCache() ([]*db.Department, error) {
getAllDepartments := func() (string, error) {
departmentList, err := imdb.GetSubDepartmentList("-1")
if err != nil {
return "", err
}
bytes, err := json.Marshal(departmentList)
return string(bytes), err
}
allDepartmentsStr, err := db.DB.Rc.Fetch(allDepartmentCache, time.Second, getAllDepartments)
if err != nil {
return nil, err
}
var allDepartments []*db.Department
err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments)
return allDepartments, err
}
func DelAllDepartmentsFromCache() error {
return db.DB.Rc.TagAsDeleted(allDepartmentCache)
}
func GetAllDepartmentMembersFromCache() ([]*db.DepartmentMember, error) {
getAllDepartmentMembers := func() (string, error) {
departmentMembers, err := imdb.GetDepartmentMemberList("-1")
if err != nil {
return "", err
}
bytes, err := json.Marshal(departmentMembers)
return string(bytes), err
}
allDepartmentMembersStr, err := db.DB.Rc.Fetch(allDepartmentMemberCache, time.Second, getAllDepartmentMembers)
if err != nil {
return nil, err
}
var allDepartmentMembers []*db.DepartmentMember
err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers)
return allDepartmentMembers, err
}
func DelAllDepartmentMembersFromCache() error {
return db.DB.Rc.TagAsDeleted(allDepartmentMemberCache)
}

@ -93,7 +93,8 @@ func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *db.Group) error {
}
dst.OwnerUserID = user.UserID
dst.MemberCount, err = imdb.GetGroupMemberNumByGroupID(src.GroupID)
memberCount, err := imdb.GetGroupMemberNumByGroupID(src.GroupID)
dst.MemberCount = uint32(memberCount)
if err != nil {
return utils.Wrap(err, "")
}

File diff suppressed because it is too large Load Diff

@ -8,26 +8,6 @@ message CommonResp{
string errMsg = 2;
}
message GetUserInfoFromCacheReq{
repeated string userIDList = 1;
string operationID = 2;
}
message GetUserInfoFromCacheResp{
CommonResp commonResp = 1;
repeated server_api_params.UserInfo userInfoList = 2;
}
message UpdateUserInfoToCacheReq{
repeated server_api_params.UserInfo userInfoList = 1;
string operationID = 2;
}
message UpdateUserInfoToCacheResp{
CommonResp commonResp = 1;
}
message GetFriendIDListFromCacheReq {
string userID = 1;
string operationID = 2;
@ -38,24 +18,13 @@ message GetFriendIDListFromCacheResp {
CommonResp commonResp = 2;
}
message AddFriendToCacheReq {
string userID = 1;
string friendID = 2;
string operationID = 3;
}
message AddFriendToCacheResp {
CommonResp commonResp = 1;
}
message ReduceFriendFromCacheReq {
string userID = 1;
string friendID = 2;
string operationID = 3;
message DelFriendIDListFromCacheReq {
string userID = 1;
string operationID = 2;
}
message ReduceFriendFromCacheResp {
CommonResp commonResp = 1;
message DelFriendIDListFromCacheResp {
CommonResp commonResp = 1;
}
message GetBlackIDListFromCacheReq {
@ -68,23 +37,12 @@ message GetBlackIDListFromCacheResp {
CommonResp commonResp = 2;
}
message AddBlackUserToCacheReq {
message DelBlackIDListFromCacheReq {
string userID = 1;
string blackUserID = 2;
string operationID = 3;
}
message AddBlackUserToCacheResp {
CommonResp commonResp = 1;
}
message ReduceBlackUserFromCacheReq {
string userID = 1;
string blackUserID = 2;
string operationID = 3;
string operationID = 2;
}
message ReduceBlackUserFromCacheResp {
message DelBlackIDListFromCacheResp {
CommonResp commonResp = 1;
}
@ -98,45 +56,34 @@ message GetGroupMemberIDListFromCacheResp {
repeated string userIDList = 2;
}
message AddGroupMemberToCacheReq {
repeated string userIDList = 1;
string groupID = 2;
string operationID = 3;
}
message AddGroupMemberToCacheResp {
CommonResp commonResp = 1;
}
message ReduceGroupMemberFromCacheReq {
repeated string userIDList = 1;
string groupID = 2;
string operationID = 3;
message DelGroupMemberIDListFromCacheReq {
string groupID = 1;
string operationID = 2;
}
message ReduceGroupMemberFromCacheResp {
message DelGroupMemberIDListFromCacheResp {
CommonResp commonResp = 1;
}
service cache{
// userInfo
rpc GetUserInfoFromCache(GetUserInfoFromCacheReq) returns(GetUserInfoFromCacheResp);
rpc UpdateUserInfoToCache(UpdateUserInfoToCacheReq) returns(UpdateUserInfoToCacheResp);
// friendInfo
rpc GetFriendIDListFromCache(GetFriendIDListFromCacheReq) returns(GetFriendIDListFromCacheResp);
rpc AddFriendToCache(AddFriendToCacheReq) returns(AddFriendToCacheResp);
rpc ReduceFriendFromCache(ReduceFriendFromCacheReq) returns(ReduceFriendFromCacheResp);
// for dtm
rpc DelFriendIDListFromCache(DelFriendIDListFromCacheReq) returns(DelFriendIDListFromCacheResp);
// blackList
rpc GetBlackIDListFromCache(GetBlackIDListFromCacheReq) returns(GetBlackIDListFromCacheResp);
rpc AddBlackUserToCache(AddBlackUserToCacheReq) returns(AddBlackUserToCacheResp);
rpc ReduceBlackUserFromCache(ReduceBlackUserFromCacheReq) returns(ReduceBlackUserFromCacheResp);
// for dtm
rpc DelBlackIDListFromCache(DelBlackIDListFromCacheReq) returns (DelBlackIDListFromCacheResp);
// group
rpc GetGroupMemberIDListFromCache(GetGroupMemberIDListFromCacheReq) returns(GetGroupMemberIDListFromCacheResp);
rpc AddGroupMemberToCache(AddGroupMemberToCacheReq) returns(AddGroupMemberToCacheResp);
rpc ReduceGroupMemberFromCache(ReduceGroupMemberFromCacheReq) returns(ReduceGroupMemberFromCacheResp);
// for dtm
rpc DelGroupMemberIDListFromCache(DelGroupMemberIDListFromCacheReq) returns(DelGroupMemberIDListFromCacheResp);
}

@ -1,94 +0,0 @@
package main
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/db"
"Open_IM/pkg/proto/user"
"database/sql"
"fmt"
"github.com/dtm-labs/rockscache"
"github.com/gin-gonic/gin"
go_redis "github.com/go-redis/redis/v8"
"github.com/dtm-labs/dtmcli"
"github.com/dtm-labs/dtmgrpc"
"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"github.com/lithammer/shortuuid"
"time"
)
func main() {
rc := rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
Addr: "43.128.5.63:16379",
Password: "openIM", // no password set
DB: 3, // use default DB
PoolSize: 100, // 连接池大小
}), rockscache.NewDefaultOptions())
rc.Options.StrongConsistency = true
//gid := dtmcli.MustGenGid(config.Config.Dtm.ServerURL)
//
//getGroupInfo := func()(string, error) {
// fmt.Println("start to fetch")
// time.Sleep(time.Second*5)
// fmt.Println("stop to fetch")
// return "value2312", nil
//}
//
//v, err := rc.Fetch("keyasd347", time.Second*120, getGroupInfo)
//fmt.Println("set success")
//gid := dtmcli.MustGenGid(config.Config.Dtm.ServerURL)
//msg := dtmcli.NewMsg(DtmServer, shortuuid.New()).
// Add(busi.Busi+"/SagaBTransIn", &TransReq{ Amount: 30 })
//
//dtmcli.DB()
//time.Sleep(time.Second*12)
//v2, _ := rc.Fetch("keyasd347", time.Second*10, func()(string, error) {
// // fetch data from database or other sources
// return "value1", nil
//})
//fmt.Println(v, err)
//fmt.Println(v2)
//err = rc.TagAsDeleted("keyasd347")
//fmt.Println(err)
}
func UpdateUserInfo(c *gin.Context) {
gid := dtmcli.MustGenGid(config.Config.Dtm.ServerURL)
var pb user.GetAllUserIDReq
msg := dtmgrpc.NewMsgGrpc(config.Config.Dtm.ServerURL, gid).Add("url1", &pb)
msg.DoAndSubmit("/QueryPreparedB", func(bb *dtmcli.BranchBarrier) error {
return bb.CallWithDB(db, func(tx *sql.Tx) error {
return UpdateInTx(tx, &DBRow{
K: body["key"].(string),
V: body["value"].(string),
TimeCost: body["time_cost"].(string),
})
})
})
}))
}
func GetUserInfo(c *gin.Context) {
// rpc logic
v2, _ := db.DB.Rc.Fetch("keyasd347", time.Second*10, func()(string, error) {
// fetch data from database or other sources
return "value1", nil
})
c.JSON(200, map[string]interface{}{"s":v2})
}
// QueryPreparedB
func QueryPreparedB() {
app.GET(BusiAPI+"/QueryPreparedB", dtmutil.WrapHandler2(func(c *gin.Context) interface{} {
bb := MustBarrierFromGin(c)
return bb.QueryPrepared(dbGet())
}))
}
Loading…
Cancel
Save