123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_chart_lib/models"
- "eta/eta_chart_lib/utils"
- "fmt"
- )
- // 需要验证密钥的图表
- type ChartAuthController struct {
- BaseAuthV2Controller
- }
- // ChartInfoDetail
- // @Title 获取图表详情
- // @Description 获取图表详情接口
- // @Param UniqueCode query string true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Success 200 {object} data_manage.ChartInfoDetailResp
- // @router /detail [get]
- func (this *ChartAuthController) ChartInfoDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- uniqueCode := this.GetString("UniqueCode")
- if uniqueCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,uniqueCode is empty"
- return
- }
- key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
- resp := new(models.ChartInfoDetailResp)
- // 图表水印
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
- return
- }
- //判断是否有缓存
- if utils.Re == nil {
- if utils.Re == nil && utils.Rc.IsExist(key) {
- if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
- err := json.Unmarshal(data, &resp)
- if err == nil && resp != nil {
- if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
- resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- fmt.Println("source redis")
- return
- }
- }
- }
- }
- chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "该图已被删除,请刷新页面"
- br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- //var resp interface{}
- var isOk bool
- var msg, errMsg string
- switch chartInfo.Source {
- case utils.CHART_SOURCE_DEFAULT:
- resp, isOk, msg, errMsg = GetChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_FUTURE_GOOD:
- resp, isOk, msg, errMsg = GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
- resp, isOk, msg, errMsg = GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
- resp, isOk, msg, errMsg = GetCorrelationChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_LINE_EQUATION:
- resp, isOk, msg, errMsg = GetLineEquationChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
- resp, isOk, msg, errMsg = GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_CROSS_HEDGING:
- resp, isOk, msg, errMsg = GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_BALANCE_EXCEL:
- resp, isOk, msg, errMsg = GetBalanceChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
- if !isOk {
- br.Msg = msg
- br.ErrMsg = errMsg
- return
- }
- case utils.CHART_SOURCE_RANGE_ANALYSIS:
- resp, isOk, msg, errMsg = GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
- if !isOk {
- br.Msg = msg
- br.ErrMsg = errMsg
- return
- }
- default:
- br.Msg = "错误的图表"
- br.ErrMsg = "错误的图表"
- return
- }
- if !isOk {
- br.Msg = msg
- br.ErrMsg = errMsg
- return
- }
- if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
- resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|