eta_chart_lib.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_yb/global"
  6. "hongze/hongze_yb/models/response/chart_info"
  7. "hongze/hongze_yb/utils"
  8. "io/ioutil"
  9. "net/http"
  10. "strings"
  11. )
  12. // ChartCommonDetailReq 请求图表详情接口
  13. type ChartCommonDetailReq struct {
  14. UniqueCode string `description:"图表唯一编码"`
  15. }
  16. type ChartCommonDetailResp struct {
  17. Ret int
  18. Msg string
  19. ErrMsg string
  20. ErrCode string
  21. Success bool `description:"true 执行成功,false 执行失败"`
  22. IsSendEmail bool `description:"true 发送邮件,false 不发送邮件"`
  23. Data *chart_info.ChartLibChartInfoDetailResp
  24. }
  25. // GetBalanceChartDetail 获取平衡表详情接口
  26. func GetBalanceChartDetail(uniqueCode string) (respData *chart_info.ChartLibChartInfoDetailResp, err error) {
  27. // https://charttest.hzinsights.com/v1/chart/common/detail?UniqueCode=3a2823954a505710b37689df3b063d68
  28. postUrl := fmt.Sprintf("%s/chart_auth/detail?UniqueCode=%s", global.CONFIG.EtaChartLib.ServerUrl, uniqueCode)
  29. /* param := &ChartCommonDetailReq{
  30. UniqueCode: uniqueCode,
  31. }
  32. postData, err := json.Marshal(param)
  33. if err != nil {
  34. return
  35. }*/
  36. result, err := httpGet(postUrl)
  37. if err != nil {
  38. return
  39. }
  40. //result := []byte(`{"Ret":200,"Msg":"获取成功","ErrMsg":"","ErrCode":"","Data":{"ChartInfo":{"ChartName":"平衡表图表1 1 1en","ChartNameEn":"平衡表图表1 1 1en","UniqueCode":"3a2823954a505710b37689df3b063d68","DateType":3,"StartDate":"","EndDate":"","IsSetName":0,"EdbInfoIds":"81,82","ChartType":1,"Calendar":"公历","SeasonStartDate":"","SeasonEndDate":"","ChartImage":"https://hzstatic.hzinsights.com/static/images/202405/20240529/DQE2jdBQImw01c3sn6wIoDXBde2W.png","XMin":"","XMax":"","LeftMin":"13","LeftMax":"65.12","RightMin":"Infinity","RightMax":"-Infinity","Right2Min":"Infinity","Right2Max":"-Infinity","MinMaxSave":1,"Source":11,"Unit":"","UnitEn":"","ChartSource":"平衡表,弘则研究","ChartSourceEn":"平衡表,弘则研究","SeasonExtraConfig":"","StartYear":0,"ChartThemeId":1,"ChartThemeStyle":"{\"colorsOptions\":[\"rgba(179, 237, 21, 1)\",\"rgba(187, 255, 0, 1)\",\"#999\",\"#000\",\"#7cb5ec\",\"#90ed7d\",\"#f7a35c\",\"#8085e9\",\"#f15c80\",\"#e4d354\"],\"lineOptions\":{\"dashStyle\":\"Solid\",\"lineWidth\":1,\"lineType\":\"line\",\"radius\":5},\"legendOptions\":{\"verticalAlign\":\"top\",\"itemStyle\":{\"color\":\"rgba(255, 98, 0, 1)\",\"fontSize\":12,\"cursor\":\"pointer\",\"fontWeight\":\"bold\",\"textOverflow\":\"ellipsis\"}},\"titleOptions\":{\"align\":\"right\",\"style\":{\"color\":\"rgba(208, 193, 20, 1)\",\"fontSize\":12}},\"markerOptions\":{\"style\":{\"color\":\"rgba(87, 205, 37, 1)\",\"fontSize\":12}},\"xAxisOptions\":{\"style\":{\"color\":\"rgba(255, 225, 0, 1)\",\"fontSize\":12}},\"yAxisOptions\":{\"style\":{\"color\":\"rgba(230, 69, 37, 1)\",\"fontSize\":12}},\"drawOption\":{\"plotBackgroundColor\":\"rgba(7, 24, 210, 0.22)\"}}","SourcesFrom":"{\"text\":\"平衡表\",\"isShow\":false}","Instructions":"","MarkersLines":"","MarkersAreas":""},"EdbInfoList":[{"EdbInfoId":81,"SourceName":"平衡表","Source":0,"EdbCode":"T240527094501_6274","EdbName":"指标1en","EdbAliasName":"指标1en","EdbAliasNameEn":"","EdbNameEn":"","Frequency":"","FrequencyEn":"","Unit":"","UnitEn":"","StartDate":"2024-01-01","EndDate":"2024-01-03","ModifyTime":"2024-05-29 17:22:42","ChartInfoId":1930,"MaxData":65.12,"MinData":13,"IsOrder":false,"IsAxis":1,"EdbInfoType":1,"EdbType":0,"LeadValue":0,"LeadUnit":"","LeadUnitEn":"","ChartStyle":"","ChartColor":"","ChartWidth":1,"DataList":[{"DataTime":"2024-01-01","DataTimestamp":1704038400000,"Value":23.11},{"DataTime":"2024-01-02","DataTimestamp":1704124800000,"Value":65.12},{"DataTime":"2024-01-12","DataTimestamp":1704211200000,"Value":13}],"EdbInfoCategoryType":0,"PredictChartColor":"","ChartType":0,"LatestDate":"2024-01-31","LatestValue":13,"MoveLatestDate":"2024-01-23","UniqueCode":"","MappingSource":0,"SubSource":0,"SubSourceName":"","IndicatorCode":"","StockCode":"","IsConvert":0,"ConvertType":0,"ConvertValue":0,"ConvertUnit":"","ConvertEnUnit":""},{"EdbInfoId":82,"SourceName":"平衡表","Source":0,"EdbCode":"T240527094501_1952","EdbName":"指标22en","EdbAliasName":"指标22en","EdbAliasNameEn":"","EdbNameEn":"","Frequency":"","FrequencyEn":"","Unit":"","UnitEn":"","StartDate":"2024-01-04","EndDate":"2024-01-05","ModifyTime":"2024-05-29 17:22:42","ChartInfoId":1930,"MaxData":15,"MinData":14,"IsOrder":false,"IsAxis":1,"EdbInfoType":1,"EdbType":0,"LeadValue":0,"LeadUnit":"","LeadUnitEn":"","ChartStyle":"","ChartColor":"","ChartWidth":1,"DataList":[{"DataTime":"2024-01-04","DataTimestamp":1704297600000,"Value":14},{"DataTime":"2024-01-05","DataTimestamp":1704384000000,"Value":15}],"EdbInfoCategoryType":0,"PredictChartColor":"","ChartType":0,"LatestDate":"2024-01-05","LatestValue":15,"MoveLatestDate":"2024-01-05","UniqueCode":"","MappingSource":0,"SubSource":0,"SubSourceName":"","IndicatorCode":"","StockCode":"","IsConvert":0,"ConvertType":0,"ConvertValue":0,"ConvertUnit":"","ConvertEnUnit":""}],"XEdbIdValue":[],"YDataList":[],"XDataList":null,"CorrelationChartInfo":null,"DataResp":null,"WaterMark":""},"Success":true,"IsSendEmail":true}`)
  41. var resp ChartCommonDetailResp
  42. if err = json.Unmarshal(result, &resp); err != nil {
  43. return
  44. }
  45. if resp.Ret != 200 {
  46. err = fmt.Errorf("%s,%s", resp.Msg, resp.ErrMsg)
  47. return
  48. }
  49. respData = resp.Data
  50. return
  51. }
  52. // GetRangeChartChartDetail 获取区间计算图表详情接口
  53. func GetRangeChartChartDetail(uniqueCode string) (respData *chart_info.ChartLibChartInfoDetailResp, err error) {
  54. postUrl := fmt.Sprintf("%s/chart_auth/detail?UniqueCode=%s", global.CONFIG.EtaChartLib.ServerUrl, uniqueCode)
  55. result, err := httpGet(postUrl)
  56. if err != nil {
  57. return
  58. }
  59. var resp ChartCommonDetailResp
  60. if err = json.Unmarshal(result, &resp); err != nil {
  61. return
  62. }
  63. if resp.Ret != 200 {
  64. err = fmt.Errorf("%s,%s", resp.Msg, resp.ErrMsg)
  65. return
  66. }
  67. respData = resp.Data
  68. return
  69. }
  70. // post请求
  71. func httpPost(url, postData string, params ...string) ([]byte, error) {
  72. body := ioutil.NopCloser(strings.NewReader(postData))
  73. client := &http.Client{}
  74. req, err := http.NewRequest("POST", url, body)
  75. if err != nil {
  76. return nil, err
  77. }
  78. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  79. if len(params) > 0 && params[0] != "" {
  80. contentType = params[0]
  81. }
  82. req.Header.Set("Content-Type", contentType)
  83. resp, err := client.Do(req)
  84. if err != nil {
  85. return nil, err
  86. }
  87. defer resp.Body.Close()
  88. b, err := ioutil.ReadAll(resp.Body)
  89. fmt.Println("HttpPost:" + string(b))
  90. return b, err
  91. }
  92. // post请求
  93. func httpGet(url string) ([]byte, error) {
  94. client := &http.Client{}
  95. req, err := http.NewRequest("GET", url, nil)
  96. if err != nil {
  97. return nil, err
  98. }
  99. req.Header.Set("authorization", utils.MD5(global.CONFIG.EtaChartLib.AppNameEn+global.CONFIG.EtaChartLib.Md5Key))
  100. resp, err := client.Do(req)
  101. if err != nil {
  102. return nil, err
  103. }
  104. defer resp.Body.Close()
  105. b, err := ioutil.ReadAll(resp.Body)
  106. fmt.Println("httpGet:" + string(b))
  107. return b, err
  108. }