1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_task/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/http"
- "time"
- )
- type EdbDataLt struct {
- EdbDataId int `orm:"column(edb_data_id);pk"`
- EdbInfoId int
- EdbCode string
- DataTime string
- Value float64
- Status int
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- // AddEdbDataLtBySql 执行添加数据的sql
- func AddEdbDataLtBySql(sqlStr string) (err error) {
- o := orm.NewOrm()
- _, err = o.Raw(sqlStr).Exec()
- return
- }
- // ModifyEdbDataLt 修改路透社数据
- func ModifyEdbDataLt(edbInfoId int64, dataTime string, value float64) (err error) {
- o := orm.NewOrm()
- sql := ` UPDATE edb_data_lt SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
- _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
- return
- }
- func GetEdbDataLtMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
- o := orm.NewOrm()
- sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_lt WHERE edb_code=? `
- err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
- return
- }
- func GetEdbDataLtByCodeAndDate(edbCode string, startDate string) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(1) AS count FROM edb_data_lt WHERE edb_code=? AND data_time=? `
- err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
- return
- }
- func GetEdbDataLtByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM edb_data_lt WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
- _, err = o.Raw(sql, edbCode, size).QueryRows(&items)
- return
- }
- type EdbDataFromLt struct {
- Close map[int64]interface{} `json:"CLOSE"`
- }
- // QueryEdbDataByLt 获取路透社数据
- func QueryEdbDataByLt(edbCode, startDate, endDate string) (dataList map[int64]interface{}, err error) {
- dataList = make(map[int64]interface{})
- ltUrl := utils.LtServerUrl + `edbInfo/ek?EdbCode=%s&StartDate=%s&EndDate=%s`
- ltUrl = fmt.Sprintf(ltUrl, edbCode, startDate, endDate)
- utils.FileLog.Info("ltUrl:%s", ltUrl)
- body, err := http.Get(ltUrl)
- utils.FileLog.Info("lt result:%s", string(body))
- if err != nil {
- return
- }
- //fmt.Println(string(body))
- item := new(EdbDataFromLt)
- err = json.Unmarshal(body, &item)
- if err != nil {
- return
- }
- dataList = item.Close
- return
- }
|