package data_manage

import (
	"fmt"
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type GieData struct {
	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
}

func GetEdbDataGieMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_gie WHERE edb_code=? `
	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
	return
}

type EicIndexV2 struct {
	BaseFromEicIndexId     int `orm:"column(base_from_eic_index_id);pk"`
	Type                   string
	EicCode                string
	Name                   string
	Status                 string
	GasDayStart            string
	GasInStorage           string
	GasInStorageCode       string
	Consumption            string
	ConsumptionCode        string
	ConsumptionFull        string
	ConsumptionFullCode    string
	Full                   string
	FullCode               string
	Trend                  string
	TrendCode              string
	Injection              string
	InjectionCode          string
	Withdrawal             string
	WithdrawalCode         string
	WorkingGasVolume       string
	WorkingGasVolumeCode   string
	InjectionCapacity      string
	InjectionCapacityCode  string
	WithdrawalCapacity     string
	WithdrawalCapacityCode string
	Info                   string
	Parent                 string
	CreateTime             time.Time
	ModifyTime             time.Time
	Children               []BaseFromTradeEicIndexV2
}

func GetBaseFromEicDataAllByIndexCodeV2(indexCode, suffix string) (list []*BaseFromTradeEicIndexV2, err error) {
	o := orm.NewOrmUsingDB("data")
	var name string
	if suffix == "" {
		name = "eic_code"
	} else if suffix == "GS" {
		name = "gas_in_storage_code"
	} else if suffix == "C" {
		name = "consumption_code"
	} else if suffix == "CF" {
		name = "consumption_full_code"
	} else if suffix == "F" {
		name = "full_code"
	} else if suffix == "T" {
		name = "trend_code"
	} else if suffix == "In" {
		name = "injection_code"
	} else if suffix == "Out" {
		name = "withdrawal_code"
	} else if suffix == "WGV" {
		name = "working_gas_volume_code"
	} else if suffix == "IC" {
		name = "injection_capacity_code"
	} else if suffix == "WC" {
		name = "withdrawal_capacity_code"
	}
	sql := `SELECT * FROM base_from_trade_eic_index_v2 WHERE %s=? `
	sql = fmt.Sprintf(sql, name)
	_, err = o.Raw(sql, indexCode).QueryRows(&list)
	return
}
