base_from_trade_guangzhou.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type BaseFromTradeGuangzhouIndex struct {
  8. BaseFromTradeGuangzhouIndexId int `orm:"column(base_from_trade_guangzhou_index_id);pk"`
  9. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  10. BaseFromTradeGuangzhouContractId int `description:"合约id"`
  11. IndexCode string `description:"指标编码"`
  12. IndexName string `description:"指标名称"`
  13. Frequency string `description:"频率"`
  14. Unit string `description:"单位"`
  15. StartDate string `description:"开始日期"`
  16. EndDate string `description:"结束日期"`
  17. CreateTime time.Time `description:"创建日期"`
  18. ModifyTime time.Time `description:"修改日期"`
  19. Value float64 `description:"数据值"`
  20. }
  21. func AddBaseFromTradeGuangzhouIndex(item *BaseFromTradeGuangzhouIndex) (lastId int64, err error) {
  22. o := orm.NewOrm()
  23. lastId, err = o.InsertOrUpdate(item)
  24. return
  25. }
  26. func GetBaseFromTradeGuangzhouIndexAll() (list []*BaseFromTradeGuangzhouIndex, err error) {
  27. o := orm.NewOrm()
  28. sql := `SELECT * FROM base_from_trade_guangzhou_index `
  29. _, err = o.Raw(sql).QueryRows(&list)
  30. return
  31. }
  32. type GuangzhouIndexResp struct {
  33. Ret int
  34. Msg string
  35. ErrMsg string
  36. ErrCode string
  37. Data []*BaseFromTradeGuangzhouIndex
  38. }
  39. type BaseFromTradeGuangzhouClassify struct {
  40. BaseFromTradeGuangzhouClassifyId int `orm:"column(base_from_trade_guangzhou_classify_id);pk"`
  41. ClassifyName string `description:"分类名称"`
  42. ClassifyCode string `description:"分类编码"`
  43. ParentId int `description:"分类父级id"`
  44. ModifyTime time.Time `description:"修改时间"`
  45. CreateTime time.Time `description:"创建时间"`
  46. }
  47. type GuangzhouClassifyResp struct {
  48. Ret int
  49. Msg string
  50. ErrMsg string
  51. ErrCode string
  52. Data []*BaseFromTradeGuangzhouClassify
  53. }
  54. func GetBaseFromTradeGuangzhouClassifyAll() (list []*BaseFromTradeGuangzhouClassify, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT * FROM base_from_trade_guangzhou_classify `
  57. _, err = o.Raw(sql).QueryRows(&list)
  58. return
  59. }
  60. func AddBaseFromTradeGuangzhouClassify(item *BaseFromTradeGuangzhouClassify) (lastId int64, err error) {
  61. o := orm.NewOrm()
  62. lastId, err = o.Insert(item)
  63. return
  64. }
  65. type BaseFromTradeGuangzhouContract struct {
  66. BaseFromTradeGuangzhouContractId int `orm:"column(base_from_trade_guangzhou_contract_id);pk"`
  67. BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
  68. ClassifyCode string `description:"分类编码"`
  69. Contract string `description:"合约编码"`
  70. TradeDate string `description:"合约日期"`
  71. }
  72. // 新增合约
  73. func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouContract(item *BaseFromTradeGuangzhouContract) (err error) {
  74. o := orm.NewOrmUsingDB("data")
  75. _, err = o.Insert(item)
  76. return
  77. }
  78. type GuangzhouContractResp struct {
  79. Ret int
  80. Msg string
  81. ErrMsg string
  82. ErrCode string
  83. Data []*BaseFromTradeGuangzhouContract
  84. }
  85. func GetBaseFromTradeGuangzhouContractAll() (list []*BaseFromTradeGuangzhouContract, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT * FROM base_from_trade_guangzhou_contract `
  88. _, err = o.Raw(sql).QueryRows(&list)
  89. return
  90. }
  91. // GetBaseFromComTradeMaxDate 获取广州期货交易所最大数据
  92. func GetBaseFromTradeGuangzhouMaxDate() (max_date time.Time, err error) {
  93. o := orm.NewOrm()
  94. sql := ` SELECT max(a.create_time)as max_date FROM base_from_trade_guangzhou_data as a `
  95. err = o.Raw(sql).QueryRow(&max_date)
  96. return
  97. }
  98. type BaseFromTradeGuangzhouData struct {
  99. BaseFromTradeGuangzhouDataId int `orm:"column(base_from_trade_guangzhou_data_id);pk"`
  100. BaseFromTradeGuangzhouIndexId int `description:"指标id"`
  101. IndexCode string `description:"指标编码"`
  102. DataTime string `description:"数据日期"`
  103. Value float64 `description:"数据值"`
  104. QtySub float64 `description:"增减"`
  105. CreateTime time.Time `description:"创建日期"`
  106. ModifyTime time.Time `description:"修改日期"`
  107. }
  108. // GetAllComTradeDataList 获取广州期货交易所数据
  109. func GetAllBaseFromTradeGuangzhouDataList(startDate string) (list []*BaseFromTradeGuangzhouData, err error) {
  110. o := orm.NewOrm()
  111. sql := `SELECT * FROM base_from_trade_guangzhou_data WHERE create_time>=? ORDER BY base_from_trade_guangzhou_data_id ASC `
  112. _, err = o.Raw(sql, startDate).QueryRows(&list)
  113. return
  114. }
  115. type BaseFromTradeGuangzhouDataResp struct {
  116. Ret int
  117. Msg string
  118. ErrMsg string
  119. ErrCode string
  120. Data BaseFromTradeGuangzhouIndexAndDataResp
  121. }
  122. // ComTradeIndexDataResp 分页列表响应体
  123. type BaseFromTradeGuangzhouIndexAndDataResp struct {
  124. List []*BaseFromTradeGuangzhouData
  125. Paging *paging.PagingItem `description:"分页数据"`
  126. }
  127. // MultiAddBaseFromComTradeData 批量添加数据
  128. func MultiAddBaseFromTradeGuangzhouData(items []*BaseFromTradeGuangzhouData) (lastId int64, err error) {
  129. num := len(items)
  130. if num <= 0 {
  131. return
  132. }
  133. o := orm.NewOrm()
  134. lastId, err = o.InsertMulti(num, items)
  135. return
  136. }