|
@@ -0,0 +1,91 @@
|
|
|
+package data
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_hub/models"
|
|
|
+ "eta/eta_hub/utils"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// PushEdb
|
|
|
+// @Description:处理外部(商家)指标的接口
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-04-28 11:10:44
|
|
|
+// @param paramStr string
|
|
|
+// @return resp *models.BaseResponse
|
|
|
+// @return err error
|
|
|
+func PushEdb(paramStr string) (resp *models.BaseResponse, err error) {
|
|
|
+ _, resultByte, err := postEdbLib(paramStr, "/business_index/handle")
|
|
|
+ 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
|
|
|
+}
|