Browse Source

混合表格中的累计值

xyxie 1 year ago
parent
commit
689356d683
2 changed files with 12 additions and 24 deletions
  1. 7 4
      models/base_calculate.go
  2. 5 20
      models/edb_data_calculate_ljz.go

+ 7 - 4
models/base_calculate.go

@@ -1374,20 +1374,23 @@ func (obj BaseCalculate) Ljz() (dateDataMap map[time.Time]float64, err error, er
 			itemDate := item.DataTime
 			dayInt := itemDate.Year()*100 + int(itemDate.Month())
 			var currTime time.Time
-			if itemDate.Month() <= 10 {
-				tmpK := fmt.Sprint(dayInt*100, "10")
+			if itemDate.Day() <= 10 {
+				//本月上旬
+				tmpK := fmt.Sprint(dayInt, "10")
 				currTime, err = time.ParseInLocation(utils.FormatDateUnSpace, tmpK, time.Local)
 				if err != nil {
 					return
 				}
 
-			} else if itemDate.Month() <= 20 {
-				tmpK := fmt.Sprint(dayInt*100, "20")
+			} else if itemDate.Day() <= 20 {
+				// 本月中旬
+				tmpK := fmt.Sprint(dayInt, "20")
 				currTime, err = time.ParseInLocation(utils.FormatDateUnSpace, tmpK, time.Local)
 				if err != nil {
 					return
 				}
 			} else {
+				// 本月下旬
 				currTime, err = time.ParseInLocation(utils.FormatYearMonthUnSpace, fmt.Sprint(dayInt), time.Local)
 				if err != nil {
 					return

+ 5 - 20
models/edb_data_calculate_ljz.go

@@ -383,12 +383,8 @@ func (obj Ljz) refresh(to orm.TxOrmer, edbInfoId, source, subSource int, edbInfo
 
 			daysT := decimal.NewFromInt(int64(days))
 			initValAndMonthT := decimal.NewFromFloat(initVal * float64(allDays))
-			val, ok := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
+			val, _ := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
 			fmt.Printf("最新值 计算公式:%d*%f/(%d) = %f\n", allDays, initVal, days, val)
-			if !ok {
-				err = fmt.Errorf("最新值,均值计算失败")
-				return
-			}
 			valueMap[lastNewDate] = val
 		}
 	case "半年度":
@@ -449,12 +445,8 @@ func (obj Ljz) refresh(to orm.TxOrmer, edbInfoId, source, subSource int, edbInfo
 
 			daysT := decimal.NewFromInt(int64(days))
 			initValAndMonthT := decimal.NewFromFloat(initVal * float64(allDays))
-			val, ok := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
+			val, _ := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
 			fmt.Printf("最新值 计算公式:%d*%f/(%d) = %f\n", allDays, initVal, days, val)
-			if !ok {
-				err = fmt.Errorf("最新值,均值计算失败")
-				return
-			}
 			valueMap[lastNewDate] = val
 		}
 	case "季度":
@@ -518,12 +510,9 @@ func (obj Ljz) refresh(to orm.TxOrmer, edbInfoId, source, subSource int, edbInfo
 
 			daysT := decimal.NewFromInt(int64(days))
 			initValAndMonthT := decimal.NewFromFloat(initVal * float64(allDays))
-			val, ok := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
+			val, _ := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
 			fmt.Printf("最新值 计算公式:%d*%f/(%d) = %f\n", allDays, initVal, days, val)
-			if !ok {
-				err = fmt.Errorf("最新值,均值计算失败")
-				return
-			}
+
 			valueMap[lastNewDate] = val
 		}
 	case "月度":
@@ -578,12 +567,8 @@ func (obj Ljz) refresh(to orm.TxOrmer, edbInfoId, source, subSource int, edbInfo
 
 			daysT := decimal.NewFromInt(int64(days))
 			initValAndMonthT := decimal.NewFromFloat(initVal * float64(monthDays))
-			val, ok := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
+			val, _ := initValAndMonthT.Div(daysT).RoundCeil(4).Float64()
 			fmt.Printf("最新值 计算公式:%d*%f/(%d) = %f\n", monthDays, initVal, days, val)
-			if !ok {
-				err = fmt.Errorf("最新值,均值计算失败")
-				return
-			}
 			valueMap[lastNewDate] = val
 		}
 	case "旬度":