base_future_good_lib.go 2.8 KB

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