mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-28 04:48:44 +08:00
office
This commit is contained in:
parent
3c68ecb7f1
commit
2cf070a26c
@ -239,7 +239,8 @@ func GetWorkMomentByID(c *gin.Context) {
|
|||||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||||
}
|
}
|
||||||
resp.Data.WorkMoment = &apiStruct.WorkMoment{LikeUserList: []*apiStruct.WorkMomentUser{}, Comments: []*apiStruct.Comment{}, AtUserList: []*apiStruct.WorkMomentUser{}}
|
resp.Data.WorkMoment = &apiStruct.WorkMoment{LikeUserList: []*apiStruct.WorkMomentUser{}, Comments: []*apiStruct.Comment{},
|
||||||
|
AtUserList: []*apiStruct.WorkMomentUser{}, PermissionUserList: []*apiStruct.WorkMomentUser{}}
|
||||||
if err := utils.CopyStructFields(&resp.Data.WorkMoment, respPb.WorkMoment); err != nil {
|
if err := utils.CopyStructFields(&resp.Data.WorkMoment, respPb.WorkMoment); err != nil {
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -287,17 +287,6 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
|
|||||||
workMoment.UserName = createUser.Nickname
|
workMoment.UserName = createUser.Nickname
|
||||||
workMoment.FaceURL = createUser.FaceURL
|
workMoment.FaceURL = createUser.FaceURL
|
||||||
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
|
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
|
||||||
for _, userID := range workMoment.PermissionUserIDList {
|
|
||||||
userName, err := imdb.GetUserNameByUserID(userID)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
workMoment.PermissionUserList = append(workMoment.PermissionUserList, &db.WorkMomentUser{
|
|
||||||
UserID: userID,
|
|
||||||
UserName: userName,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
|
||||||
err = db.DB.CreateOneWorkMoment(&workMoment)
|
err = db.DB.CreateOneWorkMoment(&workMoment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3,8 +3,6 @@ package db
|
|||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
||||||
|
|
||||||
//"Open_IM/pkg/common/log"
|
//"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -72,104 +70,165 @@ func init() {
|
|||||||
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
|
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
|
||||||
dataBase := mongoClient.Database(config.Config.Mongo.DBDatabase)
|
dataBase := mongoClient.Database(config.Config.Mongo.DBDatabase)
|
||||||
|
|
||||||
cSendLogModels := []mongo.IndexModel{
|
//cSendLogModels := []mongo.IndexModel{
|
||||||
{
|
// {
|
||||||
Keys: bsonx.Doc{
|
// Keys: bsonx.Doc{
|
||||||
{
|
// {
|
||||||
Key: "send_id",
|
// Key: "send_id",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// Options: options.Index().SetUnique(true),
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// Keys: bsonx.Doc{
|
||||||
|
// {
|
||||||
|
// Key: "send_time",
|
||||||
|
// Value: bsonx.Int32(-1),
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
//result, err := dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts)
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Println("mongodb create cSendLogModels failed", result, err.Error())
|
||||||
|
//}
|
||||||
|
|
||||||
|
result, err := dataBase.Collection(cSendLog).Indexes().CreateOne(context.Background(), mongo.IndexModel{
|
||||||
|
Keys: bson.D{
|
||||||
|
{Key: "send_id"},
|
||||||
|
{Key: "send_time", Value: -1},
|
||||||
},
|
},
|
||||||
},
|
}, opts)
|
||||||
Options: options.Index().SetUnique(true),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bsonx.Doc{
|
|
||||||
{
|
|
||||||
Key: "send_time",
|
|
||||||
Value: bsonx.Int32(-1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
result, err := dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("mongodb create cSendLogModels failed", result, err.Error())
|
fmt.Println("mongodb create cSendLog index failed", result, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cChatModels := []mongo.IndexModel{
|
cChatModels := []mongo.IndexModel{
|
||||||
{
|
{
|
||||||
Keys: bson.M{"uid": -1},
|
Keys: bson.M{"uid": -1},
|
||||||
|
Options: options.Index().SetUnique(true),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
result, err = dataBase.Collection(cChat).Indexes().CreateMany(context.Background(), cChatModels, opts)
|
_, err = dataBase.Collection(cChat).Indexes().CreateMany(context.Background(), cChatModels, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("mongodb create cChatModels failed", result, err.Error())
|
fmt.Println("mongodb create cChatModels failed", result, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cWorkMomentModels := []mongo.IndexModel{
|
//
|
||||||
{
|
//cWorkMomentModels := []mongo.IndexModel{
|
||||||
Keys: bsonx.Doc{
|
// {
|
||||||
{
|
// Keys: bsonx.Doc{
|
||||||
Key: "create_time",
|
// {
|
||||||
Value: bsonx.Int32(-1),
|
// Key: "create_time",
|
||||||
|
// Value: bsonx.Int32(-1),
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// Keys: bsonx.Doc{
|
||||||
|
// {
|
||||||
|
// Key: "work_moment_id",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// Options: options.Index().SetUnique(true),
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
//cWorkMomentModel2 := []mongo.IndexModel{
|
||||||
|
// {
|
||||||
|
// Keys: bsonx.Doc{
|
||||||
|
// {
|
||||||
|
// Key: "work_moment_id",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// Options: options.Index().SetUnique(true),
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
//result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModels, opts)
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||||
|
//}
|
||||||
|
//result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModel2, opts)
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||||
|
//}
|
||||||
|
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateOne(context.Background(), mongo.IndexModel{
|
||||||
|
Keys: bson.D{
|
||||||
|
{Key: "create_time", Value: -1},
|
||||||
|
{Key: "work_moment_id"},
|
||||||
},
|
},
|
||||||
},
|
}, opts)
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bsonx.Doc{
|
|
||||||
{
|
|
||||||
Key: "work_moment_id",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Options: options.Index().SetUnique(true),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
cWorkMomentModel2 := []mongo.IndexModel{
|
|
||||||
{
|
|
||||||
Keys: bsonx.Doc{
|
|
||||||
{
|
|
||||||
Key: "work_moment_id",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Options: options.Index().SetUnique(true),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModels, opts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
fmt.Println("mongodb create cWorkMoment index failed", result, err.Error())
|
||||||
}
|
|
||||||
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModel2, opts)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cTagModel1 := []mongo.IndexModel{
|
_, err = dataBase.Collection(cWorkMoment).Indexes().CreateOne(context.Background(), mongo.IndexModel{
|
||||||
{
|
Keys: bson.D{
|
||||||
Keys: bsonx.Doc{
|
{Key: "work_moment_id"},
|
||||||
{
|
|
||||||
Key: "tag_id",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
},
|
}, opts)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("mongodb create cWorkMoment index failed", err.Error())
|
||||||
}
|
}
|
||||||
cTagModel2 := []mongo.IndexModel{
|
|
||||||
{
|
_, err = dataBase.Collection(cWorkMoment).Indexes().CreateOne(context.Background(), mongo.IndexModel{
|
||||||
Keys: bsonx.Doc{
|
Keys: bson.D{
|
||||||
{
|
{Key: "user_id"},
|
||||||
Key: "user_id",
|
{Key: "create_time", Value: -1},
|
||||||
},
|
},
|
||||||
|
}, opts)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("mongodb create cWorkMoment index failed", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
//cTagModel1 := []mongo.IndexModel{
|
||||||
|
// {
|
||||||
|
// Keys: bsonx.Doc{
|
||||||
|
// {
|
||||||
|
// Key: "tag_id",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// Options: options.Index().SetUnique(true),
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
//cTagModel2 := []mongo.IndexModel{
|
||||||
|
// {
|
||||||
|
// Keys: bsonx.Doc{
|
||||||
|
// {
|
||||||
|
// Key: "user_id",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// Options: options.Index().SetUnique(true),
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
//result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModel1, opts)
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Println("mongodb create cTagModel1 failed", result, err.Error())
|
||||||
|
//}
|
||||||
|
//result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModel2, opts)
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Println("mongodb create cTagModel2 failed", result, err.Error())
|
||||||
|
//}
|
||||||
|
result, err = dataBase.Collection(cTag).Indexes().CreateOne(context.Background(), mongo.IndexModel{
|
||||||
|
Keys: bson.D{
|
||||||
|
{Key: "user_id"},
|
||||||
|
{Key: "create_time", Value: -1},
|
||||||
|
},
|
||||||
|
}, opts)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("mongodb create cSendLog index failed", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = dataBase.Collection(cTag).Indexes().CreateOne(context.Background(), mongo.IndexModel{
|
||||||
|
Keys: bson.D{
|
||||||
|
{Key: "tag_id"},
|
||||||
},
|
},
|
||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
},
|
})
|
||||||
}
|
|
||||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModel1, opts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("mongodb create cTagModel1 failed", result, err.Error())
|
fmt.Println("mongodb create cSendLog index failed", result, err.Error())
|
||||||
}
|
|
||||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModel2, opts)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("mongodb create cTagModel2 failed", result, err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.mongoClient = mongoClient
|
DB.mongoClient = mongoClient
|
||||||
|
|
||||||
// redis pool init
|
// redis pool init
|
||||||
|
Loading…
x
Reference in New Issue
Block a user