123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- 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)
- 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)
- }
- }
- objectNameMap := make(map[int]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 {
- objectNameMap[v.SandboxId] = 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 {
- objectNameMap[v.FeCalendarMatterId] = 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 {
- objectNameMap[v.ChartInfoId] = 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 {
- if v.ParentId > 0 {
- parentName := excelParentName[v.ParentId]
- objectNameMap[v.ExcelInfoId] = fmt.Sprintf("%s_%s", parentName, v.ExcelName)
- } else {
- objectNameMap[v.ExcelInfoId] = v.ExcelName
- }
- }
- }
- for _, v := range relationList {
- referObjectName, _ := objectNameMap[v.ReferObjectId]
- 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.EDB_RELATION_TABLE:
- switch v.ReferObjectSubType {
- case utils.TIME_TABLE:
- tmp.ReferObjectTypeName = "时间序列表格"
- case utils.MIXED_TABLE:
- tmp.ReferObjectTypeName = "混合表格"
- case utils.BALANCE_TABLE:
- 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
- }
|