From 073cfde4c9be050cba7459ebd75087bf4a42298c Mon Sep 17 00:00:00 2001 From: wubin Date: Tue, 7 Jul 2020 13:42:16 +0800 Subject: [PATCH] update --- .../Business/School/SchoolDao/SchoolDao.go | 8 +-- .../StudentController/StudentController.go | 23 ++++++++ .../Business/Student/StudentDao/StudentDao.go | 56 ++++++++++++++++++- .../Student/StudentModel/StudentModel.go | 10 +--- .../Student/StudentService/StudentService.go | 5 ++ .../TeacherController/TeacherController.go | 55 +++++++++++++++++- .../Business/Teacher/TeacherDao/TeacherDao.go | 43 +++++++++++++- .../Teacher/TeacherModel/TeacherModel.go | 10 ++++ .../Teacher/TeacherService/TeacherService.go | 5 ++ dsBigData/Utils/CommonUtil/CommonUtil.go | 10 ++++ 10 files changed, 208 insertions(+), 17 deletions(-) diff --git a/dsBigData/Business/School/SchoolDao/SchoolDao.go b/dsBigData/Business/School/SchoolDao/SchoolDao.go index 5d24dec4..037364bd 100644 --- a/dsBigData/Business/School/SchoolDao/SchoolDao.go +++ b/dsBigData/Business/School/SchoolDao/SchoolDao.go @@ -106,7 +106,7 @@ func AggsDistrictStatEduAssist(districtCodeArr []string) ([]SchoolModel.EduAssis result, err := esClient.Search(). Index("org_school"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("district", districtCodeAggs). Do(CTX) @@ -146,7 +146,7 @@ func AggsDistrictStatSchoolCount(districtCodeArr []string) ([]SchoolModel.School result, err := esClient.Search(). Index("org_school"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("district", districtCodeAggs). Do(CTX) @@ -185,7 +185,7 @@ func AggsXxbxlxStatSchoolCountByDistrictCode(districtCode string) ([]SchoolModel result, err := esClient.Search(). Index("org_school"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("xxbxlx", xxbxlxAggs). Do(CTX) @@ -242,7 +242,7 @@ func GetSchoolCountAggsDistrict(districtCodeArr []string, aggsXxbxlx bool) ([]Sc result, err := esClient.Search(). Index("org_school"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("district", districtCodeAggs). Do(CTX) if err != nil { diff --git a/dsBigData/Business/Student/StudentController/StudentController.go b/dsBigData/Business/Student/StudentController/StudentController.go index 340fefb8..22fef150 100644 --- a/dsBigData/Business/Student/StudentController/StudentController.go +++ b/dsBigData/Business/Student/StudentController/StudentController.go @@ -18,10 +18,33 @@ func Routers(r *gin.RouterGroup) { rr.GET("/GetStudentCountAggsXxbxlxByArea", GetStudentCountAggsXxbxlxByArea) rr.GET("/GetStudentCountAggsOrgByDistrict", GetStudentCountAggsOrgByDistrict) + rr.GET("/GetStudentCountAggsRxnfBySchoolId", GetStudentCountAggsRxnfBySchoolId) return } +/** +功能:根据学校ID聚合入学年份获取学生数量 + */ +func GetStudentCountAggsRxnfBySchoolId(c *gin.Context) { + stageId := c.Query("stageId") + schoolId := c.Query("schoolId") + + studentCountRxnfArr, err := StudentService.GetStudentCountAggsRxnf(schoolId, stageId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + c.JSON(http.StatusOK, Model.Res{ + Success: true, + List: studentCountRxnfArr, + }) + +} + /* 功能:根据区编码聚合学校获取学生数量 */ diff --git a/dsBigData/Business/Student/StudentDao/StudentDao.go b/dsBigData/Business/Student/StudentDao/StudentDao.go index c08151a4..0a32969c 100644 --- a/dsBigData/Business/Student/StudentDao/StudentDao.go +++ b/dsBigData/Business/Student/StudentDao/StudentDao.go @@ -7,6 +7,7 @@ import ( "encoding/json" "github.com/olivere/elastic/v7" "github.com/tidwall/gjson" + "time" ) var esClient = EsUtil.EsClient @@ -39,7 +40,7 @@ func GetStudentCountAggsXxbxlx(districtCode []string, schoolIds []string, xxbxlx result, err := esClient.Search(). Index("user_student"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("xxbxlx", xxbxlxAggs). Do(CTX) @@ -80,7 +81,7 @@ func GetStudentCountAggsOrgId(schoolIds []string) ([]StudentModel.StudentCountAg result, err := esClient.Search(). Index("user_student"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("orgId", orgIdAggs). Do(CTX) @@ -102,3 +103,54 @@ func GetStudentCountAggsOrgId(schoolIds []string) ([]StudentModel.StudentCountAg } return StudentCountAggsOrgArr, nil } + +func GetStudentCountAggsRxnf(schoolId string, stageId string) ([]StudentModel.StudentCountRxnf, error) { + + endYear := time.Now().Year() + startYear := 0 + month := CommonUtil.ConvertStringToInt32(time.Now().Format("1")) + if month < 8 { + endYear = endYear - 1 + } + + if stageId == "2" { + startYear = endYear - 5 + } else { + startYear = endYear - 2 + } + + orgIdTerm := elastic.NewTermQuery("org_id", schoolId) + stageIdTerm := elastic.NewTermQuery("data_content.stage_id", stageId) + rxnfRang := elastic.NewRangeQuery("data_content.rxnf").Gte(startYear).Lte(endYear) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + + boolQuery := elastic.NewBoolQuery().Must(orgIdTerm, stageIdTerm, bUseTerm, rxnfRang, enableFlagTerm, delFlagTerm) + + rxnfHistogramAggregation := elastic.NewHistogramAggregation().Field("data_content.rxnf").MinDocCount(0).ExtendedBounds(float64(startYear), float64(endYear)).Interval(1) + + result, err := esClient.Search(). + Index("user_student"). + Query(boolQuery). + Aggregation("rxnf", rxnfHistogramAggregation). + Do(CTX) + + if err != nil { + return nil, err + } + + resByte, err := json.Marshal(result.Aggregations) + resStr := string(resByte) + + var studentCountRxnfArr []StudentModel.StudentCountRxnf + resCount := gjson.Get(resStr, "rxnf.buckets.#") + for i := 0; i < int(resCount.Num); i++ { + var studentCountRxnf StudentModel.StudentCountRxnf + studentCountRxnf.Rxnf = CommonUtil.ConverFloat64ToString(gjson.Get(resStr, "rxnf.buckets."+CommonUtil.ConvertIntToString(i)+".key").Num) + studentCountRxnf.Count = int(gjson.Get(resStr, "rxnf.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num) + + studentCountRxnfArr = append(studentCountRxnfArr, studentCountRxnf) + } + return studentCountRxnfArr, nil +} diff --git a/dsBigData/Business/Student/StudentModel/StudentModel.go b/dsBigData/Business/Student/StudentModel/StudentModel.go index 187d4c61..a546f1d1 100644 --- a/dsBigData/Business/Student/StudentModel/StudentModel.go +++ b/dsBigData/Business/Student/StudentModel/StudentModel.go @@ -22,13 +22,7 @@ type StudentCountOrg struct { Count int `json:"count"` } -type StudentCountAggsRxnf struct { - OrgId string `json:"org_id"` +type StudentCountRxnf struct { + Rxnf string `json:"rxnf"` Count int `json:"count"` } - -type StudentCountRxnf struct { - OrgId string `json:"org_id"` - OrgName string `json:"org_name"` - Count int `json:"count"` -} \ No newline at end of file diff --git a/dsBigData/Business/Student/StudentService/StudentService.go b/dsBigData/Business/Student/StudentService/StudentService.go index 0f4b4c90..08436b15 100644 --- a/dsBigData/Business/Student/StudentService/StudentService.go +++ b/dsBigData/Business/Student/StudentService/StudentService.go @@ -14,3 +14,8 @@ func GetStudentCountAggsOrgId(schoolIds []string) ([]StudentModel.StudentCountAg arr, err := StudentDao.GetStudentCountAggsOrgId(schoolIds) return arr, err } + +func GetStudentCountAggsRxnf(schoolId string, stageId string) ([]StudentModel.StudentCountRxnf, error) { + arr, err := StudentDao.GetStudentCountAggsRxnf(schoolId, stageId) + return arr, err +} diff --git a/dsBigData/Business/Teacher/TeacherController/TeacherController.go b/dsBigData/Business/Teacher/TeacherController/TeacherController.go index 3a17e125..c909a7ba 100644 --- a/dsBigData/Business/Teacher/TeacherController/TeacherController.go +++ b/dsBigData/Business/Teacher/TeacherController/TeacherController.go @@ -17,12 +17,65 @@ func Routers(r *gin.RouterGroup) { rr := r.Group("/teacher") rr.GET("/GetTeacherCountAggsXxbxlxByArea", GetTeacherCountAggsXxbxlxByArea) - rr.GET("/GetTeacherCountAggsOrgByDistrict", GetTeacherCountAggsSchoolByDistrict) + rr.GET("/GetTeacherCountAggsSchoolByDistrict", GetTeacherCountAggsSchoolByDistrict) rr.GET("/GetTeacherCountAggsEduAssistByDistrict", GetTeacherCountAggsEduAssistByDistrict) + rr.GET("/GetTeacherCountAggsBzlbBySchoolId", GetTeacherCountAggsBzlbBySchoolId) return } +/** +功能:根据学校ID聚合编制获取教师数量 + */ +func GetTeacherCountAggsBzlbBySchoolId(c *gin.Context) { + schoolId := c.Query("schoolId") + + //获取办学类型数组 + bzlbInfo, err := DictService.GetDictInfo("bzlbm") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + bzlbArr := make([]string, 0) + for i := range bzlbInfo { + bzlbArr = append(bzlbArr, bzlbInfo[i].DictCode) + } + + resArr, err := TeacherService.GetTeacherCountAggsBzlb(schoolId, bzlbArr) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + + resMap := make(map[string]int) + for i := range resArr { + resMap[resArr[i].BzlbCode] = resArr[i].Count + } + + teacherCountBzlbArr := make([]TeacherModel.TeacherCountBzlb, 0) + for i := range bzlbInfo { + var teacherCountBzlb TeacherModel.TeacherCountBzlb + bzlbm := bzlbInfo[i].DictCode + teacherCountBzlb.BzlbCode = bzlbm + teacherCountBzlb.BzlbName = bzlbInfo[i].DictValue + if _, ok := resMap[bzlbm]; ok { + teacherCountBzlb.Count = resMap[bzlbm] + } + teacherCountBzlbArr = append(teacherCountBzlbArr, teacherCountBzlb) + } + + c.JSON(http.StatusOK, Model.Res{ + Success: true, + List: teacherCountBzlbArr, + }) +} + /* 功能:根据区编码聚合教辅单位获取教师数量 */ diff --git a/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go b/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go index b534e005..c817bcb3 100644 --- a/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go +++ b/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go @@ -39,7 +39,7 @@ func GetTeacherCountAggsXxbxlxByCityOrDistrict(districtCode []string, schoolIds result, err := esClient.Search(). Index("user_teacher"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("xxbxlx", xxbxlxAggs). Do(CTX) @@ -80,7 +80,7 @@ func GetTeacherCountAggsOrgId(schoolIds []string) ([]TeacherModel.TeacherCountAg result, err := esClient.Search(). Index("user_teacher"). Query(boolQuery). - Size(1000). + Size(0). Aggregation("orgId", orgIdAggs). Do(CTX) @@ -102,3 +102,42 @@ func GetTeacherCountAggsOrgId(schoolIds []string) ([]TeacherModel.TeacherCountAg } return teacherCountAggsOrgArr, nil } + +func GetTeacherCountAggsBzlb(schoolId string, bzlbs []string) ([]TeacherModel.TeacherCountAggsBzlb, error) { + orgIdTerm := elastic.NewTermQuery("org_id", schoolId) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + + boolQuery := elastic.NewBoolQuery().Must(orgIdTerm, bUseTerm, enableFlagTerm, delFlagTerm) + + bzlbAggs := elastic. + NewTermsAggregation(). + Field("data_content.bzlbm"). + Size(10) + + result, err := esClient.Search(). + Index("user_teacher"). + Query(boolQuery). + Size(0). + Aggregation("bzlb", bzlbAggs). + Do(CTX) + + if err != nil { + return nil, err + } + + resByte, err := json.Marshal(result.Aggregations) + resStr := string(resByte) + + var teacherCountAggsBzlbArr []TeacherModel.TeacherCountAggsBzlb + resCount := gjson.Get(resStr, "bzlb.buckets.#") + for i := 0; i < int(resCount.Num); i++ { + var teacherCountAggsBzlb TeacherModel.TeacherCountAggsBzlb + teacherCountAggsBzlb.BzlbCode = gjson.Get(resStr, "bzlb.buckets."+CommonUtil.ConvertIntToString(i)+".key").Str + teacherCountAggsBzlb.Count = int(gjson.Get(resStr, "bzlb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num) + + teacherCountAggsBzlbArr = append(teacherCountAggsBzlbArr, teacherCountAggsBzlb) + } + return teacherCountAggsBzlbArr, nil +} diff --git a/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go b/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go index 23103130..2e6124b4 100644 --- a/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go +++ b/dsBigData/Business/Teacher/TeacherModel/TeacherModel.go @@ -22,3 +22,13 @@ type TeacherCountOrg struct { Count int `json:"count"` } +type TeacherCountAggsBzlb struct { + BzlbCode string `json:"bzlb_code"` + Count int `json:"count"` +} + +type TeacherCountBzlb struct { + BzlbCode string `json:"bzlb_code"` + BzlbName string `json:"bzlb_name"` + Count int `json:"count"` +} diff --git a/dsBigData/Business/Teacher/TeacherService/TeacherService.go b/dsBigData/Business/Teacher/TeacherService/TeacherService.go index 5e3eb913..3e6704d9 100644 --- a/dsBigData/Business/Teacher/TeacherService/TeacherService.go +++ b/dsBigData/Business/Teacher/TeacherService/TeacherService.go @@ -14,3 +14,8 @@ func GetTeacherCountAggsOrgId(schoolIds []string) ([]TeacherModel.TeacherCountAg arr, err := TeacherDao.GetTeacherCountAggsOrgId(schoolIds) return arr, err } + +func GetTeacherCountAggsBzlb(schoolId string, bzlbs []string) ([]TeacherModel.TeacherCountAggsBzlb, error) { + arr, err := TeacherDao.GetTeacherCountAggsBzlb(schoolId, bzlbs) + return arr, err +} diff --git a/dsBigData/Utils/CommonUtil/CommonUtil.go b/dsBigData/Utils/CommonUtil/CommonUtil.go index 9d9ce993..d3b5068a 100644 --- a/dsBigData/Utils/CommonUtil/CommonUtil.go +++ b/dsBigData/Utils/CommonUtil/CommonUtil.go @@ -528,6 +528,16 @@ func ConvertJsonStringToMap(data string) map[string]interface{} { return m } +/** +功能:将float64转为字符串 +作者:吴缤 +时间:2020-07-07 +*/ +func ConverFloat64ToString(f float64) string { + s := strconv.FormatFloat(f, 'f', 0, 64) + return s +} + /** 功能:将int转化为string 作者:黄海