2
0

2 Commity e1fcfdc03e ... f9eca58d02

Autor SHA1 Správa Dátum
  hsun f9eca58d02 Merge branch 'feature/eta_2.1.4' into debug 1 týždeň pred
  hsun 0269209545 每日刷新持仓分析表格数据 1 týždeň pred

+ 55 - 0
models/data_manage/excel/excel_info.go

@@ -0,0 +1,55 @@
+package excel
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+// ExcelInfo excel表格详情表
+type ExcelInfo struct {
+	ExcelInfoId        int       `orm:"column(excel_info_id);pk"`
+	Source             int       `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
+	ExcelType          int       `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName          string    `description:"表格名称"`
+	UniqueCode         string    `description:"表格唯一编码"`
+	ExcelClassifyId    int       `description:"表格分类id"`
+	SysUserId          int       `description:"操作人id"`
+	SysUserRealName    string    `description:"操作人真实姓名"`
+	Content            string    `description:"表格内容"`
+	ExcelImage         string    `description:"表格图片"`
+	FileUrl            string    `description:"表格下载地址"`
+	Sort               int       `description:"排序字段,数字越小越排前面"`
+	IsDelete           int       `description:"是否删除,0:未删除,1:已删除"`
+	ModifyTime         time.Time `description:"最近修改日期"`
+	CreateTime         time.Time `description:"创建日期"`
+	IsJoinPermission   int       `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
+	ParentId           int       `description:"表格的父级id"`
+	BalanceType        int       `description:"平衡表类型:0 动态表,1静态表"`
+	UpdateUserId       int       `description:"更新人id"`
+	UpdateUserRealName string    `description:"更新人真实姓名"`
+	RelExcelInfoId     int       `description:"平衡表里静态表关联的动态表excel id"`
+	VersionName        string    `description:"静态表版本名称"`
+	SourcesFrom        string    `description:"图表来源"`
+	ExtraConfig        string    `description:"额外配置:如多空分析、相关性表格参数"`
+}
+
+func (m *ExcelInfo) TableName() string {
+	return "excel_info"
+}
+
+func (m *ExcelInfo) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ExcelInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 81 - 0
services/data/trade_analysis_table.go

@@ -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
+}

+ 9 - 5
services/task.go

@@ -34,11 +34,11 @@ func Task() {
 
 	XyTask()
 
-	// 测试-刷新同花顺高频, 上线前删除
-	//if utils.RunMode == "debug" {
-	//	refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 30 12 * * *", data.RefreshBaseFromThsHfIndex)
-	//	task.AddTask("refreshThsHfBase", refreshThsHfBase)
-	//}
+	// 测试-刷新多空分析/相关性表格
+	if utils.RunMode == "debug" {
+		refreshTradeAnalysisTables := task.NewTask("refreshTradeAnalysisTables", "0 0 20 * * *", data.RefreshTradeAnalysisTables)
+		task.AddTask("refreshTradeAnalysisTables", refreshTradeAnalysisTables)
+	}
 
 	task.StartTask()
 	fmt.Println("task end")
@@ -147,6 +147,10 @@ func releaseTask() {
 	// 刷新同花顺高频
 	refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 0 0,6,9,12,15,18,21 * * *", data.RefreshBaseFromThsHfIndex)
 	task.AddTask("refreshThsHfBase", refreshThsHfBase)
+
+	// (基于交易所数据)多空分析/相关性表格刷新
+	refreshTradeAnalysisTables := task.NewTask("refreshTradeAnalysisTables", "0 0 20 * * *", data.RefreshTradeAnalysisTables)
+	task.AddTask("refreshTradeAnalysisTables", refreshTradeAnalysisTables)
 }
 
 func RefreshData(cont context.Context) (err error) {

+ 7 - 5
utils/constants.go

@@ -188,9 +188,11 @@ const (
 
 // ETA表格
 const (
-	EXCEL_DEFAULT         = 1 // 自定义excel
-	TIME_TABLE            = 2 // 时间序列表格
-	MIXED_TABLE           = 3 // 混合表格
-	CUSTOM_ANALYSIS_TABLE = 4 // 自定义分析表格
-	BALANCE_TABLE         = 5 // 平衡表
+	EXCEL_DEFAULT                    = 1 // 自定义excel
+	TIME_TABLE                       = 2 // 时间序列表格
+	MIXED_TABLE                      = 3 // 混合表格
+	CUSTOM_ANALYSIS_TABLE            = 4 // 自定义分析表格
+	BALANCE_TABLE                    = 5 // 平衡表
+	TRADE_ANALYSIS_TABLE             = 6 // 持仓分析-多空分析表格
+	TRADE_ANALYSIS_CORRELATION_TABLE = 7 // 持仓分析-相关性表格
 )