浏览代码

更新计算指标数据

xyxie 1 周之前
父节点
当前提交
6e2b696973
共有 2 个文件被更改,包括 35 次插入24 次删除
  1. 14 6
      controllers/edb_data.go
  2. 21 18
      services/edb_data.go

+ 14 - 6
controllers/edb_data.go

@@ -139,16 +139,24 @@ func (this *EdbDataController) SaveByBinlog() {
 	for _, item := range edbInfoIdMap {
 		minDataTime := edbDataMinDataTimeMap[item.EdbInfoId]
 		maxDataTime := edbDataMaxDataTimeMap[item.EdbInfoId]
-		err := services.AddOrUpdateEdbDataWithOpType(item.EdbInfoId, item.DataList, minDataTime, maxDataTime)
-		if err != nil {
-			br.Msg = "更新指标数据失败!"
-			br.ErrMsg = "更新指标数据失败,Err:" + err.Error()
-			return
+		if item.EdbType == 1 {
+			err := services.AddOrUpdateEdbDataWithOpType(item.EdbInfoId, item.DataList, minDataTime, maxDataTime)
+			if err != nil {
+				br.Msg = "更新指标数据失败!"
+				br.ErrMsg = "更新指标数据失败,Err:" + err.Error()
+				return
+			}
+		} else {
+			err := services.AddOrUpdateEdbDataCalculateWithOpType(item.EdbInfoId, item.DataList, minDataTime, maxDataTime)
+			if err != nil {
+				br.Msg = "更新指标数据失败!"
+				br.ErrMsg = "更新指标数据失败,Err:" + err.Error()
+				return
+			}
 		}
 	}
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "更新指标数据成功"
 	return
 }
 

+ 21 - 18
services/edb_data.go

@@ -439,7 +439,8 @@ func AddOrUpdateEdbDataWithOpType(edbInfoId int, dataList []*models.EdbDataBaseW
 					err = mgodb.ModifyValueEdbDataValue(oldObj.EdbDataId, val, v.ModifyTime)
 					if err != nil {
 						err = fmt.Errorf("更新指标数据出错 error, %v", err)
-					return
+						return
+					}
 				}
 			}else if v.OpType == "delete" {
 				removeDateList = append(removeDateList, dataTime)
@@ -448,22 +449,21 @@ func AddOrUpdateEdbDataWithOpType(edbInfoId int, dataList []*models.EdbDataBaseW
 				// if err != nil {
 				// 	err = fmt.Errorf("删除指标数据出错 error, %v", err)
 				// 	return
-				}
 			}
 		}
 	}
 
 	//遍历deletemap,找出需要删除的日期
-	{
-		removeNum := len(removeDateList)
-		if removeNum > 0 {
-			err = mgodb.DeleteEdbInfoDataByEdbInfoIdAndDateList(edbInfoId, removeDateList)
-			if err != nil {
-				err = fmt.Errorf("删除多余日期失败,error, %v", err)
-				return
-			}
+	
+	removeNum := len(removeDateList)
+	if removeNum > 0 {
+		err = mgodb.DeleteEdbInfoDataByEdbInfoIdAndDateList(edbInfoId, removeDateList)
+		if err != nil {
+			err = fmt.Errorf("删除多余日期失败,error, %v", err)
+			return
 		}
 	}
+	
 
 	if len(addList) > 0 {
 		err = mgodb.InsertEdbDataBatch(addList)
@@ -489,6 +489,10 @@ func AddOrUpdateEdbDataCalculateWithOpType(edbInfoId int, dataList []*models.Edb
 		return
 	}
 	existList, err := mgodb.GetEdbCalculateDataList(edbInfoId, minDataTimeT, maxDataTimeT)
+	if err != nil {
+		err = fmt.Errorf("查询指标数据出错 error, %v", err)
+		return
+	}
 	existMap := make(map[string]*mgodb.EdbDataBase, len(existList))
 	removeDateList := make([]time.Time, 0)
 	for _, exist := range existList {
@@ -544,16 +548,15 @@ func AddOrUpdateEdbDataCalculateWithOpType(edbInfoId int, dataList []*models.Edb
 		}
 	}
 	//遍历deleteMap,找出需要删除的日期
-	{
-		removeNum := len(removeDateList)
-		if removeNum > 0 {
-			err = mgodb.DeleteEdbCalculateDataByEdbInfoIdAndDateList(edbInfoId, removeDateList)
-			if err != nil {
-				err = fmt.Errorf("删除多余日期失败,error, %v", err)
-				return
-			}
+	removeNum := len(removeDateList)
+	if removeNum > 0 {
+		err = mgodb.DeleteEdbCalculateDataByEdbInfoIdAndDateList(edbInfoId, removeDateList)
+		if err != nil {
+			err = fmt.Errorf("删除多余日期失败,error, %v", err)
+			return
 		}
 	}
+
 	if len(addList) > 0 {
 		err = mgodb.InsertEdbCalculateDataBatch(addList)
 	}