base_from_trade_zhengzhou.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 BaseFromTradeZhengzhouIndex struct {
  10. BaseFromTradeZhengzhouIndexId int `gorm:"column:base_from_trade_zhengzhou_index_id;primaryKey;autoIncrement"`
  11. Rank int
  12. DealShortName string
  13. DealName string
  14. DealCode string
  15. DealValue int
  16. DealChange int
  17. BuyShortName string
  18. BuyName string
  19. BuyCode string
  20. BuyValue int
  21. BuyChange int
  22. SoldShortName string
  23. SoldName string
  24. SoldCode string
  25. SoldValue int
  26. SoldChange int
  27. Frequency string
  28. ClassifyName string
  29. ClassifyType string
  30. CreateTime time.Time
  31. ModifyTime time.Time
  32. DataTime string
  33. }
  34. func (m *BaseFromTradeZhengzhouIndex) AfterFind(db *gorm.DB) (err error) {
  35. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  36. return
  37. }
  38. func AddBaseFromTradeZhengzhouIndex(item *BaseFromTradeZhengzhouIndex) (lastId int64, err error) {
  39. err = global.DbMap[utils.DbNameIndex].Create(item).Error
  40. return
  41. }
  42. func GetBaseFromTradeZhengzhouIndexAll(dateStr string) (list []*BaseFromTradeZhengzhouIndex, err error) {
  43. o := global.DbMap[utils.DbNameIndex]
  44. sql := `SELECT * FROM base_from_trade_zhengzhou_index WHERE data_time>=?`
  45. err = o.Raw(sql, dateStr).Find(&list).Error
  46. return
  47. }
  48. func ModifyBaseFromTradeZhengzhouIndex(dealValue, buyValue, soldValue int, dataId int) (err error) {
  49. o := global.DbMap[utils.DbNameIndex]
  50. sql := `UPDATE base_from_trade_zhengzhou_index SET deal_value=?,buy_value=?,sold_value=?,modify_time=NOW() WHERE base_from_trade_zhengzhou_index_id=? `
  51. err = o.Exec(sql, dealValue, buyValue, soldValue, dataId).Error
  52. return
  53. }
  54. type ZhengzhouIndexResp struct {
  55. Ret int
  56. Msg string
  57. ErrMsg string
  58. ErrCode string
  59. Data []*BaseFromTradeZhengzhouIndex
  60. }
  61. func GetBaseFromTradeZhengzhouIndexMaxDate() (maxDate time.Time, err error) {
  62. o := global.DbMap[utils.DbNameIndex]
  63. sql := ` SELECT max(a.data_time) as max_date FROM base_from_trade_zhengzhou_index as a `
  64. var timeNull sql2.NullTime
  65. err = o.Raw(sql).Scan(&timeNull).Error
  66. if err != nil {
  67. return
  68. }
  69. if timeNull.Valid {
  70. maxDate = timeNull.Time
  71. }
  72. return
  73. }