package data_manage import ( sql2 "database/sql" "eta/eta_task/global" "eta/eta_task/utils" "gorm.io/gorm" "time" ) type BaseFromTradeIneIndex struct { BaseFromTradeIneIndexId int `gorm:"column:base_from_trade_ine_index_id;primaryKey;autoIncrement"` Rank int DealShortName string DealName string DealCode string DealValue int DealChange int BuyShortName string BuyName string BuyCode string BuyValue int BuyChange int SoldShortName string SoldName string SoldCode string SoldValue int SoldChange int Frequency string ClassifyName string ClassifyType string CreateTime time.Time ModifyTime time.Time DataTime string } func (m *BaseFromTradeIneIndex) AfterFind(db *gorm.DB) (err error) { m.DataTime = utils.GormDateStrToDateStr(m.DataTime) return } func AddBaseFromTradeIneIndex(item *BaseFromTradeIneIndex) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } func GetBaseFromTradeIneIndexAll(dateStr string) (list []*BaseFromTradeIneIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_trade_ine_index where data_time>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } func ModifyBaseFromTradeIneIndex(dealValue, buyValue, soldValue int, dataId int) (err error) { o := global.DbMap[utils.DbNameIndex] sql := `UPDATE base_from_trade_ine_index SET deal_value=?,buy_value=?,sold_value=?,modify_time=NOW() WHERE base_from_trade_ine_index_id=? ` err = o.Exec(sql, dealValue, buyValue, soldValue, dataId).Error return } type IneIndexResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromTradeIneIndex } func GetBaseFromTradeIneIndexMaxDate() (maxDate time.Time, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT max(a.data_time) AS max_date FROM base_from_trade_ine_index as a ` var timeNull sql2.NullTime err = o.Raw(sql).Scan(&timeNull).Error if err != nil { return } if timeNull.Valid { maxDate = timeNull.Time } return }