From 284ce9af606b41d9507bff3038149706e4826fe4 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Sun, 25 Jun 2023 16:44:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B4=BB=E5=8A=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/activity/api_gethddata.go | 28 +++++++++++++++++++++ modules/activity/model_hddata.go | 42 +++++++++++++++---------------- modules/activity/model_hdlist.go | 10 +++++++- modules/activity/module.go | 13 +++++----- pb/activity_db.pb.go | 22 ++++++++-------- 5 files changed, 76 insertions(+), 39 deletions(-) create mode 100644 modules/activity/api_gethddata.go diff --git a/modules/activity/api_gethddata.go b/modules/activity/api_gethddata.go new file mode 100644 index 000000000..3bb8f2845 --- /dev/null +++ b/modules/activity/api_gethddata.go @@ -0,0 +1,28 @@ +package activity + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" +) + +//参数校验 +func (this *apiComp) GetHdDataCheck(session comm.IUserSession, req *pb.ActivityGetHdDataReq) (errdata *pb.ErrorData) { + + return +} + +func (this *apiComp) GetHdData(session comm.IUserSession, req *pb.ActivityGetHdDataReq) (errdata *pb.ErrorData) { + + list, err := this.module.modelhdData.getHddata(session.GetUserId()) + if err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + } + return + } + session.SendMsg(string(this.module.GetType()), "gethddata", &pb.ActivityGetHdDataResp{ + Data: list, + }) + return +} diff --git a/modules/activity/model_hddata.go b/modules/activity/model_hddata.go index b6901c5af..5d04858cf 100644 --- a/modules/activity/model_hddata.go +++ b/modules/activity/model_hddata.go @@ -6,17 +6,16 @@ import ( "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 modelActivity struct { +type modelhdData struct { modules.MCompModel module *Activity } -func (this *modelActivity) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *modelhdData) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.TableName = string(comm.TableHdData) err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*Activity) @@ -24,30 +23,31 @@ func (this *modelActivity) Init(service core.IService, module core.IModule, comp this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "hdid", Value: bsonx.Int32(1)}}, + }) return } -func (this *modelActivity) getActivityList(uid string) (result *pb.DBActivityData, err error) { - result = &pb.DBActivityData{ - Uid: uid, - Hid: 0, - Gotarr: []int32{}, - Lasttime: 0, - Val: 0, - } - if err = this.Get(uid, result); err != nil { - if mongo.ErrNoDocuments == err { - result.Id = primitive.NewObjectID().Hex() - result.Uid = uid - - this.Add(uid, result) - err = nil - } +// 获取用户活动数据 +func (this *modelhdData) getHddata(uid string) (result []*pb.DBActivityData, err error) { + result = make([]*pb.DBActivityData, 0) + if err = this.GetList(uid, &result); err != nil { + this.module.Errorf("err:%v", err) return } return } -func (this *modelActivity) modifyActivityList(uid string, data map[string]interface{}) error { - return this.Change(uid, data) +// 新增一条活动数据 +func (this *modelhdData) Insert(uid string, data *pb.DBActivityData) (err error) { + if err = this.AddList(uid, data.Id, data); err != nil { + this.module.Errorf("err:%v", err) + return + } + return +} + +func (this *modelhdData) modifyActivityList(uid string, oid string, data map[string]interface{}) error { + return this.ChangeList(uid, oid, data) } diff --git a/modules/activity/model_hdlist.go b/modules/activity/model_hdlist.go index a4e1c5464..590edc298 100644 --- a/modules/activity/model_hdlist.go +++ b/modules/activity/model_hdlist.go @@ -5,6 +5,9 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type modelHdList struct { @@ -16,7 +19,12 @@ func (this *modelHdList) Init(service core.IService, module core.IModule, comp c this.TableName = string(comm.TableHdList) err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*Activity) - + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "hdid", Value: bsonx.Int32(1)}}, + }) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } diff --git a/modules/activity/module.go b/modules/activity/module.go index d9040b914..5b103689c 100644 --- a/modules/activity/module.go +++ b/modules/activity/module.go @@ -12,11 +12,12 @@ import ( type Activity struct { modules.ModuleBase - api *apiComp - configure *configureComp - modelActivity *modelActivity - service core.IService - modelhdList *modelHdList + api *apiComp + configure *configureComp + + service core.IService + modelhdList *modelHdList + modelhdData *modelhdData } func NewModule() core.IModule { @@ -48,7 +49,7 @@ func (this *Activity) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) - this.modelActivity = this.RegisterComp(new(modelActivity)).(*modelActivity) + this.modelhdData = this.RegisterComp(new(modelhdData)).(*modelhdData) this.modelhdList = this.RegisterComp(new(modelHdList)).(*modelHdList) } diff --git a/pb/activity_db.pb.go b/pb/activity_db.pb.go index b423a3d1a..ed35a5b0c 100644 --- a/pb/activity_db.pb.go +++ b/pb/activity_db.pb.go @@ -329,7 +329,7 @@ type DBActivityData 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"` - Hid int32 `protobuf:"varint,3,opt,name=hid,proto3" json:"hid"` + Hdid int32 `protobuf:"varint,3,opt,name=hdid,proto3" json:"hdid"` Gotarr []int32 `protobuf:"varint,4,rep,packed,name=gotarr,proto3" json:"gotarr"` Lasttime int64 `protobuf:"varint,5,opt,name=lasttime,proto3" json:"lasttime"` Val int32 `protobuf:"varint,6,opt,name=val,proto3" json:"val"` @@ -381,9 +381,9 @@ func (x *DBActivityData) GetUid() string { return "" } -func (x *DBActivityData) GetHid() int32 { +func (x *DBActivityData) GetHdid() int32 { if x != nil { - return x.Hid + return x.Hdid } return 0 } @@ -450,16 +450,16 @@ var file_activity_activity_db_proto_rawDesc = []byte{ 0x13, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x68, 0x74, 0x79, 0x70, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, - 0x8a, 0x01, 0x0a, 0x0e, 0x44, 0x42, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x44, 0x61, + 0x8c, 0x01, 0x0a, 0x0e, 0x44, 0x42, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x44, 0x61, 0x74, 0x61, 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, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x03, 0x68, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x6f, 0x74, 0x61, 0x72, 0x72, - 0x18, 0x04, 0x20, 0x03, 0x28, 0x05, 0x52, 0x06, 0x67, 0x6f, 0x74, 0x61, 0x72, 0x72, 0x12, 0x1a, - 0x0a, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, - 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x42, 0x06, 0x5a, 0x04, - 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x64, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x04, 0x68, 0x64, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x6f, 0x74, 0x61, + 0x72, 0x72, 0x18, 0x04, 0x20, 0x03, 0x28, 0x05, 0x52, 0x06, 0x67, 0x6f, 0x74, 0x61, 0x72, 0x72, + 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, + 0x76, 0x61, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (