|
@@ -0,0 +1,89 @@
|
|
|
+package data
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_api/models/data_manage"
|
|
|
+ "eta/eta_api/services/alarm_msg"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+)
|
|
|
+
|
|
|
+// SaveChartEdbInfoRelation 添加/编辑图表指标引用关联记录
|
|
|
+func SaveChartEdbInfoRelation(edbInfoIds []int, chartInfo *data_manage.ChartInfo) (err error) {
|
|
|
+ // 实现添加引用记录的逻辑
|
|
|
+ if len(edbInfoIds) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tips := "SaveChartEdbInfoRelation-添加/编辑图表指标引用关联记录失败, ErrMsg:\n" + err.Error()
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ go alarm_msg.SendAlarmMsg(tips, 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ refreshIds := make([]int, 0)
|
|
|
+ indexCodeList := make([]string, 0)
|
|
|
+ // 查询指标信息
|
|
|
+ edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询指标信息失败,%s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 只统计钢联化工和wind来源的指标
|
|
|
+ for _, edbInfo := range edbInfoList {
|
|
|
+ if edbInfo.Source != utils.DATA_SOURCE_WIND && edbInfo.Source != utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ refreshIds = append(refreshIds, edbInfo.EdbInfoId)
|
|
|
+ if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
+ indexCodeList = append(indexCodeList, edbInfo.EdbCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 循转组装引用
|
|
|
+ // 查询已有的引用关系
|
|
|
+ existList, e := data_manage.GetEdbInfoRelationByReferObjectId(chartInfo.ChartInfoId, utils.EDB_RELATION_CHART)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询已有的引用关系失败,%s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ deleteMap := make(map[int]bool)
|
|
|
+ relationMap := make(map[int]bool)
|
|
|
+ for _, exist := range existList {
|
|
|
+ deleteMap[exist.EdbInfoId] = true
|
|
|
+ relationMap[exist.EdbInfoId] = true
|
|
|
+ }
|
|
|
+ // 新增不存在的引用关系
|
|
|
+ // 删除不再需要的引用关系
|
|
|
+ addList := make([]*data_manage.EdbInfoRelation, 0)
|
|
|
+ deleteRelationIds := make([]int, 0)
|
|
|
+ for _, edbInfo := range edbInfoList {
|
|
|
+ if edbInfo.Source != utils.DATA_SOURCE_WIND && edbInfo.Source != utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if _, ok := relationMap[edbInfo.EdbInfoId]; ok {
|
|
|
+ delete(deleteMap, edbInfo.EdbInfoId)
|
|
|
+ } else {
|
|
|
+ tmp := &data_manage.EdbInfoRelation{
|
|
|
+ ReferObjectId: chartInfo.ChartInfoId,
|
|
|
+ ReferObjectType: utils.EDB_RELATION_CHART,
|
|
|
+ ReferObjectSubType: chartInfo.Source,
|
|
|
+ EdbInfoId: edbInfo.EdbInfoId,
|
|
|
+ EdbName: edbInfo.EdbName,
|
|
|
+ Source: edbInfo.Source,
|
|
|
+ EdbCode: edbInfo.EdbCode,
|
|
|
+ }
|
|
|
+ addList = append(addList, tmp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除不再需要的引用关系
|
|
|
+ for deleteId, _ := range deleteMap {
|
|
|
+ deleteRelationIds = append(deleteRelationIds, deleteId)
|
|
|
+ }
|
|
|
+ //更新指标刷新状态为启用
|
|
|
+ err = data_manage.AddOrUpdateEdbInfoRelation(addList, deleteRelationIds, refreshIds, indexCodeList)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("删除不再需要的引用关系失败,%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|