diff --git a/dsBigData/Business/School/SchoolController/SchoolController.go b/dsBigData/Business/School/SchoolController/SchoolController.go index e1c89488..4a1c3a47 100644 --- a/dsBigData/Business/School/SchoolController/SchoolController.go +++ b/dsBigData/Business/School/SchoolController/SchoolController.go @@ -5,6 +5,9 @@ import ( "dsBigData/Business/Dict/DictService" "dsBigData/Business/School/SchoolModel" "dsBigData/Business/School/SchoolService" + "dsBigData/Business/Student/StudentService" + "dsBigData/Business/Teacher/TeacherDao" + "dsBigData/Business/Teacher/TeacherService" "dsBigData/Model" "dsBigData/Utils/CommonUtil" "encoding/json" @@ -20,12 +23,334 @@ func Routers(r *gin.RouterGroup) { rr.GET("/GetEduAssistCountByCity", GetEduAssistCountByCity) rr.GET("/PageStageBySchoolId", PageStageBySchoolId) + rr.GET("/GetCityBaseInfo", GetCityBaseInfo) + rr.GET("/GetDistrictBaseInfo", GetDistrictBaseInfo) + rr.GET("/GetSchoolBaseInfo", GetSchoolBaseInfo) + return } +func test(c *gin.Context) { + count, _ := TeacherDao.GetTeacherCurrentTermAddCount("150400") + + c.JSON(http.StatusOK, Model.Res{ + Success: true, + List: count, + }) +} + +/** +功能:获取市级的基本信息统计 +*/ +func GetCityBaseInfo(c *gin.Context) { + cityCode := c.Query("cityCode") + + TotalCountAndCurrentTermCountArr := make([]SchoolModel.TotalCountAndCurrentTermCount, 0) + + var schoolTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + schoolTotalCount, err := SchoolService.GetOrgTotalCount(cityCode, "2") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + schoolCurrentTermCount, err := SchoolService.GetOrgCurrentTermAddCount(cityCode, "2") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + schoolTotalCountAndCurrentTermCount.Title = "学校数量" + schoolTotalCountAndCurrentTermCount.TotalCount = schoolTotalCount + schoolTotalCountAndCurrentTermCount.CurrentTermAddCount = schoolCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, schoolTotalCountAndCurrentTermCount) + + var eduAssistTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + eduAssistTotalCount, err := SchoolService.GetOrgTotalCount(cityCode, "7") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + eduAssistCurrentTermCount, err := SchoolService.GetOrgCurrentTermAddCount(cityCode, "7") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + eduAssistTotalCountAndCurrentTermCount.Title = "教辅单位数量" + eduAssistTotalCountAndCurrentTermCount.TotalCount = eduAssistTotalCount + eduAssistTotalCountAndCurrentTermCount.CurrentTermAddCount = eduAssistCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, eduAssistTotalCountAndCurrentTermCount) + + var teacherTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + teacherTotalCount, err := TeacherService.GetTeacherTotalCount(cityCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + teacherCurrentTermCount, err := TeacherService.GetTeacherCurrentTermAddCount(cityCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + teacherTotalCountAndCurrentTermCount.Title = "教职工数量" + teacherTotalCountAndCurrentTermCount.TotalCount = teacherTotalCount + teacherTotalCountAndCurrentTermCount.CurrentTermAddCount = teacherCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, teacherTotalCountAndCurrentTermCount) + + var studentTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + studentTotalCount, err := StudentService.GetStudentTotalCount(cityCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + studentCurrentTermCount, err := StudentService.GetStudentCurrentTermAddCount(cityCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + studentTotalCountAndCurrentTermCount.Title = "学生数量" + studentTotalCountAndCurrentTermCount.TotalCount = studentTotalCount + studentTotalCountAndCurrentTermCount.CurrentTermAddCount = studentCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, studentTotalCountAndCurrentTermCount) + + c.JSON(http.StatusOK, Model.Res{ + Success: true, + List: TotalCountAndCurrentTermCountArr, + }) + +} + +/** +功能:获取区级的基本信息统计 +*/ +func GetDistrictBaseInfo(c *gin.Context) { + districtCode := c.Query("districtCode") + + TotalCountAndCurrentTermCountArr := make([]SchoolModel.TotalCountAndCurrentTermCount, 0) + + var schoolTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + schoolTotalCount, err := SchoolService.GetOrgTotalCount(districtCode, "2") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + schoolCurrentTermCount, err := SchoolService.GetOrgCurrentTermAddCount(districtCode, "2") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + schoolTotalCountAndCurrentTermCount.Title = "学校数量" + schoolTotalCountAndCurrentTermCount.TotalCount = schoolTotalCount + schoolTotalCountAndCurrentTermCount.CurrentTermAddCount = schoolCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, schoolTotalCountAndCurrentTermCount) + + var eduAssistTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + eduAssistTotalCount, err := SchoolService.GetOrgTotalCount(districtCode, "7") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + eduAssistCurrentTermCount, err := SchoolService.GetOrgCurrentTermAddCount(districtCode, "7") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + eduAssistTotalCountAndCurrentTermCount.Title = "教辅单位数量" + eduAssistTotalCountAndCurrentTermCount.TotalCount = eduAssistTotalCount + eduAssistTotalCountAndCurrentTermCount.CurrentTermAddCount = eduAssistCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, eduAssistTotalCountAndCurrentTermCount) + + var teacherTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + teacherTotalCount, err := TeacherService.GetTeacherTotalCount(districtCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + teacherCurrentTermCount, err := TeacherService.GetTeacherCurrentTermAddCount(districtCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + teacherTotalCountAndCurrentTermCount.Title = "教职工数量" + teacherTotalCountAndCurrentTermCount.TotalCount = teacherTotalCount + teacherTotalCountAndCurrentTermCount.CurrentTermAddCount = teacherCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, teacherTotalCountAndCurrentTermCount) + + var studentTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + studentTotalCount, err := StudentService.GetStudentTotalCount(districtCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + studentCurrentTermCount, err := StudentService.GetStudentCurrentTermAddCount(districtCode) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + studentTotalCountAndCurrentTermCount.Title = "学生数量" + studentTotalCountAndCurrentTermCount.TotalCount = studentTotalCount + studentTotalCountAndCurrentTermCount.CurrentTermAddCount = studentCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, studentTotalCountAndCurrentTermCount) + + c.JSON(http.StatusOK, Model.Res{ + Success: true, + List: TotalCountAndCurrentTermCountArr, + }) + +} + +/** +功能:获取校级的基本信息统计 +*/ +func GetSchoolBaseInfo(c *gin.Context) { + schoolId := c.Query("schoolId") + + TotalCountAndCurrentTermCountArr := make([]SchoolModel.TotalCountAndCurrentTermCount, 0) + + var classTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + classTotalCount, err := SchoolService.GetClassTotalCount(schoolId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + classCurrentTermCount, err := SchoolService.GetClassCurrentTermAddCount(schoolId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + classTotalCountAndCurrentTermCount.Title = "班级数量" + classTotalCountAndCurrentTermCount.TotalCount = classTotalCount + classTotalCountAndCurrentTermCount.CurrentTermAddCount = classCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, classTotalCountAndCurrentTermCount) + + var orgTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + orgTotalCount, err := SchoolService.GetOrgTotalCount(schoolId,"3") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + orgCurrentTermCount, err := SchoolService.GetOrgCurrentTermAddCount(schoolId,"3") + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + orgTotalCountAndCurrentTermCount.Title = "部门数量" + orgTotalCountAndCurrentTermCount.TotalCount = orgTotalCount + orgTotalCountAndCurrentTermCount.CurrentTermAddCount = orgCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, orgTotalCountAndCurrentTermCount) + + var teacherTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + teacherTotalCount, err := TeacherService.GetTeacherTotalCount(schoolId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + teacherCurrentTermCount, err := TeacherService.GetTeacherCurrentTermAddCount(schoolId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + teacherTotalCountAndCurrentTermCount.Title = "教职工数量" + teacherTotalCountAndCurrentTermCount.TotalCount = teacherTotalCount + teacherTotalCountAndCurrentTermCount.CurrentTermAddCount = teacherCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, teacherTotalCountAndCurrentTermCount) + + var studentTotalCountAndCurrentTermCount SchoolModel.TotalCountAndCurrentTermCount + studentTotalCount, err := StudentService.GetStudentTotalCount(schoolId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + studentCurrentTermCount, err := StudentService.GetStudentCurrentTermAddCount(schoolId) + if err != nil { + c.JSON(http.StatusOK, Model.Res{ + Success: false, + Message: err.Error(), + }) + return + } + studentTotalCountAndCurrentTermCount.Title = "学生数量" + studentTotalCountAndCurrentTermCount.TotalCount = studentTotalCount + studentTotalCountAndCurrentTermCount.CurrentTermAddCount = studentCurrentTermCount + TotalCountAndCurrentTermCountArr = append(TotalCountAndCurrentTermCountArr, studentTotalCountAndCurrentTermCount) + + c.JSON(http.StatusOK, Model.Res{ + Success: true, + List: TotalCountAndCurrentTermCountArr, + }) + +} + /** 功能:根据学校ID获取该学校有哪些学段 - */ +*/ func PageStageBySchoolId(c *gin.Context) { schoolId := c.Query("schoolId") diff --git a/dsBigData/Business/School/SchoolDao/SchoolDao.go b/dsBigData/Business/School/SchoolDao/SchoolDao.go index 325e2124..6be9b13e 100644 --- a/dsBigData/Business/School/SchoolDao/SchoolDao.go +++ b/dsBigData/Business/School/SchoolDao/SchoolDao.go @@ -7,6 +7,8 @@ import ( "encoding/json" "github.com/olivere/elastic/v7" "github.com/tidwall/gjson" + "strings" + "time" ) var esClient = EsUtil.EsClient @@ -327,5 +329,140 @@ func PageStageBySchoolId(schoolId string) ([]SchoolModel.Stage, error) { stageArr = append(stageArr, stage) } return stageArr, nil +} + +/** +功能:根据市或区的编码(也可传单位ID)和机构类型获取总数 +*/ +func GetOrgTotalCount(areaCode string, orgType string) (int, error) { + var areaCodeTerm *elastic.TermQuery + if len(areaCode) == 6 { + if strings.HasSuffix(areaCode, "00") { //市 + areaCodeTerm = elastic.NewTermQuery("city_code", areaCode) + } else { //区 + areaCodeTerm = elastic.NewTermQuery("district_code", areaCode) + } + } else { + areaCodeTerm = elastic.NewTermQuery("org_id", areaCode) + } + orgTypeTerm := elastic.NewTermQuery("data_content.org_type", orgType) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + + boolQuery := elastic.NewBoolQuery().Must(areaCodeTerm, orgTypeTerm, enableFlagTerm, delFlagTerm, bUseTerm) + + result, err := esClient.Search(). + Index("org_school"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} + +/** +功能:根据市或区的编码和机构类型获取当前学期新增数 +*/ +func GetOrgCurrentTermAddCount(areaCode string, orgType string) (int, error) { + endYearStr := CommonUtil.ConvertIntToString(time.Now().Year()) + month := CommonUtil.ConvertStringToInt32(time.Now().Format("1")) + monthStr := "08" + if month >= 3 && month <= 7 { + monthStr = "03" + } + + createTime := endYearStr + "/" + monthStr + "/01 00:00:01" + + var areaCodeTerm *elastic.TermQuery + if len(areaCode) == 6 { + if strings.HasSuffix(areaCode, "00") { //市 + areaCodeTerm = elastic.NewTermQuery("city_code", areaCode) + } else { //区 + areaCodeTerm = elastic.NewTermQuery("district_code", areaCode) + } + } else { + areaCodeTerm = elastic.NewTermQuery("org_id", areaCode) + } + orgTypeTerm := elastic.NewTermQuery("data_content.org_type", orgType) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + createTimeRang := elastic.NewRangeQuery("data_content.create_time").Gte(createTime) + + boolQuery := elastic.NewBoolQuery().Must(areaCodeTerm, orgTypeTerm, enableFlagTerm, delFlagTerm, bUseTerm, createTimeRang) + + result, err := esClient.Search(). + Index("org_school"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} + +/** +功能:根据学校ID获取班级总数 +*/ +func GetClassTotalCount(schoolId string) (int, error) { + orgIdTerm := elastic.NewTermQuery("org_id", schoolId) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + + boolQuery := elastic.NewBoolQuery().Must(orgIdTerm, enableFlagTerm, delFlagTerm, bUseTerm) + + result, err := esClient.Search(). + Index("org_class"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} + +/** +功能:根据学校ID获取班级当前学期新增数 +*/ +func GetClassCurrentTermAddCount(schoolId string) (int, error) { + endYearStr := CommonUtil.ConvertIntToString(time.Now().Year()) + month := CommonUtil.ConvertStringToInt32(time.Now().Format("1")) + monthStr := "08" + if month >= 3 && month <= 7 { + monthStr = "03" + } + + createTime := endYearStr + "/" + monthStr + "/01 00:00:01" + + orgIdTerm := elastic.NewTermQuery("org_id", schoolId) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + createTimeRang := elastic.NewRangeQuery("data_content.create_time").Gte(createTime) + + boolQuery := elastic.NewBoolQuery().Must(orgIdTerm, enableFlagTerm, delFlagTerm, bUseTerm, createTimeRang) + + result, err := esClient.Search(). + Index("org_class"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + return int(result.TotalHits()), nil } diff --git a/dsBigData/Business/School/SchoolModel/SchoolModel.go b/dsBigData/Business/School/SchoolModel/SchoolModel.go index 50f21b25..2ff74096 100644 --- a/dsBigData/Business/School/SchoolModel/SchoolModel.go +++ b/dsBigData/Business/School/SchoolModel/SchoolModel.go @@ -48,3 +48,9 @@ type Stage struct { StageId string `json:"stage_id"` StageName string `json:"stage_name"` } + +type TotalCountAndCurrentTermCount struct { + Title string `json:"title"` + TotalCount int `json:"total_count"` + CurrentTermAddCount int `json:"current_term_add_count"` +} diff --git a/dsBigData/Business/School/SchoolService/SchoolService.go b/dsBigData/Business/School/SchoolService/SchoolService.go index 109b1a91..10c1bce7 100644 --- a/dsBigData/Business/School/SchoolService/SchoolService.go +++ b/dsBigData/Business/School/SchoolService/SchoolService.go @@ -52,3 +52,23 @@ func PageStageBySchoolId(schoolId string) ([]SchoolModel.Stage, error) { arr, err := SchoolDao.PageStageBySchoolId(schoolId) return arr, err } + +func GetOrgTotalCount(areaCode string, orgType string) (int, error) { + count, err := SchoolDao.GetOrgTotalCount(areaCode, orgType) + return count, err +} + +func GetOrgCurrentTermAddCount(areaCode string, orgType string) (int, error) { + count, err := SchoolDao.GetOrgCurrentTermAddCount(areaCode, orgType) + return count, err +} + +func GetClassTotalCount(schoolId string) (int, error) { + count, err := SchoolDao.GetClassTotalCount(schoolId) + return count, err +} + +func GetClassCurrentTermAddCount(schoolId string) (int, error) { + count, err := SchoolDao.GetClassCurrentTermAddCount(schoolId) + return count, err +} diff --git a/dsBigData/Business/Student/StudentDao/StudentDao.go b/dsBigData/Business/Student/StudentDao/StudentDao.go index efbadf1a..05a5414f 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" + "strings" "time" ) @@ -196,3 +197,79 @@ func GetStudentCountAggsRxnf(schoolId string, stageId string) ([]StudentModel.St } return studentCountRxnfArr, nil } + +/** +功能:根据市或区的编码(也可传单位ID)获取学生总数 +*/ +func GetStudentTotalCount(areaCode string) (int, error) { + var areaCodeTerm *elastic.TermQuery + if len(areaCode) == 6 { + if strings.HasSuffix(areaCode, "00") { //市 + areaCodeTerm = elastic.NewTermQuery("city_code", areaCode) + } else { //区 + areaCodeTerm = elastic.NewTermQuery("district_code", areaCode) + } + } else { + areaCodeTerm = elastic.NewTermQuery("org_id", areaCode) + } + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + + boolQuery := elastic.NewBoolQuery().Must(areaCodeTerm, enableFlagTerm, delFlagTerm, bUseTerm) + + result, err := esClient.Search(). + Index("user_student"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} + +/** +功能:根据市或区的编码(也可传单位ID)获取学生当前学期新增数 +*/ +func GetStudentCurrentTermAddCount(areaCode string) (int, error) { + endYearStr := CommonUtil.ConvertIntToString(time.Now().Year()) + month := CommonUtil.ConvertStringToInt32(time.Now().Format("1")) + monthStr := "08" + if month >= 3 && month <= 7 { + monthStr = "03" + } + + createTime := endYearStr + "/" + monthStr + "/01 00:00:01" + + var areaCodeTerm *elastic.TermQuery + if len(areaCode) == 6 { + if strings.HasSuffix(areaCode, "00") { //市 + areaCodeTerm = elastic.NewTermQuery("city_code", areaCode) + } else { //区 + areaCodeTerm = elastic.NewTermQuery("district_code", areaCode) + } + } else { + areaCodeTerm = elastic.NewTermQuery("org_id", areaCode) + } + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + createTimeRang := elastic.NewRangeQuery("data_content.create_time").Gte(createTime) + + boolQuery := elastic.NewBoolQuery().Must(areaCodeTerm, enableFlagTerm, delFlagTerm, bUseTerm, createTimeRang) + + result, err := esClient.Search(). + Index("user_student"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} diff --git a/dsBigData/Business/Student/StudentService/StudentService.go b/dsBigData/Business/Student/StudentService/StudentService.go index 55c65e29..1d06812d 100644 --- a/dsBigData/Business/Student/StudentService/StudentService.go +++ b/dsBigData/Business/Student/StudentService/StudentService.go @@ -24,3 +24,13 @@ func GetStudentCountAggsXb(schoolId string) ([]StudentModel.StudentCountXb, erro arr, err := StudentDao.GetStudentCountAggsXb(schoolId) return arr, err } + +func GetStudentTotalCount(areaCode string) (int, error) { + count, err := StudentDao.GetStudentTotalCount(areaCode) + return count, err +} + +func GetStudentCurrentTermAddCount(areaCode string) (int, error) { + count, err := StudentDao.GetStudentCurrentTermAddCount(areaCode) + return count, err +} diff --git a/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go b/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go index 01ed857a..03e6ea12 100644 --- a/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go +++ b/dsBigData/Business/Teacher/TeacherDao/TeacherDao.go @@ -7,6 +7,8 @@ import ( "encoding/json" "github.com/olivere/elastic/v7" "github.com/tidwall/gjson" + "strings" + "time" ) var esClient = EsUtil.EsClient @@ -183,3 +185,81 @@ func GetTeacherCountAggsBzlb(schoolId string, bzlbs []string) ([]TeacherModel.Te } return teacherCountAggsBzlbArr, nil } + +/** +功能:根据市或区的编码(也可传单位ID)获取教职工总数 +*/ +func GetTeacherTotalCount(areaCode string) (int, error) { + var areaCodeTerm *elastic.TermQuery + if len(areaCode) == 6 { + if strings.HasSuffix(areaCode, "00") { //市 + areaCodeTerm = elastic.NewTermQuery("city_code", areaCode) + } else { //区 + areaCodeTerm = elastic.NewTermQuery("district_code", areaCode) + } + } else { + areaCodeTerm = elastic.NewTermQuery("org_id", areaCode) + } + orgTypeTerm := elastic.NewTermQuery("data_content.identity_id", 5) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + + boolQuery := elastic.NewBoolQuery().Must(areaCodeTerm, orgTypeTerm, enableFlagTerm, delFlagTerm, bUseTerm) + + result, err := esClient.Search(). + Index("user_teacher"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} + +/** +功能:根据市或区的编码(也可传单位ID)获取教职工当前学期新增数 +*/ +func GetTeacherCurrentTermAddCount(areaCode string) (int, error) { + endYearStr := CommonUtil.ConvertIntToString(time.Now().Year()) + month := CommonUtil.ConvertStringToInt32(time.Now().Format("1")) + monthStr := "08" + if month >= 3 && month <= 7 { + monthStr = "03" + } + + createTime := endYearStr + "/" + monthStr + "/01 00:00:01" + + var areaCodeTerm *elastic.TermQuery + if len(areaCode) == 6 { + if strings.HasSuffix(areaCode, "00") { //市 + areaCodeTerm = elastic.NewTermQuery("city_code", areaCode) + } else { //区 + areaCodeTerm = elastic.NewTermQuery("district_code", areaCode) + } + } else { + areaCodeTerm = elastic.NewTermQuery("org_id", areaCode) + } + orgTypeTerm := elastic.NewTermQuery("data_content.identity_id", 5) + enableFlagTerm := elastic.NewTermQuery("enable_flag", 1) + delFlagTerm := elastic.NewTermQuery("del_flag", 0) + bUseTerm := elastic.NewTermQuery("data_content.b_use", 1) + createTimeRang := elastic.NewRangeQuery("data_content.create_time").Gte(createTime) + + boolQuery := elastic.NewBoolQuery().Must(areaCodeTerm, orgTypeTerm, enableFlagTerm, delFlagTerm, bUseTerm, createTimeRang) + + result, err := esClient.Search(). + Index("user_teacher"). + Query(boolQuery). + TrackTotalHits(true). + Do(CTX) + + if err != nil { + return 0, err + } + + return int(result.TotalHits()), nil +} diff --git a/dsBigData/Business/Teacher/TeacherService/TeacherService.go b/dsBigData/Business/Teacher/TeacherService/TeacherService.go index 2fa7921f..ee15a738 100644 --- a/dsBigData/Business/Teacher/TeacherService/TeacherService.go +++ b/dsBigData/Business/Teacher/TeacherService/TeacherService.go @@ -24,3 +24,13 @@ func GetTeacherCountAggsXb(schoolId string) ([]TeacherModel.TeacherCountXb, erro arr, err := TeacherDao.GetTeacherCountAggsXb(schoolId) return arr, err } + +func GetTeacherTotalCount(areaCode string) (int, error) { + count, err := TeacherDao.GetTeacherTotalCount(areaCode) + return count, err +} + +func GetTeacherCurrentTermAddCount(areaCode string) (int, error) { + count, err := TeacherDao.GetTeacherCurrentTermAddCount(areaCode) + return count, err +}