瀏覽代碼

Merge branch 'feature/chart_add_unit'

xyxie 2 周之前
父節點
當前提交
cb378ab080

+ 222 - 0
controllers/business_chart.go

@@ -0,0 +1,222 @@
+package controllers
+
+import (
+	"eta/eta_hub/models"
+	"eta/eta_hub/models/data_manage"
+	"eta/eta_hub/services"
+	"eta/eta_hub/services/data"
+	"eta/eta_hub/utils"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type BusinessChartController struct {
+	BaseAuthController
+}
+
+// List
+// @Title 图表列表
+// @Description 图表列表
+// @Param   BusinessCode  query  string  true  "商家编码"
+// @Success 200 {object} data_manage.ChartInfoItem
+// @router /list [get]
+func (this *BusinessChartController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	businessCode := this.GetString("BusinessCode")
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+
+	if businessCode == "" {
+		br.Msg = "商家编码不允许为空"
+		return
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	if pageSize <= 0 {
+		pageSize = 100
+	}
+	startSize := utils.StartIndex(currentIndex, pageSize)
+
+	chartOb := new(data_manage.EtaBusinessChartPermission)
+		
+	total, err := chartOb.GetChartListByBusinessCodeTotal(businessCode)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartList GetItemTotal err: " + err.Error()
+		return
+	}
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+	resp := new(data_manage.BusinessChartInfoResp)
+	if total == 0 {
+		resp.List = make([]*data_manage.BusinessChartInfoView, 0)
+		resp.Paging = page
+
+		br.Data = resp
+		br.Ret = 200
+		br.Msg = "获取成功"
+		return
+	}
+
+	chartList, err := chartOb.GetChartListByBusinessCode(businessCode, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartList GetChartListByBusinessCode err: " + err.Error()
+		return
+	}
+	chartInfoIds := make([]int, 0)
+	for _, v := range chartList {
+		chartInfoIds = append(chartInfoIds, v.ChartInfoId)
+	}
+	descriptionList, err := chartOb.GetChartDescriptionListByChartInfoIds(chartInfoIds)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartList GetChartDescriptionListByChartInfoIds err: " + err.Error()
+		return
+	}
+	descriptionMap := make(map[int][]string)
+	for _, v := range descriptionList {
+		descriptionMap[v.ChartInfoId] = append(descriptionMap[v.ChartInfoId], v.Description)
+	}
+	edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfoIds)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartList GetChartEdbMappingList err: " + err.Error()
+		return
+	}
+	edbInfoIds := make([]int, 0)
+	chartMappingMap := make(map[int][]*data_manage.BusinessChartEdbListItem)
+	for _, v := range edbMappingList {
+		edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+	}
+	edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartList GetItemsByIdList err: " + e.Error()
+		return
+	}
+	edbInfoMap := make(map[int]*data_manage.BusinessChartEdbListItem)
+	// 根据chartInfoId 将edbInfoList 转换为chartMappingMap
+	for _, v := range edbInfoList {
+		endValue := v.EndValue
+		if v.EdbInfoType == 0 {
+			endValue = v.LatestValue
+		}
+		item := &data_manage.BusinessChartEdbListItem{
+			EdbInfoId: v.EdbInfoId,
+			EdbName: v.EdbName,
+			EdbCode: v.EdbCode,
+			EdbInfoType: v.EdbInfoType,
+			Frequency: v.Frequency,
+			Unit: v.Unit,
+			EndDate: v.EndDate,
+			EndValue: endValue,
+			LatestDate: v.LatestDate,
+			LatestValue: v.LatestValue,
+			UniqueCode: v.UniqueCode,
+		}
+		edbInfoMap[v.EdbInfoId] = item
+	}
+	for _, v := range edbMappingList {
+		item := edbInfoMap[v.EdbInfoId]
+		chartMappingMap[v.ChartInfoId] = append(chartMappingMap[v.ChartInfoId], item)
+	}
+
+	for _, v := range chartList {
+		v.EdbInfoList = chartMappingMap[v.ChartInfoId]
+		description, ok := descriptionMap[v.ChartInfoId]
+		if !ok {
+			v.Description = make([]string, 0)
+		} else {
+			v.Description = description
+		}
+	}
+
+	resp.List = chartList
+	resp.Paging = page
+
+	br.Data = resp
+	br.Ret = 200
+	br.Msg = "获取成功"
+}
+
+// ChartEdbDataList
+// @Title 图表指标数据列表
+// @Description 图表指标数据列表
+// @Param   EdbCode   query   string  true       "指标编码"
+// @Success 200 {object} data_manage.EdbInfoDataResp
+// @router /edb/data [get]
+func (this *BusinessChartController) ChartEdbDataList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	edbInfoCode := this.GetString("EdbCode")
+	if edbInfoCode == "" {
+		br.Msg = "参数有误"
+		return
+	}
+	edbOb := new(data_manage.EdbInfo)
+	edbInfo, e := edbOb.GetItemByEdbCode(edbInfoCode)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "指标不存在"
+			return
+		}
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartEdbDataList GetItemByEdbCode err: " + e.Error()
+		return
+	}
+
+	edbDataList, e := services.GetEdbInfoDataList(edbInfo)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "ChartEdbDataList GetEdbInfoDataList err: " + e.Error()
+		return
+	}
+
+	br.Data = edbDataList
+	br.Ret = 200
+	br.Msg = "获取成功"
+
+}
+
+// TraceEdbInfo
+// @Title 指标溯源接口
+// @Description 指标溯源接口
+// @Param   EdbInfoId   query   int  true       "指标id"
+// @Success 200 {object} data_manage.ChartListResp
+// @router /edb/trace [get]
+func (this *BusinessChartController) TraceEdbInfo() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	edbInfoId, _ := this.GetInt("EdbInfoId")
+	edbInfoCode := this.GetString("EdbCode")
+	if edbInfoId <= 0 && edbInfoCode == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+
+	resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId, edbInfoCode)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.Msg = "获取失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Data = resp
+	br.Msg = "刷新成功"
+}

+ 3 - 2
controllers/edb.go

@@ -350,13 +350,14 @@ func (this *EdbInfoController) TraceEdbInfo() {
 	}()
 
 	edbInfoId, _ := this.GetInt("EdbInfoId")
-	if edbInfoId <= 0 {
+	edbInfoCode := this.GetString("EdbCode")
+	if edbInfoId <= 0 && edbInfoCode == "" {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误"
 		return
 	}
 
-	resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId)
+	resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId, edbInfoCode)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.Msg = "获取失败,Err:" + err.Error()

+ 16 - 0
models/data_manage/chart_edb_mapping.go

@@ -1,5 +1,11 @@
 package data_manage
 
+import (
+	"eta/eta_hub/utils"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
 type ChartEdbInfoMapping struct {
 	EdbInfoId           int     `description:"指标id"`
 	SourceName          string  `description:"来源名称"`
@@ -51,3 +57,13 @@ type ChartEdbInfoMapping struct {
 	ConvertUnit       string    `description:"数据转换单位"`
 	ConvertEnUnit     string    `description:"数据转换单位"`
 }
+
+func GetChartEdbMappingList(chartInfoIds []int) (mappingList []*ChartEdbInfoMapping, err error) {
+	o := orm.NewOrmUsingDB("data")
+	
+	sql := `
+		SELECT * FROM chart_edb_mapping WHERE chart_info_id in (`+utils.GetOrmInReplace(len(chartInfoIds))+`)
+	`
+	_, err = o.Raw(sql, chartInfoIds).QueryRows(&mappingList)
+	return
+}

+ 15 - 0
models/data_manage/chart_info.go

@@ -479,3 +479,18 @@ type ChartDetailApiResponse struct {
 	ErrMsg string
 	Data   *ChartInfoDetailResp
 }
+
+
+func GetChartInfoByUniqueCode(uniqueCode string) (chartInfo *ChartInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	
+	sql := `
+		SELECT * FROM chart_info WHERE unique_code = ?
+	`
+	err = o.Raw(sql, uniqueCode).QueryRow(&chartInfo)
+	if err != nil {
+		return nil, err
+	}
+	
+	return chartInfo, nil
+}

+ 2 - 0
models/data_manage/edb_info.go

@@ -24,6 +24,7 @@ type EdbInfo struct {
 	UnitEn           string    `description:"英文单位"`
 	StartDate        string    `description:"起始日期"`
 	EndDate          string    `description:"终止日期"`
+	EndValue         float64   `description:"终止值"`
 	ClassifyId       int       `description:"分类ID"`
 	SysUserId        int       `description:"创建人ID"`
 	SysUserRealName  string    `description:"创建人姓名"`
@@ -182,6 +183,7 @@ func FormatEdbInfo2Item(origin *EdbInfo) (item *EdbInfoItem) {
 // TraceEdbInfoResp 指标追溯数据返回
 type TraceEdbInfoResp struct {
 	EdbInfoId   int                `description:"指标id"`
+	EdbCode     string             `description:"指标编码"`
 	EdbInfoType int                `description:"指标类型: 0-普通指标; 1-预测指标"`
 	EdbName     string             `description:"指标名称"`
 	EdbType     int                `description:"指标类型: 1-基础指标; 2-计算指标"`

+ 127 - 0
models/data_manage/eta_business_chart_permission.go

@@ -0,0 +1,127 @@
+package data_manage
+
+import (
+	"eta/eta_hub/utils"
+	"fmt"
+	"time"
+
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+// EtaBusinessChartPermission 商家图表权限表
+type EtaBusinessChartPermission struct {
+	EtaBusinessChartPermissionId int64     `orm:"column(eta_business_chart_permission_id);pk;auto"`
+	ChartInfoId                  int       `orm:"column(chart_info_id)" description:"图表id"`
+	Source                       int       `orm:"column(source)" description:"分类来源: 1-图库; 2-商品价格曲线; 3-相关性图表; 6-拟合方程图表; 7-统计特征"`
+	BusinessCode                 string    `orm:"column(business_code)" description:"客户编码"`
+	EtaBusinessId                int       `orm:"column(eta_business_id)" description:"商家ID"`
+	ModifyTime                   time.Time `orm:"column(modify_time);type(datetime);null" description:"变更时间"`
+	CreateTime                   time.Time `orm:"column(create_time);type(datetime);null" description:"关系建立时间"`
+}
+
+// TableName 设置表名
+func (m *EtaBusinessChartPermission) TableName() string {
+	return "eta_business_chart_permission"
+}
+
+type BusinessChartInfoView struct {
+	ChartInfoId int
+	ChartName string
+	UniqueCode string	
+	Description []string
+	EdbInfoList []*BusinessChartEdbListItem
+}
+	
+// GetChartListByBusinessCode 根据商家编码获取图表列表
+func (m *EtaBusinessChartPermission) GetChartListByBusinessCode(businessCode string, startSize int, pageSize int) ([]*BusinessChartInfoView, error) {
+	if businessCode == "" {
+		return nil, fmt.Errorf("business code cannot be empty")
+	}
+
+	var chartList []*BusinessChartInfoView
+	o := orm.NewOrmUsingDB("data")
+
+	// 构建SQL查询
+	sql := `
+		SELECT 
+			c.chart_info_id, c.chart_name, c.unique_code
+		FROM 
+			eta_business_chart_permission p
+		JOIN 
+			chart_info c ON p.chart_info_id = c.chart_info_id
+		WHERE 
+			p.business_code = ? 
+		ORDER BY 
+			c.sort ASC, c.chart_info_id DESC
+		LIMIT ?, ?
+	`
+
+	_, err := o.Raw(sql, businessCode, startSize, pageSize).QueryRows(&chartList)
+	if err != nil {
+		return nil, fmt.Errorf("failed to get chart list: %v", err)
+	}
+
+	return chartList, nil
+}
+
+func (m *EtaBusinessChartPermission) GetChartListByBusinessCodeTotal(businessCode string) (int64, error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `
+		SELECT COUNT(*) FROM eta_business_chart_permission p
+		JOIN 
+			chart_info c ON p.chart_info_id = c.chart_info_id
+		WHERE 
+			p.business_code = ?
+	`
+	var total int64
+	err := o.Raw(sql, businessCode).QueryRow(&total)
+	if err != nil {
+		return 0, fmt.Errorf("failed to get chart list total: %v", err)
+	}
+	return total, nil
+}
+
+// Init 初始化表结构
+func init() {
+	orm.RegisterModel(new(EtaBusinessChartPermission))
+}
+
+
+type BusinessChartInfoResp struct {
+	List []*BusinessChartInfoView
+	Paging *paging.PagingItem
+}
+
+type BusinessChartEdbListResp struct {
+	List []*BusinessChartEdbListItem
+}
+
+type BusinessChartEdbListItem struct {
+	EdbInfoId int
+	EdbCode string
+	EdbName string
+	EdbInfoType int
+	Frequency string
+	Unit string
+	EndDate string
+	EndValue float64
+	LatestDate string
+	LatestValue float64
+	UniqueCode string
+}
+
+type ChartDescription struct {
+	ChartInfoId int
+	Description string
+}
+
+// 查询图表描述列表
+func (m *EtaBusinessChartPermission) GetChartDescriptionListByChartInfoIds(chartInfoIds []int) (list []*ChartDescription, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `
+		SELECT * FROM chart_description WHERE chart_info_id IN (`+utils.GetOrmInReplace(len(chartInfoIds))+`)
+	`
+	_, err = o.Raw(sql, chartInfoIds).QueryRows(&list)
+	return list, err
+}

+ 27 - 0
routers/commentsRouter.go

@@ -7,6 +7,33 @@ import (
 
 func init() {
 
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:BusinessChartController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:BusinessChartController"],
+        beego.ControllerComments{
+            Method: "ChartEdbDataList",
+            Router: `/edb/data`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:BusinessChartController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:BusinessChartController"],
+        beego.ControllerComments{
+            Method: "TraceEdbInfo",
+            Router: `/edb/trace`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:BusinessChartController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:BusinessChartController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_hub/controllers:ChartController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:ChartController"],
         beego.ControllerComments{
             Method: "ClassifyList",

+ 5 - 0
routers/router.go

@@ -88,6 +88,11 @@ func init() {
 				&controllers.SandboxController{},
 			),
 		),
+		web.NSNamespace("/business_chart",
+			web.NSInclude(
+				&controllers.BusinessChartController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 124 - 8
services/data/edb_info.go

@@ -6,22 +6,35 @@ import (
 	"eta/eta_hub/models/data_manage"
 	"eta/eta_hub/utils"
 	"fmt"
+	"sort"
 	"strings"
 	"time"
 )
 
 // TraceEdbInfoByEdbInfoId 指标追溯
-func TraceEdbInfoByEdbInfoId(edbInfoId int) (traceEdbInfo data_manage.TraceEdbInfoResp, err error) {
-	edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
-	if err != nil {
-		return
+func TraceEdbInfoByEdbInfoId(edbInfoId int, edbInfoCode string) (traceEdbInfo data_manage.TraceEdbInfoResp, err error) {
+	var edbInfo *data_manage.EdbInfo
+	edbInfoOb := new(data_manage.EdbInfo)
+	if edbInfoId > 0 {
+		edbInfo, err = data_manage.GetEdbInfoById(edbInfoId)
+		if err != nil {
+			return
+		}
+	}else if edbInfoCode != "" {
+		edbInfo, err = edbInfoOb.GetItemByEdbCode(edbInfoCode)
+		if err != nil {
+			return
+		}
+		edbInfoId = edbInfo.EdbInfoId
 	}
+	
 	edbInfoRuleMap := make(map[int]string, 0)
 	edbMappingMap := make(map[int][]*data_manage.EdbInfoCalculateMappingInfo)
 	//edbInfoRuleMap[edbInfoId] = getEdbRuleTitle(edbInfo)
 	traceEdbInfo = data_manage.TraceEdbInfoResp{
 		//EdbInfoId: edbInfo.EdbInfoId,
 		EdbInfoId:   edbInfoId,
+		EdbCode: edbInfo.EdbCode,
 		EdbInfoType: edbInfo.EdbInfoType,
 		EdbName:     edbInfo.EdbName,
 		EdbType:     edbInfo.EdbType,
@@ -88,6 +101,7 @@ func traceEdbInfoByEdbInfoId(edbInfoId int, traceEdbInfo data_manage.TraceEdbInf
 		tmpEdbInfoId := v.FromEdbInfoId
 		tmpTraceEdbInfo := data_manage.TraceEdbInfoResp{
 			EdbInfoId:   tmpEdbInfoId,
+			EdbCode:     v.FromEdbCode,
 			EdbInfoType: v.FromEdbInfoType,
 			EdbType:     v.FromEdbType,
 			UniqueCode:  v.FromUniqueCode,
@@ -130,7 +144,7 @@ func handleTraceEdbInfo(traceEdbInfoResp data_manage.TraceEdbInfoResp, parentEdb
 	}
 
 	//traceEdbInfoResp.EdbName = edbInfo.EdbName
-	traceEdbInfoResp.EdbName, traceEdbInfoResp.RuleTitle = getEdbRuleTitle(edbInfo, parentEdbInfo, traceEdbInfoResp.Child, edbInfoMap, edbMappingMap)
+	traceEdbInfoResp.EdbName, _, traceEdbInfoResp.RuleTitle, _ = getEdbRuleTitle(edbInfo, parentEdbInfo, traceEdbInfoResp.Child, edbInfoMap, edbMappingMap)
 
 	if traceEdbInfoResp.Child != nil && len(traceEdbInfoResp.Child) > 0 {
 		for k, v := range traceEdbInfoResp.Child {
@@ -146,9 +160,11 @@ func handleTraceEdbInfo(traceEdbInfoResp data_manage.TraceEdbInfoResp, parentEdb
 }
 
 // getEdbRule 获取规则名称
-func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []data_manage.TraceEdbInfoResp, edbInfoMap map[int]*data_manage.EdbInfo, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (edbName, ruleTitle string) {
+func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []data_manage.TraceEdbInfoResp, edbInfoMap map[int]*data_manage.EdbInfo, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (edbName, edbNameEn, ruleTitle, ruleTitleEn string) {
 	edbName = edbInfo.EdbName
+	edbNameEn = edbInfo.EdbNameEn
 	ruleTitle = `来源于` + edbInfo.SourceName
+	ruleTitleEn = `Source From: ` + edbInfo.SourceName
 
 	if parentEdbInfo != nil {
 		edbMappingList, ok := edbMappingMap[parentEdbInfo.EdbInfoId]
@@ -161,6 +177,7 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 			for _, v := range edbMappingList {
 				if v.FromEdbInfoId == edbInfo.EdbInfoId {
 					edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
+					edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, v.FromTag)
 				}
 			}
 
@@ -168,12 +185,16 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 			for _, v := range edbMappingList {
 				if v.FromEdbInfoId == edbInfo.EdbInfoId {
 					tmpName := ``
+					tmpNameEn := ``
 					if v.FromTag == `A` {
 						tmpName = `拼接日期前`
+						tmpNameEn = `Before Concatenation Date:`
 					} else if v.FromTag == `B` {
 						tmpName = `拼接日期后`
+						tmpNameEn = `After Concatenation Date:`
 					}
 					edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
+					edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, tmpNameEn)
 				}
 			}
 		case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
@@ -181,18 +202,23 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 				//(需对上游指标+自变量,领先10天/因变量)
 				if v.FromEdbInfoId == edbInfo.EdbInfoId {
 					tmpName := ``
+					tmpNameEn := ``
 					if v.FromTag == `A` {
 						tmpName = fmt.Sprintf(`自变量,领先%d天`, v.MoveValue)
+						tmpNameEn = fmt.Sprintf(`Independent Variable, Lead %d Days:`, v.MoveValue)
 					} else if v.FromTag == `B` {
 						tmpName = `因变量`
+						tmpNameEn = `Dependent Variable`
 					}
 					edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
+					edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, tmpNameEn)
 				}
 			}
 		case utils.DATA_SOURCE_CALCULATE_CORRELATION: // 滚动相关性
 			for _, v := range edbMappingList {
 				if v.FromEdbInfoId == edbInfo.EdbInfoId {
 					edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
+					edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, v.FromTag)
 				}
 			}
 
@@ -210,42 +236,55 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 	// 规则
 	switch edbInfo.Source {
 	case utils.DATA_SOURCE_CALCULATE, utils.DATA_SOURCE_PREDICT_CALCULATE:
-		ruleTitle = "=" + edbInfo.CalculateFormula
+		ruleTitle = formatCalculateFormula(edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_LJZZY, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
 		ruleTitle = `累计转月值计算`
+		ruleTitleEn = `Cumulative to Monthly Calculation`
 	case utils.DATA_SOURCE_CALCULATE_TBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
 		ruleTitle = `同比值计算`
+		ruleTitleEn = `Year-on-Year Value Calculation`
 	case utils.DATA_SOURCE_CALCULATE_TCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
 		ruleTitle = `同差值计算`
+		ruleTitleEn = `Yearly Difference Calculation`
 	case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS, utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
 		ruleTitle = fmt.Sprintf("N数值移动均值计算(N=%s)", edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("N-Value Moving Average Calculation(N=%s)", edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_HBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
 		ruleTitle = fmt.Sprintf("N数值环比值计算(N=%s)", edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("N-Value Sequential Comparison Calculation(N=%s)", edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_HCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
 		ruleTitle = fmt.Sprintf("N数值环差值计算(N=%s)", edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("N-Value Sequential Difference Calculation(N=%s)", edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT, utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
 		moveType := `领先`
+		moveTypeEn := `Lead`
 		if edbInfo.MoveType == 2 {
 			moveType = "滞后"
+			moveTypeEn = `Lag`
 		}
 		ruleTitle = fmt.Sprintf("时间移位计算(%s%s%s)", moveType, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
+		ruleTitleEn = fmt.Sprintf("Time Shift Calculation(%s%s%s)", moveTypeEn, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
 	case utils.DATA_SOURCE_CALCULATE_BP, utils.DATA_SOURCE_PREDICT_CALCULATE_BP: // 变频
 		childFrequency := ``
 		if len(childList) > 0 {
 			if childEdbInfo, ok := edbInfoMap[childList[0].EdbInfoId]; ok {
 				childFrequency = childEdbInfo.Frequency
 			}
-
 		}
 		ruleTitle = fmt.Sprintf("升频计算(%s转%s)", childFrequency, edbInfo.Frequency)
+		ruleTitleEn = fmt.Sprintf("Upsampling Calculation(%s转%s)", childFrequency, edbInfo.Frequency)
 	case utils.DATA_SOURCE_CALCULATE_ZJPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ: // 直接拼接
 		ruleTitle = fmt.Sprintf("直接拼接计算(%s)", edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("Direct Concatenation Calculation(%s)", edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_LJZTBPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ: // 累计值同比拼
 		ruleTitle = fmt.Sprintf("累计值同比值拼接计算(%s)", edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("Cumulative Year-on-Year Concatenation Calculation(%s)", edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_PYTHON:
 		ruleTitle = `代码运算`
+		ruleTitleEn = `Code Computation`
 	case utils.DATA_SOURCE_CALCULATE_CJJX, utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
 		ruleTitle = fmt.Sprintf("超季节性计算(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
+		ruleTitleEn = fmt.Sprintf("Super Seasonality Calculation(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
 	case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
 		var startDate, endDate string
 		dateList := strings.Split(edbInfo.CalculateFormula, ",")
@@ -254,10 +293,13 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 			endDate = dateList[1]
 		}
 		ruleTitle = fmt.Sprintf("拟合残差计算(%s至%s)", startDate, endDate)
+		ruleTitleEn = fmt.Sprintf("Fit Residual Calculation(%s至%s)", startDate, endDate)
 	case utils.DATA_SOURCE_CALCULATE_ADJUST:
 		ruleTitle = `数据调整`
+		ruleTitleEn = `Data Adjustment`
 	case utils.DATA_SOURCE_CALCULATE_NH, utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
 		ruleTitle = `年化计算`
+		ruleTitleEn = `Annualization Calculation`
 	case utils.DATA_SOURCE_CALCULATE_KSZS, utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS: // 扩散指数->53
 		type KszsConfig struct {
 			DateType  int      `description:"扩散指标日期;1:全部指标日期并集;2:部分指标日期并集"`
@@ -313,8 +355,10 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 			}
 		}
 		ruleTitle = fmt.Sprintf("扩散指数计算(%s至%s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
+		ruleTitleEn = fmt.Sprintf("Diffusion Index Calculation(%s to %s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
 	case utils.DATA_SOURCE_STOCK_PLANT:
 		ruleTitle = `来源于装置分析`
+		ruleTitleEn = `Derived from Plant Analysis`
 	case utils.DATA_SOURCE_CALCULATE_CORRELATION:
 		type EdbCalculateFormula struct {
 			BaseCalculateValue int    `description:"基础计算窗口"`
@@ -330,6 +374,7 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 			return
 		}
 		ruleTitle = fmt.Sprintf("滚动相关性(计算窗口%d%s,B领先A%d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
+		ruleTitleEn = fmt.Sprintf("Rolling Correlation (Calculation Window %d%s, B Leads A %d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
 	case utils.DATA_SOURCE_CALCULATE_JP, utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
 		childFrequency := ``
 		if len(childList) > 0 {
@@ -339,8 +384,10 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 
 		}
 		ruleTitle = fmt.Sprintf("降频计算(%s转%s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("Downsampling Calculation(%s to %s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION:
 		ruleTitle = fmt.Sprintf("标准差(滚动%s期)", edbInfo.CalculateFormula)
+		ruleTitleEn = fmt.Sprintf("Standard Deviation (Rolling %s Periods)", edbInfo.CalculateFormula)
 	case utils.DATA_SOURCE_CALCULATE_PERCENTILE, utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE:
 		type TempCalculate struct {
 			CalculateValue int    `description:"计算窗口"`
@@ -351,9 +398,78 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
 			return
 		}
 		ruleTitle = fmt.Sprintf("百分位(时间长度%d%s)", cf.CalculateValue, cf.CalculateUnit)
+		ruleTitle = fmt.Sprintf("Percentile (Time Length %d%s)", cf.CalculateValue, cf.CalculateUnit)
 	case utils.DATA_SOURCE_CALCULATE_ZSXY, utils.DATA_SOURCE_PREDICT_CALCULATE_ZSXY:
 		ruleTitle = `指数修匀计算`
+		ruleTitle = `Index Smoothing Calculation`
 	}
 
 	return
 }
+
+func formatCalculateFormula(calculateFormula string) (ruleTitle string) {
+	var tmpCalculateFormula []map[string]string
+	if e := json.Unmarshal([]byte(calculateFormula), &tmpCalculateFormula); e != nil {
+		ruleTitle = "=" + calculateFormula
+		return
+	}
+	newCalculateFormula := make([]map[string]string, 0)
+	sort.Slice(tmpCalculateFormula, func(i, j int) bool {
+		return compareDates(tmpCalculateFormula[i]["d"], tmpCalculateFormula[j]["d"])
+	})
+
+	for i, entry := range tmpCalculateFormula {
+		if formula, ok := entry["f"]; ok {
+			singleFormula := make(map[string]string)
+			singleFormula["公式"] = formula
+			singleFormula["日期"] = determineDateRange(i, len(tmpCalculateFormula), tmpCalculateFormula)
+			newCalculateFormula = append(newCalculateFormula, singleFormula)
+		}
+
+	}
+	if b, e := json.Marshal(newCalculateFormula); e != nil {
+		ruleTitle = "=" + calculateFormula
+	} else {
+		ruleTitle = "=" + string(b)
+	}
+	return
+}
+
+// compareDates 日期比较 date1 < date2 --> true
+func compareDates(date1, date2 string) bool {
+	if date1 == "" {
+		return true
+	}
+	if date2 == "" {
+		return false
+	}
+
+	date1Parsed, err := time.Parse(utils.FormatDate, date1)
+	if err != nil {
+		return false
+	}
+	date2Parsed, err := time.Parse(utils.FormatDate, date2)
+	if err != nil {
+		return false
+	}
+
+	return date1Parsed.Before(date2Parsed)
+}
+
+func determineDateRange(index, totalLength int, formulas []map[string]string) string {
+	if totalLength == 1 {
+		return "全部"
+	}
+
+	currentDate := formulas[index]["d"]
+	if index == 0 {
+		return formulas[totalLength-1]["d"] + "(含)之后"
+	}
+	if index == totalLength-1 {
+		return formulas[1]["d"] + "之前"
+	}
+	if index >= 1 && index < totalLength-1 {
+		return fmt.Sprintf("%s(含)——%s", currentDate, formulas[index+1]["d"])
+	}
+	return ""
+}

+ 22 - 0
services/edb_info.go

@@ -0,0 +1,22 @@
+package services
+
+import (
+	"eta/eta_hub/models/data_manage"
+	"fmt"
+)
+
+func GetEdbInfoDataList(edbInfo *data_manage.EdbInfo) (edbData []*data_manage.EdbDataItem, err error) {
+	// 获取指标数据
+	dataOb := new(data_manage.EdbData)
+	dataList, e := dataOb.GetItemsBySourceAndCode(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, edbInfo.StartDate, []string{}, "")
+	if e != nil {
+		err = fmt.Errorf("获取失败,Err:" + e.Error())
+		return
+	}
+	edbData = make([]*data_manage.EdbDataItem, 0)
+	for _, v := range dataList {
+		edbData = append(edbData, data_manage.FormatEdbData2Item(v))
+	}
+
+	return
+}