123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package trade_analysis
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strings"
- "time"
- )
- const TradeFuturesCompanyTop20 = "TOP20"
- // TradeFuturesCompany 期货公司表
- type TradeFuturesCompany struct {
- TradeFuturesCompanyId int `orm:"column(trade_futures_company_id);pk"`
- CompanyName string `description:"标准公司名称"`
- ZhengzhouName string `description:"郑商所下的名称"`
- DalianName string `description:"大商所下的名称"`
- ShanghaiName string `description:"上期所下的名称"`
- IneName string `description:"上期能源下的名称"`
- GuangzhouName string `description:"广期所下的名称"`
- CffexName string `description:"中金所下的名称"`
- Sort int `description:"排序"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.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) {
- 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 *TradeFuturesCompany) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *TradeFuturesCompany, 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 *TradeFuturesCompany) 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 *TradeFuturesCompany) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*TradeFuturesCompany, 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 *TradeFuturesCompany) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*TradeFuturesCompany, 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
- }
- // 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
- }
|