Эх сурвалжийг харах

Merge branch 'hotfix/chart_threme' of eta_forum/eta_forum_admin into master

xyxie 9 сар өмнө
parent
commit
e13be24562

+ 45 - 0
models/chart_theme/request/theme.go

@@ -28,3 +28,48 @@ type SetDefaultThemeReq struct {
 	ChartThemeId     int `description:"主题id"`
 	ChartThemeTypeId int `description:"主题类型id"`
 }
+
+type LineOptions struct {
+	DashStyle string  `json:"dashStyle"`
+	LineWidth int     `json:"lineWidth"`
+	LineType  string  `json:"lineType"`
+	Radius    float64 `json:"radius"`
+}
+
+type OldChartOptions struct {
+	ColorsOptions  []string           `json:"colorsOptions"`
+	LineOptions    LineOptions        `json:"lineOptions"`
+	LegendOptions  interface{}        `json:"legendOptions"`
+	TitleOptions   interface{}        `json:"titleOptions"`
+	MarkerOptions  interface{}        `json:"markerOptions"`
+	XAxisOptions   interface{}        `json:"xAxisOptions"`
+	YAxisOptions   interface{}        `json:"yAxisOptions"`
+	DrawOption     interface{}        `json:"drawOption"`
+	LineOptionList []LineStyleOptions `json:"lineOptionList"`
+}
+
+type NewChartOptions struct {
+	OldChartOptions
+	LineOptionList []NewLineOptions `json:"lineOptionList"`
+}
+
+type NewLineOptions struct {
+	LineOptions
+	Color     string `json:"color"`
+	DataMark  string `json:"dataMark"`
+	MarkType  string `json:"markType"`
+	MarkSize  int    `json:"markSize"`
+	MarkColor string `json:"markColor"`
+}
+
+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"`
+}

+ 47 - 0
services/chart_theme.go

@@ -1,7 +1,9 @@
 package services
 
 import (
+	"encoding/json"
 	"eta/eta_forum_admin/models"
+	"eta/eta_forum_admin/models/chart_theme/request"
 	"eta/eta_forum_admin/utils"
 )
 
@@ -24,6 +26,11 @@ func GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme *model
 
 	// 如果找到了,那么就返回
 	if chartTheme != nil {
+		// 兼容历史数据,加入新字段LineOptionList
+		newConfig, e := ConvertOldChartOptions(chartTheme.Config)
+		if e == nil {
+			chartTheme.Config = newConfig
+		}
 		return
 	}
 
@@ -45,11 +52,51 @@ func GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme *model
 
 	// 如果找到了,那么就返回
 	if chartTheme != nil {
+		// 兼容历史数据,加入新字段LineOptionList
+		newConfig, e := ConvertOldChartOptions(chartTheme.Config)
+		if e == nil {
+			chartTheme.Config = newConfig
+		}
 		return
 	}
 
 	// 如果还是没找到,那就系统的主题id
 	chartTheme, err = models.GetSystemChartTheme(chartThemeType.ChartThemeTypeId)
 
+	// 兼容历史数据,加入新字段LineOptionList
+	newConfig, e := ConvertOldChartOptions(chartTheme.Config)
+	if e == nil {
+		chartTheme.Config = newConfig
+	}
+	return
+}
+
+// 兼容历史数据,加入新字段LineOptionList
+func ConvertOldChartOptions(config string) (newConfig string, err error) {
+	var oldTheme request.OldChartOptions
+
+	var newTheme request.NewChartOptions
+	err = json.Unmarshal([]byte(config), &oldTheme)
+	if err != nil {
+		return
+	}
+	if oldTheme.LineOptionList != nil && len(oldTheme.LineOptionList) > 0 {
+		newConfig = config
+		return
+	}
+	newTheme.OldChartOptions = oldTheme
+	for i := 0; i < 10; i++ {
+		newLineOption := request.NewLineOptions{
+			LineOptions: oldTheme.LineOptions,
+			Color:       oldTheme.ColorsOptions[i],
+			DataMark:    "none",
+			MarkType:    "square",
+			MarkSize:    5,
+			MarkColor:   oldTheme.ColorsOptions[i],
+		}
+		newTheme.LineOptionList = append(newTheme.LineOptionList, newLineOption)
+	}
+	newThemeStr, _ := json.Marshal(newTheme)
+	newConfig = string(newThemeStr)
 	return
 }