diff --git a/api/consts/consts.go b/api/consts/consts.go index 3c9f4f5f..acfed7d5 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -58,7 +58,8 @@ const ( StreamerScoreFormulaKey = "streamer_score_formula" HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage" QuestionMapKey = "question_map" - AgeScore2IQResultMap = "age_score_2_IQ_result_map" + AgeScore2IQResultMapKey = "age_score_2_IQ_result_map" + IQResultMapKey = "IQ_result_map" ) // del_flag diff --git a/api/proto/Raven_IQ_test/proto/Raven_IQ_test_vo_api.go b/api/proto/Raven_IQ_test/proto/Raven_IQ_test_vo_api.go index 2511a7a7..2e7c6aa6 100644 --- a/api/proto/Raven_IQ_test/proto/Raven_IQ_test_vo_api.go +++ b/api/proto/Raven_IQ_test/proto/Raven_IQ_test_vo_api.go @@ -7,9 +7,9 @@ import ( type ApiListVO struct { Id int64 `json:"id"` // 瑞文智商测试表id UserId int64 `json:"user_id"` // 用户id - Age int64 `json:"age" ` // 年龄 - TotalScores int64 `json:"total_scores"` // 总得分 - IQ float64 `json:"IQ"` // 智商值 + Age int64 `json:"age"` // 年龄 + TotalScore float64 `json:"total_score"` // 总得分 + IQBlockId int64 `json:"IQ_block_id"` // 智商值 Percentile int64 `json:"percentile"` // 百分位 Description string `json:"description"` // 描述 ClassScoreList []*ApiClassSocreVO `json:"class_score_list"` // 大类得分list @@ -28,8 +28,8 @@ func (vo *ApiListVO) CopyRavenIQTest(test *dbstruct.RavenIQTest) *ApiListVO { vo.Id = test.GetId() vo.UserId = test.GetUserId() vo.Age = test.GetAge() - vo.TotalScores = test.GetTotalScores() - vo.IQ = test.GetIQ() + vo.TotalScore = test.GetTotalScore() + vo.IQBlockId = test.GetIQBlockId() vo.ClassScoreList = make([]*ApiClassSocreVO, 0) for _, score := range test.ClassScoreList { vo.ClassScoreList = append(vo.ClassScoreList, &ApiClassSocreVO{ diff --git a/apollostruct/RavenIQtest.go b/apollostruct/RavenIQtest.go index 7afcec21..e16a63b0 100644 --- a/apollostruct/RavenIQtest.go +++ b/apollostruct/RavenIQtest.go @@ -19,5 +19,9 @@ type IQResult struct { type AgeScore2IQResultMapCfg struct { AgeBlockIndex2ScoreBlockListMap map[int][]float64 `json:"age_block_index_2_score_block_list_map"` // 年龄分段到分数分布区域的映射map AgeBlockList []int64 `json:"age_block_list"` // 年龄段区域,以年龄在该年龄段中第一次出现或最后一个比他小的位置作为年龄段索引 - ScoreBlockIndex2IQResultMap map[int]*IQResult `json:"score_block_index_2_IQ_result_map"` // 分数分段到IQ结果的映射map + ScoreBlockIndex2IQBlockIdMap map[int]int64 `json:"score_block_index_2_IQ_block_id_map"` // 分数分段到IQ范围id的映射map +} + +type IQResultMapCfg struct { + Map map[int64]*IQResult `json:"map"` } diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index bb00cb53..e84b4996 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -3620,16 +3620,17 @@ func (s *Service) ApiCreateRavenIQTest(ctx *gin.Context, req *Raven_IQ_testproto // 换算智商及百分位 cfg := apollostruct.AgeScore2IQResultMapCfg{} - err = apollo.GetJson(consts.AgeScore2IQResultMap, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) + err = apollo.GetJson(consts.AgeScore2IQResultMapKey, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) if err != nil { logger.Error("Apollo read failed : %v", err) ec = errcode.ErrCodeApolloReadFail return } - idx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge()) - list := cfg.AgeBlockIndex2ScoreBlockListMap[idx] - idx2 := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore()) - IQResult := cfg.ScoreBlockIndex2IQResultMap[idx2] + ageBlockIdx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge()) + list := cfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx] + scoreBlockIdx := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore()) + IQBlockId := cfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx] + req.IQBlockId = goproto.Int64(IQBlockId) err = _DefaultRavenIQTest.OpCreate(ctx, &Raven_IQ_testproto.OpCreateReq{ BaseRequest: req.BaseRequest, @@ -3663,6 +3664,16 @@ func (s *Service) ApiGetRavenIQTestList(ctx *gin.Context, req *Raven_IQ_testprot vo.CopyRavenIQTest(test) // 填充业务数据 + cfg := apollostruct.IQResultMapCfg{} + err = apollo.GetJson(consts.IQResultMapKey, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + ec = errcode.ErrCodeApolloReadFail + return + } + IQResult := cfg.Map[vo.IQBlockId] + vo.Percentile = IQResult.Percentile + vo.Description = IQResult.Description return } diff --git a/dbstruct/RavenIQTest.go b/dbstruct/RavenIQTest.go index 64efb754..30c03b9d 100644 --- a/dbstruct/RavenIQTest.go +++ b/dbstruct/RavenIQTest.go @@ -5,7 +5,7 @@ type RavenIQTest struct { UserId *int64 `json:"user_id" bson:"user_id"` // 用户id Age *int64 `json:"age" bson:"age"` // 年龄 TotalScore *float64 `json:"total_score" bson:"total_score"` // 总得分 - IQ *float64 `json:"IQ" bson:"IQ"` // 智商值 + IQBlockId *int64 `json:"IQ_block_id" bson:"IQ_block_id"` // 智商值key AnswerList []*RavenIQTestAnswer `json:"answer_list" bson:"answer_list"` // 答案list ClassScoreList []*RavenIQTestClassScore `json:"class_score_list" bson:"class_score_list"` // 大类得分list Ct *int64 `json:"ct" bson:"ct"` // 创建时间 @@ -51,11 +51,11 @@ func (p *RavenIQTest) GetTotalScore() float64 { return *p.TotalScore } -func (p *RavenIQTest) GetIQ() float64 { - if p == nil || p.IQ == nil { +func (p *RavenIQTest) GetIQBlockId() int64 { + if p == nil || p.IQBlockId == nil { return 0 } - return *p.IQ + return *p.IQBlockId } func (p *RavenIQTestAnswer) GetQuestionId() int64 {