package questionnaire import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/mgo" "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 ModelQuestionnaire struct { modules.MCompModel module *Questionnaire } func (this *ModelQuestionnaire) 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.TableWtask this.module = module.(*Questionnaire) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } // 获取用户全部的埋点数据 func (this *ModelQuestionnaire) getUserQuestionnaire(uid string) (results *pb.DBQuestionnaire, err error) { results = &pb.DBQuestionnaire{ Group: make(map[int32]*pb.DBQuestionGroup), } if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } if err == mgo.MongodbNil { err = nil results = &pb.DBQuestionnaire{ Id: primitive.NewObjectID().Hex(), Uid: uid, Group: make(map[int32]*pb.DBQuestionGroup), } err = this.Add(uid, results) } return } func (this *ModelQuestionnaire) updateUserQuestionnaire(uid string, data *pb.DBQuestionnaire) (err error) { if err = this.Change(uid, map[string]interface{}{ "group": data.Group, }); err != nil { this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()}) return } return }