package data_manage import ( "eta/eta_api/controllers" "eta/eta_api/models" "eta/eta_api/models/data_manage" "eta/eta_api/models/data_manage/excel" "eta/eta_api/models/fe_calendar" "eta/eta_api/models/sandbox" "eta/eta_api/services/data" "eta/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" ) // EdbInfoRelationController 指标引用管理 type EdbInfoRelationController struct { controllers.BaseAuthController } // RelationEdbList // @Title 获取被引用的指标列表接口 // @Description 获取被引用的指标列表接口 // @Param Source query int true "来源:2:wind,34:钢联化工" // @Param ClassifyId query string false "分类ID,支持多选,用英文,隔开" // @Param SysUserId query string false "创建人,支持多选,用英文,隔开" // @Param Frequency query string false "频度,支持多选,用英文,隔开" // @Param Keyword query string false "关键词" // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'RelationTime':引用日期 'RelationNum' 引用次数" // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`" // @Success 200 {object} data_manage.BaseRelationEdbInfoResp // @router /edb_info/relation/edb_list [get] func (c *EdbInfoRelationController) RelationEdbList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() source, _ := c.GetInt("Source") classifyId := c.GetString("ClassifyId") sysUserId := c.GetString("SysUserId") frequency := c.GetString("Frequency") keyword := c.GetString("Keyword") status := c.GetString("Status") sortParam := c.GetString("SortParam") sortType := c.GetString("SortType") switch sortParam { case "RelationTime": sortParam = " r.relation_time " case "RelationNum": sortParam = " r.relation_num " default: sortParam = " r.relation_time " } switch sortType { case "desc", "asc": default: sortType = "desc" } pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } edbType := 1 //基础指标 if source == -1 { //计算指标 edbType = 2 source = 0 } startSize = utils.StartIndex(currentIndex, pageSize) total, list, err := data.GetEdbRelationList(source, edbType, classifyId, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } page := paging.GetPaging(currentIndex, pageSize, total) resp := data_manage.BaseRelationEdbInfoResp{ Paging: page, List: list, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // RelationEdbListDetail // @Title 获取引用详情接口 // @Description 获取引用详情接口 // @Param EdbInfoId query int true "指标ID" // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp // @router /edb_info/relation/detail [get] func (c *EdbInfoRelationController) RelationEdbListDetail() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() edbInfoId, _ := c.GetInt("EdbInfoId") pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) total, relationList, err := data_manage.GetEdbInfoRelationDetailList(edbInfoId, startSize, pageSize) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } list := make([]*data_manage.EdbInfoRelationDetail, 0) // 查询逻辑图 sandboxIds := make([]int, 0) // 查询图库 chartInfoIds := make([]int, 0) // 查询表格 tableInfoIds := make([]int, 0) // 查询事件日历 eventInfoIds := make([]int, 0) // 预测指标 predictEdbIds := make([]int, 0) for _, v := range relationList { switch v.ReferObjectType { case utils.EDB_RELATION_SANDBOX: sandboxIds = append(sandboxIds, v.ReferObjectId) case utils.EDB_RELATION_CALENDAR: eventInfoIds = append(eventInfoIds, v.ReferObjectId) case utils.EDB_RELATION_CHART: chartInfoIds = append(chartInfoIds, v.ReferObjectId) case utils.EDB_RELATION_TABLE: tableInfoIds = append(tableInfoIds, v.ReferObjectId) case utils.EDB_RELATION_PREDICT_EDB: predictEdbIds = append(predictEdbIds, v.ReferObjectId) } } objectNameMap := make(map[string]string) if len(sandboxIds) > 0 { sandboxList, err := sandbox.GetSandboxNameByIds(sandboxIds) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } for _, v := range sandboxList { name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_SANDBOX, v.SandboxId) objectNameMap[name] = v.Name } } // 查询事件日历 if len(eventInfoIds) > 0 { matterOb := new(fe_calendar.FeCalendarMatter) cond := " AND fe_calendar_matter_id in (" + utils.GetOrmInReplace(len(eventInfoIds)) + ")" pars := make([]interface{}, 0) pars = append(pars, eventInfoIds) eventList, err := matterOb.GetItemsByCondition(cond, pars, []string{}, "") if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取事件日历数据失败,Err:" + err.Error() return } for _, v := range eventList { name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_CALENDAR, v.FeCalendarMatterId) objectNameMap[name] = fmt.Sprintf("%s, %s", v.MatterDate, v.ChartPermissionName) } } // 查询图表 if len(chartInfoIds) > 0 { chartList, err := data_manage.GetChartInfoByIdList(chartInfoIds) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取图表数据失败,Err:" + err.Error() return } for _, v := range chartList { name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_CHART, v.ChartInfoId) objectNameMap[name] = v.ChartName } } // 查询表格名称 if len(tableInfoIds) > 0 { cond := " AND excel_info_id in (" + utils.GetOrmInReplace(len(tableInfoIds)) + ")" pars := make([]interface{}, 0) pars = append(pars, tableInfoIds) tableList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取表格数据失败,Err:" + err.Error() return } // 查询父级名称 excelParentName := make(map[int]string) parentIds := make([]int, 0) for _, v := range tableList { if v.ParentId > 0 { parentIds = append(parentIds, v.ParentId) } } if len(parentIds) > 0 { cond = " AND excel_info_id in (" + utils.GetOrmInReplace(len(parentIds)) + ")" pars = make([]interface{}, 0) pars = append(pars, parentIds) parentList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取表格数据失败,Err:" + err.Error() return } for _, v := range parentList { excelParentName[v.ExcelInfoId] = v.ExcelName } } for _, v := range tableList { name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_TABLE, v.ExcelInfoId) if v.ParentId > 0 { parentName := excelParentName[v.ParentId] objectNameMap[name] = fmt.Sprintf("%s_%s", parentName, v.ExcelName) } else { objectNameMap[name] = v.ExcelName } } } // 查询预测指标名称 if len(predictEdbIds) > 0 { predictList, err := data_manage.GetEdbInfoByIdList(predictEdbIds) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取预测指标信息失败,Err:" + err.Error() return } for _, v := range predictList { name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_PREDICT_EDB, v.EdbInfoId) objectNameMap[name] = v.EdbName } } for _, v := range relationList { name := fmt.Sprintf("%d_%d", v.ReferObjectType, v.ReferObjectId) referObjectName, _ := objectNameMap[name] tmp := &data_manage.EdbInfoRelationDetail{ EdbInfoRelationId: v.EdbInfoRelationId, EdbInfoId: v.EdbInfoId, ReferObjectId: v.ReferObjectId, ReferObjectType: v.ReferObjectType, ReferObjectSubType: v.ReferObjectSubType, RelationTime: v.RelationTime.Format(utils.FormatDateTime), ReferObjectName: referObjectName, } switch v.ReferObjectType { case utils.EDB_RELATION_SANDBOX: tmp.ReferObjectTypeName = "逻辑图" case utils.EDB_RELATION_CALENDAR: tmp.ReferObjectTypeName = "事件日历" case utils.EDB_RELATION_CHART: switch v.ReferObjectSubType { case utils.CHART_SOURCE_DEFAULT: tmp.ReferObjectTypeName = "图库" case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION: tmp.ReferObjectTypeName = "相关性分析" case utils.CHART_SOURCE_LINE_EQUATION: tmp.ReferObjectTypeName = "拟合方程曲线" case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY: tmp.ReferObjectTypeName = "统计特征" case utils.CHART_SOURCE_CROSS_HEDGING: tmp.ReferObjectTypeName = "跨品种分析" case utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT: tmp.ReferObjectTypeName = "商品价格曲线" case utils.CHART_SOURCE_RANGE_ANALYSIS: tmp.ReferObjectTypeName = "区间分析" } case utils.EDB_RELATION_TABLE: switch v.ReferObjectSubType { case utils.TIME_TABLE: tmp.ReferObjectTypeName = "时间序列表格" case utils.MIXED_TABLE: tmp.ReferObjectTypeName = "混合表格" case utils.BALANCE_TABLE: tmp.ReferObjectTypeName = "平衡表" } case utils.EDB_RELATION_PREDICT_EDB: tmp.ReferObjectTypeName = "预测指标" } list = append(list, tmp) } page := paging.GetPaging(currentIndex, pageSize, total) resp := data_manage.BaseRelationEdbInfoDetailResp{ Paging: page, List: list, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }