edb_info.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package data_manage
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_task/models/data_manage"
  6. "hongze/hongze_task/utils"
  7. "rdluck_tools/http"
  8. "time"
  9. )
  10. //刷新同花顺数据
  11. func RefreshDataFromThs() (err error) {
  12. defer func() {
  13. if err != nil {
  14. fmt.Println("RefreshDataFromThs Err:" + err.Error())
  15. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromThs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  16. }
  17. }()
  18. var condition string
  19. var pars []interface{}
  20. condition += " AND source=? "
  21. pars = append(pars, utils.DATA_SOURCE_THS)
  22. items, err := data_manage.GetEdbInfoByCondition(condition, pars)
  23. if err != nil {
  24. return errors.New("GetEdbInfoByCondition:" + err.Error())
  25. }
  26. for _, v := range items {
  27. startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate)
  28. endDate := time.Now().Format(utils.FormatDate)
  29. err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  30. if err != nil {
  31. return errors.New("SyncEdbDataByThs:" + err.Error())
  32. }
  33. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  34. if err != nil {
  35. return err
  36. }
  37. if item != nil {
  38. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  39. if err != nil {
  40. return err
  41. }
  42. }
  43. //minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(v.EdbInfoId)
  44. //if err != nil {
  45. // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
  46. //}
  47. //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
  48. //err = data_manage.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
  49. //if err != nil {
  50. // return errors.New("ModifyEdbDataInfoDate:" + err.Error())
  51. //}
  52. }
  53. return err
  54. }
  55. //刷新万得数据
  56. func RefreshDataFromWind() (err error) {
  57. defer func() {
  58. if err != nil {
  59. fmt.Println("RefreshDataFromWind Err:" + err.Error())
  60. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromWind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  61. }
  62. }()
  63. var condition string
  64. var pars []interface{}
  65. condition += " AND source=? "
  66. pars = append(pars, utils.DATA_SOURCE_WIND)
  67. items, err := data_manage.GetEdbInfoByCondition(condition, pars)
  68. if err != nil {
  69. return err
  70. }
  71. for k, v := range items {
  72. fmt.Println("line 67:", k, v.EdbCode)
  73. startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate)
  74. endDate := time.Now().Format(utils.FormatDate)
  75. err = SyncEdbDataByWind(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  76. if err != nil {
  77. return err
  78. }
  79. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  80. if err != nil {
  81. return err
  82. }
  83. if item != nil {
  84. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  85. if err != nil {
  86. return err
  87. }
  88. }
  89. }
  90. return err
  91. }
  92. //刷新彭博数据
  93. func RefreshDataFromPb() (err error) {
  94. defer func() {
  95. if err != nil {
  96. fmt.Println("RefreshDataFromPb Err:" + err.Error())
  97. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  98. }
  99. }()
  100. var condition string
  101. var pars []interface{}
  102. condition += " AND source=? "
  103. pars = append(pars, utils.DATA_SOURCE_PB)
  104. items, err := data_manage.GetEdbInfoByCondition(condition, pars)
  105. if err != nil {
  106. return errors.New("GetEdbInfoByCondition:" + err.Error())
  107. }
  108. for _, v := range items {
  109. startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDateUnSpace)
  110. endDate := time.Now().Format(utils.FormatDateUnSpace)
  111. fmt.Println(startDate, endDate)
  112. err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  113. if err != nil {
  114. return errors.New("SyncEdbDataByPb:" + err.Error())
  115. }
  116. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  117. if err != nil {
  118. return err
  119. }
  120. if item != nil {
  121. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  122. if err != nil {
  123. return err
  124. }
  125. }
  126. //minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(v.EdbInfoId)
  127. //if err != nil {
  128. // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
  129. //}
  130. //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
  131. //err = data_manage.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
  132. //if err != nil {
  133. // return errors.New("ModifyEdbDataInfoDate:" + err.Error())
  134. //}
  135. }
  136. return err
  137. }
  138. func CheckDataInterface() (err error) {
  139. go func() {
  140. checkUrl := utils.Hz_Data_Url + `hz_server`
  141. body, err := http.Get(checkUrl)
  142. if err != nil {
  143. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  144. }
  145. result := string(body)
  146. if result != "1" {
  147. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
  148. }
  149. }()
  150. return
  151. }
  152. func CheckPbDataInterface() (err error) {
  153. go func() {
  154. checkUrl := utils.Hz_Data_PB_Url + `hz_server`
  155. body, err := http.Get(checkUrl)
  156. if err != nil {
  157. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  158. }
  159. result := string(body)
  160. if result != "1" {
  161. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
  162. }
  163. }()
  164. return
  165. }