go_dreamfactory/modules/forum/modelForum.go
2022-08-08 19:44:52 +08:00

63 lines
1.5 KiB
Go

package forum
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/lego/utils/codec/json"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
///论坛 数据组件
type modelForumComp struct {
modules.MCompModel
module *Forum
}
//组件初始化接口
func (this *modelForumComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Forum)
this.TableName = "forum"
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "heroid", Value: bsonx.Int32(1)}},
})
return
}
//查询用户未读消息
func (this *modelForumComp) GetComment(herocId string) (result []*pb.DBComment, err error) {
var (
key string
cdata []map[string]string
readmax_chat int32
)
if cdata, err = this.Batchgetqueues(key, readmax_chat); err == nil {
result = make([]*pb.DBComment, len(cdata))
for i, v := range cdata {
comment := &pb.DBComment{}
if err = json.UnmarshalMap(v, comment); err != nil {
return
}
result[i] = comment
}
}
if err == redis.RedisNil {
err = nil
}
return
}
///发布评论
func (this *modelForumComp) releaseComment(comment *pb.DBComment) (err error) {
if _, err = this.DB.InsertOne(core.SqlTable(this.TableName), comment); err != nil {
this.module.Errorln(err)
}
return
}