hsun 1 year ago
parent
commit
07fa6ea56c

+ 1 - 1
controller/index_data/jiayue_index.go

@@ -68,7 +68,7 @@ func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
 		return
 	}
 
-	total, list, err := indexDataService.GetPageIndexesFromJiaYue(req.PageIndex, req.PageSize, sourceArr, req.Keyword, req.Frequency)
+	total, list, err := indexDataService.GetPageIndexesFromJiaYue(req.PageIndex, req.PageSize, sourceArr, req.Keyword, req.Frequency, req.SortField, req.SortRule)
 	if err != nil {
 		resp.FailMsg("查询失败", err.Error(), c)
 		return

+ 11 - 2
models/jiayue/dict.go

@@ -30,7 +30,7 @@ func GetDictIndex(condition string, pars []interface{}) (dictIndexList []DictInd
 }
 
 // GetDictPageIndex 分页获取指标
-func GetDictPageIndex(condition string, pars []interface{}, pageIndex, pageSize int) (dictIndexList []DictIndex, err error) {
+func GetDictPageIndex(condition string, pars []interface{}, pageIndex, pageSize, sortField, sortRule int) (dictIndexList []DictIndex, err error) {
 	defer func() {
 		if err != nil {
 			fmt.Printf("查询指标信息失败 %s", err)
@@ -39,7 +39,16 @@ func GetDictPageIndex(condition string, pars []interface{}, pageIndex, pageSize
 	}()
 
 	fields := "ID, CODE, NAME, UNIT, FREQUENCY, DESCRIPTION, TABLE_NAME, SOURCE_TYPE, SOURCE_CODE, SOURCE_DESCRIPTION, INDUSTRY, TYPE, COMMODITY, SJB_ID, USER_ID, ROWS_COUNT, DATE_FIRST, DATE_LAST, TIME_LAST_UPDATE, TIME_LAST_REQUEST, PRIORITY, STATUS, SHORT_NAME, UPDATE_DESCRIPTION, FORECAST_FLAG, MANUAL_FLAG, VARIABLE_FLAG, MARKETDATA_FLAG, CREATE_USER, CREATE_TIME, UPDATE_USER, UPDATE_TIME"
-	sqlBase := fmt.Sprintf(`SELECT %s, no FROM (SELECT rownum no, a.* FROM %s a WHERE %s) WHERE no BETWEEN %d AND %d`, fields, IndexTableName, condition, (pageIndex-1)*pageSize+1, pageIndex*pageSize)
+
+	// 排序
+	order := ``
+	sortFMap := map[int]string{1: "DateFirst", 2: "DateLast", 3: "TimeLastUpdate"}
+	sortRMap := map[int]string{1: "ASC", 2: "DESC"}
+	if sortFMap[sortField] != "" && sortRMap[sortRule] != "" {
+		order = fmt.Sprintf("ORDER BY %s %s", sortFMap[sortField], sortRMap[sortRule])
+	}
+
+	sqlBase := fmt.Sprintf(`SELECT %s, no FROM (SELECT rownum no, a.* FROM %s a WHERE %s) WHERE no BETWEEN %d AND %d %s`, fields, IndexTableName, condition, (pageIndex-1)*pageSize+1, pageIndex*pageSize, order)
 	dictIndexList, err = getDictIndex(sqlBase, pars)
 	if err != nil {
 		err = fmt.Errorf("查询指标信息失败 %s", err)

+ 2 - 0
models/request/index_data/jiayue_index.go

@@ -7,4 +7,6 @@ type JiaYuePageIndexReq struct {
 	Frequency    string `json:"frequency" form:"frequency" description:"频度"`
 	PageIndex    int    `json:"page_index" form:"page_index" description:"当前页码"`
 	PageSize     int    `json:"page_size" form:"page_size" description:"每页数据量"`
+	SortField    int    `json:"sort_field" form:"sort_field" description:"排序字段: 1-指标开始时间; 2-指标最新时间; 3-更新时间"`
+	SortRule     int    `json:"sort_rule" form:"sort_rule" description:"排序方式: 1-正序; 2-倒序"`
 }

+ 2 - 2
services/index_data/jiayue_platform.go

@@ -146,7 +146,7 @@ func GetIndexFromJiaYue(indexCode, source, startDate, endDate string) (data *res
 }
 
 // GetPageIndexesFromJiaYue 分页获取指标数据
-func GetPageIndexesFromJiaYue(pageIndex, pageSize int, sourceArr []string, keyword, frequency string) (total int, result []jiayue.DictIndex, err error) {
+func GetPageIndexesFromJiaYue(pageIndex, pageSize int, sourceArr []string, keyword, frequency string, sortField, sortRule int) (total int, result []jiayue.DictIndex, err error) {
 	defer func() {
 		if err != nil {
 			global.LOG.Info("GetPageIndexesFromJiaYue Err: " + err.Error())
@@ -182,7 +182,7 @@ func GetPageIndexesFromJiaYue(pageIndex, pageSize int, sourceArr []string, keywo
 	total = t
 
 	// 列表数据
-	indexes, e := jiayue.GetDictPageIndex(indexCond, indexPars, pageIndex, pageSize)
+	indexes, e := jiayue.GetDictPageIndex(indexCond, indexPars, pageIndex, pageSize, sortField, sortRule)
 	if e != nil {
 		err = fmt.Errorf("GetDictPageIndex err: %s", e.Error())
 		return