base_future_good_lib.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package future_good
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_yb/global"
  6. "hongze/hongze_yb/utils"
  7. "io/ioutil"
  8. "net/http"
  9. "strings"
  10. )
  11. type RefreshResponse struct {
  12. Ret int
  13. Msg string
  14. ErrMsg string
  15. ErrCode string
  16. Data interface{}
  17. Success bool `description:"true 执行成功,false 执行失败"`
  18. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  19. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  20. }
  21. // RefreshEdbData 刷新指标数据
  22. func RefreshEdbData(futureGoodEdbInfoId int, futureGoodEdbCode, startDate string) (resp *RefreshResponse, err error) {
  23. param := make(map[string]interface{})
  24. param["FutureGoodEdbCode"] = futureGoodEdbCode
  25. param["FutureGoodEdbInfoId"] = futureGoodEdbInfoId
  26. param["StartDate"] = startDate
  27. urlStr := `future_good/refresh`
  28. resp, err = postRefreshEdbData(param, urlStr)
  29. return
  30. }
  31. // RefreshEdbRelation 刷新商品期货指标相关的数据
  32. func RefreshEdbRelation(futureGoodEdbInfoId int) (resp *RefreshResponse, err error) {
  33. param := make(map[string]interface{})
  34. param["FutureGoodEdbInfoId"] = futureGoodEdbInfoId
  35. urlStr := `future_good/relation/refresh`
  36. resp, err = postRefreshEdbData(param, urlStr)
  37. return
  38. }
  39. // postRefreshEdbData 刷新指标数据
  40. func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *RefreshResponse, err error) {
  41. edbLibUrl := ""
  42. if global.CONFIG.Serve.RunMode == "release" {
  43. edbLibUrl = "http://172.19.173.232:8300/edbapi/"
  44. } else {
  45. edbLibUrl = "http://8.136.199.33:8300/edbapi/"
  46. }
  47. postUrl := edbLibUrl + urlStr
  48. postData, err := json.Marshal(param)
  49. if err != nil {
  50. return
  51. }
  52. result, err := HttpPost(postUrl, string(postData), "application/json")
  53. if err != nil {
  54. return
  55. }
  56. //utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  57. err = json.Unmarshal(result, &resp)
  58. if err != nil {
  59. return
  60. }
  61. return resp, nil
  62. }
  63. func HttpPost(url, postData string, params ...string) ([]byte, error) {
  64. body := ioutil.NopCloser(strings.NewReader(postData))
  65. client := &http.Client{}
  66. req, err := http.NewRequest("POST", url, body)
  67. if err != nil {
  68. return nil, err
  69. }
  70. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  71. if len(params) > 0 && params[0] != "" {
  72. contentType = params[0]
  73. }
  74. req.Header.Set("Content-Type", contentType)
  75. req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
  76. resp, err := client.Do(req)
  77. defer resp.Body.Close()
  78. b, err := ioutil.ReadAll(resp.Body)
  79. fmt.Println("HttpPost:" + string(b))
  80. return b, err
  81. }