1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package data
- import (
- "encoding/json"
- "eta_gn/eta_task/models"
- "eta_gn/eta_task/models/data_manage"
- "eta_gn/eta_task/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- "strings"
- )
- func RefreshEdbData(edbInfoId, source, subSource int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["EdbCode"] = edbCode
- param["EdbInfoId"] = edbInfoId
- param["StartDate"] = startDate
- param["Source"] = source
- urlStr := ``
- urlStr = data_manage.GetEdbSourceRefreshMethodBySourceId(source) // 没有对应的从edb_source中取
- if urlStr == "" {
- err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
- return
- }
- resp, err = postRefreshEdbData(param, urlStr)
- return
- }
- func RefreshEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["EdbCode"] = edbCode
- param["EdbInfoId"] = edbInfoId
- param["StartDate"] = startDate
- resp, err = postRefreshEdbData(param, "calculate/refresh")
- return
- }
- func RefreshPredictEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["EdbCode"] = edbCode
- param["EdbInfoId"] = edbInfoId
- param["StartDate"] = startDate
- resp, err = postRefreshEdbData(param, "predict_calculate/refresh")
- return
- }
- func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *models.BaseResponse, err error) {
- postUrl := utils.EDB_LIB_URL + urlStr
- postData, err := json.Marshal(param)
- if err != nil {
- return
- }
- result, err := HttpPost(postUrl, string(postData), "application/json")
- if err != nil {
- return
- }
- err = json.Unmarshal(result, &resp)
- if err != nil {
- return
- }
- return resp, nil
- }
- func SetEdbSourceStat() (resp *models.BaseResponse, err error) {
- postUrl := utils.EDB_LIB_URL + "edb_stat/source_update"
- result, err := HttpPost(postUrl, "", "application/json")
- if err != nil {
- return
- }
- err = json.Unmarshal(result, &resp)
- if err != nil {
- return
- }
- return resp, nil
- }
- func HttpPost(url, postData string, params ...string) ([]byte, error) {
- body := ioutil.NopCloser(strings.NewReader(postData))
- client := &http.Client{}
- req, err := http.NewRequest("POST", url, body)
- if err != nil {
- return nil, err
- }
- contentType := "application/x-www-form-urlencoded;charset=utf-8"
- if len(params) > 0 && params[0] != "" {
- contentType = params[0]
- }
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- b, err := ioutil.ReadAll(resp.Body)
- return b, err
- }
|