Browse Source

新增指标引用查询列表

xyxie 9 months ago
parent
commit
b1fff9e544

+ 171 - 0
controllers/data_manage/edb_info_relation.go

@@ -0,0 +1,171 @@
+package data_manage
+
+import (
+	"eta/eta_api/controllers"
+	"eta/eta_api/models"
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/services/data"
+	"eta/eta_api/utils"
+	"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
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	total, list, err := data.GetEdbRelationList(source, 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)
+	for _, v := range relationList {
+		tmp := &data_manage.EdbInfoRelationDetail{
+			EdbInfoRelationId:  v.EdbInfoRelationId,
+			EdbInfoId:          v.EdbInfoId,
+			ReferObjectId:      v.ReferObjectId,
+			ReferObjectType:    v.ReferObjectType,
+			ReferObjectSubType: v.ReferObjectSubType,
+			RelationTime:       v.ModifyTime.Format(utils.FormatDateTime),
+		}
+		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 = "商品价格曲线"
+			}
+		}
+		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
+}

+ 83 - 0
models/data_manage/edb_info_relation.go

@@ -3,6 +3,7 @@ package data_manage
 import (
 	"eta/eta_api/utils"
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
@@ -105,3 +106,85 @@ func DeleteEdbRelationByObjectIds(referObjectIds []int, referObjectType int) (er
 	_, err = o.Raw(sql, referObjectIds, referObjectType).Exec()
 	return
 }
+
+type BaseRelationEdbInfo struct {
+	EdbInfoId       int
+	ClassifyId      int    `description:"指标分类id"`
+	EdbName         string `description:"指标名称"`
+	SysUserId       int    `description:"创建人id"`
+	SysUserRealName string `description:"创建人姓名"`
+	Frequency       string `description:"频度"`
+	IsStop          int    `description:"是否停更:1:停更,0:未停更"`
+	RelationNum     int    `description:"引用次数"`
+	RelationTime    string `description:"引用时间"`
+}
+
+type BaseRelationEdbInfoResp struct {
+	Paging *paging.PagingItem
+	List   []*BaseRelationEdbInfo
+}
+
+type EdbInfoRelationDetail struct {
+	EdbInfoRelationId   int    `orm:"column(edb_info_relation_id);pk"`
+	EdbInfoId           int    `description:"指标id"`
+	ReferObjectId       int    `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
+	ReferObjectTypeName string `description:"引用对象类型"`
+	ReferObjectType     int    `description:"引用对象ID类型(1.图表,2.ETA逻辑)"`
+	ReferObjectSubType  int    `description:"引用对象子类"`
+	RelationTime        string `description:"引用时间"`
+}
+type BaseRelationEdbInfoDetailResp struct {
+	Paging *paging.PagingItem
+	List   []*EdbInfoRelationDetail
+}
+
+// 查询指标引用列表
+func GetEdbInfoRelationList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRelationEdbInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	// 数量汇总
+	totalSql := ` SELECT count(1) FROM edb_info e LEFT JOIN (
+SELECT count(edb_info_id) as relation_num, edb_info_id, max(modify_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id WHERE e.source in (2,34) `
+	if condition != "" {
+		totalSql += condition
+	}
+	err = o.Raw(totalSql, pars).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	// 列表数据
+	sql := ` SELECT e.edb_info_id, e.classify_id,e.edb_code,e.edb_name,e.sys_user_id,e.sys_user_real_name,e.frequency,e.no_update as is_stop, r.relation_num, r.relation_time from edb_info e LEFT JOIN (
+SELECT count(edb_info_id) as relation_num, edb_info_id, max(modify_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id WHERE e.source in (2,34)
+ `
+	if condition != "" {
+		sql += condition
+	}
+
+	if orderBy != "" {
+		sql += ` ORDER BY ` + orderBy
+	} else {
+		sql += ` ORDER BY edb_info_id ASC `
+	}
+	sql += `  LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+
+	return
+}
+
+// GetEdbInfoRelationDetailList 查询指标引用详情列表
+func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total int, items []*EdbInfoRelation, err error) {
+	o := orm.NewOrmUsingDB("data")
+	// 数量汇总
+	totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=?`
+	err = o.Raw(totalSql, edbInfoId).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	// 列表数据
+	sql := ` SELECT *FROM edb_info_relation where edb_info_id=? ORDER BY modify_time, edb_info_id ASC `
+	sql += `  LIMIT ?,? `
+	_, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
+
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -4291,6 +4291,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoRelationController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoRelationController"],
+        beego.ControllerComments{
+            Method: "RelationEdbListDetail",
+            Router: `/edb_info/relation/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoRelationController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoRelationController"],
+        beego.ControllerComments{
+            Method: "RelationEdbList",
+            Router: `/edb_info/relation/edb_list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:JiaYueEdbSourceController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:JiaYueEdbSourceController"],
         beego.ControllerComments{
             Method: "FrequencyList",

+ 1 - 0
routers/router.go

@@ -170,6 +170,7 @@ func init() {
 				&data_manage_permission.DataMangePermissionController{},
 				&data_manage.BloombergDataController{},
 				&data_manage.EdbBusinessController{},
+				&data_manage.EdbInfoRelationController{},
 			),
 		),
 		web.NSNamespace("/my_chart",

+ 73 - 0
services/data/edb_info_relation.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_api/services/sandbox"
 	"eta/eta_api/utils"
 	"fmt"
+	"strings"
 	"time"
 )
 
@@ -240,3 +241,75 @@ func SaveCalendarEdbInfoRelation(chartPermissionId int, matterDate string, editM
 	}
 	return
 }
+
+// GetEdbRelationList 获取指标引用列表
+func GetEdbRelationList(source int, classifyId, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
+	var pars []interface{}
+	var condition string
+
+	list = make([]*data_manage.BaseRelationEdbInfo, 0)
+
+	isStop := -1
+	if status == `暂停` {
+		isStop = 1
+	} else if status == "启用" {
+		isStop = 0
+	}
+
+	switch source {
+	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND:
+		condition += ` AND e.source = ? `
+		pars = append(pars, source)
+
+		if isStop >= 0 {
+			condition += " AND e.no_update = ? "
+			pars = append(pars, isStop)
+		}
+
+		if classifyId != `` {
+			classifyIdSlice := strings.Split(classifyId, ",")
+			condition += ` AND e.classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
+			pars = append(pars, classifyIdSlice)
+		}
+		if sysUserId != `` {
+			sysUserIdSlice := strings.Split(sysUserId, ",")
+			condition += ` AND e.sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
+			pars = append(pars, sysUserIdSlice)
+		}
+		if frequency != `` {
+			frequencySlice := strings.Split(frequency, ",")
+			condition += ` AND e.frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
+			pars = append(pars, frequencySlice)
+		}
+		if keyword != `` {
+			keywordSlice := strings.Split(keyword, " ")
+			if len(keywordSlice) > 0 {
+				tmpConditionSlice := make([]string, 0)
+				tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
+				pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+
+				for _, v := range keywordSlice {
+					if v == ` ` || v == `` {
+						continue
+					}
+					tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
+					pars = utils.GetLikeKeywordPars(pars, v, 2)
+				}
+				condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
+
+			} else {
+				condition += ` AND (e.edb_name like ? or e.edb_code like ? )`
+				pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+			}
+		}
+
+		sortStr := ``
+		if sortParam != `` {
+			sortStr = fmt.Sprintf("%s %s,e.edb_info_id desc ", sortParam, sortType)
+		}
+
+		total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, sortStr, startSize, pageSize)
+	}
+
+	return
+}