edb_data_wind.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type EdbDataWind struct {
  8. EdbDataId int `orm:"column(edb_data_id);pk"`
  9. EdbInfoId int
  10. EdbCode string
  11. DataTime string
  12. Value float64
  13. Status int
  14. CreateTime time.Time
  15. ModifyTime time.Time
  16. DataTimestamp int64
  17. }
  18. func AddEdbDataWindBySql(sqlStr string) (err error) {
  19. o := orm.NewOrmUsingDB("data")
  20. _, err = o.Raw(sqlStr).Exec()
  21. return
  22. }
  23. func DeleteEdbDataWind(edbCode string) (err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. sql := `DELETE FROM edb_data_wind WHERE edb_code=? `
  26. _, err = o.Raw(sql, edbCode).Exec()
  27. return
  28. }
  29. func ModifyEdbDataWind(edbInfoId int64, dataTime string, value float64) (err error) {
  30. o := orm.NewOrmUsingDB("data")
  31. sql := ` UPDATE edb_data_wind SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  32. _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
  33. return
  34. }
  35. func GetEdbDataWindByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. sql := ` SELECT * FROM edb_data_wind WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
  38. _, err = o.Raw(sql, edbCode, size).QueryRows(&items)
  39. return
  40. }
  41. func GetEdbDataWindMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
  42. o := orm.NewOrmUsingDB("data")
  43. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_wind WHERE edb_code=? `
  44. err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
  45. return
  46. }
  47. func GetEdbDataWindByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := ` SELECT COUNT(1) AS count FROM edb_data_wind WHERE edb_code=? AND data_time=? `
  50. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  51. return
  52. }
  53. type EdbDataFromWind struct {
  54. Close map[string]float64 `json:"CLOSE"`
  55. Dt map[string]int64 `json:"DT"`
  56. ErrMsg string
  57. }
  58. func EdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateEdbInfoIds []int) (err error) {
  59. o, err := orm.NewOrmUsingDB("data").Begin()
  60. if err != nil {
  61. return
  62. }
  63. defer func() {
  64. if err != nil {
  65. _ = o.Rollback()
  66. return
  67. }
  68. _ = o.Commit()
  69. }()
  70. // 更改指标的更新状态
  71. if len(edbInfoIds) == 1 {
  72. sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id=? `
  73. _, err = o.Raw(sql, isStop, edbInfoIds[0]).Exec()
  74. if err != nil {
  75. return
  76. }
  77. } else {
  78. sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
  79. _, err = o.Raw(sql, isStop, edbInfoIds).Exec()
  80. if err != nil {
  81. return
  82. }
  83. }
  84. if len(calculateEdbInfoIds) > 0 {
  85. // 批量更新相关联的指标ID
  86. sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  87. _, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
  88. if err != nil {
  89. return
  90. }
  91. }
  92. return
  93. }