package mline import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson/primitive" ) //参数校验 func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.MlineGetListReq) (errdata *pb.ErrorData) { if req.CType == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } ///获取主线关卡信息 func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq) (errdata *pb.ErrorData) { rsp := &pb.MlineGetListResp{} errdata = this.GetListCheck(session, req) if errdata != nil { return // 参数校验失败直接返回 } list, err := this.module.modelMline.getMainlineList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } for _, v := range list { if v.CType == req.CType { rsp.Data = append(rsp.Data, v) } } if len(rsp.Data) == 0 { // 什么数据都没有 创建一条 if chapterConf, err := this.module.configure.GetFirstChapterIDByType(req.CType); err == nil { // 配置文件校验 if stageConf := this.module.configure.GetFirstStageIDByChapter(chapterConf.Id); stageConf != nil { newData := &pb.DBMline{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CType: stageConf.Episodetype, ChapterId: stageConf.Chapterid, StageId: stageConf.Id, Star: map[int32]int32{}, Award: map[int32]bool{}, Ps: map[int32]int32{}, } rsp.Data = append(rsp.Data, newData) this.module.modelMline.addNewChapter(session.GetUserId(), newData) } } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } } session.SendMsg(string(this.module.GetType()), MlineGetListResp, rsp) return }