浏览代码

test 嘉悦指标频度

hsun 1 年之前
父节点
当前提交
b88555f938
共有 3 个文件被更改,包括 64 次插入3 次删除
  1. 16 0
      controller/index_data/jiayue_index.go
  2. 47 2
      models/jiayue/dict.go
  3. 1 1
      routers/index_data.go

+ 16 - 0
controller/index_data/jiayue_index.go

@@ -3,12 +3,14 @@ package index_data
 import (
 	"eta/eta_bridge/controller/resp"
 	"eta/eta_bridge/global"
+	"eta/eta_bridge/models/jiayue"
 	indexDataReq "eta/eta_bridge/models/request/index_data"
 	indexDataService "eta/eta_bridge/services/index_data"
 	"github.com/gin-gonic/gin"
 	"github.com/go-playground/validator/v10"
 )
 
+// JiaYueIndexController 嘉悦指标
 type JiaYueIndexController struct{}
 
 // GetData
@@ -67,3 +69,17 @@ func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
 	resp.OkData("操作成功", data, c)
 	return
 }
+
+// GetIndexFrequency
+// @Description 获取指标频度列表
+// @Success 200 {string} string "获取成功"
+// @Router /jiayue/frequency_list [get]
+func (j *JiaYueIndexController) GetIndexFrequency(c *gin.Context) {
+	list, err := jiayue.GetDictFrequency()
+	if err != nil {
+		resp.FailMsg("获取失败", err.Error(), c)
+		return
+	}
+	resp.OkData("获取成功", list, c)
+	return
+}

+ 47 - 2
models/jiayue/dict.go

@@ -6,6 +6,10 @@ import (
 	"fmt"
 )
 
+var (
+	IndexTableName = "DICT_INDEX"
+)
+
 func GetDictIndex(condition string, pars []interface{}) (dictIndexList []DictIndex, err error) {
 	defer func() {
 		if err != nil {
@@ -13,7 +17,7 @@ func GetDictIndex(condition string, pars []interface{}) (dictIndexList []DictInd
 		}
 	}()
 	selectVals := "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"
-	sqlStatement := fmt.Sprintf("SELECT %s FROM DICT_INDEX WHERE %s", selectVals, condition)
+	sqlStatement := fmt.Sprintf("SELECT %s, 0 AS no FROM %s WHERE %s", selectVals, IndexTableName, condition)
 	dictIndexList, err = getDictIndex(sqlStatement, pars)
 	if err != nil {
 		fmt.Printf("查询指标信息失败 %s", err)
@@ -34,7 +38,7 @@ 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 DICT_INDEX a WHERE %s) WHERE no BETWEEN %d AND %d`, fields, condition, (pageIndex-1)*pageSize+1, pageIndex*pageSize)
+	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)
 	dictIndexList, err = getDictIndex(sqlBase, pars)
 	if err != nil {
 		err = fmt.Errorf("查询指标信息失败 %s", err)
@@ -293,3 +297,44 @@ func getDictData(sqlStatement string, pars []interface{}) (dictData []DictData,
 	fmt.Printf("序列化后 = %v\n", string(data))*/
 	return
 }
+
+// GetDictFrequency 获取指标频度
+func GetDictFrequency() (frequencies []string, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Info("嘉悦-获取指标频度失败, Err:" + err.Error())
+		}
+	}()
+
+	sqlBase := fmt.Sprintf(`SELECT DISTINCT FREQUENCY FROM %s`, IndexTableName)
+	stmt, e := global.OracleJy.Prepare(sqlBase)
+	if e != nil {
+		err = fmt.Errorf("预处理sql失败, err: %s", e.Error())
+		return
+	}
+	rows, e := stmt.Query()
+	if e != nil {
+		err = fmt.Errorf("查询sql失败, err: %s", e.Error())
+		return
+	}
+	defer func() {
+		_ = rows.Close() // 关闭查询连接
+	}()
+
+	for rows.Next() {
+		var frequency string
+		if e = rows.Scan(&frequency); e != nil {
+			err = fmt.Errorf("扫描错误, err: %s", e.Error())
+			return
+		}
+		frequencies = append(frequencies, frequency)
+	}
+	if e = rows.Err(); e != nil {
+		err = fmt.Errorf("解析行数据失败, err: %s", e.Error())
+		return
+	}
+	defer func() {
+		_ = stmt.Close()
+	}()
+	return
+}

+ 1 - 1
routers/index_data.go

@@ -8,8 +8,8 @@ import (
 // InitIndexData 获取指标信息
 func InitIndexData(r *gin.RouterGroup) {
 	control := new(index_data.JiaYueIndexController)
-	//group := r.Group("index_data/").Use(middleware.Token())
 	group := r.Group("index_data/")
 	group.GET("jiayue/index", control.GetData)
 	group.GET("jiayue/page_index", control.GetPageIndex)
+	group.GET("jiayue/frequency_list", control.GetIndexFrequency)
 }