base_from_trade_shanghai.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 BaseFromTradeShanghaiIndex struct {
  10. BaseFromTradeShangHaiIndexId int `gorm:"column:base_from_trade_shanghai_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 *BaseFromTradeShanghaiIndex) AfterFind(db *gorm.DB) (err error) {
  35. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  36. return
  37. }
  38. func AddBaseFromTradeShangHaiIndex(item *BaseFromTradeShanghaiIndex) (lastId int64, err error) {
  39. err = global.DbMap[utils.DbNameIndex].Create(item).Error
  40. if err != nil {
  41. return
  42. }
  43. lastId = int64(item.BaseFromTradeShangHaiIndexId)
  44. return
  45. }
  46. func GetBaseFromTradeShangHaiIndexAll(dateStr string) (list []*BaseFromTradeShanghaiIndex, err error) {
  47. o := global.DbMap[utils.DbNameIndex]
  48. sql := `SELECT * FROM base_from_trade_shanghai_index WHERE data_time>=?`
  49. err = o.Raw(sql, dateStr).Find(&list).Error
  50. return
  51. }
  52. func ModifyBaseFromTradeShangHaiIndex(dealValue, buyValue, soldValue int, dataId int) (err error) {
  53. o := global.DbMap[utils.DbNameIndex]
  54. sql := `UPDATE base_from_trade_shanghai_index SET deal_value=?,buy_value=?,sold_value=?,modify_time=NOW() WHERE base_from_trade_shanghai_index_id=? `
  55. err = o.Exec(sql, dealValue, buyValue, soldValue, dataId).Error
  56. return
  57. }
  58. type ShanghaiIndexResp struct {
  59. Ret int
  60. Msg string
  61. ErrMsg string
  62. ErrCode string
  63. Data []*BaseFromTradeShanghaiIndex
  64. }
  65. func GetBaseFromTradeShangHaiIndexMaxDate() (maxDate time.Time, err error) {
  66. o := global.DbMap[utils.DbNameIndex]
  67. sql := ` SELECT max(a.data_time) as max_date FROM base_from_trade_shanghai_index as a `
  68. var timeNull sql2.NullTime
  69. err = o.Raw(sql).Scan(&timeNull).Error
  70. if err != nil {
  71. return
  72. }
  73. if timeNull.Valid {
  74. maxDate = timeNull.Time
  75. }
  76. return
  77. }