future_edb_info.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package future_good
  2. import (
  3. "eta/eta_chart_lib/models/data_manage/future_good"
  4. "eta/eta_chart_lib/services/alarm_msg"
  5. "eta/eta_chart_lib/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // FutureGoodEdbInfoRefreshAllFromBase 批量刷新商品期货指标
  10. // @author Roc
  11. // @datetime 2022-09-16 11:04:44
  12. // @description 将原有的单个指标刷新,调整为批量多个指标刷新
  13. func FutureGoodEdbInfoRefreshAllFromBase(futureGoodEdbInfoList []*future_good.FutureGoodEdbInfo, refreshAll bool) (err error) {
  14. var errMsg string
  15. defer func() {
  16. if err != nil {
  17. fmt.Println("FutureGoodEdbInfoRefreshAllFromBase Err:" + err.Error() + ";errMsg:" + errMsg)
  18. go alarm_msg.SendAlarmMsg("FutureGoodEdbInfoRefreshAllFromBase,Err"+err.Error()+";errMsg:"+errMsg, 3)
  19. }
  20. }()
  21. var startDate string
  22. for _, bv := range futureGoodEdbInfoList {
  23. if bv.StartDate == "0000-00-00" {
  24. continue
  25. }
  26. //开始时间
  27. startDate = ``
  28. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  29. sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
  30. if err != nil {
  31. return err
  32. }
  33. startDate = sTime.Format(utils.FormatDate)
  34. } else {
  35. sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
  36. if err != nil {
  37. return err
  38. }
  39. limitDay := utils.DATA_REFRESH
  40. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  41. }
  42. result, err := RefreshEdbData(bv.FutureGoodEdbInfoId, bv.FutureGoodEdbCode, startDate)
  43. if err != nil {
  44. fmt.Println(bv.FutureGoodEdbInfoId, "FutureGoodRefreshBaseEdbData err", time.Now())
  45. errMsg = "FutureGoodRefreshBaseEdbData Err:" + err.Error()
  46. return err
  47. }
  48. if result.Ret != 200 {
  49. fmt.Println(bv.FutureGoodEdbInfoId, "FutureGoodRefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  50. errMsg = fmt.Sprint(bv.FutureGoodEdbInfoId, "FutureGoodRefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  51. return fmt.Errorf("刷新失败, err:%s", errMsg)
  52. }
  53. }
  54. // 刷新商品期货指标相关的数据
  55. for _, bv := range futureGoodEdbInfoList {
  56. if bv.ParentId == 0 {
  57. RefreshEdbRelation(bv.FutureGoodEdbInfoId)
  58. }
  59. }
  60. return err
  61. }