chart_auth.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. type ChartAuthController struct {
  9. BaseAuthV2Controller
  10. }
  11. // @router /detail [get]
  12. func (this *ChartAuthController) ChartInfoDetail() {
  13. br := new(models.BaseResponse).Init()
  14. defer func() {
  15. this.Data["json"] = br
  16. this.ServeJSON()
  17. }()
  18. uniqueCode := this.GetString("UniqueCode")
  19. if uniqueCode == "" {
  20. br.Msg = "参数错误"
  21. br.ErrMsg = "参数错误,uniqueCode is empty"
  22. return
  23. }
  24. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  25. resp := new(models.ChartInfoDetailResp)
  26. conf, e := models.GetBusinessConf()
  27. if e != nil {
  28. br.Msg = "获取失败"
  29. br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
  30. return
  31. }
  32. if utils.Re == nil {
  33. if utils.Re == nil && utils.Rc.IsExist(key) {
  34. if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  35. err := json.Unmarshal(data, &resp)
  36. if err == nil && resp != nil {
  37. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  38. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  39. }
  40. br.Ret = 200
  41. br.Success = true
  42. br.Msg = "获取成功"
  43. br.Data = resp
  44. fmt.Println("source redis")
  45. return
  46. }
  47. }
  48. }
  49. }
  50. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  51. if err != nil {
  52. if utils.IsErrNoRow(err) {
  53. br.Msg = "该图已被删除,请刷新页面"
  54. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  55. return
  56. }
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  59. return
  60. }
  61. var isOk bool
  62. var msg, errMsg string
  63. switch chartInfo.Source {
  64. case utils.CHART_SOURCE_DEFAULT:
  65. resp, isOk, msg, errMsg = GetChartInfoDetailFromUniqueCode(chartInfo, key)
  66. case utils.CHART_SOURCE_FUTURE_GOOD:
  67. resp, isOk, msg, errMsg = GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo, key)
  68. case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  69. resp, isOk, msg, errMsg = GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, key)
  70. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  71. resp, isOk, msg, errMsg = GetCorrelationChartInfoDetailFromUniqueCode(chartInfo, key)
  72. case utils.CHART_SOURCE_LINE_EQUATION:
  73. resp, isOk, msg, errMsg = GetLineEquationChartInfoDetailFromUniqueCode(chartInfo, key)
  74. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  75. resp, isOk, msg, errMsg = GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo, key)
  76. case utils.CHART_SOURCE_CROSS_HEDGING:
  77. resp, isOk, msg, errMsg = GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo, key)
  78. case utils.CHART_SOURCE_BALANCE_EXCEL:
  79. resp, isOk, msg, errMsg = GetBalanceChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  80. if !isOk {
  81. br.Msg = msg
  82. br.ErrMsg = errMsg
  83. return
  84. }
  85. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  86. resp, isOk, msg, errMsg = GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  87. if !isOk {
  88. br.Msg = msg
  89. br.ErrMsg = errMsg
  90. return
  91. }
  92. default:
  93. br.Msg = "错误的图表"
  94. br.ErrMsg = "错误的图表"
  95. return
  96. }
  97. if !isOk {
  98. br.Msg = msg
  99. br.ErrMsg = errMsg
  100. return
  101. }
  102. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  103. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  104. }
  105. br.Ret = 200
  106. br.Success = true
  107. br.Msg = "获取成功"
  108. br.Data = resp
  109. }