master
wubin 5 years ago
parent 89f50d0852
commit 073cfde4c9

@ -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 {

@ -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,
})
}
/*
*/

@ -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
}

@ -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"`
}

@ -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
}

@ -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,
})
}
/*
*/

@ -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
}

@ -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"`
}

@ -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
}

@ -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
}
/**
intstring

Loading…
Cancel
Save