future_good_edb_info.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package future_good
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_task/models/data_manage/future_good"
  6. "hongze/hongze_task/services/alarm_msg"
  7. "hongze/hongze_task/utils"
  8. "strings"
  9. "time"
  10. )
  11. // RefreshFutureGoodDataFromThs 刷新同花顺的商品期货数据
  12. func RefreshFutureGoodDataFromThs() (err error) {
  13. errMsgList := make([]string,0)
  14. defer func() {
  15. if err != nil {
  16. fmt.Println("RefreshDataFromThs Err:" + err.Error())
  17. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromThs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  18. go alarm_msg.SendAlarmMsg("RefreshDataFromThs ErrMsg:"+err.Error(), 3)
  19. }
  20. if len(errMsgList)>0{
  21. go alarm_msg.SendAlarmMsg("部分商品数据刷新失败 ErrMsg:"+strings.Join(errMsgList,"/n"), 3)
  22. //fmt.Println("总共",len(errMsgList),"条商品数据刷新失败:")
  23. //for _,v:=range errMsgList{
  24. // fmt.Println(v)
  25. //}
  26. }
  27. }()
  28. var condition string
  29. var pars []interface{}
  30. //condition += " AND exchange=? "
  31. //pars = append(pars, "上海期货")
  32. list, err := future_good.GetFutureGoodEdbInfoList(condition, pars)
  33. if err != nil {
  34. err = errors.New("GetEdbInfoByCondition:" + err.Error())
  35. return
  36. }
  37. lenList := len(list)
  38. fmt.Println("总共",lenList,"条")
  39. for k, v := range list {
  40. fmt.Println("剩余",lenList-k-1,"条")
  41. fmt.Println("编码:",v.FutureGoodEdbCode,";名称:",v.FutureGoodEdbName)
  42. var startDateTime time.Time
  43. startDateTime = v.EndDate
  44. // 如果指标结束日期不是空的话,那么就按照刷配置的刷新周期进行兼容性的刷新吧
  45. if v.EndDate.IsZero(){
  46. startDateTime = time.Now()
  47. }
  48. startDate := startDateTime.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  49. resp, err := RefreshEdbData(v.FutureGoodEdbInfoId, v.FutureGoodEdbCode, startDate)
  50. if err != nil {
  51. errMsgList = append(errMsgList,fmt.Sprint(v.FutureGoodEdbCode,";刷新数据失败,err:",err.Error()))
  52. continue
  53. }
  54. if resp.Ret != 200 {
  55. errMsgList = append(errMsgList,fmt.Sprint(v.FutureGoodEdbCode,";刷新数据失败,err:",resp.Msg,";ErrMsg:" , resp.ErrMsg))
  56. continue
  57. }
  58. }
  59. // 刷新商品期货指标相关的数据
  60. for _, bv := range list {
  61. if bv.ParentId == 0 {
  62. RefreshEdbRelation(bv.FutureGoodEdbInfoId)
  63. }
  64. }
  65. return err
  66. }