package data_manage import ( "github.com/rdlucklib/rdluck_tools/orm" "time" ) type BaseFromTradeShanghaiIndex struct { BaseFromTradeShangHaiIndexId int `orm:"column(base_from_trade_shanghai_index_id);pk"` Rank int DealShortName string DealName string DealCode string DealValue string DealChange string BuyShortName string BuyName string BuyCode string BuyValue string BuyChange string SoldShortName string SoldName string SoldCode string SoldValue string SoldChange string Frequency string ClassifyName string ClassifyType string CreateTime time.Time ModifyTime time.Time DataTime string } type BaseFromTradeCffexIndex struct { BaseFromTradeCffexIndexId int `orm:"column(base_from_trade_cffex_index_id);pk"` Rank int DealShortName string DealName string DealCode string DealValue string DealChange string BuyShortName string BuyName string BuyCode string BuyValue string BuyChange string SoldShortName string SoldName string SoldCode string SoldValue string SoldChange string Frequency string ClassifyName string ClassifyType string CreateTime time.Time ModifyTime time.Time DataTime string } type BaseFromTradeIneIndex struct { BaseFromTradeIneIndexId int `orm:"column(base_from_trade_ine_index_id);pk"` Rank int DealShortName string DealName string DealCode string DealValue string DealChange string BuyShortName string BuyName string BuyCode string BuyValue string BuyChange string SoldShortName string SoldName string SoldCode string SoldValue string SoldChange string Frequency string ClassifyName string ClassifyType string CreateTime time.Time ModifyTime time.Time DataTime string } func GetBaseFromTradeIndexByParam(exchange, date, classifyName, classifyType string) (list []*BaseFromTradeShanghaiIndex, err error) { o := orm.NewOrm() o.Using("data") if classifyName == ""{ sql := "SELECT * FROM base_from_trade_"+exchange+"_index where data_time=?" _, err = o.Raw(sql, date).QueryRows(&list) return }else if classifyType == ""{ sql := "SELECT * FROM base_from_trade_"+exchange+"_index where data_time=? and classify_name=? ORDER BY classify_type,rank" _, err = o.Raw(sql, date, classifyName).QueryRows(&list) return }else { sql := "SELECT * FROM base_from_trade_"+exchange+"_index where data_time=? and classify_name=? and classify_type=?" _, err = o.Raw(sql, date, classifyName, classifyType).QueryRows(&list) return } } func GetExchangeClassify(exchange string) (classifyName []*string, err error) { o := orm.NewOrm() o.Using("data") sql := "SELECT DISTINCT classify_name FROM base_from_trade_"+exchange+"_index ORDER BY CONVERT(classify_name using gbk) DESC" _, err = o.Raw(sql).QueryRows(&classifyName) return } func GetLatestDate(exchange string) (date []*BaseFromTradeIneIndex, err error) { o := orm.NewOrm() o.Using("data") sql := "SELECT * FROM base_from_trade_"+exchange+"_index ORDER BY data_time desc limit 1" _, err = o.Raw(sql).QueryRows(&date) return } func GetExchangeClassifyContract(exchange, Classify, dataTime string) (classifyName []*string, err error) { o := orm.NewOrm() o.Using("data") sql := "SELECT DISTINCT classify_type FROM base_from_trade_"+exchange+"_index where classify_name=? and data_time=?" _, err = o.Raw(sql, Classify, dataTime).QueryRows(&classifyName) return }