浏览代码

获取社区图表数据

xyxie 3 月之前
父节点
当前提交
f70edfd79d
共有 4 个文件被更改,包括 230 次插入246 次删除
  1. 0 243
      controllers/chart_common.go
  2. 228 0
      controllers/chart_info.go
  3. 2 2
      routers/commentsRouter.go
  4. 0 1
      routers/router.go

+ 0 - 243
controllers/chart_common.go

@@ -1,243 +0,0 @@
-package controllers
-
-import (
-	"encoding/json"
-	"eta/eta_forum_hub/models"
-	"eta/eta_forum_hub/models/system"
-	"eta/eta_forum_hub/services"
-	"eta/eta_forum_hub/utils"
-	"fmt"
-	"strings"
-	"time"
-)
-
-// 公用图表数据
-type ChartCommonController struct {
-	BaseCommonController
-}
-
-// CommonChartInfoDetailFromUniqueCode
-// @Title 根据编码获取图表详情
-// @Description 根据编码获取图表详情接口
-// @Param   UniqueCode   query   int  true       "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
-// @Param   IsCache   query   bool  true       "是否走缓存,默认false"
-// @Param   Token   query   string  true       "东吴小程序token"
-// @Param   Source   query   int  true       "查询来源 1:东吴"
-// @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
-// @router /common/detail [get]
-func (this *ChartCommonController) CommonChartInfoDetailFromUniqueCode() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-
-	uniqueCode := this.GetString("UniqueCode")
-	//token := this.GetString("Token")
-	//source, _ := this.GetInt("Source")
-	if uniqueCode == "" {
-		br.Msg = "参数错误"
-		br.ErrMsg = "参数错误,uniqueCode is empty"
-		return
-	}
-	key := utils.CACHE_CHART_INFO_DATA + uniqueCode
-	resp := new(models.ChartInfoDetailResp)
-
-	// 图表水印
-	conf, e := system.GetCrmConfigDetailByCode(system.CrmConfWatermarkChart)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		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 != nil && conf.ConfigValue != "" {
-						resp.WaterMark = conf.ConfigValue
-					}
-					br.Ret = 200
-					br.Success = true
-					br.Msg = "获取成功"
-					br.Data = resp
-					fmt.Println("source redis")
-					return
-				}
-			}
-		}
-	}
-
-	chartInfo, err := models.GetChartInfoViewByUniqueCode(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)
-	default:
-		br.Msg = "错误的图表"
-		br.ErrMsg = "错误的图表"
-		return
-	}
-	if !isOk {
-		br.Msg = msg
-		br.ErrMsg = errMsg
-		return
-	}
-
-	if conf != nil && conf.ConfigValue != "" {
-		resp.WaterMark = conf.ConfigValue
-	}
-
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "获取成功"
-	br.Data = resp
-}
-
-// GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
-func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfoView, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
-	resp = new(models.ChartInfoDetailResp)
-	// 获取主题样式
-	chartTheme, err := services.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
-	if err != nil {
-		msg = "获取失败"
-		errMsg = "获取主题信息失败,Err:" + err.Error()
-		return
-	}
-
-	chartInfo.ChartThemeStyle = chartTheme.Config
-	chartInfo.ChartThemeId = chartTheme.ChartThemeId
-
-	chartInfoId := chartInfo.ChartInfoId
-	mappingList, err := models.GetChartEdbMappingList(chartInfoId)
-	if err != nil {
-		msg = "获取失败"
-		errMsg = "获取图表,指标信息失败,Err:" + err.Error()
-		return
-	}
-
-	dateType := chartInfo.DateType
-	startDate := chartInfo.StartDate
-	endDate := chartInfo.EndDate
-	startYear := chartInfo.StartYear
-	seasonStartDate := chartInfo.SeasonStartDate
-	seasonEndDate := chartInfo.SeasonEndDate
-	calendar := chartInfo.Calendar
-	chartType := chartInfo.ChartType
-
-	if calendar == "" {
-		calendar = "公历"
-	}
-
-	if chartType == 2 {
-		startDate = seasonStartDate
-		endDate = seasonEndDate
-		if dateType <= 0 {
-			if startDate != "" {
-				dateType = 5
-			} else {
-				dateType = utils.DateTypeNYears
-			}
-		}
-	} else {
-		if dateType <= 0 {
-			dateType = 3
-		}
-	}
-	yearMax := 0
-	if dateType == utils.DateTypeNYears {
-		for _, v := range mappingList {
-			if v.LatestDate != "" {
-				lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
-				if tErr != nil {
-					msg = "获取失败"
-					errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
-					return
-				}
-				if lastDateT.Year() > yearMax {
-					yearMax = lastDateT.Year()
-				}
-			}
-		}
-	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
-	if chartInfo.ChartType == 2 {
-		chartInfo.StartDate = startDate
-		chartInfo.EndDate = endDate
-		chartInfo.Calendar = calendar
-	}
-	extraConfigStr := chartInfo.ExtraConfig
-	// 柱方图的一些配置
-	var barConfig models.BarChartInfoReq
-	if chartInfo.ChartType == 7 {
-		if chartInfo.BarConfig == `` {
-			msg = "柱方图未配置"
-			errMsg = "柱方图未配置"
-			return
-		}
-		err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
-		if err != nil {
-			msg = "柱方图配置异常"
-			errMsg = "柱方图配置异常"
-			return
-		}
-		extraConfigStr = chartInfo.BarConfig
-	}
-
-	edbList, xEdbIdValue, yDataList, dataResp, err, tmpErrMsg := services.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
-	if err != nil {
-		msg = "获取失败"
-		if tmpErrMsg != `` {
-			msg = tmpErrMsg
-		}
-		errMsg = "获取图表,指标信息失败,Err:" + err.Error()
-		return
-	}
-	// 单位
-	if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
-		chartInfo.Unit = yDataList[0].Unit
-		chartInfo.UnitEn = yDataList[0].UnitEn
-	}
-	warnEdbList := make([]string, 0)
-	for _, v := range edbList {
-		if v.IsNullData {
-			warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
-		}
-	}
-	if len(warnEdbList) > 0 {
-		chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
-	}
-	// 图表的指标来源
-	sourceNameList, sourceNameEnList := services.GetEdbSourceByEdbInfoIdList(edbList)
-	chartInfo.ChartSource = strings.Join(sourceNameList, ",")
-	chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
-
-	resp.ChartInfo = chartInfo
-	resp.EdbInfoList = edbList
-	resp.XEdbIdValue = xEdbIdValue
-	resp.YDataList = yDataList
-	resp.DataResp = dataResp
-
-	if utils.Re == nil {
-		jsonData, _ := json.Marshal(resp)
-		utils.Rc.Put(key, jsonData, 10*time.Minute)
-	}
-
-	isOk = true
-	return
-}

+ 228 - 0
controllers/chart_info.go

@@ -3,8 +3,10 @@ package controllers
 import (
 	"encoding/json"
 	"eta/eta_forum_hub/models"
+	"eta/eta_forum_hub/models/system"
 	"eta/eta_forum_hub/services"
 	"eta/eta_forum_hub/utils"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"strings"
 	"time"
@@ -314,3 +316,229 @@ func (this *ChartInfoController) UserChartList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// CommonChartInfoDetailFromUniqueCode
+// @Title 根据编码获取图表详情
+// @Description 根据编码获取图表详情接口
+// @Param   UniqueCode   query   int  true       "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
+// @Param   IsCache   query   bool  true       "是否走缓存,默认false"
+// @Param   Token   query   string  true       "东吴小程序token"
+// @Param   Source   query   int  true       "查询来源 1:东吴"
+// @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
+// @router /common/from_unique_code [get]
+func (this *ChartInfoController) CommonChartInfoDetailFromUniqueCode() {
+	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
+	}
+	//是否走缓存
+	isCache, _ := this.GetBool("IsCache")
+	key := utils.CACHE_CHART_INFO_DATA + uniqueCode
+	resp := new(models.ChartInfoDetailResp)
+
+	// 图表水印
+	conf, e := system.GetCrmConfigDetailByCode(system.CrmConfWatermarkChart)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
+		return
+	}
+	//判断是否有缓存
+	if utils.Re == nil && isCache {
+		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 != nil && conf.ConfigValue != "" {
+						resp.WaterMark = conf.ConfigValue
+					}
+					br.Ret = 200
+					br.Success = true
+					br.Msg = "获取成功"
+					br.Data = resp
+					fmt.Println("source redis")
+					return
+				}
+			}
+		}
+	}
+
+	chartInfo, err := models.GetChartInfoViewByUniqueCode(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)
+	default:
+		br.Msg = "错误的图表"
+		br.ErrMsg = "错误的图表"
+		return
+	}
+	if !isOk {
+		br.Msg = msg
+		br.ErrMsg = errMsg
+		return
+	}
+
+	if conf != nil && conf.ConfigValue != "" {
+		resp.WaterMark = conf.ConfigValue
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
+func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfoView, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
+	resp = new(models.ChartInfoDetailResp)
+	// 获取主题样式
+	chartTheme, err := services.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
+	if err != nil {
+		msg = "获取失败"
+		errMsg = "获取主题信息失败,Err:" + err.Error()
+		return
+	}
+
+	chartInfo.ChartThemeStyle = chartTheme.Config
+	chartInfo.ChartThemeId = chartTheme.ChartThemeId
+
+	chartInfoId := chartInfo.ChartInfoId
+	mappingList, err := models.GetChartEdbMappingList(chartInfoId)
+	if err != nil {
+		msg = "获取失败"
+		errMsg = "获取图表,指标信息失败,Err:" + err.Error()
+		return
+	}
+
+	dateType := chartInfo.DateType
+	startDate := chartInfo.StartDate
+	endDate := chartInfo.EndDate
+	startYear := chartInfo.StartYear
+	seasonStartDate := chartInfo.SeasonStartDate
+	seasonEndDate := chartInfo.SeasonEndDate
+	calendar := chartInfo.Calendar
+	chartType := chartInfo.ChartType
+
+	if calendar == "" {
+		calendar = "公历"
+	}
+
+	if chartType == 2 {
+		startDate = seasonStartDate
+		endDate = seasonEndDate
+		if dateType <= 0 {
+			if startDate != "" {
+				dateType = 5
+			} else {
+				dateType = utils.DateTypeNYears
+			}
+		}
+	} else {
+		if dateType <= 0 {
+			dateType = 3
+		}
+	}
+	yearMax := 0
+	if dateType == utils.DateTypeNYears {
+		for _, v := range mappingList {
+			if v.LatestDate != "" {
+				lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
+				if tErr != nil {
+					msg = "获取失败"
+					errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
+					return
+				}
+				if lastDateT.Year() > yearMax {
+					yearMax = lastDateT.Year()
+				}
+			}
+		}
+	}
+	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+	if chartInfo.ChartType == 2 {
+		chartInfo.StartDate = startDate
+		chartInfo.EndDate = endDate
+		chartInfo.Calendar = calendar
+	}
+	extraConfigStr := chartInfo.ExtraConfig
+	// 柱方图的一些配置
+	var barConfig models.BarChartInfoReq
+	if chartInfo.ChartType == 7 {
+		if chartInfo.BarConfig == `` {
+			msg = "柱方图未配置"
+			errMsg = "柱方图未配置"
+			return
+		}
+		err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
+		if err != nil {
+			msg = "柱方图配置异常"
+			errMsg = "柱方图配置异常"
+			return
+		}
+		extraConfigStr = chartInfo.BarConfig
+	}
+
+	edbList, xEdbIdValue, yDataList, dataResp, err, tmpErrMsg := services.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
+	if err != nil {
+		msg = "获取失败"
+		if tmpErrMsg != `` {
+			msg = tmpErrMsg
+		}
+		errMsg = "获取图表,指标信息失败,Err:" + err.Error()
+		return
+	}
+	// 单位
+	if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
+		chartInfo.Unit = yDataList[0].Unit
+		chartInfo.UnitEn = yDataList[0].UnitEn
+	}
+	warnEdbList := make([]string, 0)
+	for _, v := range edbList {
+		if v.IsNullData {
+			warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
+		}
+	}
+	if len(warnEdbList) > 0 {
+		chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
+	}
+	// 图表的指标来源
+	sourceNameList, sourceNameEnList := services.GetEdbSourceByEdbInfoIdList(edbList)
+	chartInfo.ChartSource = strings.Join(sourceNameList, ",")
+	chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
+
+	resp.ChartInfo = chartInfo
+	resp.EdbInfoList = edbList
+	resp.XEdbIdValue = xEdbIdValue
+	resp.YDataList = yDataList
+	resp.DataResp = dataResp
+
+	if utils.Re == nil {
+		jsonData, _ := json.Marshal(resp)
+		utils.Rc.Put(key, jsonData, 10*time.Minute)
+	}
+
+	isOk = true
+	return
+}

+ 2 - 2
routers/commentsRouter.go

@@ -52,10 +52,10 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartCommonController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartCommonController"],
+    beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartInfoController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartInfoController"],
         beego.ControllerComments{
             Method: "CommonChartInfoDetailFromUniqueCode",
-            Router: `/common/detail`,
+            Router: `/common/from_unique_code`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,

+ 0 - 1
routers/router.go

@@ -18,7 +18,6 @@ func init() {
 			web.NSInclude(
 				&controllers.ChartInfoController{},
 				&controllers.ChartThemeController{},
-				&controllers.ChartCommonController{},
 			),
 		),
 		web.NSNamespace("/auth",