|
@@ -22,17 +22,19 @@ type EdbInfoRelation struct {
|
|
|
RelationType int `description:"引用类型,0:直接饮用,1间接引用"`
|
|
|
RootEdbInfoId int `description:"间接引用时,关联的直接引用的指标ID"`
|
|
|
ChildEdbInfoId int `description:"间接引用时,关联的计算指标ID"`
|
|
|
+ RelationCode string `description:"引用标识"`
|
|
|
+ ParentRelationId int `description:"间接引用关联的直接引用的ID"`
|
|
|
}
|
|
|
|
|
|
func (e *EdbInfoRelation) TableName() string {
|
|
|
return "edb_info_relation"
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoRelationByEdbInfoIds 查询引用的指标ID
|
|
|
-func GetEdbInfoRelationByEdbInfoIds(edbInfoIds []int) (edbIds []int, err error) {
|
|
|
+// GetEdbInfoRelationByRelationIds 查询引用的指标ID
|
|
|
+func GetEdbInfoRelationByRelationIds(ids []int) (items []*EdbInfoRelation, 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)
|
|
|
+ msql := ` SELECT * FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
|
|
|
+ _, err = o.Raw(msql, ids).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -87,7 +89,13 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ relationCodesMap := make(map[string]struct{}, 0)
|
|
|
if len(relationList) > 0 {
|
|
|
+ for _, relation := range relationList {
|
|
|
+ if relation.RelationType == 1 {
|
|
|
+ relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
_, err = o.InsertMulti(len(relationList), relationList)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -113,12 +121,30 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // todo 由此被禁用的计算指标是否能恢复刷新
|
|
|
+ if len(relationList) > 0 {
|
|
|
+ // 更新间接引用指标的关联ID
|
|
|
+ relationCodes := make([]string, 0)
|
|
|
+ for relationCode := range relationCodesMap {
|
|
|
+ relationCodes = append(relationCodes, relationCode)
|
|
|
+ }
|
|
|
+ if len(relationCodes) > 0 {
|
|
|
+ sql := ` UPDATE edb_info_relation e1
|
|
|
+JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
|
|
|
+SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
+WHERE
|
|
|
+ e1.relation_type = 1
|
|
|
+ AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
+ _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 新增记录
|
|
|
-func AddOrUpdateEdbInfoRelationFeMatter(relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
|
|
|
+func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
|
|
|
o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -131,7 +157,13 @@ func AddOrUpdateEdbInfoRelationFeMatter(relationList []*EdbInfoRelation, refresh
|
|
|
_ = o.Commit()
|
|
|
}()
|
|
|
|
|
|
+ relationCodesMap := make(map[string]struct{}, 0)
|
|
|
if len(relationList) > 0 {
|
|
|
+ for _, relation := range relationList {
|
|
|
+ if relation.RelationType == 1 {
|
|
|
+ relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
_, err = o.InsertMulti(len(relationList), relationList)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -157,7 +189,25 @@ func AddOrUpdateEdbInfoRelationFeMatter(relationList []*EdbInfoRelation, refresh
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // todo 由此被禁用的计算指标是否能恢复刷新
|
|
|
+ if len(relationList) > 0 {
|
|
|
+ // 更新间接引用指标的关联ID
|
|
|
+ relationCodes := make([]string, 0)
|
|
|
+ for relationCode := range relationCodesMap {
|
|
|
+ relationCodes = append(relationCodes, relationCode)
|
|
|
+ }
|
|
|
+ if len(relationCodes) > 0 {
|
|
|
+ sql := ` UPDATE edb_info_relation e1
|
|
|
+JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
|
|
|
+SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
+WHERE
|
|
|
+ e1.relation_type = 1
|
|
|
+ AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
+ _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -251,3 +301,127 @@ func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 查询相关的指标记录总数
|
|
|
+func GetReplaceChildEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ // 数量汇总
|
|
|
+ totalSql := ` SELECT count(*) FROM edb_info_relation where child_edb_info_id=? and root_edb_info_id !=? group by parent_relation_id`
|
|
|
+ err = o.Raw(totalSql, edbInfoId, edbInfoId).QueryRow(&total)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 查询相关的指标记录列表
|
|
|
+func GetReplaceChildEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ // 列表数据
|
|
|
+ sql := ` SELECT * FROM edb_info_relation where child_edb_info_id=? and root_edb_info_id !=? ORDER BY edb_info_relation_id ASC group by parent_relation_id LIMIT ?,? `
|
|
|
+ _, err = o.Raw(sql, edbInfoId, edbInfoId, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 查询相关的指标记录总数
|
|
|
+func GetReplaceEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ // 数量汇总
|
|
|
+ totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=? and relation_type = 0`
|
|
|
+ err = o.Raw(totalSql, edbInfoId).QueryRow(&total)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 查询相关的指标记录列表
|
|
|
+func GetReplaceEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ // 列表数据
|
|
|
+ sql := ` SELECT * FROM edb_info_relation where edb_info_id=? and relation_type = 0 ORDER BY edb_info_relation_id ASC LIMIT ?,? `
|
|
|
+ _, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 替换指标引用表中的指标
|
|
|
+func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []int, relationList []*EdbInfoRelation, 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()
|
|
|
+ }()
|
|
|
+
|
|
|
+ now := time.Now()
|
|
|
+ // 删除相关的间接引用
|
|
|
+ sql := ` DELETE FROM edb_info_relation WHERE root_edb_info_id=? and relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
|
|
|
+ _, err = o.Raw(sql, oldEdbInfo.EdbInfoId, edbRelationIds).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 替换edb_info_id
|
|
|
+ sql = ` UPDATE edb_info_relation SET edb_info_id=?, source=?, edb_name=?, edb_code=?, modify_time=?, relation_time=? WHERE edb_info_id=? and edb_info_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
|
|
|
+ _, err = o.Raw(sql, newEdbInfo.EdbInfoId, newEdbInfo.Source, newEdbInfo.EdbName, newEdbInfo.EdbCode, now, now, oldEdbInfo.EdbInfoId, edbRelationIds).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 新增间接引用
|
|
|
+ relationCodesMap := make(map[string]struct{}, 0)
|
|
|
+ if len(relationList) > 0 {
|
|
|
+ for _, relation := range relationList {
|
|
|
+ if relation.RelationType == 1 {
|
|
|
+ relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _, err = o.InsertMulti(len(relationList), relationList)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(relationList) > 0 {
|
|
|
+ // 更新间接引用指标的关联ID
|
|
|
+ relationCodes := make([]string, 0)
|
|
|
+ for relationCode := range relationCodesMap {
|
|
|
+ relationCodes = append(relationCodes, relationCode)
|
|
|
+ }
|
|
|
+ if len(relationCodes) > 0 {
|
|
|
+ sql := ` UPDATE edb_info_relation e1
|
|
|
+JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
|
|
|
+SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
+WHERE
|
|
|
+ e1.relation_type = 1
|
|
|
+ AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
+ _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|