future_good_edb_info.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package future_good
  2. import (
  3. "fmt"
  4. "hongze/hongze_yb/models/tables/future_good_edb_info"
  5. "hongze/hongze_yb/services/alarm_msg"
  6. "hongze/hongze_yb/utils"
  7. "time"
  8. )
  9. // FutureGoodEdbInfoRefreshAllFromBase 批量刷新商品期货指标
  10. // @author Roc
  11. // @datetime 2022-09-16 11:04:44
  12. // @description 将原有的单个指标刷新,调整为批量多个指标刷新
  13. func FutureGoodEdbInfoRefreshAllFromBase(futureGoodEdbInfoList []*future_good_edb_info.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.IsZero() {
  24. continue
  25. }
  26. //开始时间
  27. startDate = ``
  28. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  29. startDate = bv.StartDate.Format(utils.FormatDate)
  30. } else {
  31. limitDay := utils.DATA_REFRESH
  32. startDate = bv.StartDate.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  33. }
  34. result, err := RefreshEdbData(int(bv.FutureGoodEdbInfoID), bv.FutureGoodEdbCode, startDate)
  35. if err != nil {
  36. fmt.Println(bv.FutureGoodEdbInfoID, "FutureGoodRefreshBaseEdbData err", time.Now())
  37. errMsg = "FutureGoodRefreshBaseEdbData Err:" + err.Error()
  38. return err
  39. }
  40. if result.Ret != 200 {
  41. fmt.Println(bv.FutureGoodEdbInfoID, "FutureGoodRefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  42. errMsg = fmt.Sprint(bv.FutureGoodEdbInfoID, "FutureGoodRefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  43. return fmt.Errorf("刷新失败, err:%s", errMsg)
  44. }
  45. }
  46. // 刷新商品期货指标相关的数据
  47. for _, bv := range futureGoodEdbInfoList {
  48. if bv.ParentID == 0 {
  49. RefreshEdbRelation(int(bv.FutureGoodEdbInfoID))
  50. }
  51. }
  52. return err
  53. }