123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package data
- import (
- "encoding/json"
- "eta_gn/eta_task/models"
- "eta_gn/eta_task/models/data_manage"
- "eta_gn/eta_task/services/alarm_msg"
- "eta_gn/eta_task/utils"
- "fmt"
- )
- // RefreshFactorEdbCalculateData 刷新因子指标计算数据
- func RefreshFactorEdbCalculateData() (err error) {
- defer func() {
- if err != nil {
- tips := fmt.Sprintf("RefreshFactorEdbCalculateData ErrMsg: %v", err)
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- mappingOb := new(data_manage.FactorEdbSeriesMapping)
- 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))
- if e != nil {
- err = fmt.Errorf("获取系列因子指标失败, err: %v", e)
- return
- }
- if len(list) == 0 {
- return
- }
- for _, v := range list {
- _, e = PostRefreshFactorEdbRecalculate(v.EdbInfoId, v.EdbCode)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("PostRefreshFactorEdbRecalculate err, EdbInfoId: %d, err: %v", v.EdbInfoId, e))
- continue
- }
- }
- return
- }
- // RefreshFactorEdbChartCalculateData 刷新因子指标图表计算数据
- func RefreshFactorEdbChartCalculateData() (err error) {
- defer func() {
- if err != nil {
- tips := fmt.Sprintf("RefreshFactorEdbChartCalculateData ErrMsg: %v", err)
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- mappingOb := new(data_manage.FactorEdbSeriesChartMapping)
- list, e := mappingOb.GetItemsByCondition(``, make([]interface{}, 0), []string{fmt.Sprintf("DISTINCT %s", mappingOb.Cols().ChartInfoId)}, fmt.Sprintf("%s ASC", mappingOb.Cols().ChartInfoId))
- if e != nil {
- err = fmt.Errorf("获取指标系列关联图表失败, err: %v", e)
- return
- }
- if len(list) == 0 {
- return
- }
- for _, v := range list {
- _, e = PostRefreshFactorEdbChartRecalculate(v.ChartInfoId)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("PostRefreshFactorEdbChartRecalculate err, ChartInfoId: %d, err: %v", v.ChartInfoId, e))
- continue
- }
- }
- return
- }
- // PostRefreshFactorEdbRecalculate 因子指标重计算
- func PostRefreshFactorEdbRecalculate(edbInfoId int, edbCode string) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["EdbInfoId"] = edbInfoId
- param["EdbCode"] = edbCode
- postUrl := fmt.Sprintf("%s%s", utils.EDB_LIB_URL, "factor_edb_series/recalculate")
- 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("PostRefreshFactorEdbRecalculate:" + postUrl + ";" + string(postData) + ";result:" + string(result))
- if e = json.Unmarshal(result, &resp); e != nil {
- err = fmt.Errorf("resp unmarshal err: %v", e)
- return
- }
- return
- }
- // PostRefreshFactorEdbChartRecalculate 因子指标图表重计算
- func PostRefreshFactorEdbChartRecalculate(chartInfoId int) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["ChartInfoId"] = chartInfoId
- postUrl := fmt.Sprintf("%s%s", utils.EDB_LIB_URL, "factor_edb_series/chart_recalculate")
- 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("PostRefreshFactorEdbChartRecalculate:" + postUrl + ";" + string(postData) + ";result:" + string(result))
- if e = json.Unmarshal(result, &resp); e != nil {
- err = fmt.Errorf("resp unmarshal err: %v", e)
- return
- }
- return
- }
|