123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package controllers
- import (
- "eta/eta_hub/models"
- "eta/eta_hub/models/data_manage"
- "eta/eta_hub/services"
- "eta/eta_hub/utils"
- )
- // ChartController 图表
- type ChartController struct {
- BaseAuthController
- }
- // ClassifyList
- // @Title 分类列表
- // @Description 分类列表
- // @Success 200 {object} data_manage.ChartClassifyItem
- // @router /classify/list [get]
- func (this *ChartController) ClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source := utils.CHART_SOURCE_DEFAULT
- cond := ` AND source = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, source)
- classifyOb := new(data_manage.ChartClassify)
- classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartClassifyList GetItemsByCondition err: " + e.Error()
- return
- }
- resp := make([]*data_manage.ChartClassifyItem, 0)
- for _, v := range classifies {
- resp = append(resp, data_manage.FormatChartClassify2Item(v))
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // ClassifyTree
- // @Title 图库分类树
- // @Description 图库分类树
- // @Success 200 {object} data_manage.ChartClassifyItem
- // @router /classify/tree [get]
- func (this *ChartController) ClassifyTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 获取所有分类
- classifyOb := new(data_manage.ChartClassify)
- cond := ` AND source = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, utils.CHART_SOURCE_DEFAULT)
- classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, parent_id ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartClassifyTree GetItemsByCondition err: " + e.Error()
- return
- }
- // 递归生成分类树
- classifyTree := services.GetChartClassifyTreeRecursive(classifies, 0)
- br.Data = classifyTree
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // List
- // @Title 图表列表
- // @Description 图表列表
- // @Param ClassifyId query int true "图表分类ID"
- // @Success 200 {object} data_manage.ChartInfoItem
- // @router /list [get]
- func (this *ChartController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数有误"
- return
- }
- chartOb := new(data_manage.ChartInfo)
- cond := ` AND chart_classify_id = ? AND source = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, classifyId, utils.CHART_SOURCE_DEFAULT)
- charts, e := chartOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetItemsByCondition err: " + e.Error()
- return
- }
- resp := make([]*data_manage.ChartInfoItem, 0)
- for _, v := range charts {
- resp = append(resp, data_manage.FormatChartInfo2Item(v))
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // Detail
- // @Title 图表详情
- // @Description 图表详情(这个接口的意义不大, 拿到数据也没啥用=_=!)
- // @Success 200 {object} models.Report
- // @router /detail [get]
- //func (this *ChartController) Detail() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- //
- // unicode := this.GetString("UniqueCode")
- // if unicode == "" {
- // br.Msg = "参数有误"
- // return
- // }
- // chartOb := new(data_manage.ChartInfo)
- // _, e := chartOb.GetItemByCode(unicode)
- // if e != nil {
- // if e.Error() == utils.ErrNoRow() {
- // br.Msg = "图表不存在"
- // return
- // }
- // br.Msg = "获取失败"
- // br.ErrMsg = "ChartDetail GetItemByCode err: " + e.Error()
- // return
- // }
- //
- // // 从edb_chart_lib中获取图详情, 这边只做部分数据的返回
- // detail, e := services.GetChartDetailFromChartLibByUnicode(unicode)
- // if e != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "ChartDetail GetChartDetailFromChartLibByUnicode err: " + e.Error()
- // return
- // }
- //
- // br.Data = detail
- // br.Ret = 200
- // br.Msg = "获取成功"
- //}
|