瀏覽代碼

Merge branch 'ETA_1.9.4' into debug

zwxi 8 月之前
父節點
當前提交
eadd666677
共有 3 個文件被更改,包括 294 次插入67 次删除
  1. 23 24
      models/chart_info.go
  2. 10 10
      models/chart_theme/request/theme.go
  3. 261 33
      services/chart_info_show.go

+ 23 - 24
models/chart_info.go

@@ -1113,22 +1113,21 @@ type SeasonExtraItem struct {
 	SamePeriodStandardDeviation SamePeriodStandardDeviation `description:"自定义同期标准差"`
 }
 
-
 // 自定义右轴指标
 type SeasonRightAxis struct {
-	IndicatorType int    `description:"右轴指标类型 1:左轴指标同比,2:指标库,3:预测指标 "`
-	Style         string `description:"生成样式"`
-	Shape         string `description:"形状"`
-	ChartColor    string `description:"图表颜色"`
-	Size          int    `description:"大小"`
-	Legend        string `description:"图例名称"`
-	NumFormat     int    `description:"数值格式 1:百分比 2:小数"`
-	IsConnected   int    `description:"是否连接 0不连接 1连接"`
-	LineColor     string `description:"线条颜色"`
-	LineWidth     int    `description:"线条宽度"`
-	LineStyle     string `description:"线条样式"`
-	IsShow        bool   `description:"是否显示"`
-	IsAdd         bool   `description:"是否添加"`
+	IndicatorType int     `description:"右轴指标类型 1:左轴指标同比,2:指标库,3:预测指标 "`
+	Style         string  `description:"生成样式"`
+	Shape         string  `description:"形状"`
+	ChartColor    string  `description:"图表颜色"`
+	Size          int     `description:"大小"`
+	Legend        string  `description:"图例名称"`
+	NumFormat     int     `description:"数值格式 1:百分比 2:小数"`
+	IsConnected   int     `description:"是否连接 0不连接 1连接"`
+	LineColor     string  `description:"线条颜色"`
+	LineWidth     float64 `description:"线条宽度"`
+	LineStyle     string  `description:"线条样式"`
+	IsShow        bool    `description:"是否显示"`
+	IsAdd         bool    `description:"是否添加"`
 }
 
 // 自定义同期上下限
@@ -1142,13 +1141,13 @@ type MaxMinLimits struct {
 
 // 自定义同期均线
 type SamePeriodAverage struct {
-	Color     string `description:"颜色"`
-	Year      int    `description:"均线取值范围"`
-	Legend    string `description:"图例名称"`
-	LineType  string `description:"线型"`
-	LineWidth int    `description:"线宽"`
-	IsShow    bool   `description:"是否显示"`
-	IsAdd     bool   `description:"是否添加"`
+	Color     string  `description:"颜色"`
+	Year      int     `description:"均线取值范围"`
+	Legend    string  `description:"图例名称"`
+	LineType  string  `description:"线型"`
+	LineWidth float64 `description:"线宽"`
+	IsShow    bool    `description:"是否显示"`
+	IsAdd     bool    `description:"是否添加"`
 }
 
 // 自定义同期均线
@@ -1157,7 +1156,7 @@ type SamePeriodAverageResp struct {
 	Year      int                      `description:"均线取值范围"`
 	Legend    string                   `description:"图例名称"`
 	LineType  string                   `description:"线型"`
-	LineWidth int                      `description:"线宽"`
+	LineWidth float64                  `description:"线宽"`
 	IsShow    bool                     `description:"是否显示"`
 	List      []*SamePeriodAverageData `description:"自定义均线列表"`
 	IsAdd     bool                     `description:"是否添加"`
@@ -2319,7 +2318,7 @@ type MarkersLine struct {
 	Value            string          `json:"value" description:"连线指向的数值,例如'4000'"`
 	FromValue        string          `json:"fromValue" description:"连线的起始点,可以为空"`
 	ToValue          string          `json:"toValue" description:"连线的结束点,可以为空"`
-	LineWidth        int             `json:"lineWidth" description:"连线的宽度"`
+	LineWidth        float64         `json:"lineWidth" description:"连线的宽度"`
 	DashStyle        string          `json:"dashStyle" description:"连线的虚线样式,例如'ShortDashDot'"`
 	Color            string          `json:"color" description:"连线的颜色"`
 	Text             string          `json:"text" description:"连线旁边显示的文本"`
@@ -2357,4 +2356,4 @@ type EdbDateConfDateChange struct {
 	Frequency    string `description:"频度变换"`
 	FrequencyDay string `description:"频度的固定日期"`
 	ChangeType   int    `description:"日期变换类型1日期位移,2指定频率"`
-}
+}

+ 10 - 10
models/chart_theme/request/theme.go

@@ -31,7 +31,7 @@ type SetDefaultThemeReq struct {
 
 type LineOptions struct {
 	DashStyle string  `json:"dashStyle"`
-	LineWidth int     `json:"lineWidth"`
+	LineWidth float64 `json:"lineWidth"`
 	LineType  string  `json:"lineType"`
 	Radius    float64 `json:"radius"`
 }
@@ -63,13 +63,13 @@ type NewLineOptions struct {
 }
 
 type LineStyleOptions struct {
-	DashStyle string `json:"dashStyle"`
-	Color     string `json:"color"`
-	LineWidth int    `json:"lineWidth"`
-	LineType  string `json:"lineType"`
-	Radius    int    `json:"radius"`
-	DataMark  string `json:"dataMark"`
-	MarkType  string `json:"markType"`
-	MarkSize  int    `json:"markSize"`
-	MarkColor string `json:"markColor"`
+	DashStyle string  `json:"dashStyle"`
+	Color     string  `json:"color"`
+	LineWidth float64 `json:"lineWidth"`
+	LineType  string  `json:"lineType"`
+	Radius    int     `json:"radius"`
+	DataMark  string  `json:"dataMark"`
+	MarkType  string  `json:"markType"`
+	MarkSize  int     `json:"markSize"`
+	MarkColor string  `json:"markColor"`
 }

+ 261 - 33
services/chart_info_show.go

@@ -284,7 +284,16 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
 		dataResp = models.ChartTimeCombineDataResp{IsHeap: timeConf.IsHeap}
 	case 2: // 季节性图
 		if seasonExtraConfig != "" {
-			dataResp, err = SeasonChartData(edbList, seasonExtraConfig)
+			// 季节性图计算不管图上数据时间,拿所有数据
+			_, tempEdbList, e := getEdbDataMapList(chartInfoId, chartType, calendar, "1990-01-01", "", mappingList, seasonExtraConfig)
+			if e != nil {
+				err = e
+				return
+			}
+			dataResp, err = SeasonChartData(tempEdbList, seasonExtraConfig)
+		} else {
+			// 兼容无配置的老图
+			dataResp = new(models.SeasonChartResp)
 		}
 	case 7: // 柱形图
 		barChartConf := extraConfig.(models.BarChartInfoReq)
@@ -1806,7 +1815,6 @@ func RadarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap ma
 	return
 }
 
-
 // SeasonChartData 季节性图的数据处理
 func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig string) (dataResp models.SeasonChartResp, err error) {
 	var seasonConfig models.SeasonExtraItem
@@ -1820,9 +1828,14 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 		if mappingItem.IsAxis == 0 {
 			continue
 		}
-		quarterDataList := mappingItem.DataList.(models.QuarterDataList)
+		quarterDataList, ok := mappingItem.DataList.(models.QuarterDataList)
+		if !ok {
+			continue
+		}
 		// 上下限区间
 		if seasonConfig.MaxMinLimits.Year > 0 {
+			yearRange := time.Now().Year() - seasonConfig.MaxMinLimits.Year
+			startYear := time.Now().AddDate(-yearRange, 0, 0).Year()
 			dataResp.MaxMinLimits.List = make([]*models.MaxMinLimitsData, 0)
 			dataTimeMap := make(map[time.Time]time.Time)
 			dataTimeList := make([]string, 0)
@@ -1830,6 +1843,22 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 			minValueMap := make(map[time.Time]float64)
 
 			maxMinDataList := make([]*models.MaxMinLimitsData, 0)
+			var startDateStr string
+			var endDateStr string
+			var newDate time.Time
+
+			startDateStr = fmt.Sprintf("%d-%s", time.Now().Year(), seasonConfig.XStartDate)
+			endDateStr = fmt.Sprintf("%d-%s", time.Now().Year(), seasonConfig.XEndDate)
+			startDate, e := time.Parse(utils.FormatDate, startDateStr)
+			if e != nil {
+				err = e
+				return
+			}
+			endDate, e := time.Parse(utils.FormatDate, endDateStr)
+			if e != nil {
+				err = e
+				return
+			}
 			// 日度 周度插值
 			for _, v := range quarterDataList {
 				if mappingItem.Frequency == "日度" || mappingItem.Frequency == "周度" {
@@ -1839,31 +1868,123 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 						err = errors.New("插值处理数据异常, Err:" + err.Error())
 						return
 					}
+					// 不包含当年
+					if v.ChartLegend == strconv.Itoa(time.Now().Year()) {
+						continue
+					}
 					for _, date := range dataTimeList {
 						dateTime, e := time.Parse(utils.FormatDate, date)
 						if e != nil {
 							err = errors.New("时间格式化异常, Err:" + e.Error())
 							return
 						}
-						newDate := dateTime.AddDate(time.Now().Year()-dateTime.Year(), 0, 0)
-						// 处理上下限列表
-						if value, ok := maxValueMap[newDate]; ok {
-							if value < handleDataMap[date] {
-								maxValueMap[newDate] = handleDataMap[date]
+						if dateTime.Year() < startYear {
+							continue
+						}
+						// 不包含2月29号
+						if dateTime.Month() == 2 && dateTime.Day() == 29 {
+							continue
+						}
+						newDate = dateTime.AddDate(time.Now().Year()-dateTime.Year(), 0, 0)
+						if seasonConfig.JumpYear == 1 {
+							if startDate.After(endDate) {
+								// 如果跨年且不到一年
+								// 全年截取一部分
+								if newDate.Before(startDate.AddDate(0, 0, 1)) && newDate.After(endDate) {
+									continue
+								}
+								if newDate.After(startDate.AddDate(0, 0, -1)) {
+									// 减一年
+									newDate = dateTime.AddDate(time.Now().Year()-dateTime.Year()-1, 0, 0)
+								}
+								// 处理上下限列表
+								if value, ok := maxValueMap[newDate]; ok {
+									if value < handleDataMap[date] {
+										maxValueMap[newDate] = handleDataMap[date]
+									}
+								} else {
+									maxValueMap[newDate] = handleDataMap[date]
+								}
+
+								if value, ok := minValueMap[newDate]; ok {
+									if value > handleDataMap[date] {
+										minValueMap[newDate] = handleDataMap[date]
+									}
+								} else {
+									minValueMap[newDate] = handleDataMap[date]
+								}
+
+								dataTimeMap[newDate] = newDate
+							} else {
+								// 如果跨年且大于等于一年
+								// double后截取
+								if newDate.After(startDate) {
+									// 处理上下限列表
+									if value, ok := maxValueMap[newDate]; ok {
+										if value < handleDataMap[date] {
+											maxValueMap[newDate] = handleDataMap[date]
+										}
+									} else {
+										maxValueMap[newDate] = handleDataMap[date]
+									}
+
+									if value, ok := minValueMap[newDate]; ok {
+										if value > handleDataMap[date] {
+											minValueMap[newDate] = handleDataMap[date]
+										}
+									} else {
+										minValueMap[newDate] = handleDataMap[date]
+									}
+
+									dataTimeMap[newDate] = newDate
+								}
+
+								newDate = dateTime.AddDate(time.Now().Year()-dateTime.Year()+1, 0, 0)
+								newEndDate := endDate.AddDate(1, 0, 0)
+								if newDate.Before(newEndDate) {
+									// 处理上下限列表
+									if value, ok := maxValueMap[newDate]; ok {
+										if value < handleDataMap[date] {
+											maxValueMap[newDate] = handleDataMap[date]
+										}
+									} else {
+										maxValueMap[newDate] = handleDataMap[date]
+									}
+
+									if value, ok := minValueMap[newDate]; ok {
+										if value > handleDataMap[date] {
+											minValueMap[newDate] = handleDataMap[date]
+										}
+									} else {
+										minValueMap[newDate] = handleDataMap[date]
+									}
+
+									dataTimeMap[newDate] = newDate
+								}
+
 							}
 						} else {
-							maxValueMap[newDate] = handleDataMap[date]
-						}
+							// 如果不跨年 正常获取
+							// 获取当前日期所在区间
+							// 处理上下限列表
+							if value, ok := maxValueMap[newDate]; ok {
+								if value < handleDataMap[date] {
+									maxValueMap[newDate] = handleDataMap[date]
+								}
+							} else {
+								maxValueMap[newDate] = handleDataMap[date]
+							}
 
-						if value, ok := minValueMap[newDate]; ok {
-							if value > handleDataMap[date] {
+							if value, ok := minValueMap[newDate]; ok {
+								if value > handleDataMap[date] {
+									minValueMap[newDate] = handleDataMap[date]
+								}
+							} else {
 								minValueMap[newDate] = handleDataMap[date]
 							}
-						} else {
-							minValueMap[newDate] = handleDataMap[date]
-						}
 
-						dataTimeMap[newDate] = newDate
+							dataTimeMap[newDate] = newDate
+						}
 					}
 				} else {
 					// 旬度、月度、季度、半年度 不插值,需要先把日期列表和数据map取出来
@@ -1873,24 +1994,120 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 							err = errors.New("时间格式化异常, Err:" + e.Error())
 							return
 						}
-						newDate := dateTime.AddDate(time.Now().Year()-dateTime.Year(), 0, 0)
 
-						if value, ok := maxValueMap[newDate]; ok {
-							if value < vv.Value {
-								maxValueMap[newDate] = vv.Value
+						// 不包含当年
+						if v.ChartLegend == strconv.Itoa(time.Now().Year()) {
+							continue
+						}
+
+						if dateTime.Year() < startYear {
+							continue
+						}
+						// 不包含2月29号
+						if dateTime.Month() == 2 && dateTime.Day() == 29 {
+							continue
+						}
+						newDate = dateTime.AddDate(time.Now().Year()-dateTime.Year(), 0, 0)
+						if seasonConfig.JumpYear == 1 {
+							if startDate.After(endDate) {
+								// 如果跨年且不到一年
+								// 全年截取一部分
+								if newDate.Before(startDate.AddDate(0, 0, 1)) && newDate.After(endDate) {
+									continue
+								}
+								if newDate.After(startDate.AddDate(0, 0, -1)) {
+									// 减一年
+									newDate = dateTime.AddDate(time.Now().Year()-dateTime.Year()-1, 0, 0)
+								}
+								// 处理上下限列表
+								if value, ok := maxValueMap[newDate]; ok {
+									if value < vv.Value {
+										maxValueMap[newDate] = vv.Value
+									}
+								} else {
+									maxValueMap[newDate] = vv.Value
+								}
+
+								if value, ok := minValueMap[newDate]; ok {
+									if value > vv.Value {
+										minValueMap[newDate] = vv.Value
+									}
+								} else {
+									minValueMap[newDate] = vv.Value
+								}
+
+								dataTimeMap[newDate] = newDate
+							} else {
+								// 如果跨年且大于等于一年
+								// double后截取
+								if newDate.After(startDate) {
+									// 处理上下限列表
+									if value, ok := maxValueMap[newDate]; ok {
+										if value < vv.Value {
+											maxValueMap[newDate] = vv.Value
+										}
+									} else {
+										maxValueMap[newDate] = vv.Value
+									}
+
+									if value, ok := minValueMap[newDate]; ok {
+										if value > vv.Value {
+											minValueMap[newDate] = vv.Value
+										}
+									} else {
+										minValueMap[newDate] = vv.Value
+									}
+
+									dataTimeMap[newDate] = newDate
+								}
+
+								newDate = dateTime.AddDate(time.Now().Year()-dateTime.Year()+1, 0, 0)
+								newEndDate := endDate.AddDate(1, 0, 0)
+								if newDate.Before(newEndDate) {
+									// 处理上下限列表
+									if value, ok := maxValueMap[newDate]; ok {
+										if value < vv.Value {
+											maxValueMap[newDate] = vv.Value
+										}
+									} else {
+										maxValueMap[newDate] = vv.Value
+									}
+
+									if value, ok := minValueMap[newDate]; ok {
+										if value > vv.Value {
+											minValueMap[newDate] = vv.Value
+										}
+									} else {
+										minValueMap[newDate] = vv.Value
+									}
+
+									dataTimeMap[newDate] = newDate
+								}
+
 							}
 						} else {
-							maxValueMap[newDate] = vv.Value
-						}
+							// 如果不跨年 正常获取
+							// 获取当前日期所在区间
+							// 处理上下限列表
+							if value, ok := maxValueMap[newDate]; ok {
+								if value < vv.Value {
+									maxValueMap[newDate] = vv.Value
+								}
+							} else {
+								maxValueMap[newDate] = vv.Value
+							}
 
-						if value, ok := minValueMap[newDate]; ok {
-							if value > vv.Value {
+							if value, ok := minValueMap[newDate]; ok {
+								if value > vv.Value {
+									minValueMap[newDate] = vv.Value
+								}
+							} else {
 								minValueMap[newDate] = vv.Value
 							}
-						} else {
-							minValueMap[newDate] = vv.Value
+
+							dataTimeMap[newDate] = newDate
 						}
-						dataTimeMap[newDate] = newDate
+
 					}
 				}
 			}
@@ -1908,6 +2125,7 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 				} else {
 					maxMinItem.MinValue = maxValueMap[v]
 				}
+
 				maxMinItem.DataTime = v.Format(utils.FormatDate)
 				maxMinItem.DataTimestamp = v.UnixNano() / 1e6
 
@@ -1934,7 +2152,6 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 			dataTimeMap := make(map[time.Time]time.Time)
 			dataTimeList := make([]string, 0)
 			valueMap := make(map[time.Time]float64)
-
 			averageDataList := make([]*models.SamePeriodAverageData, 0)
 			for i := len(quarterDataList) - 1; i > len(quarterDataList)-seasonConfig.SamePeriodAverage.Year && i > 0; i-- {
 				// 插值成日度
@@ -1949,8 +2166,13 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 						err = errors.New("时间格式化异常, Err:" + e.Error())
 						return
 					}
-					// 不包含今年
-					if dateTime.Year() == time.Now().Year() {
+					yearRange := time.Now().Year() - seasonConfig.SamePeriodAverage.Year
+					startYear := time.Now().AddDate(-yearRange, 0, 0).Year()
+					if dateTime.Year() < startYear {
+						continue
+					}
+					// 不包含2月29号
+					if dateTime.Month() == 2 && dateTime.Day() == 29 {
 						continue
 					}
 					newDate := dateTime.AddDate(time.Now().Year()-dateTime.Year(), 0, 0)
@@ -1995,6 +2217,9 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 
 		// 自定义同期标准差
 		if seasonConfig.SamePeriodStandardDeviation.Year > 1 && seasonConfig.SamePeriodStandardDeviation.Multiple > 0 {
+			yearRange := time.Now().Year() - seasonConfig.SamePeriodAverage.Year
+			startYear := time.Now().AddDate(-yearRange, 0, 0).Year()
+
 			// 先算均值,再算标准差
 			handleDataMap := make(map[string]float64)
 			dataTimeMap := make(map[time.Time]time.Time)
@@ -2016,8 +2241,11 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 						err = errors.New("时间格式化异常, Err:" + e.Error())
 						return
 					}
-					// 不包含今年
-					if dateTime.Year() == time.Now().Year() {
+					if dateTime.Year() < startYear {
+						continue
+					}
+					// 不包含2月29号
+					if dateTime.Month() == 2 && dateTime.Day() == 29 {
 						continue
 					}
 					newDate := dateTime.AddDate(time.Now().Year()-dateTime.Year(), 0, 0)
@@ -2092,4 +2320,4 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 	}
 
 	return
-}
+}