guagnzhouqihuo.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package data_source
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. type BaseFromTradeGuangzhouClassify struct {
  7. BaseFromTradeGuangzhouClassifyId int `gorm:"primaryKey;column:base_from_trade_guangzhou_classify_id;type:int(11);not null"`
  8. ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称
  9. ClassifyCode string `gorm:"column:classify_code;type:varchar(100);default:''"` // 分类编码
  10. ParentId int `gorm:"column:parent_id;type:int(11) unsigned;default:0"` // 上级id
  11. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
  12. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  13. }
  14. type BaseFromTradeGuangzhouIndex struct {
  15. BaseFromTradeGuangzhouIndexId int `gorm:"primaryKey;column:base_from_trade_guangzhou_index_id;type:int(11);not null"`
  16. BaseFromTradeGuangzhouClassifyId int `gorm:"column:base_from_trade_guangzhou_classify_id;type:int(11);default:0"` // 分类id/指标id
  17. BaseFromTradeGuangzhouContractId int `gorm:"column:base_from_trade_guangzhou_contract_id;type:int(11);default:0"` // 合约id
  18. IndexCode string `gorm:"unique;column:index_code;type:varchar(100);default:''"` // 指标编码
  19. IndexName string `gorm:"column:index_name;type:varchar(100);default:''"` // 指标名称
  20. Frequency string `gorm:"column:frequency;type:varchar(30);default:''"` // 频度
  21. Unit string `gorm:"column:unit;type:varchar(20);default:''"` // 单位
  22. StartDate string `gorm:"column:start_date;type:date"` // 开始日期
  23. EndDate string `gorm:"column:end_date;type:date"` // 结束日期
  24. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  25. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改日期
  26. Value float64 `gorm:"column:value;type:double;default:0"` // 数据值
  27. }
  28. type BaseFromTradeGuangzhouData struct {
  29. BaseFromTradeGuangzhouDataId int `gorm:"primaryKey;index:idx_index_id;column:base_from_trade_guangzhou_data_id;type:int(10) unsigned;not null"`
  30. BaseFromTradeGuangzhouIndexId int `gorm:"column:base_from_trade_guangzhou_index_id;type:int(11) unsigned;not null;default:0"` // 指标ID
  31. IndexCode string `gorm:"uniqueIndex:idx_code_time;index:idx_index_code;column:index_code;type:varchar(128);not null;default:''"` // 指标编码
  32. DataTime string `gorm:"uniqueIndex:idx_code_time;index:idx_data_time;column:data_time;type:date"` // 数据日期
  33. Value float64 `gorm:"column:value;type:double;not null;default:0"` // 数据值
  34. QtySub float64 `gorm:"column:qty_sub;type:double;default:0"` // 增减
  35. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  36. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  37. }
  38. type BaseFromTradeGuangzhouClassifyView struct {
  39. BaseFromTradeGuangzhouClassifyId int `gorm:"column:base_from_trade_guangzhou_classify_id;type:int(11);not null"`
  40. ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称
  41. ClassifyCode string `gorm:"column:classify_code;type:varchar(100);default:''"` // 分类编码
  42. ParentId int `gorm:"column:parent_id;type:int(11) unsigned;default:0"` // 上级id
  43. Children []*BaseFromTradeGuangzhouClassifyView `gorm:"-"`
  44. }
  45. type BaseFromTradeGuangzhouContract struct {
  46. BaseFromTradeGuangzhouContractId int `gorm:"primaryKey;column:base_from_trade_guangzhou_contract_id;type:int(11);not null"`
  47. BaseFromTradeGuangzhouClassifyId int `gorm:"column:base_from_trade_guangzhou_classify_id;type:int(11);default:0"` // 分类id
  48. ClassifyCode string `gorm:"column:classify_code;type:varchar(100);default:''"` // 分类编码
  49. Contract string `gorm:"index:idx_contract;column:contract;type:varchar(20);default:''"` // 合约代码
  50. TradeDate string `gorm:"index:idx_trade_date;column:trade_date;type:varchar(20);default:''"` // 合约日期
  51. }
  52. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouClassifyAll() (list []*BaseFromTradeGuangzhouClassifyView, err error) {
  53. sql := `SELECT * FROM base_from_trade_guangzhou_classify`
  54. err = global.DmSQL["data"].Raw(sql).Find(&list).Error
  55. return list, err
  56. }
  57. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouMaxDate() (max_date string, err error) {
  58. sql := ` SELECT MAX(a.end_date) AS max_date FROM base_from_trade_guangzhou_index AS a `
  59. err = global.DmSQL["data"].Raw(sql).Scan(&max_date).Error
  60. return max_date, err
  61. }
  62. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouContract(classifyId int, tradeDate string) (list []*BaseFromTradeGuangzhouContract, err error) {
  63. sql := ` SELECT * FROM base_from_trade_guangzhou_contract AS a WHERE base_from_trade_guangzhou_classify_id=? AND trade_date=? `
  64. err = global.DmSQL["data"].Raw(sql, classifyId, tradeDate).Find(&list).Error
  65. return
  66. }
  67. type BaseFromTradeGuangzhouIndexView struct {
  68. BaseFromTradeGuangzhouIndexId int `gorm:"column:base_from_trade_guangzhou_index_id;type:int(11);not null"`
  69. BaseFromTradeGuangzhouClassifyId int `gorm:"column:base_from_trade_guangzhou_classify_id;type:int(11);default:0"` // 分类id/指标id
  70. IndexCode string `gorm:"unique;column:index_code;type:varchar(100);default:''"` // 指标编码
  71. IndexName string `gorm:"column:index_name;type:varchar(100);default:''"` // 指标名称
  72. Frequency string `gorm:"column:frequency;type:varchar(30);default:''"` // 频度
  73. Unit string `gorm:"column:unit;type:varchar(20);default:''"` // 单位
  74. StartDate string `gorm:"column:start_date;type:date"` // 开始日期
  75. EndDate string `gorm:"column:end_date;type:date"` // 结束日期
  76. Value float64 `gorm:"column:value;type:double;default:0"` // 数据值
  77. }
  78. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouIndex(condition string, pars []interface{}, baseFromTradeGuangzhouContractId int) (list []*BaseFromTradeGuangzhouIndexView, err error) {
  79. if baseFromTradeGuangzhouContractId <= 0 {
  80. sql := ` SELECT b.base_from_trade_guangzhou_index_id,b.index_code,b.index_name,b.unit,b.frequency,b.start_date,b.end_date,a.value,c.base_from_trade_guangzhou_contract_id
  81. FROM base_from_trade_guangzhou_data AS a
  82. INNER JOIN base_from_trade_guangzhou_index AS b ON a.base_from_trade_guangzhou_index_id=b.base_from_trade_guangzhou_index_id
  83. LEFT JOIN base_from_trade_guangzhou_contract AS c ON b.base_from_trade_guangzhou_classify_id=c.base_from_trade_guangzhou_classify_id
  84. WHERE `
  85. if condition != "" {
  86. sql += condition
  87. }
  88. sql += ` ORDER BY a.index_code ASC `
  89. err = global.DmSQL["data"].Raw(sql, pars...).Find(&list).Error
  90. return
  91. } else {
  92. condition += ` AND a.base_from_trade_guangzhou_contract_id=? `
  93. pars = append(pars, baseFromTradeGuangzhouContractId)
  94. sql := ` SELECT a.*,b.value
  95. FROM base_from_trade_guangzhou_index AS a
  96. INNER JOIN base_from_trade_guangzhou_data AS b ON a.base_from_trade_guangzhou_index_id=b.base_from_trade_guangzhou_index_id
  97. WHERE `
  98. if condition != "" {
  99. sql += condition
  100. }
  101. sql += ` ORDER BY a.index_code ASC `
  102. err = global.DmSQL["data"].Raw(sql, pars...).Find(&list).Error
  103. return
  104. }
  105. }
  106. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouIndexDetail(condition string, pars []interface{}) (list []*BaseFromTradeGuangzhouIndexView, err error) {
  107. sql := ` SELECT a.*
  108. FROM base_from_trade_guangzhou_index AS a
  109. WHERE `
  110. if condition != "" {
  111. sql += condition
  112. }
  113. sql += ` ORDER BY a.index_code ASC `
  114. err = global.DmSQL["data"].Raw(sql, pars...).Find(&list).Error
  115. return
  116. }