123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- 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"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type BusinessChartController struct {
- BaseAuthController
- }
- // List
- // @Title 图表列表
- // @Description 图表列表
- // @Param BusinessCode query string true "商家编码"
- // @Success 200 {object} data_manage.ChartInfoItem
- // @router /list [get]
- func (this *BusinessChartController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- businessCode := this.GetString("BusinessCode")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if businessCode == "" {
- br.Msg = "商家编码不允许为空"
- return
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if pageSize <= 0 {
- pageSize = 100
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- chartOb := new(data_manage.EtaBusinessChartPermission)
-
- total, err := chartOb.GetChartListByBusinessCodeTotal(businessCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetItemTotal err: " + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := new(data_manage.BusinessChartInfoResp)
- if total == 0 {
- resp.List = make([]*data_manage.BusinessChartInfoView, 0)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- return
- }
- chartList, err := chartOb.GetChartListByBusinessCode(businessCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetChartListByBusinessCode err: " + err.Error()
- return
- }
- chartInfoIds := make([]int, 0)
- for _, v := range chartList {
- chartInfoIds = append(chartInfoIds, v.ChartInfoId)
- }
- descriptionList, err := chartOb.GetChartDescriptionListByChartInfoIds(chartInfoIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetChartDescriptionListByChartInfoIds err: " + err.Error()
- return
- }
- descriptionMap := make(map[int][]string)
- for _, v := range descriptionList {
- descriptionMap[v.ChartInfoId] = append(descriptionMap[v.ChartInfoId], v.Description)
- }
- edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfoIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetChartEdbMappingList err: " + err.Error()
- return
- }
- edbInfoIds := make([]int, 0)
- chartMappingMap := make(map[int][]*data_manage.BusinessChartEdbListItem)
- for _, v := range edbMappingList {
- edbInfoIds = append(edbInfoIds, v.EdbInfoId)
- }
- edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetItemsByIdList err: " + e.Error()
- return
- }
- edbInfoMap := make(map[int]*data_manage.BusinessChartEdbListItem)
- // 根据chartInfoId 将edbInfoList 转换为chartMappingMap
- for _, v := range edbInfoList {
- endValue := v.EndValue
- if v.EdbInfoType == 0 {
- endValue = v.LatestValue
- }
- item := &data_manage.BusinessChartEdbListItem{
- EdbInfoId: v.EdbInfoId,
- EdbName: v.EdbName,
- EdbCode: v.EdbCode,
- EdbInfoType: v.EdbInfoType,
- Frequency: v.Frequency,
- Unit: v.Unit,
- EndDate: v.EndDate,
- EndValue: endValue,
- LatestDate: v.LatestDate,
- LatestValue: v.LatestValue,
- UniqueCode: v.UniqueCode,
- }
- edbInfoMap[v.EdbInfoId] = item
- }
- for _, v := range edbMappingList {
- item := edbInfoMap[v.EdbInfoId]
- chartMappingMap[v.ChartInfoId] = append(chartMappingMap[v.ChartInfoId], item)
- }
- for _, v := range chartList {
- v.EdbInfoList = chartMappingMap[v.ChartInfoId]
- description, ok := descriptionMap[v.ChartInfoId]
- if !ok {
- v.Description = make([]string, 0)
- } else {
- v.Description = description
- }
- }
- resp.List = chartList
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // ChartEdbDataList
- // @Title 图表指标数据列表
- // @Description 图表指标数据列表
- // @Param EdbCode query string true "指标编码"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb/data [get]
- func (this *BusinessChartController) ChartEdbDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- businessCode := this.GetString("BusinessCode")
- if businessCode == "" {
- br.Msg = "商家编码不允许为空"
- return
- }
- edbInfoCode := this.GetString("EdbCode")
- if edbInfoCode == "" {
- br.Msg = "参数有误"
- return
- }
- edbOb := new(data_manage.EdbInfo)
- edbInfo, e := edbOb.GetItemByEdbCode(edbInfoCode)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "ChartEdbDataList GetItemByEdbCode err: " + e.Error()
- return
- }
- // 判断这个指标ID是否是用于画图的指标ID
- chartOb := new(data_manage.EtaBusinessChartPermission)
- chartCount, err := chartOb.GetChartCountByBusinessCodeAndEdbInfoId(businessCode, edbInfo.EdbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartEdbDataList GetChartInfoByEdbInfoId err: " + err.Error()
- return
- }
- if chartCount == 0 { //禁止图表之外的指标数据
- br.Data = make([]*data_manage.EdbDataList, 0)
- br.Ret = 200
- br.Msg = "获取成功"
- return
- }
- edbDataList, e := services.GetEdbInfoDataList(edbInfo)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartEdbDataList GetEdbInfoDataList err: " + e.Error()
- return
- }
- br.Data = edbDataList
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // TraceEdbInfo
- // @Title 指标溯源接口
- // @Description 指标溯源接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb/trace [get]
- func (this *BusinessChartController) TraceEdbInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- edbInfoCode := this.GetString("EdbCode")
- if edbInfoId <= 0 && edbInfoCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- businessCode := this.GetString("BusinessCode")
- if businessCode == "" {
- br.Msg = "商家编码不允许为空"
- return
- }
- resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId, edbInfoCode)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Data = resp
- br.Msg = "刷新成功"
- }
- // List
- // @Title 图表详情
- // @Description 图表详情
- // @Param ChartInfoId query int true "图表id"
- // @Success 200 {object} data_manage.ChartInfoItem
- // @router /detail [get]
- func (this *BusinessChartController) ChartDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- businessCode := this.GetString("BusinessCode")
- uniqueCode := this.GetString("UniqueCode")
- if businessCode == "" {
- br.Msg = "商家编码不允许为空"
- return
- }
- if uniqueCode == "" {
- br.Msg = "图表唯一编码不允许为空"
- return
- }
- chartOb := new(data_manage.EtaBusinessChartPermission)
-
-
- chartInfo, err := chartOb.GetChartInfoByUniqueCode(businessCode, uniqueCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "图表不存在"
- return
- }
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "ChartList GetChartListByBusinessCode err: " + err.Error()
- return
- }
- descriptionList, err := chartOb.GetChartDescriptionListByChartInfoId(chartInfo.ChartInfoId)
- if err != nil {
- br.Msg = "获取图表描述信息失败"
- br.ErrMsg = "ChartList GetChartDescriptionListByChartInfoIds err: " + err.Error()
- return
- }
- descriptionStr := make([]string, 0)
- for _, v := range descriptionList {
- descriptionStr = append(descriptionStr, v.Description)
- }
- edbMappingList, err := data_manage.GetChartEdbMappingListByChartInfoId(chartInfo.ChartInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetChartEdbMappingList err: " + err.Error()
- return
- }
- edbList := make([]data_manage.TraceEdbInfoMoreResp, 0)
- for _, v := range edbMappingList {
- traceList, err := data.TraceBusinessEdbInfoByEdbInfoId(v.EdbInfoId, "")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "ChartList GetChartEdbMappingList err: " + err.Error()
- return
- }
- edbList = append(edbList, traceList)
- }
-
-
- resp := new(data_manage.BusinessChartDetailResp)
- resp.ChartInfoId = chartInfo.ChartInfoId
- resp.ChartName = chartInfo.ChartName
- resp.UniqueCode = chartInfo.UniqueCode
- resp.Description = descriptionStr
- resp.EdbInfoList = edbList
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- }
|