Parcourir la source

季节性图展示

xyxie il y a 1 mois
Parent
commit
5d98bc29ad
1 fichiers modifiés avec 20 ajouts et 47 suppressions
  1. 20 47
      services/chart/chart_info.go

+ 20 - 47
services/chart/chart_info.go

@@ -716,7 +716,13 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
 func getEdbDataMapListForSeason(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*chartEdbMappingModel.ChartEdbInfoMapping, seasonExtraConfig string) (edbDataListMap map[int][]*edbDataModel.EdbDataList, edbList []*chartEdbMappingModel.ChartEdbInfoMappingList, err error) {
 	// 指标对应的所有数据
 	edbDataListMap = make(map[int][]*edbDataModel.EdbDataList)
-
+	seasonXStartDateWithYear := ""
+	seasonXEndDateWithYear := ""
+	if chartType == 2 {
+		sort.Slice(mappingList, func(i, j int) bool {
+			return mappingList[i].IsAxis > mappingList[j].IsAxis
+		})
+	}
 	for _, v := range mappingList {
 		//fmt.Println("v:", v.EdbInfoId)
 		item := new(chartEdbMappingModel.ChartEdbInfoMappingList)
@@ -917,75 +923,42 @@ func getEdbDataMapListForSeason(chartInfoId, chartType int, calendar, startDate,
 						err = errors.New("获取农历数据失败,Err:" + tmpErr.Error())
 						return
 					}
-					quarterDataList, _, _, tErr := GetSeasonEdbInfoDataListByXDateNong(result, latestDate, seasonExtraConfig, calendarPreYear)
+					quarterDataList, seasonXStartDateWithYearTmp, seasonXEndDateWithYearTmp, tErr := GetSeasonEdbInfoDataListByXDateNong(result, latestDate, seasonExtraConfig, calendarPreYear)
 					if tErr != nil {
 						err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
 						return
 					}
 					item.DataList = quarterDataList
+					seasonXStartDateWithYear = seasonXStartDateWithYearTmp
+					seasonXEndDateWithYear = seasonXEndDateWithYearTmp
 				}
 
 			} else {
-				quarterDataList, _, _, tErr := GetSeasonEdbInfoDataListByXDate(newDataList, latestDate, seasonExtraConfig)
+				quarterDataList, seasonXStartDateWithYearTmp, seasonXEndDateWithYearTmp, tErr := GetSeasonEdbInfoDataListByXDate(newDataList, latestDate, seasonExtraConfig)
 				if tErr != nil {
 					err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
 					return
 				}
 				item.DataList = quarterDataList
+				seasonXStartDateWithYear = seasonXStartDateWithYearTmp
+				seasonXEndDateWithYear = seasonXEndDateWithYearTmp
 			}
 
 		} else if chartType == 2 && item.IsAxis == 0 {
-			// 右轴数据处理
-			xStartDate := "01-01"
-
-			jumpYear := 0
-			var seasonExtra edbDataModel.SeasonExtraItem
-			if seasonExtraConfig != "" {
-				err = json.Unmarshal([]byte(seasonExtraConfig), &seasonExtra)
-				if err != nil {
-					return
-				}
-			}
-
-			if seasonExtra.XStartDate != "" {
-				xStartDate = seasonExtra.XStartDate
-				jumpYear = seasonExtra.JumpYear
-			}
-
-			length := len(newDataList)
-			if length == 0 {
-				return
-			}
-			latestDate := v.LatestDate
-			if latestDate.IsZero() {
-				//item.DataList = newDataList
-				item.IsNullData = true
-				edbList = append(edbList, item)
-				continue
-			}
-
-			var rightAxisDate time.Time
-			if jumpYear == 1 {
-				latestDate = latestDate.AddDate(-1, 0, 0)
-			}
-			latestDateStr := fmt.Sprintf("%d-%s", latestDate.Year(), xStartDate)
-			rightAxisDate, err = time.Parse(utils.FormatDate, latestDateStr)
-			if err != nil {
-				return
-			}
-
-			newList := make([]*edbDataModel.EdbDataList, 0)
-			for _, v := range newDataList {
+			newDataList := make([]*edbDataModel.EdbDataList, 0)
+			for _, v := range dataList {
 				dataTime, e := time.Parse(utils.FormatDate, v.DataTime)
 				if e != nil {
 					err = errors.New("季节性图处理右轴指标数据转换日期失败,Err:" + e.Error())
 					return
 				}
-				if dataTime.Equal(rightAxisDate) || dataTime.After(rightAxisDate) {
-					newList = append(newList, v)
+				seasonXStartDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXStartDateWithYear)
+				seasonXEndDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXEndDateWithYear)
+				if dataTime.Equal(seasonXStartDateWithYearT) || (dataTime.After(seasonXStartDateWithYearT) && dataTime.Before(seasonXEndDateWithYearT)) || dataTime.Equal(seasonXEndDateWithYearT) {
+					newDataList = append(newDataList, v)
 				}
 			}
-			item.DataList = newList
+			item.DataList = newDataList
 		} else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
 			//item.DataList = newDataList
 		} else {