base_from_trade_cffex.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 BaseFromTradeCffexIndex struct {
  10. BaseFromTradeCffexIndexId int `gorm:"column:base_from_trade_cffex_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 *BaseFromTradeCffexIndex) AfterFind(db *gorm.DB) (err error) {
  35. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  36. return
  37. }
  38. func AddBaseFromTradeCffexIndex(item *BaseFromTradeCffexIndex) (lastId int64, err error) {
  39. err = global.DbMap[utils.DbNameIndex].Create(item).Error
  40. if err != nil {
  41. return
  42. }
  43. lastId = int64(item.BaseFromTradeCffexIndexId)
  44. return
  45. }
  46. func GetBaseFromTradeCffexIndexAll(dateStr string) (list []*BaseFromTradeCffexIndex, err error) {
  47. o := global.DbMap[utils.DbNameIndex]
  48. sql := `SELECT * FROM base_from_trade_cffex_index WHERE data_time=?`
  49. err = o.Raw(sql, dateStr).Find(&list).Error
  50. return
  51. }
  52. func ModifyBaseFromTradeCffexIndex(columnList [5]string, dataList [5]interface{}, dataId int) (err error) {
  53. o := global.DbMap[utils.DbNameIndex]
  54. sql := "UPDATE base_from_trade_cffex_index SET " +
  55. columnList[0] + "=?," + columnList[1] + "=?," + columnList[2] + "=?," + columnList[3] + "=?," + columnList[4] +
  56. "=?,modify_time=NOW() WHERE base_from_trade_cffex_index_id=? "
  57. err = o.Exec(sql, dataList[0], dataList[1], dataList[2], dataList[3], dataList[4], dataId).Error
  58. return
  59. }
  60. type CffexIndexResp struct {
  61. Ret int
  62. Msg string
  63. ErrMsg string
  64. ErrCode string
  65. Data []*BaseFromTradeCffexIndex
  66. }
  67. func GetBaseFromTradeCffexIndexMaxDate() (maxDate time.Time, err error) {
  68. o := global.DbMap[utils.DbNameIndex]
  69. sql := ` SELECT max(a.data_time) AS max_date FROM base_from_trade_cffex_index as a `
  70. var timeNull sql2.NullTime
  71. err = o.Raw(sql).Scan(&timeNull).Error
  72. if err != nil {
  73. return
  74. }
  75. if timeNull.Valid {
  76. maxDate = timeNull.Time
  77. }
  78. return
  79. }