package data_manage import ( "eta/eta_api/utils" "github.com/beego/beego/v2/client/orm" "time" ) type EdbInfoRelation struct { EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk"` EdbInfoId int `description:"指标id"` Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,9:手工指标,10:隆众"` EdbName string `description:"指标名称"` EdbCode string `description:"指标编码"` ReferObjectId int `description:"引用对象ID(图表ID,ETA逻辑ID等)"` ReferObjectType int `description:"引用对象ID类型(1.图表,2.ETA逻辑)"` ReferObjectSubType int `description:"引用对象子类"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } func (e *EdbInfoRelation) TableName() string { return "edb_info_relation" } // GetEdbInfoRelationByEdbInfoIds 查询引用的指标ID func GetEdbInfoRelationByEdbInfoIds(edbInfoIds []int) (edbIds []int, err error) { o := orm.NewOrmUsingDB("data") msql := ` SELECT edb_info_id FROM edb_info_relation WHERE edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) GROUP BY edb_info_id ` _, err = o.Raw(msql, edbInfoIds).QueryRows(&edbIds) return } // GetEdbInfoRelationByReferObjectId 查询引用的指标ID func GetEdbInfoRelationByReferObjectId(referObjectId int, referObjectType int) (items []*EdbInfoRelation, err error) { o := orm.NewOrmUsingDB("data") msql := ` SELECT * FROM edb_info_relation WHERE referObjectId =? AND referObjectType=? GROUP BY edb_info_id ` _, err = o.Raw(msql, referObjectId, referObjectType).QueryRows(&items) return } // 新增记录 func AddOrUpdateEdbInfoRelation(relationList []*EdbInfoRelation, deleteIds []int, refreshEdbInfoIds []int, indexCodeList []string) (err error) { o, err := orm.NewOrmUsingDB("data").Begin() if err != nil { return } defer func() { if err != nil { _ = o.Rollback() return } _ = o.Commit() }() if len(deleteIds) > 0 { sql := ` DELETE FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(deleteIds)) + `) ` _, err = o.Raw(sql, deleteIds).Exec() if err != nil { return } } if len(relationList) > 0 { _, err = o.InsertMulti(len(relationList), relationList) if err != nil { return } } if len(refreshEdbInfoIds) > 0 { //更新指标的刷新状态 sql := ` UPDATE edb_info SET no_update = 0 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1` _, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, refreshEdbInfoIds).Exec() if err != nil { return } } //更新数据源钢联化工指标 if len(indexCodeList) > 0 { // 更改数据源的更新状态 sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1` _, err = o.Raw(sql, indexCodeList).Exec() if err != nil { return } } // todo 由此被禁用的计算指标是否能恢复刷新 return }