浏览代码

gie models

ziwen 3 年之前
父节点
当前提交
6b988a2e9d
共有 1 个文件被更改,包括 101 次插入0 次删除
  1. 101 0
      models/base_from_trade_eic.go

+ 101 - 0
models/base_from_trade_eic.go

@@ -0,0 +1,101 @@
+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
+}