Browse Source

面积图 init

gmy 3 tuần trước cách đây
mục cha
commit
d83a5e4664

+ 64 - 0
controllers/data_manage/chart_info.go

@@ -2,6 +2,7 @@ package data_manage
 
 import (
 	"encoding/json"
+	"errors"
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
 	"eta/eta_api/models/data_manage"
@@ -1370,6 +1371,8 @@ func (this *ChartInfoController) PreviewChartInfoDetail() {
 		extraConfigStr = chartInfo.BarConfig
 	} else if chartInfo != nil && chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
 		extraConfigStr = req.ExtraConfig
+	} else if chartInfo != nil && chartInfo.ChartType == utils.CHART_TYPE_AREA {
+		extraConfigStr = req.ExtraConfig
 	}
 
 	// 获取图表中的指标数据
@@ -1397,6 +1400,11 @@ func (this *ChartInfoController) PreviewChartInfoDetail() {
 		chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
 	}
 
+	// 面积图 面积堆积 数据处理
+	if req.ChartType == utils.CHART_TYPE_AREA {
+		fillAreaGraphData(extraConfigStr, edbList)
+	}
+
 	//图表操作权限
 	chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
 	//判断是否需要展示英文标识
@@ -1489,6 +1497,62 @@ func (this *ChartInfoController) PreviewChartInfoDetail() {
 	br.Data = resp
 }
 
+func fillAreaGraphData(extraConfigStr string, edbDataList []*data_manage.ChartEdbInfoMapping) (edbList []*data_manage.ChartEdbInfoMapping, err error, errMsg string) {
+
+	var tmpConfig data_manage.AreaExtraConf
+	if extraConfigStr != `` {
+		err := json.Unmarshal([]byte(extraConfigStr), &tmpConfig)
+		if err != nil {
+			errMsg = "面积图配置异常"
+			err = errors.New(errMsg)
+			return
+		}
+		if tmpConfig.StandardEdbInfoId <= 0 {
+			errMsg = "面积图配置异常"
+			err = errors.New(errMsg)
+		}
+	}
+	if tmpConfig.IsHeap == 1 {
+		standardIndexMap := make(map[string]*data_manage.EdbDataList)
+		for _, v := range edbDataList {
+			// 判断是否为基准指标
+			if v.EdbInfoId == tmpConfig.StandardEdbInfoId {
+				if dataList, ok := v.DataList.([]*data_manage.EdbDataList); ok {
+					for _, dataObject := range dataList {
+						standardIndexMap[dataObject.DataTime] = dataObject
+					}
+				}
+				break
+			}
+		}
+		switch tmpConfig.NullDealWay {
+		case 1:
+			// 插值填充
+			//interpolate()
+
+		case 2:
+			// 前值填充
+			//fillWithPrevious()
+			// 按自然日补充,再根据基准指标取对应数据
+
+		case 3:
+			// 后值填充
+			fillWithNext()
+		case 4:
+			// 等于0
+			setToZero()
+		case 5:
+			// 删除日期
+			deleteDate()
+		default:
+			fmt.Println("Unknown NullDealWay:", tmpConfig.NullDealWay)
+		}
+
+	}
+
+	return nil, nil, ""
+}
+
 // ChartInfoDetailV2
 // @Title 获取图表详情
 // @Description 获取图表详情接口

+ 8 - 0
models/data_manage/chart_info.go

@@ -63,6 +63,14 @@ type ChartInfo struct {
 	DateTypeNum       int    `description:"date_type=25(N月前)时的N值,其他N值可复用此字段"`
 }
 
+// AreaExtraConf 面积图配置
+type AreaExtraConf struct {
+	IsHeap            int `description:"是否堆积 1-堆积 2-不堆积"`
+	HeapWay           int `description:"堆积方式 1-普通 2-百分比"`
+	StandardEdbInfoId int `description:"基准指标id"`
+	NullDealWay       int `description:"空值处理方式,1-插值填充 2-前值填充 3-后值填充 4-等于0 5-删除日期"`
+}
+
 type ChartInfoMore struct {
 	ChartInfo
 	IsEnChart     bool `description:"是否展示英文标识"`

+ 1 - 0
utils/constants.go

@@ -329,6 +329,7 @@ const (
 const (
 	CHART_TYPE_CURVE           = 1  //曲线图
 	CHART_TYPE_SEASON          = 2  //季节性图
+	CHART_TYPE_AREA            = 3  // 面积图
 	CHART_TYPE_BAR             = 7  //柱形图
 	CHART_TYPE_SECTION_SCATTER = 10 //截面散点图样式
 	CHART_TYPE_RADAR           = 11 //雷达图