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