go_dreamfactory/modules/atlas/model_atlas.go
2023-02-24 16:26:56 +08:00

51 lines
1.3 KiB
Go

package atlas
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelPandaAtlas struct {
modules.MCompModel
module *PandaAtlas
}
func (this *modelPandaAtlas) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TablePandaAtlas)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*PandaAtlas)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelPandaAtlas) getPandaAtlasList(uid string) (result *pb.DBPandaAtlas, err error) {
result = &pb.DBPandaAtlas{
Collect: map[string]*pb.CollectInfo{},
}
if err = this.Get(uid, result); err != nil {
if mongo.ErrNoDocuments == err {
result.Id = primitive.NewObjectID().Hex()
result.Uid = uid
result.Collect = make(map[string]*pb.CollectInfo, 0)
result.Award = 1 // 初始1级
this.Add(uid, result)
err = nil
}
return
}
return
}
func (this *modelPandaAtlas) modifyPandaAtlasList(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}