From b283c34f44a383941c86e046db3dcbc2c0a6bd28 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 22 Jul 2024 09:17:49 +0800 Subject: [PATCH] by Robin at 20240722 --- api/consts/consts.go | 2 + .../proto/Raven_IQ_test_vo_api.go | 12 +++-- apollostruct/RavenIQtest.go | 13 ++++++ app/mix/service/apiservice.go | 46 +++++++++++++++---- dbstruct/RavenIQTest.go | 12 ++++- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/api/consts/consts.go b/api/consts/consts.go index acfed7d5..01bc4720 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -59,7 +59,9 @@ const ( HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage" QuestionMapKey = "question_map" AgeScore2IQResultMapKey = "age_score_2_IQ_result_map" + ClassScore2ClassResultMapKey = "class_score_2_class_result_map" IQResultMapKey = "IQ_result_map" + ClassResultMapKey = "class_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 2e7c6aa6..abd90fba 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 @@ -16,9 +16,10 @@ type ApiListVO struct { } type ApiClassSocreVO struct { - ClassId int64 `json:"class_id"` // 大类id - Score int64 `json:"score"` // 得分 - Suggestions string `json:"suggestions"` // 建议 + ClassId int64 `json:"class_id"` // 大类id + Score int64 `json:"score"` // 得分 + ClassBlockId int64 `json:"class_block_id"` // 大类得分key + Suggestions string `json:"suggestions"` // 建议 } func (vo *ApiListVO) CopyRavenIQTest(test *dbstruct.RavenIQTest) *ApiListVO { @@ -33,8 +34,9 @@ func (vo *ApiListVO) CopyRavenIQTest(test *dbstruct.RavenIQTest) *ApiListVO { vo.ClassScoreList = make([]*ApiClassSocreVO, 0) for _, score := range test.ClassScoreList { vo.ClassScoreList = append(vo.ClassScoreList, &ApiClassSocreVO{ - ClassId: score.GetClassId(), - Score: score.GetScore(), + ClassId: score.GetClassId(), + Score: score.GetScore(), + ClassBlockId: score.GetClassBlockId(), }) } return vo diff --git a/apollostruct/RavenIQtest.go b/apollostruct/RavenIQtest.go index e16a63b0..7d0efe66 100644 --- a/apollostruct/RavenIQtest.go +++ b/apollostruct/RavenIQtest.go @@ -22,6 +22,19 @@ type AgeScore2IQResultMapCfg struct { ScoreBlockIndex2IQBlockIdMap map[int]int64 `json:"score_block_index_2_IQ_block_id_map"` // 分数分段到IQ范围id的映射map } +type ClassScore2ClassResultMapCfg struct { + ClassId2ClassScoreBlockListMap map[int64][]int64 `json:"class_id_2_class_score_block_list_map" bson:"class_id_2_class_score_block_list_map"` // 大类Id到大类分数分布区域的映射map +} + type IQResultMapCfg struct { Map map[int64]*IQResult `json:"map"` } + +type ClassResult struct { + ClassId int64 `json:"class_id"` // 大类id + Description string `json:"description"` // 描述 +} + +type ClassResultMapCfg struct { + Map map[int64]*ClassResult `json:"map"` +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index e84b4996..b8d6eb95 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -3619,17 +3619,33 @@ func (s *Service) ApiCreateRavenIQTest(ctx *gin.Context, req *Raven_IQ_testproto req.TotalScore = goproto.Float64(totalScore) // 换算智商及百分位 - cfg := apollostruct.AgeScore2IQResultMapCfg{} - err = apollo.GetJson(consts.AgeScore2IQResultMapKey, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) + ageScore2IQResultMapCfg := apollostruct.AgeScore2IQResultMapCfg{} + err = apollo.GetJson(consts.AgeScore2IQResultMapKey, &ageScore2IQResultMapCfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) if err != nil { logger.Error("Apollo read failed : %v", err) ec = errcode.ErrCodeApolloReadFail return } - ageBlockIdx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge()) - list := cfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx] + + classScore2ClassResultMapCfg := apollostruct.ClassScore2ClassResultMapCfg{} + err = apollo.GetJson(consts.ClassScore2ClassResultMapKey, &classScore2ClassResultMapCfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + ec = errcode.ErrCodeApolloReadFail + return + } + + ageBlockIdx := util.GetLastLessOrEqualForInt64(ageScore2IQResultMapCfg.AgeBlockList, req.GetAge()) + list := ageScore2IQResultMapCfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx] scoreBlockIdx := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore()) - IQBlockId := cfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx] + IQBlockId := ageScore2IQResultMapCfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx] + + for _, classScore := range req.ClassScoreList { + classScoreBlockList := classScore2ClassResultMapCfg.ClassId2ClassScoreBlockListMap[classScore.GetClassId()] + classScoreBlockIdx := util.GetLastLessOrEqualForInt64(classScoreBlockList, classScore.GetScore()) + classScore.ClassBlockId = goproto.Int64(int64(classScoreBlockIdx)) + } + req.IQBlockId = goproto.Int64(IQBlockId) err = _DefaultRavenIQTest.OpCreate(ctx, &Raven_IQ_testproto.OpCreateReq{ @@ -3664,16 +3680,30 @@ 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")) + IQResultMpcfg := apollostruct.IQResultMapCfg{} + err = apollo.GetJson(consts.IQResultMapKey, &IQResultMpcfg, 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] + + classResultMpCfg := apollostruct.ClassResultMapCfg{} + err = apollo.GetJson(consts.ClassResultMapKey, &classResultMpCfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + ec = errcode.ErrCodeApolloReadFail + return + } + + IQResult := IQResultMpcfg.Map[vo.IQBlockId] vo.Percentile = IQResult.Percentile vo.Description = IQResult.Description + for _, classScore := range vo.ClassScoreList { + classResult := classResultMpCfg.Map[classScore.ClassBlockId] + classScore.Suggestions = classResult.Description + } + return } diff --git a/dbstruct/RavenIQTest.go b/dbstruct/RavenIQTest.go index 30c03b9d..3747d123 100644 --- a/dbstruct/RavenIQTest.go +++ b/dbstruct/RavenIQTest.go @@ -19,8 +19,9 @@ type RavenIQTestAnswer struct { } type RavenIQTestClassScore struct { - ClassId *int64 `json:"class_id" bson:"class_id"` // 大类id - Score *int64 `json:"score" bson:"score"` // 得分 + ClassId *int64 `json:"class_id" bson:"class_id"` // 大类id + Score *int64 `json:"score" bson:"score"` // 得分 + ClassBlockId *int64 `json:"class_block_id" bson:"class_block_id"` // 大类得分key } func (p *RavenIQTest) GetId() int64 { @@ -85,3 +86,10 @@ func (p *RavenIQTestClassScore) GetScore() int64 { } return *p.Score } + +func (p *RavenIQTestClassScore) GetClassBlockId() int64 { + if p == nil || p.ClassBlockId == nil { + return 0 + } + return *p.ClassBlockId +}