123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- package controllers
- import (
- "eta/eta_hub/models"
- "eta/eta_hub/models/data_manage"
- "eta/eta_hub/services"
- "eta/eta_hub/services/data"
- "eta/eta_hub/utils"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // 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")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- edbOb := new(data_manage.EdbInfo)
- cond := ``
- pars := make([]interface{}, 0)
- if classifyId > 0 {
- cond += ` AND classify_id = ?`
- pars = append(pars, classifyId)
- }
- var startSize int
- if pageSize > 0 {
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- total, e := edbOb.GetItemsTotal(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "EdbList GetItemsTotal err: " + e.Error()
- return
- }
- resp := new(data_manage.EdbInfoItemResp)
- if total == 0 {
- resp.List = make([]*data_manage.EdbInfoItem, 0)
- resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- return
- }
- edbList, e := edbOb.GetItemsPageByCondition(cond, pars, []string{}, "create_time DESC, sort ASC", startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "EdbList GetItemsPageByCondition err: " + e.Error()
- return
- }
- list := make([]*data_manage.EdbInfoItem, 0)
- for _, v := range edbList {
- list = append(list, data_manage.FormatEdbInfo2Item(v))
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = list
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- return
- }
- edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time DESC")
- 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))
- }
- 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")
- edbCode := this.GetString("EdbCode")
- if unicode == "" && edbCode == "" {
- br.Msg = "参数有误"
- return
- }
- edbOb := new(data_manage.EdbInfo)
- edb := new(data_manage.EdbInfo)
- var e error
- if unicode != "" {
- edb, e = edbOb.GetItemByUniCode(unicode)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByUniCode err: " + e.Error()
- return
- }
- } else if edbCode != "" {
- edb, e = edbOb.GetItemByEdbCode(edbCode)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByEdbCode 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)
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // EdbData
- // @Title 指标数据
- // @Description 指标数据
- // @Success 200 {object} data_manage.EdbInfoItem
- // @router /data [get]
- func (this *EdbController) EdbData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- unicode := this.GetString("UniqueCode")
- edbCode := this.GetString("EdbCode")
- if unicode == "" && edbCode == "" {
- br.Msg = "参数有误"
- return
- }
- startDate := this.GetString("StartDate")
- if startDate != "" {
- _, e := time.Parse(utils.FormatDate, startDate)
- if e != nil {
- br.Msg = "开始日期格式有误"
- return
- }
- }
- edbOb := new(data_manage.EdbInfo)
- edb := new(data_manage.EdbInfo)
- var e error
- if unicode != "" {
- edb, e = edbOb.GetItemByUniCode(unicode)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByUniCode err: " + e.Error()
- return
- }
- } else if edbCode != "" {
- edb, e = edbOb.GetItemByEdbCode(edbCode)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByEdbCode err: " + e.Error()
- return
- }
- }
- // 获取指标数据
- dataOb := new(data_manage.EdbData)
- dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.SubSource, edb.EdbCode, startDate, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "EdbData GetItemsBySourceAndCode err: " + e.Error()
- return
- }
- edbData := make([]*data_manage.EdbDataItem, 0)
- for _, v := range dataList {
- edbData = append(edbData, data_manage.FormatEdbData2Item(v))
- }
- br.Data = edbData
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // TraceEdbInfo
- // @Title 指标溯源接口
- // @Description 指标溯源接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/trace [get]
- func (this *EdbInfoController) TraceEdbInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Data = resp
- br.Msg = "刷新成功"
- }
- // EdbInfoDataTb
- // @Title 获取指标数据同比值
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /data/tb [get]
- func (this *EdbController) EdbInfoDataTb() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- unicode := this.GetString("UniqueCode")
- edbCode := this.GetString("EdbCode")
- if unicode == "" && edbCode == "" {
- br.Msg = "参数有误"
- return
- }
- edbOb := new(data_manage.EdbInfo)
- edbInfo := new(data_manage.EdbInfo)
- var err error
- if unicode != "" {
- edbInfo, err = edbOb.GetItemByUniCode(unicode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByUniCode err: " + err.Error()
- return
- }
- } else if edbCode != "" {
- edbInfo, err = edbOb.GetItemByEdbCode(edbCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByEdbCode err: " + err.Error()
- return
- }
- }
- if edbInfo.EdbInfoType != 0 {
- br.Msg = "不支持预测指标"
- return
- }
- var startDateTime time.Time
- if startDate != `` {
- startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- if err != nil {
- br.Msg = "开始日期异常"
- br.Msg = "开始日期异常,Err:" + err.Error()
- return
- }
- //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
- startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
- }
- tmpDataList, err := data.GetEdbDataList(edbInfo, startDate)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- // 计算同比值
- dataList, _, _, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "计算同比值失败,Err:" + err.Error()
- return
- }
- //edbInfo.MaxValue = maxValue
- //edbInfo.MinValue = minValue
- resp := new(data_manage.EdbInfoDataResp)
- //resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoDataSeasonal
- // @Title 获取指标数据(季节性)
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Param Calendar query string true "公历/农历"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /data/seasonal [get]
- func (this *EdbController) EdbInfoDataSeasonal() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- startDate := this.GetString("StartDate")
- calendar := this.GetString("Calendar")
- if calendar == "" {
- calendar = "公历"
- }
- unicode := this.GetString("UniqueCode")
- edbCode := this.GetString("EdbCode")
- if unicode == "" && edbCode == "" {
- br.Msg = "参数有误"
- return
- }
- edbOb := new(data_manage.EdbInfo)
- edbInfo := new(data_manage.EdbInfo)
- var err error
- if unicode != "" {
- edbInfo, err = edbOb.GetItemByUniCode(unicode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByUniCode err: " + err.Error()
- return
- }
- } else if edbCode != "" {
- edbInfo, err = edbOb.GetItemByEdbCode(edbCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "EdbDetail GetItemByEdbCode err: " + err.Error()
- return
- }
- }
- if edbInfo.EdbInfoType != 0 {
- br.Msg = "不支持预测指标"
- return
- }
- dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, edbInfo)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.EdbInfoDataSeasonalResp)
- //resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = resp
- }
|