base_future_good_lib.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // postRefreshEdbData 刷新指标数据
  32. func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *RefreshResponse, err error) {
  33. edbLibUrl := ""
  34. if global.CONFIG.Serve.RunMode == "release" {
  35. edbLibUrl = "http://172.19.173.232:8300/edbapi/"
  36. } else {
  37. edbLibUrl = "http://8.136.199.33:8300/edbapi/"
  38. }
  39. postUrl := edbLibUrl + urlStr
  40. postData, err := json.Marshal(param)
  41. if err != nil {
  42. return
  43. }
  44. result, err := HttpPost(postUrl, string(postData), "application/json")
  45. if err != nil {
  46. return
  47. }
  48. //utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  49. err = json.Unmarshal(result, &resp)
  50. if err != nil {
  51. return
  52. }
  53. return resp, nil
  54. }
  55. func HttpPost(url, postData string, params ...string) ([]byte, error) {
  56. body := ioutil.NopCloser(strings.NewReader(postData))
  57. client := &http.Client{}
  58. req, err := http.NewRequest("POST", url, body)
  59. if err != nil {
  60. return nil, err
  61. }
  62. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  63. if len(params) > 0 && params[0] != "" {
  64. contentType = params[0]
  65. }
  66. req.Header.Set("Content-Type", contentType)
  67. req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
  68. resp, err := client.Do(req)
  69. defer resp.Body.Close()
  70. b, err := ioutil.ReadAll(resp.Body)
  71. fmt.Println("HttpPost:" + string(b))
  72. return b, err
  73. }