|
@@ -2,20 +2,30 @@ package data
|
|
|
|
|
|
import (
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
+ "eta/eta_api/models/fe_calendar"
|
|
|
"eta/eta_api/services/alarm_msg"
|
|
|
+ "eta/eta_api/services/sandbox"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// SaveChartEdbInfoRelation 添加/编辑图表指标引用关联记录
|
|
|
func SaveChartEdbInfoRelation(edbInfoIds []int, chartInfo *data_manage.ChartInfo) (err error) {
|
|
|
+ //更新指标刷新状态为启用
|
|
|
+ err = saveEdbInfoRelation(edbInfoIds, chartInfo.ChartInfoId, utils.EDB_RELATION_CHART, chartInfo.Source)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// saveEdbInfoRelation 添加/编辑图表指标引用关联记录
|
|
|
+func saveEdbInfoRelation(edbInfoIds []int, objectId, objectType, objectSubType int) (err error) {
|
|
|
// 实现添加引用记录的逻辑
|
|
|
if len(edbInfoIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- tips := "SaveChartEdbInfoRelation-添加/编辑图表指标引用关联记录失败, ErrMsg:\n" + err.Error()
|
|
|
+ tips := "实现添加引用记录的逻辑-添加/编辑图表指标引用关联记录失败, ErrMsg:\n" + err.Error()
|
|
|
utils.FileLog.Info(tips)
|
|
|
go alarm_msg.SendAlarmMsg(tips, 3)
|
|
|
}
|
|
@@ -40,7 +50,7 @@ func SaveChartEdbInfoRelation(edbInfoIds []int, chartInfo *data_manage.ChartInfo
|
|
|
}
|
|
|
// 循转组装引用
|
|
|
// 查询已有的引用关系
|
|
|
- existList, e := data_manage.GetEdbInfoRelationByReferObjectId(chartInfo.ChartInfoId, utils.EDB_RELATION_CHART)
|
|
|
+ existList, e := data_manage.GetEdbInfoRelationByReferObjectId(objectId, objectType)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("查询已有的引用关系失败,%s", e.Error())
|
|
|
return
|
|
@@ -53,6 +63,7 @@ func SaveChartEdbInfoRelation(edbInfoIds []int, chartInfo *data_manage.ChartInfo
|
|
|
}
|
|
|
// 新增不存在的引用关系
|
|
|
// 删除不再需要的引用关系
|
|
|
+ nowTime := time.Now()
|
|
|
addList := make([]*data_manage.EdbInfoRelation, 0)
|
|
|
deleteRelationIds := make([]int, 0)
|
|
|
for _, edbInfo := range edbInfoList {
|
|
@@ -63,13 +74,15 @@ func SaveChartEdbInfoRelation(edbInfoIds []int, chartInfo *data_manage.ChartInfo
|
|
|
delete(deleteMap, edbInfo.EdbInfoId)
|
|
|
} else {
|
|
|
tmp := &data_manage.EdbInfoRelation{
|
|
|
- ReferObjectId: chartInfo.ChartInfoId,
|
|
|
- ReferObjectType: utils.EDB_RELATION_CHART,
|
|
|
- ReferObjectSubType: chartInfo.Source,
|
|
|
+ ReferObjectId: objectId,
|
|
|
+ ReferObjectType: objectType,
|
|
|
+ ReferObjectSubType: objectSubType,
|
|
|
EdbInfoId: edbInfo.EdbInfoId,
|
|
|
EdbName: edbInfo.EdbName,
|
|
|
Source: edbInfo.Source,
|
|
|
EdbCode: edbInfo.EdbCode,
|
|
|
+ CreateTime: nowTime,
|
|
|
+ ModifyTime: nowTime,
|
|
|
}
|
|
|
addList = append(addList, tmp)
|
|
|
}
|
|
@@ -87,3 +100,143 @@ func SaveChartEdbInfoRelation(edbInfoIds []int, chartInfo *data_manage.ChartInfo
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// SaveSandBoxEdbInfoRelation 添加/编辑 eta逻辑图指标引用
|
|
|
+func SaveSandBoxEdbInfoRelation(sandBoxId int, sandBoxContent string) (err error) {
|
|
|
+ edbInfoIds, err := sandbox.GetSandBoxEdbIdsByContent(sandBoxContent)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(edbInfoIds) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //更新指标刷新状态为启用
|
|
|
+ err = saveEdbInfoRelation(edbInfoIds, sandBoxId, utils.EDB_RELATION_SANDBOX, 0)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// SaveCalendarEdbInfoRelation 添加/编辑 事件日历指标引用
|
|
|
+func SaveCalendarEdbInfoRelation(chartPermissionId int, matterDate string, editMatters, removeMatters []*fe_calendar.FeCalendarMatter) (err error) {
|
|
|
+
|
|
|
+ //整理相关的事件ID
|
|
|
+ matterIds := make([]int, 0)
|
|
|
+ updateMatterMap := make(map[int]*fe_calendar.FeCalendarMatter)
|
|
|
+ deleteMatterMap := make(map[int]struct{})
|
|
|
+ for _, matter := range removeMatters {
|
|
|
+ deleteMatterMap[matter.FeCalendarMatterId] = struct{}{}
|
|
|
+ matterIds = append(matterIds, matter.FeCalendarMatterId)
|
|
|
+ }
|
|
|
+ for _, matter := range editMatters {
|
|
|
+ updateMatterMap[matter.FeCalendarMatterId] = matter
|
|
|
+ matterIds = append(matterIds, matter.FeCalendarMatterId)
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除ID,先删除
|
|
|
+ deleteRelationIds := make([]int, 0)
|
|
|
+ if len(matterIds) > 0 {
|
|
|
+ relationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(matterIds, utils.EDB_RELATION_CALENDAR)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询事件日历指标引用失败,%s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, relation := range relationList {
|
|
|
+ if _, ok := deleteMatterMap[relation.ReferObjectId]; ok {
|
|
|
+ deleteRelationIds = append(deleteRelationIds, relation.EdbInfoRelationId)
|
|
|
+ }
|
|
|
+ if newMatter, ok := updateMatterMap[relation.ReferObjectId]; ok {
|
|
|
+ if relation.EdbInfoId != newMatter.EdbInfoId {
|
|
|
+ deleteRelationIds = append(deleteRelationIds, relation.EdbInfoRelationId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(deleteRelationIds) > 0 {
|
|
|
+ err = data_manage.DeleteEdbRelationByObjectIds(deleteRelationIds, utils.EDB_RELATION_CALENDAR)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("删除事件日历指标引用失败,%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ deleteRelationIds = make([]int, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取已有事项
|
|
|
+ matterOb := new(fe_calendar.FeCalendarMatter)
|
|
|
+ cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, fe_calendar.FeCalendarMatterCols.ChartPermissionId, fe_calendar.FeCalendarMatterCols.MatterDate)
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, chartPermissionId, matterDate)
|
|
|
+ order := fmt.Sprintf(`%s ASC`, fe_calendar.FeCalendarMatterCols.Sort)
|
|
|
+ matters, e := matterOb.GetItemsByCondition(cond, pars, []string{}, order)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询事件日历事项失败,%s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 循环查询matters
|
|
|
+ edbInfoIds := make([]int, 0)
|
|
|
+ refreshIds := make([]int, 0)
|
|
|
+ indexCodeList := make([]string, 0)
|
|
|
+
|
|
|
+ newMatterIds := make([]int, 0)
|
|
|
+ for _, matter := range matters {
|
|
|
+ newMatterIds = append(newMatterIds, matter.FeCalendarMatterId)
|
|
|
+ edbInfoIds = append(edbInfoIds, matter.EdbInfoId)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询指标信息
|
|
|
+ edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询指标信息失败,%s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 只统计钢联化工和wind来源的指标
|
|
|
+ addEdbInfoIdMap := make(map[int]*data_manage.EdbInfo)
|
|
|
+ for _, edbInfo := range edbInfoList {
|
|
|
+ if edbInfo.Source != utils.DATA_SOURCE_WIND && edbInfo.Source != utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ refreshIds = append(refreshIds, edbInfo.EdbInfoId)
|
|
|
+ addEdbInfoIdMap[edbInfo.EdbInfoId] = edbInfo
|
|
|
+ if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
+ indexCodeList = append(indexCodeList, edbInfo.EdbCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ relationMap := make(map[int]struct{})
|
|
|
+ if len(newMatterIds) > 0 {
|
|
|
+ //查询已有的matters
|
|
|
+ relationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(newMatterIds, utils.EDB_RELATION_CALENDAR)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询事件日历指标引用失败,%s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, relation := range relationList {
|
|
|
+ relationMap[relation.ReferObjectId] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addList := make([]*data_manage.EdbInfoRelation, 0)
|
|
|
+ nowTime := time.Now()
|
|
|
+ for _, matter := range matters {
|
|
|
+ _, ok1 := relationMap[matter.FeCalendarMatterId]
|
|
|
+ edbInfo, ok2 := addEdbInfoIdMap[matter.EdbInfoId]
|
|
|
+ if !ok1 && ok2 {
|
|
|
+ tmp := &data_manage.EdbInfoRelation{
|
|
|
+ ReferObjectId: matter.FeCalendarMatterId,
|
|
|
+ ReferObjectType: utils.EDB_RELATION_CALENDAR,
|
|
|
+ ReferObjectSubType: 0,
|
|
|
+ EdbInfoId: edbInfo.EdbInfoId,
|
|
|
+ EdbName: edbInfo.EdbName,
|
|
|
+ Source: edbInfo.Source,
|
|
|
+ EdbCode: edbInfo.EdbCode,
|
|
|
+ CreateTime: nowTime,
|
|
|
+ ModifyTime: nowTime,
|
|
|
+ }
|
|
|
+ addList = append(addList, tmp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新指标刷新状态为启用
|
|
|
+ err = data_manage.AddOrUpdateEdbInfoRelation(addList, deleteRelationIds, refreshIds, indexCodeList)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("删除不再需要的引用关系失败,%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|