123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package data_manage
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "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:"引用时间"`
- }
- 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 refer_object_id =? AND refer_object_type=? GROUP BY edb_info_id `
- _, err = o.Raw(msql, referObjectId, referObjectType).QueryRows(&items)
- return
- }
- // GetEdbInfoRelationByReferObjectIds 查询引用的指标ID
- func GetEdbInfoRelationByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
- o := orm.NewOrmUsingDB("data")
- msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
- _, err = o.Raw(msql, referObjectIds, 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
- }
- // 删除指标引用内容
- func DeleteEdbRelationByObjectIds(referObjectIds []int, referObjectType int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
- _, err = o.Raw(sql, referObjectIds, referObjectType).Exec()
- return
- }
- type BaseRelationEdbInfo struct {
- EdbInfoId int
- ClassifyId int `description:"指标分类id"`
- EdbName string `description:"指标名称"`
- EdbCode 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(relation_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(relation_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 relation_time, edb_info_id ASC `
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
- return
- }
|