package data_manage

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

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

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

type BaseFromSci99IndexItem struct {
	BaseFromSciIndexId int    `orm:"column(base_from_sci_index_id);pk"` // 主键，自动递增
	IndexCode          string // 指标编码
	IndexName          string // 指标名称
	ClassifyId         int    // 分类Id
	Unit               string // 单位
	Frequency          string // 频度
	Describe           string // 指标描述
	CreateTime         string // 创建时间
	ModifyTime         string // 修改时间
}

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