base_from_trade_dalian.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package data_manage
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_task/global"
  5. "eta/eta_task/utils"
  6. "gorm.io/gorm"
  7. "time"
  8. )
  9. type BaseFromTradeDalianIndex struct {
  10. BaseFromTradeDalianIndexId int `gorm:"column:base_from_trade_dalian_index_id;primaryKey;autoIncrement"`
  11. Rank string `description:"排名"`
  12. DealShortName string `description:"成交量公司简称"`
  13. DealName string `description:"成交量指标名称"`
  14. DealCode string `description:"成交量指标编码"`
  15. DealValue string `description:"成交量"`
  16. DealChange string `description:"成交变化量"`
  17. BuyShortName string `description:"成交量公司简称"`
  18. BuyName string `description:"持买单量指标名称"`
  19. BuyCode string `description:"持买单量指标编码"`
  20. BuyValue string `description:"持买单量"`
  21. BuyChange string `description:"持买单量变化量"`
  22. SoldShortName string `description:"成交量公司简称"`
  23. SoldName string `description:"持买单量指标名称"`
  24. SoldCode string `description:"持买单量指标编码"`
  25. SoldValue string `description:"持买单量"`
  26. SoldChange string `description:"持买单量变化量"`
  27. Frequency string `description:"频度"`
  28. ClassifyName string `description:"分类名称"`
  29. ClassifyType string `description:"分类名称下的类型"`
  30. CreateTime string `description:"插入时间"`
  31. ModifyTime string `description:"修改时间"`
  32. DataTime string `description:"数据日期"`
  33. }
  34. func (m *BaseFromTradeDalianIndex) AfterFind(db *gorm.DB) (err error) {
  35. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  36. return
  37. }
  38. func AddBaseFromTradeDalianIndex(item *BaseFromTradeDalianIndex) (lastId int64, err error) {
  39. err = global.DbMap[utils.DbNameIndex].Create(item).Error
  40. if err != nil {
  41. return
  42. }
  43. lastId = int64(item.BaseFromTradeDalianIndexId)
  44. return
  45. }
  46. type BaseFromTradeDalianData struct {
  47. BaseFromTradeDalianDataId int `gorm:"column:base_from_trade_dalian_data_id;primaryKey;autoIncrement"`
  48. BaseFromTradeDalianIndexId int
  49. IndexCode string
  50. DataTime time.Time
  51. Value string
  52. AddCutValue string
  53. CreateTime time.Time
  54. ModifyTime time.Time
  55. DataTimestamp string
  56. }
  57. func GetBaseFromTradeDalianDataList(dateTime string) (items []*BaseFromTradeDalianIndex, err error) {
  58. o := global.DbMap[utils.DbNameIndex]
  59. sql := `SELECT * FROM base_from_trade_dalian_index WHERE data_time>=?`
  60. err = o.Raw(sql, dateTime).Find(&items).Error
  61. return
  62. }
  63. type DalianIndexResp struct {
  64. Ret int
  65. Msg string
  66. ErrMsg string
  67. ErrCode string
  68. Data []*BaseFromTradeDalianIndex
  69. }
  70. func GetBaseFromTradeDalianIndexMaxDate() (maxDate time.Time, err error) {
  71. o := global.DbMap[utils.DbNameIndex]
  72. sql := ` SELECT max(a.data_time) AS max_date FROM base_from_trade_dalian_index as a `
  73. var timeNull sql2.NullTime
  74. err = o.Raw(sql).Scan(&timeNull).Error
  75. if err != nil {
  76. return
  77. }
  78. if timeNull.Valid {
  79. maxDate = timeNull.Time
  80. }
  81. return
  82. }