diff --git a/modules/modeluserlog.go b/modules/modeluserlog.go index 8f1586313..64a903a0e 100644 --- a/modules/modeluserlog.go +++ b/modules/modeluserlog.go @@ -5,7 +5,6 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" - "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" "go_dreamfactory/utils" @@ -39,6 +38,17 @@ func (this *modelUserLog) Init(service core.IService, module core.IModule, comp return } +type DBUserLogRecord struct { + 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"` + Logtype string `protobuf:"bytes,3,opt,name=logtype,proto3" json:"logtype"` + Tag string `protobuf:"bytes,4,opt,name=tag,proto3" json:"tag"` + Data string `protobuf:"bytes,5,opt,name=data,proto3" json:"data"` + Ctime int64 `protobuf:"varint,6,opt,name=ctime,proto3" json:"ctime"` // 写日志的时间 + Req string `protobuf:"bytes,7,opt,name=req,proto3" json:"req"` // 请求参数 + ExpireAt time.Time `bson:"expireAt,omitempty"` +} + // 用户操作明细数据记录 func (this *modelUserLog) AddUserLog(uid string, req interface{}, itype int32, tag string, data interface{}) { var ( @@ -76,15 +86,15 @@ func (this *modelUserLog) AddUserLog(uid string, req interface{}, itype int32, t if db.IsCross() { //如果是跨服 直接找到对应的本服 if tag, _, b := utils.UIdSplit(uid); b { if conn, err := db.ServerDBConn(tag); err == nil { - if _, err = conn.Mgo.InsertOne(core.SqlTable(this.TableName), &pb.DBUserLog{ + if _, err = conn.Mgo.InsertOne(core.SqlTable(this.TableName), &DBUserLogRecord{ Id: primitive.NewObjectID().Hex(), Uid: uid, - ExpireAt: time.Now().Add(time.Hour * 24 * 8).Unix(), Logtype: logType, Tag: tag, Data: string(jsonStr), Ctime: configure.Now().Unix(), Req: string(jsonReq), + ExpireAt: configure.Now().Add(time.Hour * 24 * 8), }); err != nil { log.Errorln(err) return @@ -92,15 +102,15 @@ func (this *modelUserLog) AddUserLog(uid string, req interface{}, itype int32, t } } } else { // 本服 直接操作本服数据 - if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), &pb.DBUserLog{ + if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), &DBUserLogRecord{ Id: primitive.NewObjectID().Hex(), Uid: uid, - ExpireAt: time.Now().Add(time.Hour * 24 * 8).Unix(), Logtype: logType, Tag: tag, Data: string(jsonStr), Ctime: configure.Now().Unix(), Req: string(jsonReq), + ExpireAt: configure.Now().Add(time.Hour * 24 * 8), }); err != nil { log.Errorln(err) return diff --git a/pb/userexpand.pb.go b/pb/userexpand.pb.go index 5ba271a7d..f3a0b397f 100644 --- a/pb/userexpand.pb.go +++ b/pb/userexpand.pb.go @@ -347,14 +347,13 @@ type DBUserLog struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - 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"` - 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"` - Ctime int64 `protobuf:"varint,7,opt,name=ctime,proto3" json:"ctime"` // 写日志的时间 - Req string `protobuf:"bytes,8,opt,name=req,proto3" json:"req"` // 请求参数 + 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"` + Logtype string `protobuf:"bytes,3,opt,name=logtype,proto3" json:"logtype"` + Tag string `protobuf:"bytes,4,opt,name=tag,proto3" json:"tag"` + Data string `protobuf:"bytes,5,opt,name=data,proto3" json:"data"` + Ctime int64 `protobuf:"varint,6,opt,name=ctime,proto3" json:"ctime"` // 写日志的时间 + Req string `protobuf:"bytes,7,opt,name=req,proto3" json:"req"` // 请求参数 } func (x *DBUserLog) Reset() { @@ -403,13 +402,6 @@ func (x *DBUserLog) GetUid() string { 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 @@ -542,19 +534,18 @@ var file_userexpand_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x48, 0x65, 0x72, 0x6f, 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, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xb1, 0x01, 0x0a, 0x09, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x95, 0x01, 0x0a, 0x09, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x65, - 0x78, 0x70, 0x69, 0x72, 0x65, 0x41, 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, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x10, 0x0a, - 0x03, 0x72, 0x65, 0x71, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x42, - 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6c, + 0x6f, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x6f, + 0x67, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x63, + 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x71, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x72, 0x65, 0x71, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var (