package services import ( "encoding/json" "fmt" "hongze/hongtao3_watch/global" "hongze/hongtao3_watch/utils" "io/ioutil" "net/http" "strings" ) // HandleSciExcelDataReq 卓创(红桃3)的excel数据 type HandleSciExcelDataReq struct { DataMap map[string]map[string]string IndexNameList []string ThirdIndexIdList []string FrequencyList []string UnitList []string } // HandleExcelDataByEdbLib 调用指标库公共服务处理该数据 func HandleExcelDataByEdbLib(dataMap map[string]map[string]string, indexNameList, thirdIndexIdList, frequencyList, unitList []string, filePath string) { param := make(map[string]interface{}) param["DataMap"] = dataMap param["IndexNameList"] = indexNameList param["ThirdIndexIdList"] = thirdIndexIdList param["FrequencyList"] = frequencyList param["UnitList"] = unitList param["TerminalCode"] = global.CONFIG.Serve.TerminalCode param["FilePath"] = filePath // 指标处理的路由地址 urlStr := "sci/handle/excel_data" _, err := postRefreshEdbData(param, urlStr) if err != nil { global.LOG.Info("调用指标库公共服务处理数据失败,err:" + err.Error()) } } type BaseResponse struct { Ret int Msg string ErrMsg string ErrCode string Data interface{} Success bool `description:"true 执行成功,false 执行失败"` IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"` IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" ` } // postRefreshEdbData 刷新指标数据 func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *BaseResponse, err error) { postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr postData, err := json.Marshal(param) if err != nil { return } result, err := HttpPost(postUrl, string(postData), "application/json") if err != nil { return } if result != nil { global.LOG.Info(" Refresh Result: " + string(result)) err = json.Unmarshal(result, &resp) if err != nil { return } return resp, nil } return nil, err } 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(global.CONFIG.Serve.AppEdbLibNameEn+global.CONFIG.Serve.EdbLibMd5Key)) resp, err := client.Do(req) if resp != nil { defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) fmt.Println("HttpPost:" + string(b)) return b, err } return nil, err }