package data import ( "encoding/json" "eta/eta_hub/models" "eta/eta_hub/utils" "io" "net/http" "strings" ) type PushEdbResponse struct { Ret int Msg string ErrMsg string ErrCode string Data BaseFromBusinessIndexResp } // BaseFromBusinessIndexResp // @Description: 外部指标(商家系统)表 type BaseFromBusinessIndexResp struct { IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` SourceName string `description:"数据来源名称"` } // PushEdb // @Description:处理外部(商家)指标的接口 // @author: Roc // @datetime 2024-04-28 11:10:44 // @param paramStr string // @return resp *PushEdbResponse // @return err error func PushEdb(paramStr string) (resp *PushEdbResponse, err error) { _, resultByte, err := postEdbLib(paramStr, "/business_index/handle") if err != nil { return } err = json.Unmarshal(resultByte, &resp) if err != nil { return } return } type DelBusinessIndexResponse struct { Ret int Msg string ErrMsg string ErrCode string Data DelBusinessIndexResp } // DelBusinessIndexResp // @Description: 外部指标(商家系统)表 type DelBusinessIndexResp struct { IsDeleteEdbCodeList []string `description:"已经删除了的指标编码"` NoDeleteEdbCodeList []string `description:"未删除的指标编码"` } // DelBusinessIndex // @Description: 删除外部(商家)指标的接口 // @author: Roc // @datetime 2024-5-31 15:26:19 // @param paramStr string // @return resp *models.BaseResponse // @return err error func DelBusinessIndex(paramStr string) (resp *DelBusinessIndexResponse, err error) { _, resultByte, err := postEdbLib(paramStr, "/business_index/index/del") if err != nil { return } err = json.Unmarshal(resultByte, &resp) if err != nil { return } return } // DelBusinessIndexData // @Description:删除外部(商家)指标的明细数据接口 // @author: Roc // @datetime 2024-5-31 15:26:19 // @param paramStr string // @return resp *models.BaseResponse // @return err error func DelBusinessIndexData(paramStr string) (resp *models.BaseResponse, err error) { _, resultByte, err := postEdbLib(paramStr, "/business_index/data/del") if err != nil { return } err = json.Unmarshal(resultByte, &resp) if err != nil { return } return } // postRefreshEdbData 刷新指标数据 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 } utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result)) err = json.Unmarshal(result, &resp) if err != nil { return } return resp, nil } // postEdbLib // @Description: post请求指标服务 // @author: Roc // @datetime 2024-04-28 11:08:59 // @param paramStr string // @param urlStr string // @return resp *models.BaseResponse // @return result []byte // @return err error func postEdbLib(paramStr string, urlStr string) (resp *models.BaseResponse, result []byte, err error) { postUrl := utils.EDB_LIB_URL + urlStr result, err = HttpPost(postUrl, paramStr, "application/json") if err != nil { return } err = json.Unmarshal(result, &resp) if err != nil { return } return } func HttpPost(url, postData string, params ...string) ([]byte, error) { body := io.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 := io.ReadAll(resp.Body) utils.FileLog.Debug("HttpPost:" + string(b)) return b, err }