package controllers import ( "eta/eta_hub/models" "eta/eta_hub/models/data_manage" "eta/eta_hub/services" "eta/eta_hub/utils" "github.com/rdlucklib/rdluck_tools/paging" ) // 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") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") cond := ` AND source = ?` pars := make([]interface{}, 0) pars = append(pars, utils.CHART_SOURCE_DEFAULT) if classifyId > 0 { cond += ` AND chart_classify_id = ?` pars = append(pars, classifyId) } chartOb := new(data_manage.ChartInfo) if pageSize > 0 { if currentIndex <= 0 { currentIndex = 1 } startSize := utils.StartIndex(currentIndex, pageSize) total, err := chartOb.GetItemTotal(cond, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "ChartList GetItemTotal err: " + err.Error() return } resp := new(data_manage.ChartInfoItemResp) if total == 0 { resp.List = make([]*data_manage.ChartInfoItem, 0) resp.Paging = paging.GetPaging(currentIndex, pageSize, 0) br.Data = resp br.Ret = 200 br.Msg = "获取成功" return } charts, e := chartOb.GetItemsPageByCondition(cond, pars, []string{}, "", startSize, pageSize) if e != nil { br.Msg = "获取失败" br.ErrMsg = "ChartList GetItemsPageByCondition err: " + e.Error() return } list := make([]*data_manage.ChartInfoItem, 0) for _, v := range charts { list = append(list, data_manage.FormatChartInfo2Item(v)) } page := paging.GetPaging(currentIndex, pageSize, total) resp.List = list resp.Paging = page br.Data = resp br.Ret = 200 br.Msg = "获取成功" return } charts, e := chartOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time DESC") 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 = "获取成功" }