package data_manage import ( "eta/eta_task/utils" "fmt" "github.com/beego/beego/v2/client/orm" "strings" "time" ) // BaseFromThsHfIndex 同花顺高频数据 type BaseFromThsHfIndex struct { BaseFromThsHfIndexId int `orm:"column(base_from_ths_hf_index_id);pk"` BaseFromThsHfClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Source string `description:"数据来源"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期(至时分秒)"` EndDate time.Time `description:"结束日期(至时分秒)"` Describe string `description:"指标描述"` Sort int `description:"排序"` IsStop int `description:"是否停更:0-否;1-停更"` TerminalCode string `description:"所属终端编码"` StockCode string `description:"证券代码"` Indicator string `description:"同花顺指标代码"` ApiPars string `description:"API请求参数"` LatestValue float64 `description:"最新值"` SysUserId int `description:"创建人ID"` SysUserRealName string `description:"创建人姓名"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } func (m *BaseFromThsHfIndex) TableName() string { return "base_from_ths_hf_index" } type BaseFromThsHfIndexCols struct { PrimaryId string BaseFromThsHfClassifyId string IndexCode string IndexName string Unit string Source string Frequency string StartDate string EndDate string Describe string Sort string IsStop string TerminalCode string StockCode string Indicator string ApiPars string LatestValue string SysUserId string SysUserRealName string CreateTime string ModifyTime string } func (m *BaseFromThsHfIndex) Cols() BaseFromThsHfIndexCols { return BaseFromThsHfIndexCols{ PrimaryId: "base_from_ths_hf_index_id", BaseFromThsHfClassifyId: "base_from_ths_hf_classify_id", IndexCode: "index_code", IndexName: "index_name", Unit: "unit", Source: "source", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", Describe: "describe", Sort: "sort", IsStop: "is_stop", TerminalCode: "terminal_code", StockCode: "stock_code", Indicator: "indicator", ApiPars: "api_pars", LatestValue: "latest_value", SysUserId: "sys_user_id", SysUserRealName: "sys_user_real_name", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromThsHfIndex) Create() (err error) { o := orm.NewOrm() id, err := o.Insert(m) if err != nil { return } m.BaseFromThsHfIndexId = int(id) return } func (m *BaseFromThsHfIndex) CreateMulti(items []*BaseFromThsHfIndex) (err error) { if len(items) == 0 { return } o := orm.NewOrm() _, err = o.InsertMulti(len(items), items) return } func (m *BaseFromThsHfIndex) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(m, cols...) return } func (m *BaseFromThsHfIndex) Remove() (err error) { o := orm.NewOrm() sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId) _, err = o.Raw(sql, m.BaseFromThsHfIndexId).Exec() return } func (m *BaseFromThsHfIndex) MultiRemove(ids []int) (err error) { if len(ids) == 0 { return } o := orm.NewOrm() sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids))) _, err = o.Raw(sql, ids).Exec() return } func (m *BaseFromThsHfIndex) RemoveByCondition(condition string, pars []interface{}) (err error) { if condition == "" { return } o := orm.NewOrm() sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition) _, err = o.Raw(sql, pars).Exec() return } func (m *BaseFromThsHfIndex) GetItemById(id int) (item *BaseFromThsHfIndex, err error) { o := orm.NewOrm() sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId) err = o.Raw(sql, id).QueryRow(&item) return } func (m *BaseFromThsHfIndex) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *BaseFromThsHfIndex, err error) { o := orm.NewOrm() order := `` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order) err = o.Raw(sql, pars).QueryRow(&item) return } func (m *BaseFromThsHfIndex) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrm() sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = o.Raw(sql, pars).QueryRow(&count) return } func (m *BaseFromThsHfIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromThsHfIndex, err error) { o := orm.NewOrm() fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime) if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } func (m *BaseFromThsHfIndex) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BaseFromThsHfIndex, err error) { o := orm.NewOrm() fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime) if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order) _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return }