chart_auth.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_chart_lib/models"
  5. "eta_gn/eta_chart_lib/utils"
  6. "fmt"
  7. )
  8. // 需要验证密钥的图表
  9. type ChartAuthController struct {
  10. BaseAuthV2Controller
  11. }
  12. // ChartInfoDetail
  13. // @Title 获取图表详情
  14. // @Description 获取图表详情接口
  15. // @Param UniqueCode query string true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  16. // @Success 200 {object} data_manage.ChartInfoDetailResp
  17. // @router /detail [get]
  18. func (this *ChartAuthController) ChartInfoDetail() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. uniqueCode := this.GetString("UniqueCode")
  25. if uniqueCode == "" {
  26. br.Msg = "参数错误"
  27. br.ErrMsg = "参数错误,uniqueCode is empty"
  28. return
  29. }
  30. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  31. resp := new(models.ChartInfoDetailResp)
  32. // 图表水印
  33. conf, e := models.GetBusinessConf()
  34. if e != nil {
  35. br.Msg = "获取失败"
  36. br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
  37. return
  38. }
  39. //判断是否有缓存
  40. if utils.Re == nil {
  41. if utils.Re == nil && utils.Rc.IsExist(key) {
  42. if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  43. err := json.Unmarshal(data, &resp)
  44. if err == nil && resp != nil {
  45. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  46. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  47. }
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. br.Data = resp
  52. fmt.Println("source redis")
  53. return
  54. }
  55. }
  56. }
  57. }
  58. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  59. if err != nil {
  60. if utils.IsErrNoRow(err) {
  61. br.Msg = "该图已被删除,请刷新页面"
  62. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  63. return
  64. }
  65. br.Msg = "获取失败"
  66. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  67. return
  68. }
  69. //var resp interface{}
  70. var isOk bool
  71. var msg, errMsg string
  72. switch chartInfo.Source {
  73. case utils.CHART_SOURCE_DEFAULT:
  74. resp, isOk, msg, errMsg = GetChartInfoDetailFromUniqueCode(chartInfo, key)
  75. case utils.CHART_SOURCE_FUTURE_GOOD:
  76. resp, isOk, msg, errMsg = GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo, key)
  77. case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  78. resp, isOk, msg, errMsg = GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, key)
  79. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  80. resp, isOk, msg, errMsg = GetCorrelationChartInfoDetailFromUniqueCode(chartInfo, key)
  81. case utils.CHART_SOURCE_LINE_EQUATION:
  82. resp, isOk, msg, errMsg = GetLineEquationChartInfoDetailFromUniqueCode(chartInfo, key)
  83. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  84. resp, isOk, msg, errMsg = GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo, key)
  85. case utils.CHART_SOURCE_CROSS_HEDGING:
  86. resp, isOk, msg, errMsg = GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo, key)
  87. case utils.CHART_SOURCE_BALANCE_EXCEL:
  88. resp, isOk, msg, errMsg = GetBalanceChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  89. if !isOk {
  90. br.Msg = msg
  91. br.ErrMsg = errMsg
  92. return
  93. }
  94. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  95. resp, isOk, msg, errMsg = GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  96. if !isOk {
  97. br.Msg = msg
  98. br.ErrMsg = errMsg
  99. return
  100. }
  101. default:
  102. br.Msg = "错误的图表"
  103. br.ErrMsg = "错误的图表"
  104. return
  105. }
  106. if !isOk {
  107. br.Msg = msg
  108. br.ErrMsg = errMsg
  109. return
  110. }
  111. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  112. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  113. }
  114. br.Ret = 200
  115. br.Success = true
  116. br.Msg = "获取成功"
  117. br.Data = resp
  118. }