parent
4db5ba399e
commit
07957ec7f2
@ -0,0 +1,9 @@
|
|||||||
|
package StudentController
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func GetStudentCountByArea(c *gin.Context) {
|
||||||
|
cityCode := c.Query("cityCode")
|
||||||
|
districtCode := c.Query("districtCode")
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,59 @@
|
|||||||
package StudentDao
|
package StudentDao
|
||||||
|
|
||||||
import "dsBigData/Utils/EsUtil"
|
import (
|
||||||
|
"dsBigData/Business/Student/StudentModel"
|
||||||
|
"dsBigData/Utils/CommonUtil"
|
||||||
|
"dsBigData/Utils/EsUtil"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/olivere/elastic/v7"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
)
|
||||||
|
|
||||||
var esClient = EsUtil.EsClient
|
var esClient = EsUtil.EsClient
|
||||||
var CTX = EsUtil.CTX
|
var CTX = EsUtil.CTX
|
||||||
|
|
||||||
|
func GetStudentCountByCityOrDistrict(cityCode string, districtCode string) ([]StudentModel.StudentCountAggsXxbxlx, error) {
|
||||||
|
enableFlagTerm := elastic.NewTermQuery("enable_flag", 1)
|
||||||
|
delFlagTerm := elastic.NewTermQuery("del_flag", 0)
|
||||||
|
bUseTerm := elastic.NewTermQuery("data_content.b_use", 1)
|
||||||
|
|
||||||
|
var areaTerm *elastic.TermQuery
|
||||||
|
if len(cityCode) > 0 {
|
||||||
|
areaTerm = elastic.NewTermQuery("city_code", cityCode)
|
||||||
|
} else if len(districtCode) > 0 {
|
||||||
|
areaTerm = elastic.NewTermQuery("district_code", districtCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
boolQuery := elastic.NewBoolQuery().Must(areaTerm, enableFlagTerm, delFlagTerm, bUseTerm)
|
||||||
|
|
||||||
|
xxbxlxAggs := elastic.
|
||||||
|
NewTermsAggregation().
|
||||||
|
Field("school_type").
|
||||||
|
Size(50)
|
||||||
|
|
||||||
|
result, err := esClient.Search().
|
||||||
|
Index("user_student").
|
||||||
|
Query(boolQuery).
|
||||||
|
Size(1000).
|
||||||
|
Aggregation("district", xxbxlxAggs).
|
||||||
|
Do(CTX)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resByte, err := json.Marshal(result.Aggregations)
|
||||||
|
resStr := string(resByte)
|
||||||
|
|
||||||
|
var studentCountAggsXxbxlxArr []StudentModel.StudentCountAggsXxbxlx
|
||||||
|
resCount := gjson.Get(resStr, "xxbxlx.buckets.#")
|
||||||
|
for i := 0; i < int(resCount.Num); i++ {
|
||||||
|
var studentCountAggsXxbxlx StudentModel.StudentCountAggsXxbxlx
|
||||||
|
studentCountAggsXxbxlx.XxbxlxCode = gjson.Get(resStr, "xxbxlx.buckets."+CommonUtil.ConvertIntToString(i)+".key").Str
|
||||||
|
studentCountAggsXxbxlx.Count = gjson.Get(resStr, "xxbxlx.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Raw
|
||||||
|
|
||||||
|
studentCountAggsXxbxlxArr = append(studentCountAggsXxbxlxArr, studentCountAggsXxbxlx)
|
||||||
|
}
|
||||||
|
return studentCountAggsXxbxlxArr, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package StudentModel
|
||||||
|
|
||||||
|
type StudentCountAggsXxbxlx struct{
|
||||||
|
XxbxlxCode string `json:"xxbxlx_code"`
|
||||||
|
Count string `json:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StudentCount struct {
|
||||||
|
XxbxlxCode string `json:"xxbxlx_code"`
|
||||||
|
XxbxlxName string `json:"xxbxlx_name"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package StudentService
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dsBigData/Business/Student/StudentDao"
|
||||||
|
"dsBigData/Business/Student/StudentModel"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetStudentCountByCityOrDistrict(cityCode string, districtCode string) ([]StudentModel.StudentCountAggsXxbxlx, error) {
|
||||||
|
arr, err := StudentDao.GetStudentCountByCityOrDistrict(cityCode, districtCode)
|
||||||
|
return arr, err
|
||||||
|
}
|
Loading…
Reference in new issue