Browse Source

参考刻度线 时间戳

gmy 3 months ago
parent
commit
53a5d5c4ff

+ 10 - 0
controllers/chart.go

@@ -576,6 +576,16 @@ func fillAreaGraphData(extraConfigStr string, edbDataList []*models.ChartEdbInfo
 		if err != nil {
 			return err, err.Error()
 		}
+
+		// 时间戳处理
+		for _, mapping := range edbDataList {
+			if dataList, ok := mapping.DataList.([]*models.EdbDataList); ok {
+				for _, dataInfo := range dataList {
+					toFormatTime := utils.StringToFormatTime(dataInfo.DataTime, utils.FormatDate)
+					dataInfo.DataTimestamp = toFormatTime.UnixMilli()
+				}
+			}
+		}
 	}
 
 	return nil, ""

+ 2 - 1
models/chart.go

@@ -47,7 +47,7 @@ type ChartInfo struct {
 	Source            int       `description:"1:ETA图库;2:商品价格曲线"`
 	Unit              string    `description:"中文单位名称"`
 	UnitEn            string    `description:"英文单位名称"`
-	ExtraConfig       string    `description:"图表额外配置,json数据" json:"-"`
+	ExtraConfig       string    `description:"图表额外配置,json数据"`
 	ChartSource       string    `description:"图表来源str"`
 	ChartSourceEn     string    `description:"图表来源(英文)"`
 	SeasonExtraConfig string    `description:"季节性图表中的配置,json数据"`
@@ -97,6 +97,7 @@ type ChartEdbInfoMapping struct {
 	ChartStyle        string  `description:"图表类型"`
 	ChartColor        string  `description:"颜色"`
 	ChartWidth        float64 `description:"线条大小"`
+	ChartScale        float64 `description:"参考刻度线"`
 	DataList          interface{}
 
 	EdbInfoCategoryType int     `description:"0:普通指标,1:预测指标"`

+ 9 - 9
services/data/area_graph/processor_business_logic.go

@@ -54,25 +54,25 @@ func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataL
 
 				// 插值法补充数据
 				var startEdbInfoData *models.EdbDataList
-				for index := 0; index < len(dataList)-1; index++ {
+				for index := 0; index < len(dataList); index++ {
 					// 获取当前数据和下一个数据
-					beforeIndexData := dataList[index]
-					afterIndexData := dataList[index+1]
+					currentIndexData := dataList[index]
+					//afterIndexData := dataList[index+1]
 
 					if startEdbInfoData == nil {
-						startEdbInfoData = beforeIndexData
+						startEdbInfoData = currentIndexData
 						continue
 					}
 
 					// 获取两条数据之间相差的天数
 					startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
-					currDataTime, _ := time.ParseInLocation(utils.FormatDate, afterIndexData.DataTime, time.Local)
+					currDataTime, _ := time.ParseInLocation(utils.FormatDate, currentIndexData.DataTime, time.Local)
 					betweenHour := int(currDataTime.Sub(startDataTime).Hours())
 					betweenDay := betweenHour / 24
 
 					// 如果相差一天,那么过滤
 					if betweenDay <= 1 {
-						startEdbInfoData = afterIndexData
+						startEdbInfoData = currentIndexData
 						continue
 					}
 
@@ -87,7 +87,7 @@ func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataL
 						coordinateData = append(coordinateData, tmpCoordinate1)
 						tmpCoordinate2 := utils.Coordinate{
 							X: float64(betweenDay) + 1,
-							Y: afterIndexData.Value,
+							Y: currentIndexData.Value,
 						}
 						coordinateData = append(coordinateData, tmpCoordinate2)
 
@@ -109,7 +109,7 @@ func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataL
 						nextDay := tmpDataTime.Format(utils.FormatDate)
 
 						replenishIndexData := models.EdbDataList{
-							EdbDataId:     afterIndexData.EdbDataId,
+							EdbDataId:     currentIndexData.EdbDataId,
 							DataTime:      nextDay,
 							DataTimestamp: tmpDataTime.UnixMilli(),
 							Value:         val,
@@ -118,7 +118,7 @@ func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataL
 						// 将补充数据加入补充数据列表
 						replenishDataList = append(replenishDataList, &replenishIndexData)
 					}
-					startEdbInfoData = afterIndexData
+					startEdbInfoData = currentIndexData
 				}
 
 				// 处理从最后一个数据到 endDate 的日期补充

+ 6 - 4
services/data/chart_info.go

@@ -399,6 +399,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
 			item.ChartStyle = ""
 			item.ChartColor = ""
 			item.ChartWidth = 0
+			item.ChartScale = 0
 			item.MaxData = v.MaxValue
 			item.MinData = v.MinValue
 		} else {
@@ -412,6 +413,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
 			item.ChartStyle = v.ChartStyle
 			item.ChartColor = v.ChartColor
 			item.ChartWidth = v.ChartWidth
+			item.ChartScale = v.ChartScale
 			item.IsOrder = v.IsOrder
 			item.MaxData = v.MaxData
 			item.MinData = v.MinData
@@ -2051,7 +2053,7 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 						continue
 					}
 					// 农历时dataTimeList的年份为最新年份,图例时间的年份才是真实年份
-					chartLegend,_ := strconv.Atoi(v.ChartLegend)
+					chartLegend, _ := strconv.Atoi(v.ChartLegend)
 					if chartLegend < startYear {
 						continue
 					}
@@ -2187,7 +2189,7 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 							continue
 						}
 						// 农历时dataTimeList的年份为最新年份,图例时间的年份才是真实年份
-						chartLegend,_ := strconv.Atoi(v.ChartLegend)
+						chartLegend, _ := strconv.Atoi(v.ChartLegend)
 						if chartLegend < startYear {
 							continue
 						}
@@ -2360,7 +2362,7 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 						continue
 					}
 					// 农历时dataTimeList的年份为最新年份,图例时间的年份才是真实年份
-					chartLegend,_ := strconv.Atoi(quarterDataList[i].ChartLegend)
+					chartLegend, _ := strconv.Atoi(quarterDataList[i].ChartLegend)
 					if chartLegend < startYear {
 						continue
 					}
@@ -2448,7 +2450,7 @@ func SeasonChartData(dataList []*models.ChartEdbInfoMapping, seasonExtraConfig s
 						continue
 					}
 					// 农历时dataTimeList的年份为最新年份,图例时间的年份才是真实年份
-					chartLegend,_ := strconv.Atoi(quarterDataList[i].ChartLegend)
+					chartLegend, _ := strconv.Atoi(quarterDataList[i].ChartLegend)
 					if chartLegend < startYear {
 						continue
 					}

+ 7 - 1
utils/date_util.go

@@ -111,7 +111,13 @@ func isLeap(year int) bool {
 
 // StringToTime string 类型时间 转换为 time.Time 类型
 func StringToTime(date string) time.Time {
-	t, _ := time.Parse("2006-01-02", date)
+	t, _ := time.ParseInLocation("2006-01-02", date, time.Local)
+	return t
+}
+
+// StringToFormatTime string 类型时间 转换为指定格式的 time.Time类型
+func StringToFormatTime(data string, format string) time.Time {
+	t, _ := time.ParseInLocation(format, data, time.Local)
 	return t
 }