|
@@ -619,7 +619,16 @@ func GetEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtraConfig string) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
// 指标对应的所有数据
|
|
|
edbDataListMap = make(map[int][]*data_manage.EdbDataList)
|
|
|
-
|
|
|
+ // 设置季节性图的左右轴
|
|
|
+ seasonXStartDateWithYear := ""
|
|
|
+ seasonXEndDateWithYear := ""
|
|
|
+ // 如果是季节性图则进入特殊排序
|
|
|
+ if chartType == 2 {
|
|
|
+ // 根据设置的左右轴,对mappingList进行排序,1左轴排在前面,0右轴排在前面
|
|
|
+ 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(data_manage.ChartEdbInfoMapping)
|
|
@@ -817,77 +826,37 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
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(dataList, latestDate, seasonExtraConfig)
|
|
|
+ quarterDataList, seasonXStartDateWithYearTmp, seasonXEndDateWithYearTmp, tErr := GetSeasonEdbInfoDataListByXDate(dataList, 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 data_manage.SeasonExtraItem
|
|
|
- if seasonExtraConfig != "" {
|
|
|
- err = json.Unmarshal([]byte(seasonExtraConfig), &seasonExtra)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if seasonExtra.XStartDate != "" {
|
|
|
- xStartDate = seasonExtra.XStartDate
|
|
|
- jumpYear = seasonExtra.JumpYear
|
|
|
- }
|
|
|
-
|
|
|
- length := len(dataList)
|
|
|
- if length == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
|
|
|
- if tmpErr != nil {
|
|
|
- //item.DataList = dataList
|
|
|
- item.IsNullData = true
|
|
|
- edbList = append(edbList, item)
|
|
|
- continue
|
|
|
- err = errors.New(fmt.Sprint("获取最后实际数据的日期失败,Err:" + tmpErr.Error() + ";LatestDate:" + v.LatestDate))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
- }
|
|
|
-
|
|
|
- nowYear := time.Now().Year()
|
|
|
newDataList := make([]*data_manage.EdbDataList, 0)
|
|
|
+ seasonXStartDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXStartDateWithYear)
|
|
|
+ seasonXEndDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXEndDateWithYear)
|
|
|
for _, v := range dataList {
|
|
|
dataTime, e := time.Parse(utils.FormatDate, v.DataTime)
|
|
|
if e != nil {
|
|
|
err = errors.New("季节性图处理右轴指标数据转换日期失败,Err:" + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- dataTimeT, _ := time.Parse(utils.FormatDate, v.DataTime)
|
|
|
- year := dataTimeT.Year()
|
|
|
- newItemDate := dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
- v.DataTimestamp = newItemDate.UnixNano() / 1e6
|
|
|
- if dataTime.Equal(rightAxisDate) || dataTime.After(rightAxisDate) {
|
|
|
+ if (dataTime.After(seasonXStartDateWithYearT) && dataTime.Before(seasonXEndDateWithYearT)) || dataTime.Equal(seasonXStartDateWithYearT) || dataTime.Equal(seasonXEndDateWithYearT) {
|
|
|
newDataList = append(newDataList, v)
|
|
|
}
|
|
|
}
|
|
@@ -904,7 +873,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
}
|
|
|
|
|
|
// GetSeasonEdbInfoDataListByXDate 季节性图的指标数据根据横轴展示
|
|
|
-func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latestDate time.Time, seasonExtraConfig string) (quarterDataListSort data_manage.QuarterDataList, err error) {
|
|
|
+func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latestDate time.Time, seasonExtraConfig string) (quarterDataListSort data_manage.QuarterDataList, xStartDateWithYear string, xEndDateWithYear string, err error) {
|
|
|
xStartDate := "01-01"
|
|
|
xEndDate := "12-31"
|
|
|
jumpYear := 0
|
|
@@ -954,7 +923,7 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
|
|
|
return
|
|
|
}
|
|
|
endYear := lastDateT.Year()
|
|
|
- nowYear := time.Now().Year()
|
|
|
+ nowYear := endYear
|
|
|
chartLegendMaxYear := 0
|
|
|
dataMap := make(map[string]data_manage.QuarterXDateItem, 0)
|
|
|
|
|
@@ -1005,6 +974,8 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
|
|
|
dataMap[name] = item
|
|
|
chartLegendMap[name] = idx
|
|
|
idx++
|
|
|
+ xStartDateWithYear = startStr
|
|
|
+ xEndDateWithYear = endStr
|
|
|
fmt.Println("年份" + showName + "日期" + startStr + " " + endStr)
|
|
|
if lastDateT.Before(endT) {
|
|
|
//如果最新的日期在起始日之前,则跳出循环
|
|
@@ -1101,7 +1072,7 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
|
|
|
}
|
|
|
|
|
|
// GetSeasonEdbInfoDataListByXDateNong 季节性图的指标数据根据横轴选择农历时展示
|
|
|
-func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, latestDate time.Time, seasonExtraConfig string, calendarPreYear int) (quarterDataListSort data_manage.QuarterDataList, err error) {
|
|
|
+func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, latestDate time.Time, seasonExtraConfig string, calendarPreYear int) (quarterDataListSort data_manage.QuarterDataList, xStartDateWithYear string, xEndDateWithYear string, err error) {
|
|
|
xStartDate := "01-01"
|
|
|
xEndDate := "12-31"
|
|
|
jumpYear := 0
|
|
@@ -1153,7 +1124,7 @@ func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, late
|
|
|
return
|
|
|
}
|
|
|
endYear := lastDateT.Year()
|
|
|
- nowYear := time.Now().Year()
|
|
|
+ nowYear := endYear
|
|
|
chartLegendMaxYear := 0
|
|
|
dataMap := make(map[string]data_manage.QuarterXDateItem, 0)
|
|
|
|
|
@@ -1206,6 +1177,8 @@ func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, late
|
|
|
endTmpT = endT
|
|
|
chartLegendMap[showName] = idx
|
|
|
idx++
|
|
|
+ xStartDateWithYear = startStr
|
|
|
+ xEndDateWithYear = endStr
|
|
|
if lastDateT.Before(endT) {
|
|
|
//如果最新的日期在起始日之前,则跳出循环
|
|
|
break
|
|
@@ -3278,6 +3251,15 @@ func GetChartConvertEdbData(chartInfoId, chartType int, calendar, startDate, end
|
|
|
func getEdbConvertDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtraConfig string, isAxis int) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
// 指标对应的所有数据
|
|
|
edbDataListMap = make(map[int][]*data_manage.EdbDataList)
|
|
|
+ seasonXStartDateWithYear := ""
|
|
|
+ seasonXEndDateWithYear := ""
|
|
|
+ // 如果是季节性图则进入特殊排序
|
|
|
+ if chartType == 2 {
|
|
|
+ // 根据设置的左右轴,对mappingList进行排序,1左轴排在前面,0右轴排在前面
|
|
|
+ sort.Slice(mappingList, func(i, j int) bool {
|
|
|
+ return mappingList[i].IsAxis > mappingList[j].IsAxis
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
for _, v := range mappingList {
|
|
|
//fmt.Println("v:", v.EdbInfoId)
|
|
@@ -3469,41 +3451,39 @@ func getEdbConvertDataMapList(chartInfoId, chartType int, calendar, startDate, e
|
|
|
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(dataList, latestDate, seasonExtraConfig)
|
|
|
+ quarterDataList, seasonXStartDateWithYearTmp, seasonXEndDateWithYearTmp, tErr := GetSeasonEdbInfoDataListByXDate(dataList, latestDate, seasonExtraConfig)
|
|
|
if tErr != nil {
|
|
|
err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
|
|
|
return
|
|
|
}
|
|
|
item.DataList = quarterDataList
|
|
|
+ seasonXStartDateWithYear = seasonXStartDateWithYearTmp
|
|
|
+ seasonXEndDateWithYear = seasonXEndDateWithYearTmp
|
|
|
}
|
|
|
} else if chartType == 2 && isAxis == 0 {
|
|
|
// 右轴数据处理,只要最新一年
|
|
|
- latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
|
|
|
- if tmpErr != nil {
|
|
|
- //item.DataList = dataList
|
|
|
- item.IsNullData = true
|
|
|
- edbList = append(edbList, item)
|
|
|
- continue
|
|
|
- err = errors.New(fmt.Sprint("获取最后实际数据的日期失败,Err:" + tmpErr.Error() + ";LatestDate:" + v.LatestDate))
|
|
|
- return
|
|
|
- }
|
|
|
newDataList := make([]*data_manage.EdbDataList, 0)
|
|
|
+ seasonXStartDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXStartDateWithYear)
|
|
|
+ seasonXEndDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXEndDateWithYear)
|
|
|
for _, v := range dataList {
|
|
|
dataTime, e := time.Parse(utils.FormatDate, v.DataTime)
|
|
|
if e != nil {
|
|
|
err = errors.New("季节性图处理右轴指标数据转换日期失败,Err:" + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- if dataTime.Year() == latestDate.Year() {
|
|
|
+ // 如果数据时间在横轴的开始日期和结束日期之间,则加入到数据列表中
|
|
|
+ if (dataTime.After(seasonXStartDateWithYearT) && dataTime.Before(seasonXEndDateWithYearT)) || dataTime.Equal(seasonXStartDateWithYearT) || dataTime.Equal(seasonXEndDateWithYearT) {
|
|
|
newDataList = append(newDataList, v)
|
|
|
}
|
|
|
}
|