edb_info.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package data_manage
  2. import (
  3. "fmt"
  4. "hongze/hongze_task/models/data_manage"
  5. "hongze/hongze_task/utils"
  6. "time"
  7. )
  8. //刷新同花顺数据
  9. func RefreshDataFromThs() (err error) {
  10. defer func() {
  11. if err != nil {
  12. fmt.Println("RefreshDataFromThs Err:" + err.Error())
  13. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromThs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  14. }
  15. }()
  16. var condition string
  17. var pars []interface{}
  18. condition += " AND source=? "
  19. pars = append(pars, utils.DATA_SOURCE_THS)
  20. items, err := data_manage.GetEdbInfoByCondition(condition, pars)
  21. if err != nil {
  22. return err
  23. }
  24. for _, v := range items {
  25. startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate)
  26. endDate := time.Now().Format(utils.FormatDate)
  27. err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  28. if err != nil {
  29. return err
  30. }
  31. minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(v.EdbInfoId)
  32. if err != nil {
  33. return err
  34. }
  35. fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
  36. err = data_manage.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
  37. if err != nil {
  38. return err
  39. }
  40. }
  41. return err
  42. }
  43. //刷新万得数据
  44. func RefreshDataFromWind() (err error) {
  45. defer func() {
  46. if err != nil {
  47. fmt.Println("RefreshDataFromWind Err:" + err.Error())
  48. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromWind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  49. }
  50. }()
  51. var condition string
  52. var pars []interface{}
  53. condition += " AND source=? "
  54. pars = append(pars, utils.DATA_SOURCE_WIND)
  55. items, err := data_manage.GetEdbInfoByCondition(condition, pars)
  56. if err != nil {
  57. return err
  58. }
  59. for _, v := range items {
  60. startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate)
  61. endDate := time.Now().Format(utils.FormatDate)
  62. err = SyncEdbDataByWind(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  63. if err != nil {
  64. return err
  65. }
  66. minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(v.EdbInfoId)
  67. if err != nil {
  68. return err
  69. }
  70. fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
  71. err = data_manage.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
  72. if err != nil {
  73. return err
  74. }
  75. }
  76. return err
  77. }