hsun 1 year ago
parent
commit
2ce2d4e627

+ 4 - 0
config/config.go

@@ -15,6 +15,10 @@ type Serve struct {
 	UseRedis  bool   `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
 	AppName   string `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
 	StaticDir string `mapstructure:"static-dir" json:"static-dir" yaml:"static-dir" description:"上传的文件存储目录地址"`
+
+	AppNameEn string `mapstructure:"app-name-en" json:"app-name-en" yaml:"app-name-en" description:"项目名称英文"`
+	Md5Key    string `mapstructure:"md5-key" json:"md5-key" yaml:"md5-key" description:"Md5密钥"`
+	DesKey    string `mapstructure:"des-key" json:"des-key" yaml:"des-key" description:"Des密钥"`
 }
 
 // Log 日志配置

+ 20 - 3
controller/index_data/jiayue_index.go

@@ -5,9 +5,11 @@ import (
 	"eta/eta_bridge/global"
 	"eta/eta_bridge/models/jiayue"
 	indexDataReq "eta/eta_bridge/models/request/index_data"
+	"eta/eta_bridge/models/response"
 	indexDataService "eta/eta_bridge/services/index_data"
 	"github.com/gin-gonic/gin"
 	"github.com/go-playground/validator/v10"
+	"strings"
 )
 
 // JiaYueIndexController 嘉悦指标
@@ -56,16 +58,24 @@ func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
 		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
 		return
 	}
-	if req.Source == "" {
+	if req.SourceExtend == "" {
 		resp.FailMsg("请输入指标来源", "请输入指标来源", c)
 		return
 	}
+	sourceArr := strings.Split(req.SourceExtend, ",")
+	if len(sourceArr) == 0 {
+		resp.FailMsg("指标来源有误", "指标来源有误", c)
+		return
+	}
 
-	data, err := indexDataService.GetPageIndexesFromJiaYue(req.PageIndex, req.PageSize, req.Source, req.Keyword, req.Frequency)
+	total, list, err := indexDataService.GetPageIndexesFromJiaYue(req.PageIndex, req.PageSize, sourceArr, req.Keyword, req.Frequency)
 	if err != nil {
 		resp.FailMsg("查询失败", err.Error(), c)
 		return
 	}
+	var data response.JiaYuePageIndexResp
+	data.Total = total
+	data.List = list
 	resp.OkData("操作成功", data, c)
 	return
 }
@@ -80,6 +90,13 @@ func (j *JiaYueIndexController) GetIndexFrequency(c *gin.Context) {
 		resp.FailMsg("获取失败", err.Error(), c)
 		return
 	}
-	resp.OkData("获取成功", list, c)
+	// 过滤一下空的和斜杠
+	data := make([]string, 0)
+	for _, v := range list {
+		if v != "" && v != "/" {
+			data = append(data, v)
+		}
+	}
+	resp.OkData("获取成功", data, c)
 	return
 }

+ 25 - 0
middleware/token.go

@@ -2,6 +2,7 @@ package middleware
 
 import (
 	"eta/eta_bridge/controller/resp"
+	"eta/eta_bridge/global"
 	"eta/eta_bridge/utils"
 	"github.com/gin-gonic/gin"
 )
@@ -28,3 +29,27 @@ func Token() gin.HandlerFunc {
 		c.Next()
 	}
 }
+
+func InternalToken() gin.HandlerFunc {
+	return func(c *gin.Context) {
+		token := c.Request.Header.Get("Authorization")
+		if token == "" {
+			token = c.DefaultQuery("authorization", "")
+			if token == "" {
+				token = c.DefaultQuery("Authorization", "")
+			}
+		}
+		if token == "" {
+			resp.TokenError(nil, "非法访问", "非法访问", c)
+			c.Abort()
+			return
+		}
+		checkToken := utils.MD5(global.CONFIG.Serve.AppNameEn + global.CONFIG.Serve.Md5Key)
+		if token != checkToken {
+			resp.TokenError(nil, "非法访问", "非法访问", c)
+			c.Abort()
+			return
+		}
+		c.Next()
+	}
+}

+ 80 - 40
models/jiayue/dict.go

@@ -4,6 +4,7 @@ import (
 	"database/sql"
 	"eta/eta_bridge/global"
 	"fmt"
+	"time"
 )
 
 var (
@@ -66,38 +67,38 @@ func GetDictData(tableName string, condition string, pars []interface{}) (dictIn
 }
 
 type DictIndex struct {
-	Id                int    `description:"主键"`
-	Code              string `description:"指标编码"`
-	Name              string `description:"指标名称"`
-	Unit              string `description:"单位"`
-	Frequency         string `description:"更新频率"`
-	Description       string `description:"描述"`
-	TableName         string `description:"指标数据存储库表"`
-	SourceType        string `description:"指标来源,如:wind:万德;manual:手工导入;formula:公式;webisite:网页爬取"`
-	SourceCode        string `description:"来源编码"`
-	SourceDescription string `description:"来源说明"`
-	Industry          string `description:"品种板块"`
-	Type              string `description:"指标类型"`
-	Commodity         string `description:"商品名称"`
-	SjbId             int    `description:"SJB_ID"`
-	UserId            int    `description:"所属用户"`
-	RowsCount         int    `description:"指标数据数量"`
-	DateFirst         string `description:"指标开始时间"`
-	DateLast          string `description:"指标最新时间"`
-	TimeLastUpdate    string `description:"最新更新时间"`
-	TimeLastRequest   string `description:"下次更新时间"`
-	Priority          int    `description:"更新优先级"`
-	Status            int    `description:"指标状态"`
-	ShortName         string `description:"指标简称"`
-	UpdateDescription string `description:"更新说明"`
-	ForecastFlag      int    `description:"预测标识"`
-	ManualFlag        int    `description:"手动标识"`
-	VariableFlag      int    `description:"有效标识"`
-	MarketDataFlag    int    `description:"市场价标识"`
-	CreateUser        int    `description:"创建用户"`
-	CreateTime        string `description:"创建时间"`
-	UpdateUser        int    `description:"更新用户"`
-	UpdateTime        string `description:"更新时间"`
+	Id                int       `description:"主键"`
+	Code              string    `description:"指标编码"`
+	Name              string    `description:"指标名称"`
+	Unit              string    `description:"单位"`
+	Frequency         string    `description:"更新频率"`
+	Description       string    `description:"描述"`
+	TableName         string    `description:"指标数据存储库表"`
+	SourceType        string    `description:"指标来源,如:wind:万德;manual:手工导入;formula:公式;webisite:网页爬取"`
+	SourceCode        string    `description:"来源编码"`
+	SourceDescription string    `description:"来源说明"`
+	Industry          string    `description:"品种板块"`
+	Type              string    `description:"指标类型"`
+	Commodity         string    `description:"商品名称"`
+	SjbId             int       `description:"SJB_ID"`
+	UserId            int       `description:"所属用户"`
+	RowsCount         int       `description:"指标数据数量"`
+	DateFirst         string    `description:"指标开始时间"`
+	DateLast          string    `description:"指标最新时间"`
+	TimeLastUpdate    time.Time `description:"最新更新时间"`
+	TimeLastRequest   time.Time `description:"下次更新时间"`
+	Priority          int       `description:"更新优先级"`
+	Status            int       `description:"指标状态"`
+	ShortName         string    `description:"指标简称"`
+	UpdateDescription string    `description:"更新说明"`
+	ForecastFlag      int       `description:"预测标识"`
+	ManualFlag        int       `description:"手动标识"`
+	VariableFlag      int       `description:"有效标识"`
+	MarketDataFlag    int       `description:"市场价标识"`
+	CreateUser        int       `description:"创建用户"`
+	CreateTime        time.Time `description:"创建时间"`
+	UpdateUser        int       `description:"更新用户"`
+	UpdateTime        time.Time `description:"更新时间"`
 }
 
 type DictIndexSql struct {
@@ -119,8 +120,8 @@ type DictIndexSql struct {
 	RowsCount         sql.NullInt32  `description:"指标数据数量" json:"ROWS_COUNT"`
 	DateFirst         sql.NullString `description:"指标开始时间" json:"DATE_FIRST"`
 	DateLast          sql.NullString `description:"指标最新时间" json:"DATE_LAST"`
-	TimeLastUpdate    sql.NullString `description:"最新更新时间" json:"TIME_LAST_UPDATE"`
-	TimeLastRequest   sql.NullString `description:"下次更新时间" json:"TIME_LAST_REQUEST"`
+	TimeLastUpdate    sql.NullTime   `description:"最新更新时间" json:"TIME_LAST_UPDATE"`
+	TimeLastRequest   sql.NullTime   `description:"下次更新时间" json:"TIME_LAST_REQUEST"`
 	Priority          sql.NullInt32  `description:"更新优先级" json:"PRIORITY"`
 	Status            sql.NullInt32  `description:"指标状态" json:"STATUS"`
 	ShortName         sql.NullString `description:"指标简称" json:"SHORT_NAME"`
@@ -130,9 +131,9 @@ type DictIndexSql struct {
 	VariableFlag      sql.NullInt32  `description:"有效标识" json:"VARIABLE_FLAG"`
 	MarketDataFlag    sql.NullInt32  `description:"市场价标识" json:"MARKETDATA_FLAG"`
 	CreateUser        sql.NullInt32  `description:"创建用户" json:"CREATE_USER"`
-	CreateTime        sql.NullString `description:"创建时间" json:"CREATE_TIME"`
+	CreateTime        sql.NullTime   `description:"创建时间" json:"CREATE_TIME"`
 	UpdateUser        sql.NullInt32  `description:"更新用户" json:"UPDATE_USER"`
-	UpdateTime        sql.NullString `description:"更新时" json:"UPDATE_TIME"`
+	UpdateTime        sql.NullTime   `description:"更新时间" json:"UPDATE_TIME"`
 	No                sql.NullInt32  `description:"分页查询数" json:"no"`
 }
 
@@ -205,8 +206,8 @@ func getDictIndex(sqlStatement string, pars []interface{}) (dictIndexs []DictInd
 			RowsCount:         int(tmp.RowsCount.Int32),
 			DateFirst:         tmp.DateFirst.String,
 			DateLast:          tmp.DateLast.String,
-			TimeLastUpdate:    tmp.TimeLastUpdate.String,
-			TimeLastRequest:   tmp.TimeLastRequest.String,
+			TimeLastUpdate:    tmp.TimeLastUpdate.Time,
+			TimeLastRequest:   tmp.TimeLastRequest.Time,
 			Priority:          int(tmp.Priority.Int32),
 			Status:            int(tmp.Status.Int32),
 			ShortName:         tmp.ShortName.String,
@@ -216,9 +217,9 @@ func getDictIndex(sqlStatement string, pars []interface{}) (dictIndexs []DictInd
 			VariableFlag:      int(tmp.VariableFlag.Int32),
 			MarketDataFlag:    int(tmp.MarketDataFlag.Int32),
 			CreateUser:        int(tmp.CreateUser.Int32),
-			CreateTime:        tmp.CreateTime.String,
+			CreateTime:        tmp.CreateTime.Time,
 			UpdateUser:        int(tmp.UpdateUser.Int32),
-			UpdateTime:        tmp.UpdateTime.String,
+			UpdateTime:        tmp.UpdateTime.Time,
 		}
 		dictIndexs = append(dictIndexs, dictTmp)
 	}
@@ -338,3 +339,42 @@ func GetDictFrequency() (frequencies []string, err error) {
 	}()
 	return
 }
+
+// GetDictIndexCount 获取指标总记录数
+func GetDictIndexCount(condition string, pars []interface{}) (total int, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Info("嘉悦-获取指标总记录数失败, Err:" + err.Error())
+		}
+	}()
+
+	sqlBase := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE %s`, IndexTableName, condition)
+	stmt, e := global.OracleJy.Prepare(sqlBase)
+	if e != nil {
+		err = fmt.Errorf("预处理sql失败, err: %s", e.Error())
+		return
+	}
+	rows, e := stmt.Query(pars...)
+	if e != nil {
+		err = fmt.Errorf("查询sql失败, err: %s", e.Error())
+		return
+	}
+	defer func() {
+		_ = rows.Close()
+	}()
+
+	for rows.Next() {
+		if e = rows.Scan(&total); e != nil {
+			err = fmt.Errorf("扫描错误, err: %s", e.Error())
+			return
+		}
+	}
+	if e = rows.Err(); e != nil {
+		err = fmt.Errorf("解析行数据失败, err: %s", e.Error())
+		return
+	}
+	defer func() {
+		_ = stmt.Close()
+	}()
+	return
+}

+ 5 - 5
models/request/index_data/jiayue_index.go

@@ -2,9 +2,9 @@ package index_data
 
 // JiaYuePageIndexReq 指标列表请求体-分页
 type JiaYuePageIndexReq struct {
-	Source    string `json:"source" form:"source" description:"来源"`
-	Keyword   string `json:"keyword" form:"keyword" description:"关键词"`
-	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:"每页数据量"`
+	SourceExtend string `json:"source_extend" form:"source_extend" description:"来源"`
+	Keyword      string `json:"keyword" form:"keyword" description:"关键词"`
+	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:"每页数据量"`
 }

+ 8 - 0
models/response/index_data.go

@@ -1,5 +1,7 @@
 package response
 
+import "eta/eta_bridge/models/jiayue"
+
 type IndexResp struct {
 	IndexCode      string      `json:"index_code"`
 	LastDate       string      `description:"指标最新时间" json:"last_date"`
@@ -13,3 +15,9 @@ type IndexData struct {
 	DataTime   string  `json:"data_time"`
 	UpdateTime string  `json:"update_time"`
 }
+
+// JiaYuePageIndexResp 指标分页列表响应体
+type JiaYuePageIndexResp struct {
+	Total int                `description:"数据总量"`
+	List  []jiayue.DictIndex `description:"列表数据"`
+}

+ 5 - 4
routers/index_data.go

@@ -2,14 +2,15 @@ package routers
 
 import (
 	"eta/eta_bridge/controller/index_data"
+	"eta/eta_bridge/middleware"
 	"github.com/gin-gonic/gin"
 )
 
 // InitIndexData 获取指标信息
 func InitIndexData(r *gin.RouterGroup) {
 	control := new(index_data.JiaYueIndexController)
-	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)
+	group := r.Group("index_data/").Use(middleware.InternalToken())
+	group.POST("jiayue/index", control.GetData)
+	group.POST("jiayue/page_index", control.GetPageIndex)
+	group.POST("jiayue/frequency_list", control.GetIndexFrequency)
 }

+ 25 - 23
services/index_data/jiayue_platform.go

@@ -116,7 +116,7 @@ func GetIndexFromJiaYue(indexCode, source, startDate, endDate string) (data *res
 		}
 		list = append(list, tmp)
 	}
-	var dateLastStr, timeLastUpdateStr string
+	var dateLastStr string
 	if index.DateLast != "" {
 		dateLast, e := time.ParseInLocation(utils.FormatDateDefault, index.DateLast, time.Local)
 		if e != nil {
@@ -126,27 +126,27 @@ func GetIndexFromJiaYue(indexCode, source, startDate, endDate string) (data *res
 		}
 		dateLastStr = dateLast.Format(utils.FormatDate)
 	}
-	if index.TimeLastUpdate != "" {
-		timeLastUpdate, e := time.ParseInLocation(utils.FormatDateDefault, index.TimeLastUpdate, time.Local)
-		if e != nil {
-			err = e
-			fmt.Println("解析时间失败:", err)
-			return
-		}
-		timeLastUpdateStr = timeLastUpdate.Format(utils.FormatDateTime)
-	}
+	//if !index.TimeLastUpdate.IsZero() {
+	//	timeLastUpdate, e := time.ParseInLocation(utils.FormatDateDefault, index.TimeLastUpdate, time.Local)
+	//	if e != nil {
+	//		err = e
+	//		fmt.Println("解析时间失败:", err)
+	//		return
+	//	}
+	//	timeLastUpdateStr = timeLastUpdate.Format(utils.FormatDateTime)
+	//}
 
 	data = new(response.IndexResp)
 	data.IndexData = list
 	data.IndexCode = indexCode
 	data.LastDate = dateLastStr
-	data.LastUpdateTime = timeLastUpdateStr
+	data.LastUpdateTime = utils.TimeTransferString(utils.FormatDateTime, index.TimeLastUpdate)
 	data.Status = index.Status
 	return
 }
 
 // GetPageIndexesFromJiaYue 分页获取指标数据
-func GetPageIndexesFromJiaYue(pageIndex, pageSize int, source, keyword, frequency string) (result []jiayue.DictIndex, err error) {
+func GetPageIndexesFromJiaYue(pageIndex, pageSize int, sourceArr []string, keyword, frequency string) (total int, result []jiayue.DictIndex, err error) {
 	defer func() {
 		if err != nil {
 			global.LOG.Info("GetPageIndexesFromJiaYue Err: " + err.Error())
@@ -157,18 +157,11 @@ func GetPageIndexesFromJiaYue(pageIndex, pageSize int, source, keyword, frequenc
 
 	indexCond := ``
 	indexPars := make([]interface{}, 0)
-	var sourceArray []interface{}
-	if source == "wind" {
-		sourceArray = append(sourceArray, "wind", "wind_stop", "wind_p", "wind_tmp")
-	} else if source == "manual" {
-		sourceArray = append(sourceArray, "manual", "manul", "munal")
-	} else {
-		sourceArray = append(sourceArray, source)
-	}
-	indexCond += ` SOURCE_TYPE IN (` + utils.GetOracleInReplace(len(sourceArray)) + `)`
-	indexPars = append(indexPars, sourceArray...)
-
 	// 筛选项
+	if len(sourceArr) > 0 {
+		indexCond += ` SOURCE_TYPE IN (` + utils.GetOracleInReplace(len(sourceArr)) + `)`
+		indexPars = append(indexPars, sourceArr)
+	}
 	keyword = strings.TrimSpace(keyword)
 	if keyword != "" {
 		kw := fmt.Sprint("%", keyword, "%")
@@ -180,6 +173,15 @@ func GetPageIndexesFromJiaYue(pageIndex, pageSize int, source, keyword, frequenc
 		indexPars = append(indexPars, frequency)
 	}
 
+	// 总记录数
+	t, e := jiayue.GetDictIndexCount(indexCond, indexPars)
+	if e != nil {
+		err = fmt.Errorf("GetDictIndexCount err: %s", e.Error())
+		return
+	}
+	total = t
+
+	// 列表数据
 	indexes, e := jiayue.GetDictPageIndex(indexCond, indexPars, pageIndex, pageSize)
 	if e != nil {
 		err = fmt.Errorf("GetDictPageIndex err: %s", e.Error())