package data_manage import ( "encoding/json" "eta_gn/eta_task/global" "eta_gn/eta_task/utils" "fmt" "github.com/rdlucklib/rdluck_tools/http" "time" ) type EdbDataLt struct { EdbDataId int `gorm:"column:edb_data_id;primaryKey"` //`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() err = global.DEFAULT_DmSQL.Exec(sqlStr).Error 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() err = global.DEFAULT_DmSQL.Exec(sql, value, edbInfoId, dataTime).Error 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) err = global.DEFAULT_DmSQL.Raw(sql, edbCode).First(&min_date, &max_date).Error 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) err = global.DEFAULT_DmSQL.Raw(sql, edbCode, startDate).Scan(&count).Error 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) err = global.DEFAULT_DmSQL.Raw(sql, edbCode, size).Find(&items).Error 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 }