package controllers import ( "eta/eta_hub/models" "eta/eta_hub/models/data_manage" "eta/eta_hub/services" "eta/eta_hub/utils" ) // EdbController 指标 type EdbController struct { BaseAuthController } // SourceList // @Title 指标来源 // @Description 指标来源 // @Success 200 {object} data_manage.EdbSourceItem // @router /source/list [get] func (this *EdbController) SourceList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sources, e := data_manage.GetEdbSourceItemsByCondition(``, make([]interface{}, 0), []string{}, "") if e != nil { br.Msg = "获取失败" br.ErrMsg = "SourceList GetEdbSourceItemsByCondition err: " + e.Error() return } resp := make([]*data_manage.EdbSourceItem, 0) for _, v := range sources { resp = append(resp, data_manage.FormatEdbSource2Item(v)) } br.Data = resp br.Ret = 200 br.Msg = "获取成功" } // ClassifyList // @Title 指标分类列表 // @Description 指标分类列表 // @Param ClassifyType query int false "分类类型: 0-普通指标; 1-预测指标" // @Success 200 {object} data_manage.EdbClassifyItem // @router /classify/list [get] func (this *EdbController) ClassifyList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", 0) cond := ` AND classify_type = ?` pars := make([]interface{}, 0) pars = append(pars, classifyType) // 获取所有分类 classifyOb := new(data_manage.EdbClassify) classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC") if e != nil { br.Msg = "获取失败" br.ErrMsg = "ClassifyTree GetItemsByCondition err: " + e.Error() return } resp := make([]*data_manage.EdbClassifyItem, 0) for _, v := range classifies { resp = append(resp, data_manage.FormatEdbClassify2Item(v)) } br.Data = resp br.Ret = 200 br.Msg = "获取成功" } // ClassifyTree // @Title 指标分类树 // @Description 指标分类树 // @Param ClassifyType query int false "分类类型: 0-普通指标; 1-预测指标" // @Success 200 {object} data_manage.EdbClassifyItem // @router /classify/tree [get] func (this *EdbController) ClassifyTree() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", 0) cond := ` AND classify_type = ?` pars := make([]interface{}, 0) pars = append(pars, classifyType) // 获取所有分类 classifyOb := new(data_manage.EdbClassify) classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, parent_id ASC") if e != nil { br.Msg = "获取失败" br.ErrMsg = "EdbClassifyTree GetItemsByCondition err: " + e.Error() return } // 递归生成分类树 classifyTree := services.GetEdbClassifyTreeRecursive(classifies, 0) br.Data = classifyTree br.Ret = 200 br.Msg = "获取成功" } // List // @Title 指标列表 // @Description 指标列表 // @Param ClassifyId query int true "指标分类ID" // @Success 200 {object} data_manage.EdbInfoItem // @router /list [get] func (this *EdbController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyId, _ := this.GetInt("ClassifyId") if classifyId <= 0 { br.Msg = "参数有误" return } edbOb := new(data_manage.EdbInfo) cond := ` AND classify_id = ?` pars := make([]interface{}, 0) pars = append(pars, classifyId) edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC") if e != nil { br.Msg = "获取失败" br.ErrMsg = "EdbList GetItemsByCondition err: " + e.Error() return } resp := make([]*data_manage.EdbInfoItem, 0) for _, v := range edbList { resp = append(resp, data_manage.FormatEdbInfo2Item(v, make([]*data_manage.EdbDataItem, 0))) } br.Data = resp br.Ret = 200 br.Msg = "获取成功" } // Detail // @Title 指标详情 // @Description 指标详情 // @Success 200 {object} data_manage.EdbInfoItem // @router /detail [get] func (this *EdbController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() unicode := this.GetString("UniqueCode") if unicode == "" { br.Msg = "参数有误" return } edbOb := new(data_manage.EdbInfo) edb, e := edbOb.GetItemByUniCode(unicode) if e != nil { if e.Error() == utils.ErrNoRow() { br.Msg = "指标不存在" return } br.Msg = "获取失败" br.ErrMsg = "EdbDetail GetItemByCode err: " + e.Error() return } // 获取指标数据 dataOb := new(data_manage.EdbData) dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.EdbCode, []string{}, "") if e != nil { br.Msg = "获取失败" br.ErrMsg = "EdbDetail GetItemsBySourceAndCode err: " + e.Error() return } edbData := make([]*data_manage.EdbDataItem, 0) for _, v := range dataList { edbData = append(edbData, data_manage.FormatEdbData2Item(v)) } resp := data_manage.FormatEdbInfo2Item(edb, edbData) br.Data = resp br.Ret = 200 br.Msg = "获取成功" }