12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package models
- import (
- "eta/eta_index_lib/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:"修改时间"`
- RelationTime time.Time `description:"引用时间"`
- RelationType int `description:"引用类型,0:直接饮用,1间接引用"`
- RootEdbInfoId int `description:"间接引用时,关联的直接引用的指标ID"`
- ChildEdbInfoId int `description:"间接引用时,计算指标直接关联的指标ID"`
- }
- func (e *EdbInfoRelation) TableName() string {
- return "edb_info_relation"
- }
- // GetEdbInfoRelationByChildEdbInfoId 查询引用的指标ID
- func GetEdbInfoRelationByChildEdbInfoId(edbInfoId int) (item *EdbInfoRelation, err error) {
- o := orm.NewOrm()
- msql := ` SELECT * FROM edb_info_relation WHERE child_edb_info_id = ?`
- err = o.Raw(msql, edbInfoId).QueryRow(&item)
- return
- }
- // GetEdbInfoRelationListByChildEdbInfoId 根据间接引用中的的计算指标ID查询引用列表
- func GetEdbInfoRelationListByChildEdbInfoId(edbInfoId int) (items []*EdbInfoRelation, err error) {
- o := orm.NewOrm()
- msql := ` SELECT * FROM edb_info_relation WHERE relation_type=1 AND child_edb_info_id=? `
- _, err = o.Raw(msql, edbInfoId).QueryRows(&items)
- return
- }
- // 新增记录
- func AddOrUpdateEdbInfoRelationByChildEdbInfoId(relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string, deleteRelationIds []int) (err error) {
- o, err := orm.NewOrm().Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = o.Rollback()
- return
- }
- _ = o.Commit()
- }()
- if len(relationList) > 0 {
- _, err = o.InsertMulti(len(relationList), relationList)
- if err != nil {
- return
- }
- }
- if len(deleteRelationIds) > 0 {
- // 删除对应的记录
- sql := ` DELETE FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(deleteRelationIds)) + `)`
- _, err = o.Raw(sql, deleteRelationIds).Exec()
- if err != nil {
- return
- }
- }
- if len(refreshEdbInfoIds) > 0 {
- // todo 更新指标的刷新状态
- 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
- }
|