上传战斗记录过期时间
This commit is contained in:
parent
90e00dfd56
commit
2333e29b5b
@ -647,6 +647,6 @@ type (
|
|||||||
}
|
}
|
||||||
//战斗记录模块
|
//战斗记录模块
|
||||||
IBattleRecord interface {
|
IBattleRecord interface {
|
||||||
WrietBattleRecord(uid string, report *pb.BattleReport)
|
WrietBattleRecord(uid string, report *pb.BattleReport, expire int64)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
mgooptions "go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,6 +26,11 @@ func (this *modelComp) Init(service core.IService, module core.IModule, comp cor
|
|||||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||||
})
|
})
|
||||||
|
indexModel := mongo.IndexModel{
|
||||||
|
Keys: bson.M{"expireAt": 1}, // 设置TTL索引列"expire_date"
|
||||||
|
Options: mgooptions.Index().SetExpireAfterSeconds(0), // 设置过期时间(单位:秒)
|
||||||
|
}
|
||||||
|
_, err = this.DB.CreateIndex(core.SqlTable(this.TableName), indexModel) //设置 验证码过期时间索引
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (this *BattleRecord) Start() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//写入战斗记录
|
//写入战斗记录
|
||||||
func (this *BattleRecord) WrietBattleRecord(uid string, report *pb.BattleReport) {
|
func (this *BattleRecord) WrietBattleRecord(uid string, report *pb.BattleReport, expire int64) {
|
||||||
var (
|
var (
|
||||||
result *pb.DBBattlePlayRecord
|
result *pb.DBBattlePlayRecord
|
||||||
model *recordModel
|
model *recordModel
|
||||||
@ -62,8 +62,9 @@ func (this *BattleRecord) WrietBattleRecord(uid string, report *pb.BattleReport)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result = &pb.DBBattlePlayRecord{
|
result = &pb.DBBattlePlayRecord{
|
||||||
Id: report.Info.Id,
|
Id: report.Info.Id,
|
||||||
Record: data,
|
Record: data,
|
||||||
|
ExpireAt: expire,
|
||||||
}
|
}
|
||||||
if model, err = this.model.getrecordModel(uid); err != nil {
|
if model, err = this.model.getrecordModel(uid); err != nil {
|
||||||
this.Errorln(err)
|
this.Errorln(err)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 参数校验
|
// 参数校验
|
||||||
@ -184,7 +185,7 @@ func (this *apiComp) ChallengeFinish(session comm.IUserSession, req *pb.GuildGve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//写入战斗记录
|
//写入战斗记录
|
||||||
go this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report)
|
go this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report, time.Now().Add(time.Hour*24*8).Unix())
|
||||||
session.SendMsg(string(this.module.GetType()), "challengefinish", &pb.GuildGveChallengeFinishResp{
|
session.SendMsg(string(this.module.GetType()), "challengefinish", &pb.GuildGveChallengeFinishResp{
|
||||||
Guildid: req.Guildid,
|
Guildid: req.Guildid,
|
||||||
Boosid: req.Boosid,
|
Boosid: req.Boosid,
|
||||||
|
@ -26,8 +26,9 @@ type DBBattlePlayRecord struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID
|
||||||
Record []byte `protobuf:"bytes,5,opt,name=record,proto3" json:"record"` //BattleReport 的序列化数据
|
ExpireAt int64 `protobuf:"varint,2,opt,name=expireAt,proto3" json:"expireAt" bson:"expireAt"` //过期时间
|
||||||
|
Record []byte `protobuf:"bytes,3,opt,name=record,proto3" json:"record"` //BattleReport 的序列化数据
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBBattlePlayRecord) Reset() {
|
func (x *DBBattlePlayRecord) Reset() {
|
||||||
@ -69,6 +70,13 @@ func (x *DBBattlePlayRecord) GetId() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *DBBattlePlayRecord) GetExpireAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.ExpireAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func (x *DBBattlePlayRecord) GetRecord() []byte {
|
func (x *DBBattlePlayRecord) GetRecord() []byte {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Record
|
return x.Record
|
||||||
@ -81,12 +89,13 @@ var File_battlerecord_battlerecord_db_proto protoreflect.FileDescriptor
|
|||||||
var file_battlerecord_battlerecord_db_proto_rawDesc = []byte{
|
var file_battlerecord_battlerecord_db_proto_rawDesc = []byte{
|
||||||
0x0a, 0x22, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2f, 0x62,
|
0x0a, 0x22, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2f, 0x62,
|
||||||
0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x64, 0x62, 0x2e, 0x70,
|
0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x64, 0x62, 0x2e, 0x70,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3c, 0x0a, 0x12, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65,
|
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x58, 0x0a, 0x12, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65,
|
||||||
0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
|
0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
|
||||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x78,
|
||||||
0x63, 0x6f, 0x72, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f,
|
0x70, 0x69, 0x72, 0x65, 0x41, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x65, 0x78,
|
||||||
0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
0x70, 0x69, 0x72, 0x65, 0x41, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||||
0x6f, 0x33,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x42, 0x06,
|
||||||
|
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user