trade_futures_company.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package trade_analysis
  2. import (
  3. "eta_gn/eta_index_lib/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. const TradeFuturesCompanyTop20 = "TOP20"
  9. // TradeFuturesCompany 期货公司表
  10. type TradeFuturesCompany struct {
  11. TradeFuturesCompanyId int `gorm:"primaryKey;autoIncrement;column:trade_futures_company_id" description:"标准公司名称ID"`
  12. CompanyName string `gorm:"column:company_name" description:"标准公司名称"`
  13. ZhengzhouName string `gorm:"column:zhengzhou_name" description:"郑商所下的名称"`
  14. DalianName string `gorm:"column:dalian_name" description:"大商所下的名称"`
  15. ShanghaiName string `gorm:"column:shanghai_name" description:"上期所下的名称"`
  16. IneName string `gorm:"column:ine_name" description:"上期能源下的名称"`
  17. GuangzhouName string `gorm:"column:guangzhou_name" description:"广期所下的名称"`
  18. CffexName string `gorm:"column:cffex_name" description:"中金所下的名称"`
  19. Sort int `gorm:"column:sort" description:"排序"`
  20. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  21. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  22. }
  23. func (m *TradeFuturesCompany) TableName() string {
  24. return "trade_futures_company"
  25. }
  26. type TradeFuturesCompanyCols struct {
  27. PrimaryId string
  28. CompanyName string
  29. ZhengzhouName string
  30. DalianName string
  31. ShanghaiName string
  32. IneName string
  33. GuangzhouName string
  34. CffexName string
  35. Sort string
  36. CreateTime string
  37. ModifyTime string
  38. }
  39. func (m *TradeFuturesCompany) Cols() TradeFuturesCompanyCols {
  40. return TradeFuturesCompanyCols{
  41. PrimaryId: "trade_futures_company_id",
  42. CompanyName: "company_name",
  43. ZhengzhouName: "zhengzhou_name",
  44. DalianName: "dalian_name",
  45. ShanghaiName: "shanghai_name",
  46. IneName: "ine_name",
  47. GuangzhouName: "guangzhou_name",
  48. CffexName: "cffex_name",
  49. Sort: "sort",
  50. CreateTime: "create_time",
  51. ModifyTime: "modify_time",
  52. }
  53. }
  54. func (m *TradeFuturesCompany) GetItemById(id int) (item *TradeFuturesCompany, err error) {
  55. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  56. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  57. return
  58. }
  59. func (m *TradeFuturesCompany) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *TradeFuturesCompany, err error) {
  60. order := ``
  61. if orderRule != "" {
  62. order = ` ORDER BY ` + orderRule
  63. }
  64. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  65. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error
  66. return
  67. }
  68. func (m *TradeFuturesCompany) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  69. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  70. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  71. return
  72. }
  73. func (m *TradeFuturesCompany) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*TradeFuturesCompany, err error) {
  74. fields := strings.Join(fieldArr, ",")
  75. if len(fieldArr) == 0 {
  76. fields = `*`
  77. }
  78. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  79. if orderRule != "" {
  80. order = ` ORDER BY ` + orderRule
  81. }
  82. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  83. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error
  84. return
  85. }
  86. func (m *TradeFuturesCompany) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*TradeFuturesCompany, err error) {
  87. fields := strings.Join(fieldArr, ",")
  88. if len(fieldArr) == 0 {
  89. fields = `*`
  90. }
  91. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  92. if orderRule != "" {
  93. order = ` ORDER BY ` + orderRule
  94. }
  95. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  96. pars = append(pars, startSize, pageSize)
  97. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error
  98. return
  99. }
  100. // TradeFuturesCompanyItem 期货公司信息
  101. type TradeFuturesCompanyItem struct {
  102. CompanyId int `description:"期货公司ID"`
  103. CompanyName string `description:"标准公司名称"`
  104. Sort int `description:"排序"`
  105. }
  106. func (m *TradeFuturesCompany) Format2Item() (item *TradeFuturesCompanyItem) {
  107. item = new(TradeFuturesCompanyItem)
  108. item.CompanyId = m.TradeFuturesCompanyId
  109. item.CompanyName = m.CompanyName
  110. item.Sort = m.Sort
  111. return
  112. }