package models import ( "eta_gn/eta_index_lib/global" "eta_gn/eta_index_lib/utils" "fmt" "strings" "time" ) // FactorEdbSeriesMapping 因子指标系列-指标关联表 type FactorEdbSeriesMapping struct { FactorEdbSeriesMappingId int `gorm:"primaryKey;autoIncrement;column:factor_edb_series_mapping_id" description:"因子指标系列映射ID"` FactorEdbSeriesId int `gorm:"column:factor_edb_series_id" description:"因子指标系列ID"` EdbInfoId int `gorm:"column:edb_info_id" description:"指标ID"` EdbCode string `gorm:"column:edb_code" description:"指标编码"` CreateTime time.Time `gorm:"column:create_time" description:"创建时间"` ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"` } func (m *FactorEdbSeriesMapping) TableName() string { return "factor_edb_series_mapping" } type FactorEdbSeriesMappingCols struct { PrimaryId string FactorEdbSeriesId string EdbInfoId string EdbCode string CreateTime string ModifyTime string } func (m *FactorEdbSeriesMapping) Cols() FactorEdbSeriesMappingCols { return FactorEdbSeriesMappingCols{ PrimaryId: "factor_edb_series_mapping_id", FactorEdbSeriesId: "factor_edb_series_id", EdbInfoId: "edb_info_id", EdbCode: "edb_code", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *FactorEdbSeriesMapping) Create() (err error) { err = global.DEFAULT_DmSQL.Create(m).Error return } func (m *FactorEdbSeriesMapping) CreateMulti(items []*FactorEdbSeriesMapping) (err error) { if len(items) == 0 { return } err = global.DEFAULT_DmSQL.CreateInBatches(items, 500).Error return } func (m *FactorEdbSeriesMapping) Update(cols []string) (err error) { err = global.DEFAULT_DmSQL.Model(m).Select(cols).Updates(m).Error return } func (m *FactorEdbSeriesMapping) Remove() (err error) { sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId) err = global.DEFAULT_DmSQL.Exec(sql, m.FactorEdbSeriesMappingId).Error return } func (m *FactorEdbSeriesMapping) MultiRemove(ids []int) (err error) { if len(ids) == 0 { return } sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids))) err = global.DEFAULT_DmSQL.Exec(sql, ids).Error return } func (m *FactorEdbSeriesMapping) RemoveByCondition(condition string, pars []interface{}) (err error) { if condition == "" { return } sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition) err = global.DEFAULT_DmSQL.Exec(sql, pars...).Error return } func (m *FactorEdbSeriesMapping) GetItemById(id int) (item *FactorEdbSeriesMapping, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId) err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error return } func (m *FactorEdbSeriesMapping) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FactorEdbSeriesMapping, err error) { 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 = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error return } func (m *FactorEdbSeriesMapping) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error return } func (m *FactorEdbSeriesMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FactorEdbSeriesMapping, err error) { 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 = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error return } func (m *FactorEdbSeriesMapping) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FactorEdbSeriesMapping, err error) { 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) pars = append(pars, startSize, pageSize) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error return } // FactorEdbSeriesMappingItem 因子指标系列-指标关联信息 type FactorEdbSeriesMappingItem struct { SeriesId int `description:"因子指标系列ID"` EdbInfoId int `description:"指标ID"` EdbCode string `description:"指标编码"` EdbName string `description:"指标名称"` EdbNameEn string `description:"指标名称-英文"` } func (m *FactorEdbSeriesMapping) Format2Item() (item *FactorEdbSeriesMappingItem) { item = new(FactorEdbSeriesMappingItem) item.SeriesId = m.FactorEdbSeriesId item.EdbInfoId = m.EdbInfoId item.EdbCode = m.EdbCode return } func (m *FactorEdbSeriesMapping) GetItemBySeriesId(seriesId int) (items []*FactorEdbSeriesMapping, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? `, m.TableName(), m.Cols().FactorEdbSeriesId) err = global.DEFAULT_DmSQL.Raw(sql, seriesId).Scan(&items).Error return }