package models

import "rdluck_tools/orm"

//数据录入

type EdbInfo struct {
	UserId     int
	SecName    string `orm:"column(SEC_NAME);" description:"指标名称"`
	NoticeTime string
	Frequency  string
	TradeCode  string `orm:"column(TRADE_CODE);" description:"指标编码"`
}

//获取日度指标
func GetEdbInfoByFrequency(frequency string) (items []*EdbInfo, err error) {
	sql := `SELECT * FROM edbinfo WHERE frequency=? AND notice_time<>'' `
	o := orm.NewOrm()
	o.Using("edb")
	_, err = o.Raw(sql, frequency).QueryRows(&items)
	return
}

//获取日度指标
func GetEdbInfoByFrequencyWeek(frequency, weekDay string) (items []*EdbInfo, err error) {
	sql := `SELECT * FROM edbinfo WHERE frequency=? AND notice_time<>'' AND left(notice_time,2)=? `
	o := orm.NewOrm()
	o.Using("edb")
	_, err = o.Raw(sql, frequency, weekDay).QueryRows(&items)
	return
}

func GetEdbdataCount(tradeCode, nowDate string) (count int, err error) {
	sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
	o := orm.NewOrm()
	o.Using("edb")
	err = o.Raw(sql, tradeCode, nowDate).QueryRow(&count)
	return
}
