package trade_analysis import ( "eta_gn/eta_index_lib/global" "fmt" "strings" "time" ) const TradeFuturesCompanyTop20 = "TOP20" // TradeFuturesCompany 期货公司表 type TradeFuturesCompany struct { TradeFuturesCompanyId int `gorm:"primaryKey;autoIncrement;column:trade_futures_company_id" description:"标准公司名称ID"` CompanyName string `gorm:"column:company_name" description:"标准公司名称"` ZhengzhouName string `gorm:"column:zhengzhou_name" description:"郑商所下的名称"` DalianName string `gorm:"column:dalian_name" description:"大商所下的名称"` ShanghaiName string `gorm:"column:shanghai_name" description:"上期所下的名称"` IneName string `gorm:"column:ine_name" description:"上期能源下的名称"` GuangzhouName string `gorm:"column:guangzhou_name" description:"广期所下的名称"` CffexName string `gorm:"column:cffex_name" description:"中金所下的名称"` Sort int `gorm:"column:sort" description:"排序"` CreateTime time.Time `gorm:"column:create_time" description:"创建时间"` ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"` } func (m *TradeFuturesCompany) TableName() string { return "trade_futures_company" } type TradeFuturesCompanyCols struct { PrimaryId string CompanyName string ZhengzhouName string DalianName string ShanghaiName string IneName string GuangzhouName string CffexName string Sort string CreateTime string ModifyTime string } func (m *TradeFuturesCompany) Cols() TradeFuturesCompanyCols { return TradeFuturesCompanyCols{ PrimaryId: "trade_futures_company_id", CompanyName: "company_name", ZhengzhouName: "zhengzhou_name", DalianName: "dalian_name", ShanghaiName: "shanghai_name", IneName: "ine_name", GuangzhouName: "guangzhou_name", CffexName: "cffex_name", Sort: "sort", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *TradeFuturesCompany) GetItemById(id int) (item *TradeFuturesCompany, 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 *TradeFuturesCompany) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *TradeFuturesCompany, 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 *TradeFuturesCompany) 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 *TradeFuturesCompany) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*TradeFuturesCompany, 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 *TradeFuturesCompany) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*TradeFuturesCompany, 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 } // TradeFuturesCompanyItem 期货公司信息 type TradeFuturesCompanyItem struct { CompanyId int `description:"期货公司ID"` CompanyName string `description:"标准公司名称"` Sort int `description:"排序"` } func (m *TradeFuturesCompany) Format2Item() (item *TradeFuturesCompanyItem) { item = new(TradeFuturesCompanyItem) item.CompanyId = m.TradeFuturesCompanyId item.CompanyName = m.CompanyName item.Sort = m.Sort return }