Browse Source

Merge branch '12.4' into 13.1

hsun 2 years ago
parent
commit
e3870e27bb
4 changed files with 63 additions and 18 deletions
  1. 9 6
      models/chart.go
  2. 6 3
      models/chart_edb_mapping.go
  3. 1 3
      models/db.go
  4. 47 6
      services/data/future_good/chart_info.go

+ 9 - 6
models/chart.go

@@ -86,11 +86,13 @@ type ChartEdbInfoMapping struct {
 	MinValue            float64 `json:"-" description:"最小值"`
 	MaxValue            float64 `json:"-" description:"最大值"`
 	IsNullData          bool    `json:"-" description:"是否空数据"`
+	MappingSource       int     `description:"1:ETA图库;2:商品价格曲线"`
 }
 
 func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT a.*,b.source_name,b.source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.edb_type,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type
+	aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
+	sql := ` SELECT ` + aField + `,b.source_name,b.source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.edb_type,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type
              FROM chart_edb_mapping AS a
 			 INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
 			 WHERE chart_info_id=? 
@@ -161,11 +163,12 @@ type ChartInfoDetailResp struct {
 
 // YData 柱方图的y轴数据
 type YData struct {
-	Date   string    `description:"数据日期"`
-	Color  string    `description:"数据颜色"`
-	Value  []float64 `description:"每个指标的值"`
-	Name   string    `description:"别名"`
-	NameEn string    `description:"英文别名"`
+	Date          string    `description:"数据日期"`
+	Color         string    `description:"数据颜色"`
+	Name          string    `description:"别名"`
+	NameEn        string    `description:"英文别名"`
+	Value         []float64 `description:"每个指标的值"`
+	NoDataEdbList []int     `description:"没有数据的指标列表"`
 }
 
 // 指标季度数据计算(公历转农历)

+ 6 - 3
models/chart_edb_mapping.go

@@ -8,7 +8,9 @@ import (
 // GetEtaEdbChartEdbMapping       商品曲线图查询对应的普通指标
 func GetEtaEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT a.*,b.source_name,b.source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type
+
+	aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
+	sql := ` SELECT ` + aField + `,b.source_name,b.source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type
              FROM chart_edb_mapping AS a
 			 INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
 			 WHERE a.chart_info_id=? AND a.source = ?
@@ -20,11 +22,12 @@ func GetEtaEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err e
 // GetFutureGoodEdbChartEdbMapping       商品曲线图查询对应的商品指标
 func GetFutureGoodEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT a.*,b.future_good_edb_info_id,b.future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value
+	aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
+	sql := ` SELECT ` + aField + `,b.future_good_edb_info_id,b.future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value
              FROM chart_edb_mapping AS a
 			 INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
 			 WHERE a.chart_info_id=? AND a.source = ?
              ORDER BY chart_edb_mapping_id ASC `
 	err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRow(&item)
 	return
-}
+}

+ 1 - 3
models/db.go

@@ -49,13 +49,11 @@ func init() {
 	initFutureGood()
 }
 
-
 // initFutureGood 注册期货数据 数据表
 func initFutureGood() {
 	//注册对象
 	orm.RegisterModel(
 		new(future_good.FutureGoodEdbInfo), //期货指标表
 		new(future_good.FutureGoodEdbData), //期货指标数据表
-		new(future_good.FutureGoodChartClassify), //期货指标分类表
 	)
-}
+}

+ 47 - 6
services/data/future_good/chart_info.go

@@ -3,6 +3,7 @@ package future_good
 import (
 	"errors"
 	"fmt"
+	"github.com/shopspring/decimal"
 	"hongze/hongze_chart_lib/models"
 	"hongze/hongze_chart_lib/models/data_manage"
 	efuture_good "hongze/hongze_chart_lib/models/data_manage/future_good"
@@ -353,13 +354,17 @@ func BarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[
 	for _, barChartInfoDate := range barChartInfoDateList {
 		var maxDate time.Time
 
-		findDataList := make([]float64, 0) // 当前日期的数据值
+		findDataList := make([]float64, 0)  // 当前日期的数据值
+		noDataIdList := make([]int, 0)      // 没有数据的指标id
+		noDataIdMap := make(map[int]int, 0) // 没有数据的指标map
 		for _, edbInfoId := range edbIdList {
 			findDate := barChartInfoDate.Date     //需要的日期值
 			dataList := edbDataListMap[edbInfoId] //指标的所有数据值
 			if len(dataList) <= 0 {
 				// 没有数据的指标id
 				findDataList = append(findDataList, 0)
+				noDataIdList = append(noDataIdList, edbInfoId)
+				noDataIdMap[edbInfoId] = edbInfoId
 				continue
 			}
 			switch barChartInfoDate.Type {
@@ -422,6 +427,8 @@ func BarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[
 				findDataList = append(findDataList, tmpValue)
 			} else {
 				findDataList = append(findDataList, 0)
+				noDataIdList = append(noDataIdList, edbInfoId)
+				noDataIdMap[edbInfoId] = edbInfoId
 			}
 		}
 		yName := barChartInfoDate.Name
@@ -439,12 +446,46 @@ func BarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[
 				yNameEn = maxDate.Format(utils.FormatDate)
 			}
 		}
+		yDate := "0000-00-00"
+		if !maxDate.IsZero() {
+			yDate = maxDate.Format(utils.FormatDate)
+		}
+
+		// 数据处理,将没有数据的下标,赋值平均值
+		{
+			hasDataIndexList := make([]int, 0)
+			for dataK, edbInfoId := range edbIdList {
+				if _, ok := noDataIdMap[edbInfoId]; !ok { // 如果是没有数据的指标id
+					hasDataIndexList = append(hasDataIndexList, dataK)
+				}
+			}
+			lenHasDataIndex := len(hasDataIndexList)
+			if lenHasDataIndex > 0 {
+				for lenHasDataI := 1; lenHasDataI < lenHasDataIndex; lenHasDataI++ {
+					perK := hasDataIndexList[lenHasDataI-1] //上一个有数据的指标下标
+					currK := hasDataIndexList[lenHasDataI]  //当前有数据的指标下标
+					preVal := findDataList[perK]            //上一个有数据的坐标的值
+					currVal := findDataList[currK]          //当前有数据的指标的值
+
+					// 环差值
+					hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(currK - perK)))
+					var tmpI int64
+					// 将两个中间的数据做平均值补全
+					for hcI := perK + 1; hcI < currK; hcI++ {
+						tmpI++
+						findDataList[hcI], _ = decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(tmpI))).RoundCeil(4).Float64()
+					}
+				}
+			}
+		}
+
 		yDataList = append(yDataList, models.YData{
-			Date:   maxDate.Format(utils.FormatDate),
-			Value:  findDataList,
-			Color:  barChartInfoDate.Color,
-			Name:   yName,
-			NameEn: yNameEn,
+			Date:          yDate,
+			Value:         findDataList,
+			NoDataEdbList: noDataIdList,
+			Color:         barChartInfoDate.Color,
+			Name:          yName,
+			NameEn:        yNameEn,
 		})
 	}