package data

import (
	"encoding/json"
	"eta/eta_mobile/models"
	"eta/eta_mobile/utils"
	"fmt"
)

// 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), utils.ZhLangVersion, "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), utils.ZhLangVersion, "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
}
