future_edb_info.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package future_good
  2. import (
  3. "eta/eta_mobile/models/data_manage/future_good"
  4. "eta/eta_mobile/services/alarm_msg"
  5. "eta/eta_mobile/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_START_REFRESH_LIMIT
  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. }