sync_edb_lib.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongtao3_watch/global"
  6. "hongze/hongtao3_watch/utils"
  7. "io/ioutil"
  8. "net/http"
  9. "strings"
  10. )
  11. // HandleSciExcelDataReq 卓创(红桃3)的excel数据
  12. type HandleSciExcelDataReq struct {
  13. DataMap map[string]map[string]string
  14. IndexNameList []string
  15. ThirdIndexIdList []string
  16. FrequencyList []string
  17. UnitList []string
  18. }
  19. // HandleExcelDataByEdbLib 调用指标库公共服务处理该数据
  20. func HandleExcelDataByEdbLib(dataMap map[string]map[string]string, indexNameList, thirdIndexIdList, frequencyList, unitList []string) {
  21. param := make(map[string]interface{})
  22. param["DataMap"] = dataMap
  23. param["IndexNameList"] = indexNameList
  24. param["ThirdIndexIdList"] = thirdIndexIdList
  25. param["FrequencyList"] = frequencyList
  26. param["UnitList"] = unitList
  27. // 指标处理的路由地址
  28. urlStr := "sci/handle/excel_data"
  29. _, err := postRefreshEdbData(param, urlStr)
  30. if err != nil {
  31. global.LOG.Info("调用指标库公共服务处理数据失败,err:" + err.Error())
  32. }
  33. }
  34. type BaseResponse struct {
  35. Ret int
  36. Msg string
  37. ErrMsg string
  38. ErrCode string
  39. Data interface{}
  40. Success bool `description:"true 执行成功,false 执行失败"`
  41. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  42. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  43. }
  44. // postRefreshEdbData 刷新指标数据
  45. func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *BaseResponse, err error) {
  46. postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
  47. postData, err := json.Marshal(param)
  48. if err != nil {
  49. return
  50. }
  51. result, err := HttpPost(postUrl, string(postData), "application/json")
  52. if err != nil {
  53. return
  54. }
  55. if result != nil {
  56. global.LOG.Info(" Refresh Result: " + string(result))
  57. err = json.Unmarshal(result, &resp)
  58. if err != nil {
  59. return
  60. }
  61. return resp, nil
  62. }
  63. return nil, err
  64. }
  65. func HttpPost(url, postData string, params ...string) ([]byte, error) {
  66. body := ioutil.NopCloser(strings.NewReader(postData))
  67. client := &http.Client{}
  68. req, err := http.NewRequest("POST", url, body)
  69. if err != nil {
  70. return nil, err
  71. }
  72. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  73. if len(params) > 0 && params[0] != "" {
  74. contentType = params[0]
  75. }
  76. req.Header.Set("Content-Type", contentType)
  77. req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
  78. resp, err := client.Do(req)
  79. if resp != nil {
  80. defer resp.Body.Close()
  81. b, err := ioutil.ReadAll(resp.Body)
  82. fmt.Println("HttpPost:" + string(b))
  83. return b, err
  84. }
  85. return nil, err
  86. }