sync_edb_lib.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, filePath 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. param["TerminalCode"] = global.CONFIG.Serve.TerminalCode
  28. param["FilePath"] = filePath
  29. // 指标处理的路由地址
  30. urlStr := "sci/handle/excel_data"
  31. _, err := postRefreshEdbData(param, urlStr)
  32. if err != nil {
  33. global.LOG.Info("调用指标库公共服务处理数据失败,err:" + err.Error())
  34. }
  35. }
  36. type BaseResponse struct {
  37. Ret int
  38. Msg string
  39. ErrMsg string
  40. ErrCode string
  41. Data interface{}
  42. Success bool `description:"true 执行成功,false 执行失败"`
  43. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  44. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  45. }
  46. // postRefreshEdbData 刷新指标数据
  47. func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *BaseResponse, err error) {
  48. postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
  49. postData, err := json.Marshal(param)
  50. if err != nil {
  51. return
  52. }
  53. result, err := HttpPost(postUrl, string(postData), "application/json")
  54. if err != nil {
  55. return
  56. }
  57. if result != nil {
  58. global.LOG.Info(" Refresh Result: " + string(result))
  59. err = json.Unmarshal(result, &resp)
  60. if err != nil {
  61. return
  62. }
  63. return resp, nil
  64. }
  65. return nil, err
  66. }
  67. func HttpPost(url, postData string, params ...string) ([]byte, error) {
  68. body := ioutil.NopCloser(strings.NewReader(postData))
  69. client := &http.Client{}
  70. req, err := http.NewRequest("POST", url, body)
  71. if err != nil {
  72. return nil, err
  73. }
  74. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  75. if len(params) > 0 && params[0] != "" {
  76. contentType = params[0]
  77. }
  78. req.Header.Set("Content-Type", contentType)
  79. req.Header.Set("authorization", utils.MD5(global.CONFIG.Serve.AppEdbLibNameEn+global.CONFIG.Serve.EdbLibMd5Key))
  80. resp, err := client.Do(req)
  81. if resp != nil {
  82. defer resp.Body.Close()
  83. b, err := ioutil.ReadAll(resp.Body)
  84. fmt.Println("HttpPost:" + string(b))
  85. return b, err
  86. }
  87. return nil, err
  88. }