Kaynağa Gözat

新增平衡表图表

xyxie 9 ay önce
ebeveyn
işleme
38cc3af627

+ 13 - 7
config/config.go

@@ -3,13 +3,14 @@ package config
 import "time"
 
 type Config struct {
-	Log      Log      `mapstructure:"log" json:"log" yaml:"log"`
-	Serve    Serve    `mapstructure:"serve" json:"serve" yaml:"serve"`
-	Mysql    Mysql    `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
-	Redis    Redis    `mapstructure:"redis" json:"redis" yaml:"redis"`
-	AliOss   AliOss   `mapstructure:"ali-oss" json:"ali-oss" yaml:"ali-oss"`
-	EsClient EsClient `mapstructure:"es_client" json:"es_client" yaml:"es_client"`
-	Mongo    Mongo    `mapstructure:"mongo" json:"mongo" yaml:"mongo"`
+	Log         Log         `mapstructure:"log" json:"log" yaml:"log"`
+	Serve       Serve       `mapstructure:"serve" json:"serve" yaml:"serve"`
+	Mysql       Mysql       `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
+	Redis       Redis       `mapstructure:"redis" json:"redis" yaml:"redis"`
+	AliOss      AliOss      `mapstructure:"ali-oss" json:"ali-oss" yaml:"ali-oss"`
+	EsClient    EsClient    `mapstructure:"es_client" json:"es_client" yaml:"es_client"`
+	Mongo       Mongo       `mapstructure:"mongo" json:"mongo" yaml:"mongo"`
+	EtaChartLib EtaChartLib `mapstructure:"eta_chart_lib" json:"eta_chart_lib" yaml:"eta_chart_lib"`
 }
 
 // Serve gin服务配置
@@ -99,3 +100,8 @@ type Mongo struct {
 	Username      string `mapstructure:"username" json:"username" yaml:"username" description:"用户名"`
 	Password      string `mapstructure:"password" json:"password" yaml:"password" description:"密码"`
 }
+
+type EtaChartLib struct {
+	AppNameEn string `mapstructure:"app_name_en" json:"app_name_en" yaml:"app_name_en" description:"项目名称"`
+	Md5Key    string `mapstructure:"md5_key" json:"md5_key" yaml:"md5_key" description:"项目密钥"`
+}

+ 117 - 83
controller/chart/chart_info.go

@@ -15,6 +15,7 @@ import (
 	"hongze/hongze_yb/models/tables/chart_info_log"
 	edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
 	"hongze/hongze_yb/models/tables/yb_my_chart"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/chart"
 	"hongze/hongze_yb/services/chart/cross_variety"
@@ -74,107 +75,145 @@ func GetChartInfoDetail(c *gin.Context) {
 		response.FailMsg("获取失败", "获取图表信息失败, Err:"+err.Error(), c)
 		return
 	}
-	// 获取主题样式
-	chartTheme, err := chart.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
-	if err != nil {
-		response.FailMsg("获取失败", "获取主题信息失败, Err:"+err.Error(), c)
-		return
-	}
-	chartInfo.ChartThemeStyle = chartTheme.Config
-	chartInfo.ChartThemeId = chartTheme.ChartThemeID
+	var (
+		edbList     []*chartEdbMappingModel.ChartEdbInfoMappingList
+		xEdbIdValue []int
+		yDataList   []chart_info.YData
+		sourceArr   []string
+		dataResp    interface{}
+	)
+	// todo 特殊处理平衡表
+	if chartInfo.Source == utils.CHART_SOURCE_BALANCE_EXCEL {
+		//调用接口
+		chartData, e := services.GetBalanceChartDetail(chartInfo.UniqueCode)
+		if e != nil {
+			response.FailMsg("获取失败", "获取图表信息失败, Err:"+e.Error(), c)
+			return
+		}
+		chartDataResp := new(chart_info.ChartInfoDetailResp)
+		// 兼容返回值类型
+		chartDataString, _ := json.Marshal(chartData)
+		err = json.Unmarshal(chartDataString, chartDataResp)
+		if err != nil {
+			response.FailMsg("获取失败", "获取图表信息失败, Err:"+err.Error(), c)
+			return
+		}
+		chartInfo = chartDataResp.ChartInfo
+		yDataList = chartDataResp.YDataList
+		edbList = chartDataResp.EdbInfoList
+		xEdbIdValue = chartDataResp.XEdbIdValue
+		sourceArr = append(sourceArr, "平衡表")
+		dataResp = chartDataResp.DataResp
 
-	chartType = chartInfo.ChartType
-	startDate := chartInfo.StartDate
-	endDate := chartInfo.EndDate
-	startYear := chartInfo.StartYear
-	calendar := chartInfo.Calendar
-	if reqCalendar != "" {
-		calendar = reqCalendar
-	}
+	} else {
 
-	// 时段筛选
-	reqDateType := c.DefaultQuery("DateType", "")
-	dateType := chartInfo.DateType
-	if reqDateType != "" {
-		dateType, _ = strconv.Atoi(reqDateType)
-	}
-	if dateType <= 0 {
-		dateType = 3 // 默认同后台15年至今
-	}
-	if reqStartDate != "" {
-		startDate = reqStartDate
-	}
-	if reqEndDate != "" {
-		endDate = reqEndDate
-	}
-	// 获取图表指标映射
-	mappingList := make([]*chartEdbMappingModel.ChartEdbInfoMapping, 0)
-	if chartInfoId > 0 {
-		mappingList, err = chartEdbMappingModel.GetMappingListByChartInfoId(chartInfoId)
+		// 获取主题样式
+		chartTheme, err := chart.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
 		if err != nil {
-			response.FailMsg("获取失败", "获取图表指标信息失败4001, Err:"+err.Error(), c)
+			response.FailMsg("获取失败", "获取主题信息失败, Err:"+err.Error(), c)
 			return
 		}
-	} else {
-		if edbInfoId != "" {
-			mappingList, err = chartEdbMappingModel.GetMappingListByEdbInfoId(edbInfoId)
+		chartInfo.ChartThemeStyle = chartTheme.Config
+		chartInfo.ChartThemeId = chartTheme.ChartThemeID
+
+		chartType = chartInfo.ChartType
+		startDate := chartInfo.StartDate
+		endDate := chartInfo.EndDate
+		startYear := chartInfo.StartYear
+		calendar := chartInfo.Calendar
+		if reqCalendar != "" {
+			calendar = reqCalendar
+		}
+
+		// 时段筛选
+		reqDateType := c.DefaultQuery("DateType", "")
+		dateType := chartInfo.DateType
+		if reqDateType != "" {
+			dateType, _ = strconv.Atoi(reqDateType)
+		}
+		if dateType <= 0 {
+			dateType = 3 // 默认同后台15年至今
+		}
+		if reqStartDate != "" {
+			startDate = reqStartDate
+		}
+		if reqEndDate != "" {
+			endDate = reqEndDate
+		}
+		// 获取图表指标映射
+		mappingList := make([]*chartEdbMappingModel.ChartEdbInfoMapping, 0)
+		if chartInfoId > 0 {
+			mappingList, err = chartEdbMappingModel.GetMappingListByChartInfoId(chartInfoId)
 			if err != nil {
-				response.FailMsg("获取失败", "获取图表指标信息失败4002, Err:"+err.Error(), c)
+				response.FailMsg("获取失败", "获取图表指标信息失败4001, Err:"+err.Error(), c)
 				return
 			}
+		} else {
+			if edbInfoId != "" {
+				mappingList, err = chartEdbMappingModel.GetMappingListByEdbInfoId(edbInfoId)
+				if err != nil {
+					response.FailMsg("获取失败", "获取图表指标信息失败4002, Err:"+err.Error(), c)
+					return
+				}
+			}
 		}
-	}
 
-	yearMax := 0
-	if dateType == utils.DateTypeNYears {
-		for _, v := range mappingList {
-			if v.LatestDate.Year() > yearMax {
-				yearMax = v.LatestDate.Year()
+		yearMax := 0
+		if dateType == utils.DateTypeNYears {
+			for _, v := range mappingList {
+				if v.LatestDate.Year() > yearMax {
+					yearMax = v.LatestDate.Year()
+				}
 			}
 		}
-	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
-
-	// 图表额外数据参数
-	extraConfigStr := chartInfo.ExtraConfig
-	// 柱方图的一些配置
-	var barConfig request.BarChartInfoReq
-	if chartInfo != nil && chartInfo.ChartType == 7 {
-		if chartInfo.BarConfig == `` {
-			response.FailMsg("柱方图未配置", "柱方图未配置", c)
-			return
+		startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+
+		// 图表额外数据参数
+		extraConfigStr := chartInfo.ExtraConfig
+		// 柱方图的一些配置
+		var barConfig request.BarChartInfoReq
+		if chartInfo != nil && chartInfo.ChartType == 7 {
+			if chartInfo.BarConfig == `` {
+				response.FailMsg("柱方图未配置", "柱方图未配置", c)
+				return
+			}
+			err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
+			if err != nil {
+				response.FailMsg("柱方图配置异常", "柱方图配置异常", c)
+				return
+			}
+			extraConfigStr = chartInfo.BarConfig
 		}
-		err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
+		var errMsg string
+		// 获取图表中的指标数据
+		edbList, xEdbIdValue, yDataList, sourceArr, dataResp, err, errMsg = chart.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
 		if err != nil {
-			response.FailMsg("柱方图配置异常", "柱方图配置异常", c)
+			msg := `获取失败`
+			if errMsg != `` {
+				msg = errMsg
+			}
+			response.FailMsg(msg, "获取图表,指标信息失败, Err:"+err.Error(), c)
 			return
 		}
-		extraConfigStr = chartInfo.BarConfig
-	}
-
-	// 获取图表中的指标数据
-	edbList, xEdbIdValue, yDataList, sourceArr, dataResp, err, errMsg := chart.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
-	if err != nil {
-		msg := `获取失败`
-		if errMsg != `` {
-			msg = errMsg
-		}
-		response.FailMsg(msg, "获取图表,指标信息失败, Err:"+err.Error(), c)
-		return
-	}
 
-	for _, v := range edbList {
-		// 指标别名
-		if barConfig.EdbInfoIdList != nil && len(barConfig.EdbInfoIdList) > 0 {
-			for _, reqEdb := range barConfig.EdbInfoIdList {
-				if v.EdbInfoId == reqEdb.EdbInfoId {
-					v.EdbAliasName = reqEdb.Name
+		for _, v := range edbList {
+			// 指标别名
+			if barConfig.EdbInfoIdList != nil && len(barConfig.EdbInfoIdList) > 0 {
+				for _, reqEdb := range barConfig.EdbInfoIdList {
+					if v.EdbInfoId == reqEdb.EdbInfoId {
+						v.EdbAliasName = reqEdb.Name
+					}
 				}
 			}
 		}
+		// 图表的指标来源
+		sourceNameList, sourceNameEnList := chart.GetEdbSourceByEdbInfoIdList(edbList)
+		chartInfo.ChartSource = strings.Join(sourceNameList, ",")
+		chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
 	}
 
 	sourceArr = append(sourceArr, "弘则研究")
+
 	chartInfo.ChartSource = strings.Join(sourceArr, ",")
 
 	// 访问记录-仅普通用户记录
@@ -210,11 +249,6 @@ func GetChartInfoDetail(c *gin.Context) {
 		myChartInfo.CreateTime = utils.TimeTransferString(utils.FormatDateTime, exists.CreateTime)
 	}
 
-	// 图表的指标来源
-	sourceNameList, sourceNameEnList := chart.GetEdbSourceByEdbInfoIdList(edbList)
-	chartInfo.ChartSource = strings.Join(sourceNameList, ",")
-	chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
-
 	resp := new(chart_info.ChartInfoDetailResp)
 	resp.ChartInfo = chartInfo
 	resp.EdbInfoList = edbList

+ 11 - 0
models/response/chart_info/chart_info.go

@@ -19,6 +19,17 @@ type ChartInfoDetailResp struct {
 	DataResp             interface{}      `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
 }
 
+type ChartLibChartInfoDetailResp struct {
+	ChartInfo            *chart_info.ChartInfoView
+	EdbInfoList          []*chart_edb_mapping.ChartEdbInfoMappingTimeString
+	XEdbIdValue          []int            `description:"柱方图的x轴数据,指标id"`
+	XDataList            []XData          `description:"商品价格曲线的X轴数据"`
+	YDataList            []YData          `description:"柱方图的y轴数据"`
+	CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
+	DataResp             interface{}      `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
+	WaterMark            string           `description:"水印"`
+}
+
 // XData 商品价格曲线的的x轴数据
 type XData struct {
 	Name   string `description:"别名"`

+ 26 - 0
models/tables/chart_edb_mapping/query.go

@@ -63,6 +63,32 @@ type ChartEdbInfoMappingList struct {
 	IsNullData bool `json:"-" description:"是否空数据"`
 }
 
+type ChartEdbInfoMappingTimeString struct {
+	ChartEdbInfoMapping
+	DataList       interface{}
+	IsNullData     bool                       `json:"-" description:"是否空数据"`
+	LatestDate     ChartLibEdbInfoMappingTime `description:"数据最新日期"`
+	MoveLatestDate ChartLibEdbInfoMappingTime `description:"移动后的数据最新日期"`
+}
+
+type ChartLibEdbInfoMappingTime struct {
+	time.Time
+}
+
+// 自定义时间解析规则
+func (ct *ChartLibEdbInfoMappingTime) UnmarshalJSON(data []byte) error {
+	s := string(data)
+	if s[0] == '"' {
+		s = s[1 : len(s)-1]
+	}
+	t, err := time.ParseInLocation(utils.FormatDate, s, time.Local)
+	if err != nil {
+		return err
+	}
+	ct.Time = t
+	return nil
+}
+
 // GetMappingListByChartInfoId 根据图表ID获取指标映射列表
 func GetMappingListByChartInfoId(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
 	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`

+ 15 - 15
models/tables/chart_info/query.go

@@ -12,21 +12,21 @@ type ChartInfoView struct {
 	ChartClassifyName string `description:"图表名称"`
 	SysUserId         int
 	SysUserRealName   string
-	UniqueCode        string `description:"图表唯一编码"`
-	CreateTime        time.Time
-	ModifyTime        time.Time
-	DateType          int    `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
-	StartDate         string `description:"自定义开始日期"`
-	EndDate           string `description:"自定义结束日期"`
-	IsSetName         int    `description:"设置名称"`
-	EdbInfoIds        string `description:"指标id"`
-	ChartType         int    `description:"生成样式:1:曲线图,2:季节性图"`
-	Calendar          string `description:"公历/农历"`
-	SeasonStartDate   string `description:"季节性图开始日期"`
-	SeasonEndDate     string `description:"季节性图开始日期"`
-	ChartImage        string `description:"图表图片"`
-	Sort              int    `description:"排序字段,数字越小越排前面"`
-	IsAdd             bool   `description:"true:已加入我的图库,false:未加入我的图库"`
+	UniqueCode        string    `description:"图表唯一编码"`
+	CreateTime        time.Time `json:"-"`
+	ModifyTime        time.Time `json:"-"`
+	DateType          int       `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
+	StartDate         string    `description:"自定义开始日期"`
+	EndDate           string    `description:"自定义结束日期"`
+	IsSetName         int       `description:"设置名称"`
+	EdbInfoIds        string    `description:"指标id"`
+	ChartType         int       `description:"生成样式:1:曲线图,2:季节性图"`
+	Calendar          string    `description:"公历/农历"`
+	SeasonStartDate   string    `description:"季节性图开始日期"`
+	SeasonEndDate     string    `description:"季节性图开始日期"`
+	ChartImage        string    `description:"图表图片"`
+	Sort              int       `description:"排序字段,数字越小越排前面"`
+	IsAdd             bool      `description:"true:已加入我的图库,false:未加入我的图库"`
 	MyChartId         int
 	MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
 	EdbEndDate        string `description:"指标最新更新日期"`

Dosya farkı çok büyük olduğundan ihmal edildi
+ 47 - 0
services/eta_chart_lib.go


+ 1 - 0
utils/constants.go

@@ -296,6 +296,7 @@ const (
 	CHART_SOURCE_LINE_FEATURE_PERCENTILE         = 8  // 统计特征-百分位图表
 	CHART_SOURCE_LINE_FEATURE_FREQUENCY          = 9  // 统计特征-频率分布图表
 	CHART_SOURCE_CROSS_HEDGING                   = 10 // 跨品种分析图表
+	CHART_SOURCE_BALANCE_EXCEL                   = 11 // 平衡表图表
 )
 
 // 图表类型

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor