浏览代码

Merge branch 'feature/eta1.6.5_edb_calculate' into debug

xyxie 1 年之前
父节点
当前提交
74bcc55290
共有 3 个文件被更改,包括 28 次插入18 次删除
  1. 10 9
      models/edb_data_calculate_avg.go
  2. 2 1
      models/edb_data_calculate_ljz.go
  3. 16 8
      models/edb_data_calculate_sum.go

+ 10 - 9
models/edb_data_calculate_avg.go

@@ -67,7 +67,7 @@ func (obj CalculateAvg) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 	tagMap := make(map[string]int)
 	relationEdbInfoList := make([]*EdbInfo, 0)
 	calculateMappingItemList := make([]*EdbInfoCalculateMapping, 0)
-	for _, v := range req.EdbInfoIdArr {
+	for k, v := range req.EdbInfoIdArr {
 		tmpEdbInfo, e := GetEdbInfoById(v.EdbInfoId)
 		if e != nil {
 			err = e
@@ -78,7 +78,7 @@ func (obj CalculateAvg) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 		calculateMappingItem := new(EdbInfoCalculateMapping)
 		calculateMappingItem.CreateTime = time.Now()
 		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
+		calculateMappingItem.Sort = k
 		calculateMappingItem.EdbCode = edbCode
 		calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
 		calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
@@ -173,6 +173,7 @@ func (obj CalculateAvg) Edit(params EditCalculateBatchParams) (err error, errMsg
 			needCalculate = true
 		}
 	}
+	fmt.Printf("needCalculate:%v\n", needCalculate)
 	if !needCalculate {
 		return
 	}
@@ -195,7 +196,7 @@ func (obj CalculateAvg) Edit(params EditCalculateBatchParams) (err error, errMsg
 	tagMap := make(map[string]int)
 	relationEdbInfoList := make([]*EdbInfo, 0)
 	calculateMappingItemList := make([]*EdbInfoCalculateMapping, 0)
-	for _, v := range req.EdbInfoIdArr {
+	for k, v := range req.EdbInfoIdArr {
 		tmpEdbInfo, tmpErr := GetEdbInfoById(v.EdbInfoId)
 		if tmpErr != nil {
 			err = tmpErr
@@ -206,7 +207,7 @@ func (obj CalculateAvg) Edit(params EditCalculateBatchParams) (err error, errMsg
 		calculateMappingItem := new(EdbInfoCalculateMapping)
 		calculateMappingItem.CreateTime = time.Now()
 		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
+		calculateMappingItem.Sort = k
 		calculateMappingItem.EdbCode = edbInfo.EdbCode
 		calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
 		calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
@@ -384,13 +385,13 @@ func (obj CalculateAvg) refresh(to orm.TxOrmer, edbInfoId, source, subSource int
 	existDataMap := make(map[string]string)
 
 	for sk, sv := range saveDataMap {
+		if _, ok := dateMap[sk]; !ok {
+			continue
+		}
 		// 当空值处理类型选择了不计算时,只要有一个指标在某个日期没有值(即空值),则计算指标在该日期没有值
-		if emptyType == 1 {
-			if len(sv) != len(edbInfoIdArr) {
-				continue
-			}
+		if len(sv) != len(edbInfoIdArr) {
+			continue
 		}
-
 		var calVal float64
 		for _, value := range sv {
 			calVal += value

+ 2 - 1
models/edb_data_calculate_ljz.go

@@ -165,7 +165,7 @@ func (obj Ljz) Edit(params EditCalculateBatchParams) (err error, errMsg string)
 	edbInfo.ClassifyId = req.ClassifyId
 	edbInfo.Extra = req.Extra
 	edbInfo.ModifyTime = time.Now()
-	_, err = to.Update(edbInfo, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId", "ModifyTime")
+	_, err = to.Update(edbInfo, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId", "ModifyTime", "Extra")
 	if err != nil {
 		return
 	}
@@ -532,6 +532,7 @@ func (obj Ljz) refresh(to orm.TxOrmer, edbInfoId, source, subSource int, edbInfo
 			yearVal, ok := yearMonthMap[tmpK]
 			if ok {
 				yearMonthMap[tmpK] = item.Value + yearVal
+				fmt.Printf("%s 累加值:%f = %.6f + %.6f\n", tmpK, yearMonthMap[tmpK], item.Value, yearVal)
 			} else {
 				yearMonthList = append(yearMonthList, tmpK)
 				yearMonthMap[tmpK] = item.Value

+ 16 - 8
models/edb_data_calculate_sum.go

@@ -28,6 +28,7 @@ func (obj CalculateSum) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 	defer func() {
 		if err != nil {
 			fmt.Println("CalculateSum.Add,Err:" + err.Error())
+			fmt.Println("CalculateSum.Add,ErrMsg:" + errMsg)
 			_ = to.Rollback()
 		} else {
 			_ = to.Commit()
@@ -58,6 +59,7 @@ func (obj CalculateSum) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 	edbInfo.Extra = req.Extra
 	newEdbInfoId, tmpErr := to.Insert(edbInfo)
 	if tmpErr != nil {
+		errMsg = "新增失败"
 		err = tmpErr
 		return
 	}
@@ -67,9 +69,10 @@ func (obj CalculateSum) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 	tagMap := make(map[string]int)
 	relationEdbInfoList := make([]*EdbInfo, 0)
 	calculateMappingItemList := make([]*EdbInfoCalculateMapping, 0)
-	for _, v := range req.EdbInfoIdArr {
+	for k, v := range req.EdbInfoIdArr {
 		tmpEdbInfo, e := GetEdbInfoById(v.EdbInfoId)
 		if e != nil {
+			errMsg = "查不到原指标"
 			err = e
 			return
 		}
@@ -78,7 +81,7 @@ func (obj CalculateSum) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 		calculateMappingItem := new(EdbInfoCalculateMapping)
 		calculateMappingItem.CreateTime = time.Now()
 		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
+		calculateMappingItem.Sort = k
 		calculateMappingItem.EdbCode = edbCode
 		calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
 		calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
@@ -96,6 +99,7 @@ func (obj CalculateSum) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, e
 	}
 	_, err = to.InsertMulti(len(calculateMappingItemList), calculateMappingItemList)
 	if err != nil {
+		errMsg = "保存失败"
 		return
 	}
 
@@ -170,9 +174,11 @@ func (obj CalculateSum) Edit(params EditCalculateBatchParams) (err error, errMsg
 		}
 
 		if edbInfoIdStr != oldEdbInfoIdStr { // 不需要重复计算
+			fmt.Printf("edbInfoIdStr:%s,oldEdbInfoIdStr:%s\n", edbInfoIdStr, oldEdbInfoIdStr)
 			needCalculate = true
 		}
 	}
+	fmt.Printf("needCalculate:%v\n", needCalculate)
 	if !needCalculate {
 		return
 	}
@@ -195,9 +201,10 @@ func (obj CalculateSum) Edit(params EditCalculateBatchParams) (err error, errMsg
 	tagMap := make(map[string]int)
 	relationEdbInfoList := make([]*EdbInfo, 0)
 	calculateMappingItemList := make([]*EdbInfoCalculateMapping, 0)
-	for _, v := range req.EdbInfoIdArr {
+	for k, v := range req.EdbInfoIdArr {
 		tmpEdbInfo, tmpErr := GetEdbInfoById(v.EdbInfoId)
 		if tmpErr != nil {
+			errMsg = "获取数据失败,GetEdbInfoById:" + tmpErr.Error()
 			err = tmpErr
 			return
 		}
@@ -206,7 +213,7 @@ func (obj CalculateSum) Edit(params EditCalculateBatchParams) (err error, errMsg
 		calculateMappingItem := new(EdbInfoCalculateMapping)
 		calculateMappingItem.CreateTime = time.Now()
 		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = 1
+		calculateMappingItem.Sort = k
 		calculateMappingItem.EdbCode = edbInfo.EdbCode
 		calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
 		calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
@@ -384,11 +391,12 @@ func (obj CalculateSum) refresh(to orm.TxOrmer, edbInfoId, source, subSource int
 	existDataMap := make(map[string]string)
 
 	for sk, sv := range saveDataMap {
+		if _, ok := dateMap[sk]; !ok {
+			continue
+		}
 		// 当空值处理类型选择了不计算时,只要有一个指标在某个日期没有值(即空值),则计算指标在该日期没有值
-		if emptyType == 1 {
-			if len(sv) != len(edbInfoIdArr) {
-				continue
-			}
+		if len(sv) != len(edbInfoIdArr) {
+			continue
 		}
 
 		var calVal float64