浏览代码

fix:图表有效期鉴权

Roc 2 月之前
父节点
当前提交
578064057d
共有 7 个文件被更改,包括 107 次插入25 次删除
  1. 44 12
      controllers/chart_common.go
  2. 55 12
      controllers/excel_info.go
  3. 1 1
      models/base.go
  4. 1 0
      models/business_conf.go
  5. 1 0
      models/chart.go
  6. 1 0
      models/response/excel_info.go
  7. 4 0
      utils/constants.go

+ 44 - 12
controllers/chart_common.go

@@ -32,6 +32,7 @@ import (
 // @Param   UniqueCode   query   int  true       "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
 // @Param   IsCache   query   bool  true       "是否走缓存,默认false"
 // @Param   Token   query   string  true       "东吴小程序token"
+// @Param   AuthToken   query   string  true       "图表权限鉴权token"
 // @Param   Source   query   int  true       "查询来源 1:东吴"
 // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
 // @router /common/detail [get]
@@ -45,6 +46,7 @@ func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
 	uniqueCode := this.GetString("UniqueCode")
 	token := this.GetString("Token")
 	source, _ := this.GetInt("Source")
+	authToken := this.GetString("AuthToken")
 	if uniqueCode == "" {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误,uniqueCode is empty"
@@ -53,6 +55,18 @@ func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
 	key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
 	resp := new(models.ChartInfoDetailResp)
 
+	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
+	}
+
 	// 图表水印
 	conf, e := models.GetBusinessConf()
 	if e != nil {
@@ -60,6 +74,35 @@ func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
 		br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
 		return
 	}
+
+	// 图表有效期是否开启
+	if conf[models.BusinessConfChartAuth] == "true" {
+		resp.ChartInfo = chartInfo
+		br.Data = resp
+
+		if authToken == `` {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "无鉴权"
+			return
+		}
+
+		key := fmt.Sprint(utils.CACHE_CHART_AUTH, `chart:`, authToken)
+		redisChartCode, err := utils.Rc.RedisString(key)
+		if err != nil {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "获取成功"
+			return
+		}
+		if redisChartCode != uniqueCode {
+			br.Ret = 200
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败"
+			return
+		}
+	}
+
 	var isCollect bool
 	if source == utils.CHART_SOURCE_DW && token != "" {
 		tmpIsCollect, err := dwmini.GetMyChartIsCollect(token, uniqueCode)
@@ -93,18 +136,6 @@ func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
 		}
 	}
 
-	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
@@ -155,6 +186,7 @@ func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
 	if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
 		resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
 	}
+	resp.IsAuth = true
 
 	br.Ret = 200
 	br.Success = true

+ 55 - 12
controllers/excel_info.go

@@ -27,6 +27,7 @@ type ExcelInfoController struct {
 // @Description 获取表格表详情接口
 // @Param   UniqueCode   query   string  true       "表格表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
 // @Param   FromScene   query   int  true       "场景来源,1:智能研报,2:研报列表;3:英文研报;4:中文PPT;5:英文PPT"
+// @Param   AuthToken   query   string  true       "图表权限鉴权token"
 // @Success 200 {object} response.ExcelTableDetailResp
 // @router /detail [get]
 func (this *ExcelInfoController) GetTableDetail() {
@@ -43,8 +44,60 @@ func (this *ExcelInfoController) GetTableDetail() {
 		return
 	}
 	fromScene, _ := this.GetInt("FromScene", 0)
-	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + uniqueCode
+	authToken := this.GetString("AuthToken")
+
+	businessConf, err := models.GetBusinessConfByKey(models.BusinessConfChartAuth)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取配置失败,Err:" + err.Error()
+		return
+	}
+
 	resp := new(response.ExcelTableDetailResp)
+	excelInfo, err := models.GetExcelInfoByUniqueCode(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
+	}
+
+	if businessConf.ConfVal == `true` {
+		resp.ExcelType = excelInfo.ExcelType
+		resp.ExcelName = excelInfo.ExcelName
+		resp.ExcelImage = excelInfo.ExcelImage
+		resp.UniqueCode = excelInfo.UniqueCode
+		resp.SourcesFrom = excelInfo.SourcesFrom
+
+		if authToken == `` {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "无鉴权"
+			return
+		}
+
+		redisChartCode, err := utils.Rc.RedisString(authToken)
+		if err != nil {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "获取成功"
+			br.Data = resp
+			return
+		}
+		if redisChartCode != uniqueCode {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "获取成功"
+			br.Data = resp
+			return
+		}
+	}
+
+	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + uniqueCode
 	switch fromScene {
 	case 1, 2:
 		fromScene = 2
@@ -84,17 +137,6 @@ func (this *ExcelInfoController) GetTableDetail() {
 	//	}
 	//}
 
-	excelInfo, err := models.GetExcelInfoByUniqueCode(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 tableData excel.TableData
 	switch excelInfo.Source {
 	case utils.EXCEL_DEFAULT:
@@ -257,6 +299,7 @@ func (this *ExcelInfoController) GetTableDetail() {
 		}
 	}
 
+	resp.IsAuth = true
 	resp.TableInfo = tableData
 	resp.Source = excelInfo.Source
 	resp.ExcelType = excelInfo.ExcelType

+ 1 - 1
models/base.go

@@ -27,7 +27,7 @@ type BaseResponseResult struct {
 }
 
 func (r *BaseResponse) Init() *BaseResponse {
-	return &BaseResponse{Ret: 403,IsSendEmail: true}
+	return &BaseResponse{Ret: 403, IsSendEmail: true}
 }
 
 type BaseRequest struct {

+ 1 - 0
models/business_conf.go

@@ -13,6 +13,7 @@ const (
 	BusinessConfCompanyName      = "CompanyName"
 	BusinessConfCompanyWatermark = "CompanyWatermark"
 	BusinessConfWatermarkChart   = "WatermarkChart"
+	BusinessConfChartAuth        = "ChartAuth" // 图表是否鉴权
 )
 
 // FromSceneMap 数据源名称与数据源ID的对应关系

+ 1 - 0
models/chart.go

@@ -288,6 +288,7 @@ type ChartInfoDetailResp struct {
 	DataResp             interface{}      `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
 	WaterMark            string           `description:"水印"`
 	IsCollect            bool             `description:"是否收藏"`
+	IsAuth               bool             `description:"是否授权"`
 }
 
 // XData 商品价格曲线的的x轴数据

+ 1 - 0
models/response/excel_info.go

@@ -18,6 +18,7 @@ type ExcelTableDetailResp struct {
 	SourcesFrom   string `description:"图表来源"`
 	ExcelSource   string `description:"表格来源str"`
 	ExcelSourceEn string `description:"表格来源(英文)"`
+	IsAuth        bool   `description:"是否授权"`
 	TableInfo     excel.TableData
 	Config        ExcelTableDetailConfigResp
 }

+ 4 - 0
utils/constants.go

@@ -229,3 +229,7 @@ const (
 	ZhLangVersion = "zh" // 中文语言版本
 	EnLangVersion = "en" // 英文语言版本
 )
+
+const (
+	CACHE_CHART_AUTH = "chart:auth:" //图表数据
+)