package data_manage

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

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

func GetEdbDataGzMaxOrMinDate(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_gz WHERE edb_code=? `
	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
	return
}

type GzIndexView struct {
	BaseFromTradeGuangzhouIndexId    int     `description:"指标id"`
	BaseFromTradeGuangzhouClassifyId int     `description:"分类id"`
	IndexCode                        string  `description:"指标编码"`
	IndexName                        string  `description:"指标名称"`
	Frequency                        string  `description:"频率"`
	Unit                             string  `description:"单位"`
	StartDate                        string  `description:"开始日期"`
	EndDate                          string  `description:"结束日期"`
	Value                            float64 `description:"数据"`
}

// GetBaseInfoFromShByIndexCode 获取指标信息
func GetBaseInfoFromGzByIndexCode(indexCode string) (item *GzIndexView, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := `SELECT * FROM base_from_trade_guangzhou_index WHERE index_code=? `
	sql = fmt.Sprintf(sql)
	err = o.Raw(sql, indexCode).QueryRow(&item)
	return
}
