|
@@ -0,0 +1,81 @@
|
|
|
+package data
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_task/models"
|
|
|
+ excelModel "eta/eta_task/models/data_manage/excel"
|
|
|
+ "eta/eta_task/services/alarm_msg"
|
|
|
+ "eta/eta_task/utils"
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+const TradeAnalysisTableRefreshUrl = "/trade_analysis/table/refresh"
|
|
|
+
|
|
|
+// RefreshTradeAnalysisTables 刷新持仓分析表格
|
|
|
+func RefreshTradeAnalysisTables(cont context.Context) (err error) {
|
|
|
+ var errMsgList []string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tips := fmt.Sprintf("RefreshTradeAnalysisTables err: %v", err)
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ go alarm_msg.SendAlarmMsg(tips, 3)
|
|
|
+ }
|
|
|
+ if len(errMsgList) > 0 {
|
|
|
+ errMsg := strings.Join(errMsgList, "\n")
|
|
|
+ utils.FileLog.Info(errMsg)
|
|
|
+ go alarm_msg.SendAlarmMsg(errMsg, 3)
|
|
|
+ }
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("持仓分析指标刷新结束: %s", time.Now().Format(utils.FormatDateTime)))
|
|
|
+ }()
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("持仓分析-表格刷新开始: %s", time.Now().Format(utils.FormatDateTime)))
|
|
|
+
|
|
|
+ excelOb := new(excelModel.ExcelInfo)
|
|
|
+ var cond string
|
|
|
+ var pars []interface{}
|
|
|
+ cond += ` AND is_delete = 0 AND source IN (?, ?)`
|
|
|
+ pars = append(pars, utils.TRADE_ANALYSIS_TABLE, utils.TRADE_ANALYSIS_CORRELATION_TABLE)
|
|
|
+ items, e := excelOb.GetItemsByCondition(cond, pars, []string{"excel_info_id"}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取持仓分析表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range items {
|
|
|
+ resp, e := refreshTradeAnalysisTable(v.ExcelInfoId)
|
|
|
+ if e != nil {
|
|
|
+ errMsgList = append(errMsgList, fmt.Sprintf("ExcelId: %d, refresh err: %v", v.ExcelInfoId, e))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if resp.Ret != 200 {
|
|
|
+ errMsgList = append(errMsgList, fmt.Sprintf("ExcelId: %d, refresh err: %v, errMsg: %s", v.ExcelInfoId, e, resp.ErrMsg))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+// refreshTradeAnalysisTable 刷新表格数据
|
|
|
+func refreshTradeAnalysisTable(excelId int) (resp *models.BaseResponse, err error) {
|
|
|
+ param := make(map[string]interface{})
|
|
|
+ param["ExcelInfoId"] = excelId
|
|
|
+
|
|
|
+ postUrl := utils.EDB_LIB_URL + TradeAnalysisTableRefreshUrl
|
|
|
+ postData, e := json.Marshal(param)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("post data json err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, e := HttpPost(postUrl, string(postData), "application/json")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("http post err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if e = json.Unmarshal(result, &resp); e != nil {
|
|
|
+ err = fmt.Errorf("resp json unmarshal err: %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|