guagnzhouqihuo.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package data_source
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type BaseFromTradeGuangzhouClassify struct {
  7. BaseFromTradeGuangzhouClassifyId int `orm:"column(base_from_trade_guangzhou_classify_id);pk"`
  8. ClassifyName string `description:"分类名称"`
  9. ClassifyCode string `description:"分类编码"`
  10. ParentId int `description:"分类父级id"`
  11. ModifyTime time.Time `description:"修改时间"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. type BaseFromTradeGuangzhouIndex struct {
  15. BaseFromTradeGuangzhouIndexId int `orm:"column(base_from_trade_guangzhou_index_id);pk"`
  16. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  17. IndexCode string `description:"指标编码"`
  18. IndexName string `description:"指标名称"`
  19. Frequency string `description:"频率"`
  20. Unit string `description:"单位"`
  21. StartDate string `description:"开始日期"`
  22. EndDate string `description:"结束日期"`
  23. CreateTime time.Time `description:"创建日期"`
  24. ModifyTime time.Time `description:"修改日期"`
  25. }
  26. type BaseFromTradeGuangzhouData struct {
  27. BaseFromTradeGuangzhouDataId int `orm:"column(base_from_trade_guangzhou_data_id);pk"`
  28. BaseFromTradeGuangzhouIndexId int `description:"指标id"`
  29. IndexCode string `description:"指标编码"`
  30. DataTime string `description:"数据日期"`
  31. Value float64 `description:"数据值"`
  32. QtySub float64 `description:"增减"`
  33. CreateTime time.Time `description:"创建日期"`
  34. ModifyTime time.Time `description:"修改日期"`
  35. }
  36. type BaseFromTradeGuangzhouClassifyView struct {
  37. BaseFromTradeGuangzhouClassifyId int `orm:"column(base_from_trade_guangzhou_classify_id);pk"`
  38. ClassifyName string `description:"分类名称"`
  39. ClassifyCode string `description:"分类编码"`
  40. ParentId int `description:"分类父级id"`
  41. Children []*BaseFromTradeGuangzhouClassifyView
  42. }
  43. type BaseFromTradeGuangzhouContract struct {
  44. BaseFromTradeGuangzhouContractId int `orm:"column(base_from_trade_guangzhou_contract_id);pk"`
  45. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  46. ClassifyCode string `description:"分类编码"`
  47. Contract string `description:"合约编码"`
  48. TradeDate string `description:"合约日期"`
  49. }
  50. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouClassifyAll() (list []*BaseFromTradeGuangzhouClassifyView, err error) {
  51. o := orm.NewOrmUsingDB("data")
  52. sql := `SELECT * FROM base_from_trade_guangzhou_classify`
  53. _, err = o.Raw(sql).QueryRows(&list)
  54. return list, err
  55. }
  56. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouMaxDate() (max_date string, err error) {
  57. o := orm.NewOrmUsingDB("data")
  58. sql := ` SELECT MAX(a.end_date) AS max_date FROM base_from_trade_guangzhou_index AS a `
  59. err = o.Raw(sql).QueryRow(&max_date)
  60. return max_date, err
  61. }
  62. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouContract(classifyId int, tradeDate string) (list []*BaseFromTradeGuangzhouContract, err error) {
  63. o := orm.NewOrmUsingDB("data")
  64. sql := ` SELECT * FROM base_from_trade_guangzhou_contract AS a WHERE base_from_trade_guangzhou_classify_id=? AND trade_date=? `
  65. _, err = o.Raw(sql, classifyId, tradeDate).QueryRows(&list)
  66. return
  67. }
  68. type BaseFromTradeGuangzhouIndexView struct {
  69. BaseFromTradeGuangzhouIndexId int `description:"指标id"`
  70. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  71. IndexCode string `description:"指标编码"`
  72. IndexName string `description:"指标名称"`
  73. Frequency string `description:"频率"`
  74. Unit string `description:"单位"`
  75. StartDate string `description:"开始日期"`
  76. EndDate string `description:"结束日期"`
  77. Value float64 `description:"数据"`
  78. }
  79. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouIndex(condition string, pars []interface{}, baseFromTradeGuangzhouContractId int) (list []*BaseFromTradeGuangzhouIndexView, err error) {
  80. o := orm.NewOrmUsingDB("data")
  81. if baseFromTradeGuangzhouContractId <= 0 {
  82. 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
  83. FROM base_from_trade_guangzhou_data AS a
  84. INNER JOIN base_from_trade_guangzhou_index AS b ON a.base_from_trade_guangzhou_index_id=b.base_from_trade_guangzhou_index_id
  85. LEFT JOIN base_from_trade_guangzhou_contract AS c ON b.base_from_trade_guangzhou_classify_id=c.base_from_trade_guangzhou_classify_id
  86. WHERE `
  87. if condition != "" {
  88. sql += condition
  89. }
  90. sql += ` ORDER BY a.index_code ASC `
  91. _, err = o.Raw(sql, pars).QueryRows(&list)
  92. return
  93. } else {
  94. condition += ` AND a.base_from_trade_guangzhou_contract_id=? `
  95. pars = append(pars, baseFromTradeGuangzhouContractId)
  96. sql := ` SELECT a.*,b.value
  97. FROM base_from_trade_guangzhou_index AS a
  98. INNER JOIN base_from_trade_guangzhou_data AS b ON a.base_from_trade_guangzhou_index_id=b.base_from_trade_guangzhou_index_id
  99. WHERE `
  100. if condition != "" {
  101. sql += condition
  102. }
  103. sql += ` ORDER BY a.index_code ASC `
  104. _, err = o.Raw(sql, pars).QueryRows(&list)
  105. return
  106. }
  107. }
  108. func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouIndexDetail(condition string, pars []interface{}) (list []*BaseFromTradeGuangzhouIndexView, err error) {
  109. o := orm.NewOrmUsingDB("data")
  110. sql := ` SELECT a.*
  111. FROM base_from_trade_guangzhou_index AS a
  112. WHERE `
  113. if condition != "" {
  114. sql += condition
  115. }
  116. sql += ` ORDER BY a.index_code ASC `
  117. _, err = o.Raw(sql, pars).QueryRows(&list)
  118. return
  119. }