Browse Source

Merge branch 'debug' of http://8.136.199.33:3000/eta_server/eta_index_lib into debug

gmy 7 months ago
parent
commit
13dccae702
1 changed files with 46 additions and 30 deletions
  1. 46 30
      models/edb_data_calculate_qjjs.go

+ 46 - 30
models/edb_data_calculate_qjjs.go

@@ -40,10 +40,10 @@ type ChartRangeAnalysisAutoDateConf struct { //智能划分
 type ChartRangeAnalysisAutoDateChangeConf struct {
 	BaseDateType int `description:"基准日期类型:0指标日期,1系统日期,2固定日期"`
 	MoveForward  int `description:"前移的期数"`
-	DateChange   []*EdbDateConfDateChange
+	DateChange   []*EdbDataDateChangeConf
 }
 
-type EdbDateConfDateChange struct {
+type EdbDataDateChangeConf struct {
 	Year         int
 	Month        int
 	Day          int
@@ -436,7 +436,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 	switch calculateType {
 	case 0: //均值
 		var sum float64
-		if req.DateRangeType == 0 {
+		if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
 			for _, item := range originList {
 				for _, v := range item.DataList {
 					sum = 0
@@ -476,7 +476,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 
 	case 1: //累计值
 		var sum float64
-		if req.DateRangeType == 0 {
+		if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
 			for _, item := range originList {
 				sum = 0
 				for _, v := range item.DataList {
@@ -516,7 +516,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 		}
 
 	case 2: //涨幅
-		if req.DateRangeType == 0 {
+		if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
 			for _, item := range originList {
 				for _, v := range item.DataList {
 					var baseVal float64
@@ -530,9 +530,13 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 						continue
 					}
 					baseVal = calDataList[len(calDataList)-1].Value
+					baseDate := calDataList[len(calDataList)-1].DataTime
 					if baseVal == 0 {
 						continue
 					}
+					if v.DataTime == baseDate {
+						continue
+					}
 
 					val := (v.Value - baseVal) / baseVal
 					val, _ = decimal.NewFromFloat(val).Round(4).Float64()
@@ -545,13 +549,17 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 			}
 		} else {
 			for _, item := range originList {
-				var baseVal float64
-				for k, v := range item.DataList {
-					if k == 0 {
-						baseVal = v.Value
-						if baseVal == 0 {
-							break
-						}
+				if len(item.DataList) == 0 {
+					break
+				}
+				baseVal := item.DataList[len(item.DataList)-1].Value
+				baseDate := item.DataList[len(item.DataList)-1].DataTime
+				if baseVal == 0 {
+					break
+				}
+				for _, v := range item.DataList {
+					if v.DataTime == baseDate {
+						continue
 					}
 					val := (v.Value - baseVal) / baseVal
 					val, _ = decimal.NewFromFloat(val).Round(4).Float64()
@@ -564,7 +572,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 			}
 		}
 	case 3: //复合增长率
-		if req.DateRangeType == 0 {
+		if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
 			for _, item := range originList {
 				for _, v := range item.DataList {
 					var baseVal float64
@@ -606,15 +614,16 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 			}
 		} else {
 			for _, item := range originList {
-				var baseVal float64
-				var baseDate string
-				for k, v := range item.DataList {
-					if k == 0 {
-						baseVal = v.Value
-						baseDate = v.DataTime
-						if baseVal == 0 {
-							break
-						}
+				if len(item.DataList) == 0 {
+					break
+				}
+				baseVal := item.DataList[len(item.DataList)-1].Value
+				baseDate := item.DataList[len(item.DataList)-1].DataTime
+				if baseVal == 0 {
+					break
+				}
+				for _, v := range item.DataList {
+					if v.DataTime == baseDate {
 						continue
 					}
 					baseDateT, e := time.ParseInLocation(utils.FormatDate, baseDate, time.Local)
@@ -638,7 +647,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 		}
 	case 4: //最大值
 		var maxVal float64
-		if req.DateRangeType == 0 {
+		if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
 			for _, item := range originList {
 				for _, v := range item.DataList {
 					calDataList, e := GetAutoCalculateDateDataList(v.DataTime, originDataList, req)
@@ -677,7 +686,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
 		}
 	case 5: //最小值
 		var minVal float64
-		if req.DateRangeType == 0 {
+		if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
 			for _, item := range originList {
 				for _, v := range item.DataList {
 					calDataList, e := GetAutoCalculateDateDataList(v.DataTime, originDataList, req)
@@ -753,7 +762,13 @@ func GetRangeAnalysisChartDataByEdbInfo(fromEdbInfo *EdbInfo, calculateFormula R
 		// 智能划分得到一个开始日期,和结束日期
 		var startDateTime, endDateTime time.Time
 		startDateTime = edbStartDateTime
-
+		if calculateFormula.AutoDateConf.IsAutoStartDate == 0 { //固定设置
+			startDate := calculateFormula.AutoDateConf.StartDate
+			if startDate == "" {
+				startDate = "2020-01-01"
+			}
+			startDateTime, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
+		}
 		if calculateFormula.AutoDateConf.IsAutoEndDate == 0 { //固定设置
 			endDate := calculateFormula.AutoDateConf.EndDate
 			if endDate == "" {
@@ -891,20 +906,21 @@ func GetEdbDateByMoveForward(startDate string, moveForward int, edbDataList []*E
 	for _, v := range edbDataList {
 		if v.DataTime == startDate {
 			index += 1
+			continue
 		}
-		if index > 0 {
-			index += 1
-		}
-		if index == moveForward {
+		if index >= moveForward {
 			date = v.DataTime
 			break
 		}
+		if index > 0 {
+			index += 1
+		}
 	}
 	return
 }
 
 // HandleEdbDateChange 处理日期变换
-func HandleEdbDateChange(date string, dateChange []*EdbDateConfDateChange) (newDate string, err error) {
+func HandleEdbDateChange(date string, dateChange []*EdbDataDateChangeConf) (newDate string, err error) {
 	newDate = date
 	if newDate != "" {
 		if len(dateChange) > 0 {