trade_analysis_table.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package data
  2. import (
  3. "context"
  4. "encoding/json"
  5. "eta/eta_task/models"
  6. excelModel "eta/eta_task/models/data_manage/excel"
  7. "eta/eta_task/services/alarm_msg"
  8. "eta/eta_task/utils"
  9. "fmt"
  10. "strings"
  11. "time"
  12. )
  13. const TradeAnalysisTableRefreshUrl = "/trade_analysis/table/refresh"
  14. // RefreshTradeAnalysisTables 刷新持仓分析表格
  15. func RefreshTradeAnalysisTables(cont context.Context) (err error) {
  16. var errMsgList []string
  17. defer func() {
  18. if err != nil {
  19. tips := fmt.Sprintf("RefreshTradeAnalysisTables err: %v", err)
  20. utils.FileLog.Info(tips)
  21. go alarm_msg.SendAlarmMsg(tips, 3)
  22. }
  23. if len(errMsgList) > 0 {
  24. errMsg := strings.Join(errMsgList, "\n")
  25. utils.FileLog.Info(errMsg)
  26. go alarm_msg.SendAlarmMsg(errMsg, 3)
  27. }
  28. utils.FileLog.Info(fmt.Sprintf("持仓分析指标刷新结束: %s", time.Now().Format(utils.FormatDateTime)))
  29. }()
  30. utils.FileLog.Info(fmt.Sprintf("持仓分析-表格刷新开始: %s", time.Now().Format(utils.FormatDateTime)))
  31. excelOb := new(excelModel.ExcelInfo)
  32. var cond string
  33. var pars []interface{}
  34. cond += ` AND is_delete = 0 AND source IN (?, ?)`
  35. pars = append(pars, utils.TRADE_ANALYSIS_TABLE, utils.TRADE_ANALYSIS_CORRELATION_TABLE)
  36. items, e := excelOb.GetItemsByCondition(cond, pars, []string{"excel_info_id"}, "")
  37. if e != nil {
  38. err = fmt.Errorf("获取持仓分析表失败, %v", e)
  39. return
  40. }
  41. for _, v := range items {
  42. resp, e := refreshTradeAnalysisTable(v.ExcelInfoId)
  43. if e != nil {
  44. errMsgList = append(errMsgList, fmt.Sprintf("ExcelId: %d, refresh err: %v", v.ExcelInfoId, e))
  45. continue
  46. }
  47. if resp.Ret != 200 {
  48. errMsgList = append(errMsgList, fmt.Sprintf("ExcelId: %d, refresh err: %v, errMsg: %s", v.ExcelInfoId, e, resp.ErrMsg))
  49. continue
  50. }
  51. }
  52. return err
  53. }
  54. // refreshTradeAnalysisTable 刷新表格数据
  55. func refreshTradeAnalysisTable(excelId int) (resp *models.BaseResponse, err error) {
  56. param := make(map[string]interface{})
  57. param["ExcelInfoId"] = excelId
  58. postUrl := utils.EDB_LIB_URL + TradeAnalysisTableRefreshUrl
  59. postData, e := json.Marshal(param)
  60. if e != nil {
  61. err = fmt.Errorf("post data json err: %v", e)
  62. return
  63. }
  64. result, e := HttpPost(postUrl, string(postData), "application/json")
  65. if e != nil {
  66. err = fmt.Errorf("http post err: %v", e)
  67. return
  68. }
  69. if e = json.Unmarshal(result, &resp); e != nil {
  70. err = fmt.Errorf("resp json unmarshal err: %v", e)
  71. return
  72. }
  73. return
  74. }