12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package future_good
- import (
- "encoding/json"
- "fmt"
- "hongze/hz_eta_api/models"
- "hongze/hz_eta_api/models/data_manage"
- "hongze/hz_eta_api/utils"
- "io/ioutil"
- "net/http"
- "strings"
- )
- type AddPredictEdbDataResponse struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Data data_manage.AddEdbInfoResp
- Success bool `description:"true 执行成功,false 执行失败"`
- IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
- IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
- }
- // AddEdbData 添加指标数据
- func AddEdbData(futureGoodEdbCode string) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["EdbCode"] = futureGoodEdbCode
- urlStr := `future_good/add`
- resp, err = postRefreshEdbData(param, urlStr)
- return
- }
- // RefreshEdbData 刷新指标数据
- func RefreshEdbData(futureGoodEdbInfoId int, futureGoodEdbCode, startDate string) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["FutureGoodEdbCode"] = futureGoodEdbCode
- param["FutureGoodEdbInfoId"] = futureGoodEdbInfoId
- param["StartDate"] = startDate
- urlStr := `future_good/refresh`
- resp, err = postRefreshEdbData(param, urlStr)
- return
- }
- // RefreshEdbRelation 刷新商品期货指标相关的数据
- func RefreshEdbRelation(futureGoodEdbInfoId int) (resp *models.BaseResponse, err error) {
- param := make(map[string]interface{})
- param["FutureGoodEdbInfoId"] = futureGoodEdbInfoId
- urlStr := `future_good/relation/refresh`
- resp, err = postRefreshEdbData(param, urlStr)
- 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
- }
- 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)
- defer resp.Body.Close()
- b, err := ioutil.ReadAll(resp.Body)
- fmt.Println("HttpPost:" + string(b))
- return b, err
- }
|