factor_edb_series.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package data
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_task/models"
  5. "eta_gn/eta_task/models/data_manage"
  6. "eta_gn/eta_task/services/alarm_msg"
  7. "eta_gn/eta_task/utils"
  8. "fmt"
  9. )
  10. // RefreshFactorEdbCalculateData 刷新因子指标计算数据
  11. func RefreshFactorEdbCalculateData() (err error) {
  12. defer func() {
  13. if err != nil {
  14. tips := fmt.Sprintf("RefreshFactorEdbCalculateData ErrMsg: %v", err)
  15. utils.FileLog.Info(tips)
  16. go alarm_msg.SendAlarmMsg(tips, 3)
  17. }
  18. }()
  19. mappingOb := new(data_manage.FactorEdbSeriesMapping)
  20. list, e := mappingOb.GetItemsByCondition(``, make([]interface{}, 0), []string{fmt.Sprintf("DISTINCT %s", mappingOb.Cols().EdbInfoId), mappingOb.Cols().EdbCode}, fmt.Sprintf("%s ASC", mappingOb.Cols().EdbInfoId))
  21. if e != nil {
  22. err = fmt.Errorf("获取系列因子指标失败, err: %v", e)
  23. return
  24. }
  25. if len(list) == 0 {
  26. return
  27. }
  28. for _, v := range list {
  29. _, e = PostRefreshFactorEdbRecalculate(v.EdbInfoId, v.EdbCode)
  30. if e != nil {
  31. utils.FileLog.Info(fmt.Sprintf("PostRefreshFactorEdbRecalculate err, EdbInfoId: %d, err: %v", v.EdbInfoId, e))
  32. continue
  33. }
  34. }
  35. return
  36. }
  37. // RefreshFactorEdbChartCalculateData 刷新因子指标图表计算数据
  38. func RefreshFactorEdbChartCalculateData() (err error) {
  39. defer func() {
  40. if err != nil {
  41. tips := fmt.Sprintf("RefreshFactorEdbChartCalculateData ErrMsg: %v", err)
  42. utils.FileLog.Info(tips)
  43. go alarm_msg.SendAlarmMsg(tips, 3)
  44. }
  45. }()
  46. mappingOb := new(data_manage.FactorEdbSeriesChartMapping)
  47. list, e := mappingOb.GetItemsByCondition(``, make([]interface{}, 0), []string{fmt.Sprintf("DISTINCT %s", mappingOb.Cols().ChartInfoId)}, fmt.Sprintf("%s ASC", mappingOb.Cols().ChartInfoId))
  48. if e != nil {
  49. err = fmt.Errorf("获取指标系列关联图表失败, err: %v", e)
  50. return
  51. }
  52. if len(list) == 0 {
  53. return
  54. }
  55. for _, v := range list {
  56. _, e = PostRefreshFactorEdbChartRecalculate(v.ChartInfoId)
  57. if e != nil {
  58. utils.FileLog.Info(fmt.Sprintf("PostRefreshFactorEdbChartRecalculate err, ChartInfoId: %d, err: %v", v.ChartInfoId, e))
  59. continue
  60. }
  61. }
  62. return
  63. }
  64. // PostRefreshFactorEdbRecalculate 因子指标重计算
  65. func PostRefreshFactorEdbRecalculate(edbInfoId int, edbCode string) (resp *models.BaseResponse, err error) {
  66. param := make(map[string]interface{})
  67. param["EdbInfoId"] = edbInfoId
  68. param["EdbCode"] = edbCode
  69. postUrl := fmt.Sprintf("%s%s", utils.EDB_LIB_URL, "factor_edb_series/recalculate")
  70. postData, e := json.Marshal(param)
  71. if e != nil {
  72. err = fmt.Errorf("param json err: %v", e)
  73. return
  74. }
  75. result, e := HttpPost(postUrl, string(postData), "application/json")
  76. if e != nil {
  77. err = fmt.Errorf("http post err: %v", e)
  78. return
  79. }
  80. utils.FileLog.Info("PostRefreshFactorEdbRecalculate:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  81. if e = json.Unmarshal(result, &resp); e != nil {
  82. err = fmt.Errorf("resp unmarshal err: %v", e)
  83. return
  84. }
  85. return
  86. }
  87. // PostRefreshFactorEdbChartRecalculate 因子指标图表重计算
  88. func PostRefreshFactorEdbChartRecalculate(chartInfoId int) (resp *models.BaseResponse, err error) {
  89. param := make(map[string]interface{})
  90. param["ChartInfoId"] = chartInfoId
  91. postUrl := fmt.Sprintf("%s%s", utils.EDB_LIB_URL, "factor_edb_series/chart_recalculate")
  92. postData, e := json.Marshal(param)
  93. if e != nil {
  94. err = fmt.Errorf("param json err: %v", e)
  95. return
  96. }
  97. result, e := HttpPost(postUrl, string(postData), "application/json")
  98. if e != nil {
  99. err = fmt.Errorf("http post err: %v", e)
  100. return
  101. }
  102. utils.FileLog.Info("PostRefreshFactorEdbChartRecalculate:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  103. if e = json.Unmarshal(result, &resp); e != nil {
  104. err = fmt.Errorf("resp unmarshal err: %v", e)
  105. return
  106. }
  107. return
  108. }