package models import ( "fmt" "hongze/hongze_data_crawler/utils" "rdluck_tools/orm" "time" ) type BaseFromTradeEicIndex struct { BaseFromEicIndexId int `orm:"column(base_from_eic_index_id);pk"` Country string Type string EicCode string ShortName string Name string Status string GasDayStartedOn string GasInStorage float64 Full float64 Trend float64 Injection float64 Withdrawal float64 WorkingGasVolume float64 InjectionCapacity float64 WithdrawalCapacity float64 Info string CreateTime time.Time ModifyTime time.Time } type BaseFromTradeMapping struct { BaseFromTradeMappingId int `orm:"column(base_from_trade_mapping_id);pk"` IndexName string IndexCode string Exchange string } func AddBaseFromEicIndex(item *BaseFromTradeEicIndex) (lastId int64, err error) { o := orm.NewOrm() o.Using("data") lastId, err = o.Insert(item) return } func GetSSOFromEicIndexAll(name string) (list []*BaseFromTradeEicIndex, err error) { o := orm.NewOrm() o.Using("data") sql := `SELECT * FROM base_from_trade_eic_index where name=? and type='SSO'` _, err = o.Raw(sql, name).QueryRows(&list) return } func GetFacFromEicIndexAll(name string) (list []*BaseFromTradeEicIndex, err error) { o := orm.NewOrm() o.Using("data") sql := `SELECT * FROM base_from_trade_eic_index where name=? and type='Storage Facility'` _, err = o.Raw(sql, name).QueryRows(&list) return } func ModifyBaseFromEicIndex(gasInStorage, full, trend, injection, withdrawal float64, dataId int) (err error) { o := orm.NewOrm() o.Using("data") sql := `UPDATE base_from_trade_eic_index SET gas_in_storage=?,full=?,trend=?,injection=?,withdrawal=?,modify_time=NOW() WHERE base_from_eic_index_id=? ` _, err = o.Raw(sql, gasInStorage, full, trend, injection, withdrawal, dataId).Exec() return } func GetCountryFromEicIndexAll(name string) (list []*BaseFromTradeEicIndex, err error) { o := orm.NewOrm() o.Using("data") sql := `SELECT * FROM base_from_trade_eic_index where country=? and (type='country' or type='continent')` _, err = o.Raw(sql, name).QueryRows(&list) return } func GetEicAddSql(item *BaseFromTradeEicIndex) (addSql string) { addSql += "('" + item.Country + "','" + item.Type + "','" + item.EicCode + "','" + item.ShortName + "','" + item.Name + "','" + item.Status + "','" + item.GasDayStartedOn + "','" + fmt.Sprintf("%f", item.GasInStorage) + "','" + fmt.Sprintf("%f", item.Full) + "','" + fmt.Sprintf("%f", item.Trend) + "','" + fmt.Sprintf("%f", item.Injection) + "','" + fmt.Sprintf("%f", item.Withdrawal) + "','" + fmt.Sprintf("%f", item.WorkingGasVolume) + "','" + fmt.Sprintf("%f", item.InjectionCapacity) + "','" + fmt.Sprintf("%f", item.WithdrawalCapacity) + "','" + item.Info + "','" + item.CreateTime.Format(utils.FormatDateTime) + "','" + item.ModifyTime.Format(utils.FormatDateTime) + "')," return } func GetMappingAddSql(indexName, indexCode, exchange string) (addSql string) { addSql += "('" + indexName + "','" + indexCode + "','" + exchange + "')," return } func AddEicDataMulti(items []*BaseFromTradeEicIndex) (successNums int64, err error) { o := orm.NewOrm() o.Using("data") successNums, err = o.InsertMulti(1, items) return } func AddEicCodeMulti(items []*BaseFromTradeMapping) (successNums int64, err error) { o := orm.NewOrm() o.Using("data") successNums, err = o.InsertMulti(1, items) return }