base_from_trade_guangzhou.go 5.3 KB

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