Browse Source

Merge branch 'feature/pool255_future_good' of eta_server/eta_task into master

xyxie 1 month ago
parent
commit
d46420eb9d

+ 75 - 0
models/data_manage/future_good/chart_info_future_good_profit.go

@@ -0,0 +1,75 @@
+package future_good
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+// ChartInfoFutureGoodProfit 商品利润图表-扩展信息
+type ChartInfoFutureGoodProfit struct {
+	ChartInfoId  int       `orm:"column(chart_info_id);pk" description:"商品利润图表ID(chart_info表source=5的)"`
+	ProfitName   string    `description:"利润名称"`
+	ProfitNameEn string    `description:"利润英文名称"`
+	XValue       string    `description:"X轴数据值"`
+	YValue       string    `description:"Y轴数据值"`
+	CreateTime   time.Time `description:"创建时间"`
+	ModifyTime   time.Time `description:"更新时间"`
+}
+
+func (m *ChartInfoFutureGoodProfit) TableName() string {
+	return "chart_info_future_good_profit"
+}
+
+func (m *ChartInfoFutureGoodProfit) Create() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(m)
+	if err != nil {
+		return
+	}
+	//m.CorrelationChartInfoId = int(id)
+	return
+}
+
+func (m *ChartInfoFutureGoodProfit) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *ChartInfoFutureGoodProfit) Delete() (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE chart_info_id = ? LIMIT 1`, m.TableName())
+	_, err = o.Raw(sql, m.ChartInfoId).Exec()
+	return
+}
+
+func (m *ChartInfoFutureGoodProfit) GetItemById(id int) (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE chart_info_id = ? LIMIT 1`, m.TableName())
+	err = o.Raw(sql, id).QueryRow(&m)
+	return
+}
+
+func (m *ChartInfoFutureGoodProfit) GetItemByCondition(condition string, pars []interface{}) (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&m)
+	return
+}
+
+func (m *ChartInfoFutureGoodProfit) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ChartInfoFutureGoodProfit, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := ``
+	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
+}

+ 58 - 0
services/data/future_good.go

@@ -0,0 +1,58 @@
+package data
+
+import (
+	"encoding/json"
+	"eta/eta_task/models/data_manage/future_good"
+	"eta/eta_task/services/alarm_msg"
+	"eta/eta_task/utils"
+	"fmt"
+)
+
+// RefreshFutureGoodProfitChart 刷新商品利润曲线图
+func RefreshFutureGoodProfitChart() (err error) {
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("RefreshFactorEdbCalculateData ErrMsg: %v", err)
+			utils.FileLog.Info(tips)
+			go alarm_msg.SendAlarmMsg(tips, 3)
+		}
+	}()
+
+	profitOb := new(future_good.ChartInfoFutureGoodProfit)
+	list, e := profitOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
+	if e != nil {
+		err = fmt.Errorf("获取系列因子指标失败, err: %v", e)
+		return
+	}
+	if len(list) == 0 {
+		return
+	}
+
+	for _, v := range list {
+		e = PostRefreshFutureGoodProfitChart(v.ChartInfoId)
+		if e != nil {
+			utils.FileLog.Info(fmt.Sprintf("PostRefreshFutureGoodProfitChart err, ChartInfoId: %d, err: %v", v.ChartInfoId, e))
+			continue
+		}
+	}
+	return
+}
+
+// PostRefreshFutureGoodProfitChart 因子指标图表重计算
+func PostRefreshFutureGoodProfitChart(chartInfoId int) (err error) {
+	param := make(map[string]interface{})
+	param["ChartInfoId"] = chartInfoId
+	postUrl := fmt.Sprintf("%s%s", utils.EDB_LIB_URL, "future_good/relation/refresh")
+	postData, e := json.Marshal(param)
+	if e != nil {
+		err = fmt.Errorf("param 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
+	}
+	utils.FileLog.Info("PostRefreshFutureGoodProfitChart:" + postUrl + ";" + string(postData) + ";result:" + string(result))
+	return
+}

+ 3 - 0
services/task.go

@@ -220,6 +220,9 @@ func RefreshData(cont context.Context) (err error) {
 	// 指标系列图表计算数据
 	_ = data.RefreshFactorEdbChartCalculateData()
 
+	// 刷新商品利润曲线图表数据
+	_ = data.RefreshFutureGoodProfitChart()
+
 	time.Sleep(5 * time.Second)
 	//data.RefreshNotice()