go_dreamfactory/modules/smithy/model_stove.go
2023-02-15 19:28:14 +08:00

61 lines
1.6 KiB
Go

package smithy
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis"
"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 modelStove struct {
modules.MCompModel
module *Smithy
}
func (this *modelStove) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableStove)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Smithy)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 获取铁匠铺信息
func (this *modelStove) getSmithyStoveList(uid string) (result *pb.DBStove, err error) {
result = &pb.DBStove{}
if err = this.Get(uid, result); err != nil {
if redis.RedisNil != err { // 没有数据直接创建新的数据
result.Id = primitive.NewObjectID().Hex()
result.Uid = uid
result.Data = make(map[int32]int32, 0)
result.Skill = make(map[int32]int32, 0)
result.Forge = make(map[int32]int32, 0)
result.Lv = 1
result.Temperature = 20000 // 配置
result.RecoveTime = 0
if err = this.Add(uid, result); err != nil {
this.module.Errorf("err:%v", err)
err = nil
return
}
}
return
}
err = nil
return result, err
}
func (this *modelStove) updateSmithyStove(uid string, update map[string]interface{}) (err error) {
err = this.Change(uid, update)
return err
}