diff --git a/dsBigData/Business/Student/StudentDao/StudentDao.go b/dsBigData/Business/Student/StudentDao/StudentDao.go index 05a5414f..dbfa24d8 100644 --- a/dsBigData/Business/Student/StudentDao/StudentDao.go +++ b/dsBigData/Business/Student/StudentDao/StudentDao.go @@ -5,8 +5,10 @@ import ( "dsBigData/Utils/CommonUtil" "dsBigData/Utils/EsUtil" "encoding/json" + "fmt" "github.com/olivere/elastic/v7" "github.com/tidwall/gjson" + "strconv" "strings" "time" ) @@ -45,12 +47,18 @@ func GetStudentCountAggsXb(schoolId string) ([]StudentModel.StudentCountXb, erro var studentCountXbArr []StudentModel.StudentCountXb resCount := gjson.Get(resStr, "xb.buckets.#") + totalCount := CommonUtil.ConvertInt64ToString(result.TotalHits()) + totalCountFloat, _ := strconv.ParseFloat(totalCount, 64) for i := 0; i < int(resCount.Num); i++ { var studentCountXb StudentModel.StudentCountXb studentCountXb.XbName = gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".key").Str studentCountXb.Count = int(gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num) - + percent := gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num / totalCountFloat * 100 + percentFloat, _ := strconv.ParseFloat(fmt.Sprintf("%.0f", percent), 64) + percentString := CommonUtil.ConverFloat64ToString(percentFloat) + studentCountXb.Percent = percentString + "%" studentCountXbArr = append(studentCountXbArr, studentCountXb) + } return studentCountXbArr, nil diff --git a/dsBigData/Business/Student/StudentModel/StudentModel.go b/dsBigData/Business/Student/StudentModel/StudentModel.go index 42bfbb9b..6e9d0e3c 100644 --- a/dsBigData/Business/Student/StudentModel/StudentModel.go +++ b/dsBigData/Business/Student/StudentModel/StudentModel.go @@ -28,6 +28,7 @@ type StudentCountRxnf struct { } type StudentCountXb struct { - XbName string `json:"xb_name"` - Count int `json:"count"` + XbName string `json:"xb_name"` + Count int `json:"count"` + Percent string `json:"percent"` } diff --git a/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go b/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go index 03e6ea12..14c01d69 100644 --- a/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go +++ b/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go @@ -5,8 +5,10 @@ import ( "dsBigData/Utils/CommonUtil" "dsBigData/Utils/EsUtil" "encoding/json" + "fmt" "github.com/olivere/elastic/v7" "github.com/tidwall/gjson" + "strconv" "strings" "time" ) @@ -42,14 +44,18 @@ func GetTeacherCountAggsXb(schoolId string) ([]TeacherModel.TeacherCountXb, erro resByte, err := json.Marshal(result.Aggregations) resStr := string(resByte) - + totalCount := CommonUtil.ConvertInt64ToString(result.TotalHits()) + totalCountFloat, _ := strconv.ParseFloat(totalCount, 64) var teacherCountXbArr []TeacherModel.TeacherCountXb resCount := gjson.Get(resStr, "xb.buckets.#") for i := 0; i < int(resCount.Num); i++ { var teacherCountXb TeacherModel.TeacherCountXb teacherCountXb.XbName = gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".key").Str teacherCountXb.Count = int(gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num) - + percent := gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num / totalCountFloat * 100 + percentFloat, _ := strconv.ParseFloat(fmt.Sprintf("%.0f", percent), 64) + percentString := CommonUtil.ConverFloat64ToString(percentFloat) + teacherCountXb.Percent = percentString + "%" teacherCountXbArr = append(teacherCountXbArr, teacherCountXb) } return teacherCountXbArr, nil diff --git a/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go b/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go index e5afa298..16157fc2 100644 --- a/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go +++ b/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go @@ -34,6 +34,7 @@ type TeacherCountBzlb struct { } type TeacherCountXb struct { - XbName string `json:"xb_name"` - Count int `json:"count"` + XbName string `json:"xb_name"` + Count int `json:"count"` + Percent string `json:"percent"` }