上传用户日志功能实现
This commit is contained in:
parent
a6ae6bf2cb
commit
95582456d4
@ -415,6 +415,9 @@ const (
|
|||||||
TableIsLandHero = "islandhero"
|
TableIsLandHero = "islandhero"
|
||||||
//彩蛋
|
//彩蛋
|
||||||
TableEgghunt = "egghunt"
|
TableEgghunt = "egghunt"
|
||||||
|
|
||||||
|
//用户日志
|
||||||
|
TableUserLog = "userlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RPC服务接口定义处
|
// RPC服务接口定义处
|
||||||
|
58
modules/modeluserlog.go
Normal file
58
modules/modeluserlog.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package modules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
mgooptions "go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type modelUserLog struct {
|
||||||
|
MCompModel
|
||||||
|
module core.IModule
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *modelUserLog) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
|
this.TableName = comm.TableUserLog
|
||||||
|
this.module = module
|
||||||
|
// uid 创建索引
|
||||||
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *modelUserLog) AddUserLog(uid string, tag string, data interface{}) {
|
||||||
|
var (
|
||||||
|
jsonStr []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if jsonStr, err = json.Marshal(data); err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), &pb.DBUserLog{
|
||||||
|
Id: primitive.NewObjectID().Hex(),
|
||||||
|
Uid: uid,
|
||||||
|
ExpireAt: time.Now().Add(time.Hour * 24 * 8).Unix(),
|
||||||
|
Tag: tag,
|
||||||
|
Data: string(jsonStr),
|
||||||
|
}); err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,7 @@ type ModuleBase struct {
|
|||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
options IOptions
|
options IOptions
|
||||||
scomp comm.ISC_GateRouteComp //网关服务组件
|
scomp comm.ISC_GateRouteComp //网关服务组件
|
||||||
|
userlog *modelUserLog //用户日志
|
||||||
//常用的一些通用模块 在底层注册好
|
//常用的一些通用模块 在底层注册好
|
||||||
ModuleSys comm.ISys //系统
|
ModuleSys comm.ISys //系统
|
||||||
ModuleUser comm.IUser //用户模块
|
ModuleUser comm.IUser //用户模块
|
||||||
@ -63,6 +64,10 @@ func (this *ModuleBase) Init(service core.IService, module core.IModule, options
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
func (this *ModuleBase) OnInstallComp() {
|
||||||
|
this.ModuleBase.OnInstallComp()
|
||||||
|
this.userlog = this.RegisterComp(new(modelUserLog)).(*modelUserLog)
|
||||||
|
}
|
||||||
|
|
||||||
// 模块启动接口
|
// 模块启动接口
|
||||||
func (this *ModuleBase) Start() (err error) {
|
func (this *ModuleBase) Start() (err error) {
|
||||||
@ -946,3 +951,8 @@ func (this *ModuleBase) AsynHandleSession(session comm.IUserSession, handle func
|
|||||||
session.Push()
|
session.Push()
|
||||||
this.PutUserSession(session)
|
this.PutUserSession(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//写用户日志
|
||||||
|
func (this *ModuleBase) WriteUserLog(uid string, tag string, data interface{}) {
|
||||||
|
this.userlog.AddUserLog(uid, tag, data)
|
||||||
|
}
|
||||||
|
@ -354,8 +354,12 @@ type DBUserLog 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
|
||||||
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID
|
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"`
|
||||||
|
ExpireAt int64 `protobuf:"varint,3,opt,name=expireAt,proto3" json:"expireAt"`
|
||||||
|
Logtype string `protobuf:"bytes,4,opt,name=logtype,proto3" json:"logtype"`
|
||||||
|
Tag string `protobuf:"bytes,5,opt,name=tag,proto3" json:"tag"`
|
||||||
|
Data string `protobuf:"bytes,6,opt,name=data,proto3" json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBUserLog) Reset() {
|
func (x *DBUserLog) Reset() {
|
||||||
@ -404,6 +408,34 @@ func (x *DBUserLog) GetUid() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *DBUserLog) GetExpireAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.ExpireAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DBUserLog) GetLogtype() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Logtype
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DBUserLog) GetTag() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Tag
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DBUserLog) GetData() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Data
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
var File_userexpand_proto protoreflect.FileDescriptor
|
var File_userexpand_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_userexpand_proto_rawDesc = []byte{
|
var file_userexpand_proto_rawDesc = []byte{
|
||||||
@ -508,11 +540,17 @@ var file_userexpand_proto_rawDesc = []byte{
|
|||||||
0x66, 0x72, 0x61, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
|
0x66, 0x72, 0x61, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
|
||||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
|
||||||
0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
|
0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
|
||||||
0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x2d, 0x0a, 0x09, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x4c,
|
0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x89, 0x01, 0x0a, 0x09, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72,
|
||||||
0x6f, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02,
|
0x4c, 0x6f, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x03, 0x75, 0x69, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x41,
|
||||||
0x6f, 0x74, 0x6f, 0x33,
|
0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x41,
|
||||||
|
0x74, 0x12, 0x18, 0x0a, 0x07, 0x6c, 0x6f, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01,
|
||||||
|
0x28, 0x09, 0x52, 0x07, 0x6c, 0x6f, 0x67, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74,
|
||||||
|
0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x12, 0x0a,
|
||||||
|
0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74,
|
||||||
|
0x61, 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