package data_manage import ( sql2 "database/sql" "eta/eta_task/global" "eta/eta_task/utils" "gorm.io/gorm" "time" ) type BaseFromTradeShanghaiIndex struct { BaseFromTradeShangHaiIndexId int `gorm:"column:base_from_trade_shanghai_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 *BaseFromTradeShanghaiIndex) AfterFind(db *gorm.DB) (err error) { m.DataTime = utils.GormDateStrToDateStr(m.DataTime) return } func AddBaseFromTradeShangHaiIndex(item *BaseFromTradeShanghaiIndex) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error if err != nil { return } lastId = int64(item.BaseFromTradeShangHaiIndexId) return } func GetBaseFromTradeShangHaiIndexAll(dateStr string) (list []*BaseFromTradeShanghaiIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_trade_shanghai_index WHERE data_time>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } func ModifyBaseFromTradeShangHaiIndex(dealValue, buyValue, soldValue int, dataId int) (err error) { o := global.DbMap[utils.DbNameIndex] sql := `UPDATE base_from_trade_shanghai_index SET deal_value=?,buy_value=?,sold_value=?,modify_time=NOW() WHERE base_from_trade_shanghai_index_id=? ` err = o.Exec(sql, dealValue, buyValue, soldValue, dataId).Error return } type ShanghaiIndexResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromTradeShanghaiIndex } func GetBaseFromTradeShangHaiIndexMaxDate() (maxDate time.Time, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT max(a.data_time) as max_date FROM base_from_trade_shanghai_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 }