浏览代码

新增广期所数据同步

tuoling805 1 年之前
父节点
当前提交
c2b211ead9
共有 4 个文件被更改,包括 178 次插入0 次删除
  1. 70 0
      models/data_manage/base_from_trade_guangzhou.go
  2. 3 0
      models/db.go
  3. 17 0
      services/sync_hz_data.go
  4. 88 0
      services/trade_guangzhou.go

+ 70 - 0
models/data_manage/base_from_trade_guangzhou.go

@@ -0,0 +1,70 @@
+package data_manage
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type BaseFromTradeGuangzhouIndex struct {
+	BaseFromTradeGuangzhouIndexId    int       `orm:"column(base_from_trade_guangzhou_index_id);pk"`
+	BaseFromTradeGuangzhouClassifyId int       `description:"分类id"`
+	IndexCode                        string    `description:"指标编码"`
+	IndexName                        string    `description:"指标名称"`
+	Frequency                        string    `description:"频率"`
+	Unit                             string    `description:"单位"`
+	StartDate                        string    `description:"开始日期"`
+	EndDate                          string    `description:"结束日期"`
+	CreateTime                       time.Time `description:"创建日期"`
+	ModifyTime                       time.Time `description:"修改日期"`
+}
+
+func AddBaseFromTradeGuangzhouIndex(item *BaseFromTradeGuangzhouIndex) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+func GetBaseFromTradeGuangzhouIndexAll() (list []*BaseFromTradeGuangzhouIndex, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM base_from_trade_guangzhou_index `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+type GuangzhouIndexResp struct {
+	Ret     int
+	Msg     string
+	ErrMsg  string
+	ErrCode string
+	Data    []*BaseFromTradeGuangzhouIndex
+}
+
+type BaseFromTradeGuangzhouClassify struct {
+	BaseFromTradeGuangzhouClassifyId int       `orm:"column(base_from_trade_guangzhou_classify_id);pk"`
+	ClassifyName                     string    `description:"分类名称"`
+	ClassifyCode                     string    `description:"分类编码"`
+	ParentId                         int       `description:"分类父级id"`
+	ModifyTime                       time.Time `description:"修改时间"`
+	CreateTime                       time.Time `description:"创建时间"`
+}
+
+type GuangzhouClassifyResp struct {
+	Ret     int
+	Msg     string
+	ErrMsg  string
+	ErrCode string
+	Data    []*BaseFromTradeGuangzhouClassify
+}
+
+func GetBaseFromTradeGuangzhouClassifyAll() (list []*BaseFromTradeGuangzhouClassify, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM base_from_trade_guangzhou_classify `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+func AddBaseFromTradeGuangzhouClassify(item *BaseFromTradeGuangzhouClassify) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 3 - 0
models/db.go

@@ -111,6 +111,9 @@ func initEdbDataTable() {
 		new(data_manage.ComTradeCodeMapping),  // 联合国指标关系表
 		new(data_manage.ComTradeData),         // 联合国数据表
 		new(data_manage.MeetingProbabilities), // 联储加息概率
+
+		//广期所
+		new(data_manage.BaseFromTradeGuangzhouClassify),
 	)
 }
 

+ 17 - 0
services/sync_hz_data.go

@@ -73,8 +73,25 @@ func SyncHzDataIndex(cont context.Context) (err error) {
 		return
 	}
 
+	//广期所
+	{
+		//分类信息
+		err = SyncFromGuangzhouClassify()
+		if err != nil {
+			fmt.Println("SyncFromGuangzhouClassify Err:" + err.Error())
+			return
+		}
+		//指标信息
+		err = SyncFromGuangzhouIndex()
+		if err != nil {
+			fmt.Println("SyncRankingFromCffex Err:" + err.Error())
+			return
+		}
+	}
+
 	// 同步指标数据
 	SyncHzDataIndexData()
+
 	fmt.Println("SyncHzDataIndex end:", time.Now().Format(utils.FormatDateTime))
 	return err
 }

+ 88 - 0
services/trade_guangzhou.go

@@ -0,0 +1,88 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_task/models/data_manage"
+	"eta/eta_task/utils"
+	"fmt"
+)
+
+// 广州商品交易所-分类
+func SyncFromGuangzhouClassify() (err error) {
+	data := make(map[string]interface{})
+	data["Source"] = utils.DATA_SOURCE_GFEX
+	method := `classify/list`
+	result, err := HttpPost("SyncFromGuangzhouClassify", method, data)
+	if err != nil {
+		fmt.Println("SyncFromGuangzhouClassify HttpPost Err:", err.Error())
+	}
+	utils.FileLog.Info(result)
+	fmt.Println("SyncFromGuangzhouClassify result:", result)
+
+	respObj := new(data_manage.GuangzhouClassifyResp)
+	err = json.Unmarshal([]byte(result), &respObj)
+	if err != nil {
+		return err
+	}
+	//获取所有指标信息  某一天的
+	allClassify, err := data_manage.GetBaseFromTradeGuangzhouClassifyAll()
+	if err != nil {
+		return
+	}
+
+	existIndexMap := make(map[int]*data_manage.BaseFromTradeGuangzhouClassify)
+	for _, v := range allClassify {
+		existIndexMap[v.BaseFromTradeGuangzhouClassifyId] = v
+	}
+
+	for _, item := range respObj.Data {
+		if _, ok := existIndexMap[item.BaseFromTradeGuangzhouClassifyId]; !ok {
+			newID, err := data_manage.AddBaseFromTradeGuangzhouClassify(item)
+			if err != nil {
+				fmt.Println("AddBaseFromTradeGuangzhouClassify error:", err)
+			}
+			fmt.Println("AddBaseFromTradeGuangzhouClassify new indexID:", newID)
+		}
+	}
+	return err
+}
+
+// 广州商品交易所-指标信息
+func SyncFromGuangzhouIndex() (err error) {
+	method := `index/list`
+	data := make(map[string]interface{})
+	data["Source"] = utils.DATA_SOURCE_GFEX
+	result, err := HttpPost("SyncFromGuangzhou", method, data)
+	if err != nil {
+		fmt.Println("SyncFromGuangzhou HttpPost Err:", err.Error())
+	}
+	utils.FileLog.Info(result)
+	fmt.Println("SyncFromGuangzhou result:", result)
+
+	respObj := new(data_manage.GuangzhouIndexResp)
+	err = json.Unmarshal([]byte(result), &respObj)
+	if err != nil {
+		return err
+	}
+	//获取所有指标信息  某一天的
+	allIndex, err := data_manage.GetBaseFromTradeGuangzhouIndexAll()
+	if err != nil {
+		return
+	}
+
+	existIndexMap := make(map[int]*data_manage.BaseFromTradeGuangzhouIndex)
+	for _, v := range allIndex {
+		existIndexMap[v.BaseFromTradeGuangzhouIndexId] = v
+	}
+
+	for _, item := range respObj.Data {
+		if _, ok := existIndexMap[item.BaseFromTradeGuangzhouIndexId]; !ok {
+			newID, err := data_manage.AddBaseFromTradeGuangzhouIndex(item)
+			if err != nil {
+				fmt.Println("insert error:", err)
+			}
+			fmt.Println("insert new indexID:", newID)
+		}
+	}
+	return err
+}