浏览代码

初始化指标分类

xyxie 9 月之前
父节点
当前提交
574b0411e7

+ 48 - 0
models/data_manage/chart_edb_mapping.go

@@ -0,0 +1,48 @@
+package data_manage
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type ChartEdbMapping struct {
+	ChartEdbMappingId int       `orm:"column(chart_edb_mapping_id);pk"`
+	ChartInfoId       int       `description:"图表id"`
+	EdbInfoId         int       `description:"指标id"`
+	CreateTime        time.Time `description:"创建时间"`
+	ModifyTime        time.Time `description:"修改时间"`
+	UniqueCode        string    `description:"唯一编码"`
+	MaxData           float64   `description:"上限"`
+	MinData           float64   `description:"下限"`
+	IsOrder           bool      `description:"true:正序,false:逆序"`
+	IsAxis            int       `description:"true:左轴,false:右轴"`
+	EdbInfoType       int       `description:"true:标准指标,false:领先指标"`
+	LeadValue         int       `description:"领先值"`
+	LeadUnit          string    `description:"领先单位"`
+	ChartStyle        string    `description:"图表类型"`
+	ChartColor        string    `description:"颜色"`
+	PredictChartColor string    `description:"预测数据的颜色"`
+	ChartWidth        float64   `description:"线条大小"`
+	Source            int       `description:"1:ETA图库;2:商品价格曲线"`
+	EdbAliasName      string    `description:"中文别名"`
+	IsConvert         int       `description:"是否数据转换 0不转 1转"`
+	ConvertType       int       `description:"数据转换类型 1乘 2除 3对数"`
+	ConvertValue      float64   `description:"数据转换值"`
+	ConvertUnit       string    `description:"数据转换单位"`
+	ConvertEnUnit     string    `description:"数据转换单位"`
+}
+
+func GetChartEdbMappingTotal() (total int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT COUNT(1) AS count FROM chart_edb_mapping `
+	err = o.Raw(sql).QueryRow(&total)
+	return
+}
+
+func GetChartEdbMappingList(startSize, pageSize int) (items []*ChartEdbMapping, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM chart_edb_mapping WHERE 1=1 `
+	sql += " LIMIT ?,? "
+	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 10 - 0
models/data_manage/chart_info.go

@@ -1,6 +1,7 @@
 package data_manage
 
 import (
+	"eta/eta_task/utils"
 	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
@@ -26,6 +27,7 @@ type ChartInfo struct {
 	ChartImage      string `description:"图表图片"`
 	Sort            int    `description:"排序字段,数字越小越排前面"`
 	EdbEndDate      string `description:"指标最后更新日期"`
+	Source          int    `description:"1:ETA图库;2:商品价格曲线"`
 }
 
 func GetAllChartInfo() (list []*ChartInfo, err error) {
@@ -51,3 +53,11 @@ func ModifyChartInfoEdbEndDate(chartInfoId int, edbEndDate string) (err error) {
 	_, err = o.Raw(sql, edbEndDate, chartInfoId).Exec()
 	return
 }
+
+// 根据chart_info_id数组获取图表信息
+func GetChartInfoByChartInfoIds(chartInfoIds []int) (list []*ChartInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM chart_info  WHERE chart_info_id IN (` + utils.GetOrmInReplace(len(chartInfoIds)) + `) `
+	_, err = o.Raw(sql, chartInfoIds).QueryRows(&list)
+	return
+}

+ 34 - 0
models/data_manage/cross_variety/chart_info_cross_variety.go

@@ -0,0 +1,34 @@
+package cross_variety
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// ChartInfoCrossVariety
+// @Description: 跨品种分析配置表
+type ChartInfoCrossVariety struct {
+	Id             int       `orm:"column(id);pk"`
+	ChartInfoId    int       `description:"图表id"`
+	ChartXTagId    int       `description:"X轴的标签ID"`
+	ChartYTagId    int       `description:"X轴的标签ID"`
+	CalculateValue int       `description:"计算窗口"`
+	CalculateUnit  string    `description:"计算频度"`
+	ModifyTime     time.Time `description:"修改时间"`
+	CreateTime     time.Time `description:"创建时间"`
+}
+
+func GetChartInfoCrossVarietyList(startSize, pageSize int) (items []*ChartInfoCrossVariety, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM chart_info_cross_variety WHERE 1=1 `
+	sql += " LIMIT ?,? "
+	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+func GetChartInfoCrossVarietyTotal() (total int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT count(*) FROM chart_info_cross_variety`
+	err = o.Raw(sql).QueryRow(&total)
+	return
+}

+ 27 - 0
models/data_manage/cross_variety/chart_tag_variety.go

@@ -0,0 +1,27 @@
+package cross_variety
+
+import (
+	"eta/eta_task/utils"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// ChartTagVariety
+// @Description: chart_tag_variety 图表标签品种关系表
+type ChartTagVariety struct {
+	Id                        int       `orm:"column(id);pk"`
+	ChartTagId                int       `description:"标签id"`
+	ChartVarietyId            int       `description:"品种id"`
+	EdbInfoId                 int       `description:"指标id"`
+	LastUpdateSysUserId       int       `description:"最后一次操作人"`
+	LastUpdateSysUserRealName string    `description:"最后一次操作人真实姓名"`
+	ModifyTime                time.Time `description:"修改时间"`
+	CreateTime                time.Time `description:"创建时间"`
+}
+
+func GetChartTagVarietyEdbInfoIdsByTagIds(chartTagIds []int) (items []*ChartTagVariety, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM chart_tag_variety WHERE chart_tag_id in (` + utils.GetOrmInReplace(len(chartTagIds)) + `)`
+	_, err = o.Raw(sql, chartTagIds).QueryRows(&items)
+	return
+}

+ 8 - 0
models/data_manage/edb_info.go

@@ -350,3 +350,11 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
 	}
 	return
 }
+
+// GetEdbInfoByIdListAndSource 根据指标id集合 获取 指标列表
+func GetEdbInfoByIdListAndSource(edbInfoIdList []int, source []int) (items []*EdbInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIdList)) + `)  AND source in (` + utils.GetOrmInReplace(len(source)) + `)`
+	_, err = o.Raw(sql, edbInfoIdList, source).QueryRows(&items)
+	return
+}

+ 25 - 8
models/data_manage/edb_info_relation.go

@@ -7,20 +7,29 @@ import (
 )
 
 type EdbInfoRelation struct {
-	EdbInfoRelationId int       `orm:"column(edb_info_relation_id);pk"`
-	EdbInfoId         int       `description:"指标id"`
-	Source            int       `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,9:手工指标,10:隆众"`
-	EdbName           string    `description:"指标名称"`
-	ReferObjectId     int       `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
-	ReferObjectType   int       `description:"引用对象ID类型(1.图表,2.ETA逻辑)"`
-	CreateTime        time.Time `description:"创建时间"`
-	ModifyTime        time.Time `description:"修改时间"`
+	EdbInfoRelationId  int       `orm:"column(edb_info_relation_id);pk"`
+	EdbInfoId          int       `description:"指标id"`
+	Source             int       `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,9:手工指标,10:隆众"`
+	EdbName            string    `description:"指标名称"`
+	EdbCode            string    `description:"指标编码"`
+	ReferObjectId      int       `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
+	ReferObjectType    int       `description:"引用对象ID类型(1.图表,2.ETA逻辑)"`
+	ReferObjectSubType int       `description:"引用对象子类"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	RelationTime       time.Time `description:"引用时间"`
 }
 
 func (e *EdbInfoRelation) TableName() string {
 	return "edb_info_relation"
 }
 
+func AddEdbInfoRelationMulti(items []*EdbInfoRelation) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
 // GetEdbInfoRelationByEdbInfoIds 查询引用的指标ID
 func GetEdbInfoRelationByEdbInfoIds(edbInfoIds []int) (edbIds []int, err error) {
 	o := orm.NewOrmUsingDB("data")
@@ -31,3 +40,11 @@ func GetEdbInfoRelationByEdbInfoIds(edbInfoIds []int) (edbIds []int, err error)
 	}
 	return
 }
+
+// GetEdbInfoRelationByReferObjectIds 查询引用的指标ID
+func GetEdbInfoRelationByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
+	o := orm.NewOrmUsingDB("data")
+	msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
+	_, err = o.Raw(msql, referObjectIds, referObjectType).QueryRows(&items)
+	return
+}

+ 2 - 0
models/db.go

@@ -127,6 +127,8 @@ func initEdbDataTable() {
 		new(data_manage.BaseFromIcpiClassify),
 		new(data_manage.BaseFromIcpiData),
 		new(data_manage.BusinessSysInteractionLog), // 商家系统交互记录表
+
+		new(data_manage.EdbInfoRelation), //指标引用关联表
 	)
 }
 

+ 117 - 0
models/fe_calendar/fe_calendar_matter.go

@@ -0,0 +1,117 @@
+package fe_calendar
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+const (
+	MatterTypeFree    = 1 // 事项类型-自定义事项
+	MatterTypeEdb     = 2 // 事项类型-基础指标
+	MatterTypePredict = 3 // 事项类型-预测指标
+)
+
+// FeCalendarMatter 外汇日历-事项表
+type FeCalendarMatter struct {
+	FeCalendarMatterId  int       `orm:"column(fe_calendar_matter_id);pk" description:"事项ID"`
+	ChartPermissionId   int       `description:"品种ID"`
+	ChartPermissionName string    `description:"品种名称"`
+	MatterMonth         string    `description:"事项年月:格式2006-01"`
+	MatterDate          time.Time `description:"事项日期"`
+	Title               string    `description:"标题"`
+	MatterType          int       `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
+	EdbInfoId           int       `description:"指标ID"`
+	EdbUniqueCode       string    `description:"指标唯一编码"`
+	EdbCode             string    `description:"指标编码"`
+	FontColor           string    `description:"字体颜色"`
+	FillingColor        string    `description:"填充颜色"`
+	FontBold            int       `description:"字体加粗:0-否;1-是"`
+	Sort                int       `description:"排序"`
+	SysUserId           int       `description:"创建人ID"`
+	SysUserName         string    `description:"创建人姓名"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"更新时间"`
+}
+
+var FeCalendarMatterCols = struct {
+	FeCalendarMatterId  string
+	ChartPermissionId   string
+	ChartPermissionName string
+	MatterMonth         string
+	MatterDate          string
+	Title               string
+	MatterType          string
+	EdbInfoId           string
+	EdbUniqueCode       string
+	EdbCode             string
+	FontColor           string
+	FillingColor        string
+	FontBold            string
+	Sort                string
+	SysUserId           string
+	SysUserName         string
+	CreateTime          string
+	ModifyTime          string
+}{
+	FeCalendarMatterId:  "fe_calendar_matter_id",
+	ChartPermissionId:   "chart_permission_id",
+	ChartPermissionName: "chart_permission_name",
+	MatterMonth:         "matter_month",
+	MatterDate:          "matter_date",
+	Title:               "title",
+	MatterType:          "matter_type",
+	EdbInfoId:           "edb_info_id",
+	EdbUniqueCode:       "edb_unique_code",
+	EdbCode:             "edb_code",
+	FontColor:           "font_color",
+	FillingColor:        "filling_color",
+	FontBold:            "font_bold",
+	Sort:                "sort",
+	SysUserId:           "sys_user_id",
+	SysUserName:         "sys_user_name",
+	CreateTime:          "create_time",
+	ModifyTime:          "modify_time",
+}
+
+func (m *FeCalendarMatter) TableName() string {
+	return "fe_calendar_matter"
+}
+
+func (m *FeCalendarMatter) PrimaryId() string {
+	return FeCalendarMatterCols.FeCalendarMatterId
+}
+
+func (m *FeCalendarMatter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FeCalendarMatter, err error) {
+	o := orm.NewOrmUsingDB("data")
+	order := ``
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+func (m *FeCalendarMatter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *FeCalendarMatter) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FeCalendarMatter, err error) {
+	o := orm.NewOrmUsingDB("data")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 91 - 0
models/sandbox/sandbox.go

@@ -0,0 +1,91 @@
+package sandbox
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// Sandbox 沙盘推演主表
+//type Sandbox struct {
+//	SandboxId           int       `orm:"column(sandbox_id);pk" description:"沙盘id"`
+//	Name                string    `description:"沙盘名称"`
+//	ChartPermissionId   int       `description:"品种id"`
+//	ChartPermissionName string    `description:"品种名称"`
+//	CurrVersion         int       `description:"当前版本"`
+//	Code                string    `description:"沙盘code"`
+//	Content             string    `description:"沙盘数据"`
+//	PicUrl              string    `description:"沙盘图片地址"`
+//	OpUserId            int       `description:"最近一次编辑操作的用户id"`
+//	OpUserName          string    `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
+//	IsDelete            int8      `description:"是否删除,0:未删除,1:已删除"`
+//	ModifyTime          time.Time `description:"修改时间"`
+//	CreateTime          time.Time `description:"创建时间"`
+//	SandboxClassifyId   int       `description:"分类id"`
+//	Sort                int       `description:"排序"`
+//}
+
+type Sandbox struct {
+	SandboxId         int       `orm:"column(sandbox_id);pk" description:"沙盘id"`
+	Name              string    `description:"沙盘名称"`
+	Code              string    `description:"沙盘code"`
+	Content           string    `description:"沙盘数据"`
+	MindmapData       string    `description:"思维导图数据"`
+	PicUrl            string    `description:"沙盘图片地址"`
+	SysUserId         int       `description:"作者id"`
+	SysUserName       string    `description:"作者名称"`
+	IsDelete          int8      `description:"是否删除,0:未删除,1:已删除"`
+	ModifyTime        time.Time `description:"修改时间"`
+	CreateTime        time.Time `description:"创建时间"`
+	SandboxClassifyId int       `description:"分类id"`
+	Sort              int       `description:"排序"`
+	Style             int       `description:"风格"`
+}
+
+func GetSandboxListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*Sandbox, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM sandbox WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += " ORDER BY create_time DESC LIMIT ?,? "
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
+	return
+}
+
+func GetSandboxListCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT COUNT(1) AS count FROM sandbox WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+// ContentDataStruct 沙盘内容结构体
+type ContentDataStruct struct {
+	Cells []struct {
+		Data *NodeData `json:"data,omitempty"`
+	} `json:"cells"`
+}
+
+type NodeData struct {
+	LinkData []*LinkData `json:"linkData"`
+	LinkFold bool        `json:"linkFold"`
+}
+
+type LinkData struct {
+	RId          string       `json:"RId"`
+	Id           int          `json:"Id"`
+	Name         string       `json:"Name"`
+	Type         int          `json:"Type"`
+	Editing      bool         `json:"editing"`
+	DatabaseType int          `json:"databaseType"`
+	DetailParams DetailParams `json:"detailParams"`
+}
+
+type DetailParams struct {
+	Code       string `json:"code"`
+	Id         int    `json:"id"`
+	ClassifyId int    `json:"classifyId"`
+}

+ 628 - 0
services/edb_relation.go

@@ -0,0 +1,628 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_task/models/data_manage"
+	"eta/eta_task/models/data_manage/cross_variety"
+	"eta/eta_task/models/fe_calendar"
+	"eta/eta_task/models/sandbox"
+	"eta/eta_task/services/alarm_msg"
+	"eta/eta_task/utils"
+	"fmt"
+	"time"
+)
+
+func InitEdbRelation() {
+	//InitChartEdbRelation()
+	//InitChartCrossVariety()
+	//initCalendarIndicatorRelation()
+	initSandBoxEdbRelation()
+}
+func InitChartEdbRelation() {
+	fmt.Println("开始处理图表中的指标引用")
+	var err error
+	defer func() {
+		if err != nil {
+			msg := fmt.Sprintf("初始化指标在图表中的引用失败 InitChartEdbRelation  err: %v", err)
+			utils.FileLog.Info(msg)
+			fmt.Println(msg)
+			go alarm_msg.SendAlarmMsg(msg, 3)
+		}
+	}()
+	//查询chart_edb_mapping 表
+	total, err := data_manage.GetChartEdbMappingTotal()
+	if err != nil {
+		err = fmt.Errorf("查询图表关联指标失败 err: %v", err)
+		return
+	}
+	if total == 0 {
+		return
+	}
+	//分页查询,每次处理500条记录
+	pageSize := 500
+	totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
+	addList := make([]*data_manage.EdbInfoRelation, 0)
+	//查询图表列表
+	for i := 0; i < totalPage; i += 1 {
+		startSize := i * pageSize
+		list, e := data_manage.GetChartEdbMappingList(startSize, pageSize)
+		if e != nil {
+			err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
+			return
+		}
+		if len(list) == 0 {
+			break
+		}
+
+		edbInfoIds := make([]int, 0)
+		for _, v := range list {
+			edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+		}
+		// 查询指标信息表
+		edbInfoList, e := data_manage.GetEdbInfoByIdListAndSource(edbInfoIds, []int{utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_MYSTEEL_CHEMICAL})
+		if e != nil {
+			err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
+			return
+		}
+		if len(edbInfoList) == 0 {
+			continue
+		}
+		edbInfoMap := make(map[int]*data_manage.EdbInfo)
+		for _, v := range edbInfoList {
+			edbInfoMap[v.EdbInfoId] = v
+		}
+
+		// 筛选有用的图表
+		finalList := make([]*data_manage.ChartEdbMapping, 0)
+		chartIds := make([]int, 0)
+		for _, v := range list {
+			if _, ok2 := edbInfoMap[v.EdbInfoId]; !ok2 {
+				continue
+			}
+			finalList = append(finalList, v)
+			chartIds = append(chartIds, v.ChartInfoId)
+		}
+		if len(chartIds) == 0 {
+			continue
+		}
+		// 查询图表信息
+		chartInfoList, e := data_manage.GetChartInfoByChartInfoIds(chartIds)
+		if e != nil {
+			err = fmt.Errorf("查询图表信息列表失败 Err:%s", e)
+			return
+		}
+		chartInfoMap := make(map[int]*data_manage.ChartInfo)
+		for _, v := range chartInfoList {
+			chartInfoMap[v.ChartInfoId] = v
+		}
+
+		//查询引用关系列表,
+		chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(chartIds, utils.EDB_RELATION_CHART)
+		if e != nil {
+			err = fmt.Errorf("查询图表引用关系列表失败 Err:%s", e)
+			return
+		}
+		existRelationMap := make(map[string]struct{})
+		for _, v := range chartEdbRelationList {
+			name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
+			existRelationMap[name] = struct{}{}
+		}
+		for _, v := range finalList {
+			nowTime := time.Now()
+			name := fmt.Sprintf("%d-%d", v.ChartInfoId, v.EdbInfoId)
+			if _, ok := existRelationMap[name]; !ok {
+				//查询图表信息
+				chartInfo, ok1 := chartInfoMap[v.ChartInfoId]
+				if !ok1 {
+					continue
+				}
+				edbInfo, ok2 := edbInfoMap[v.EdbInfoId]
+				if !ok2 {
+					continue
+				}
+				//todo 引用时间
+				tmp := &data_manage.EdbInfoRelation{
+					ReferObjectId:      v.ChartInfoId,
+					ReferObjectType:    utils.EDB_RELATION_CHART,
+					ReferObjectSubType: chartInfo.Source,
+					EdbInfoId:          v.EdbInfoId,
+					EdbName:            edbInfo.EdbName,
+					Source:             edbInfo.Source,
+					EdbCode:            edbInfo.EdbCode,
+					CreateTime:         nowTime,
+					ModifyTime:         nowTime,
+					RelationTime:       v.CreateTime,
+				}
+				addList = append(addList, tmp)
+				existRelationMap[name] = struct{}{}
+				if len(addList) > pageSize {
+					err = data_manage.AddEdbInfoRelationMulti(addList)
+					if err != nil {
+						err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+						return
+					}
+					addList = make([]*data_manage.EdbInfoRelation, 0)
+				}
+			}
+		}
+	}
+	//拿到500个数据ID,判断相关的引用记录,如果已存在则直接过滤,不存在则新增
+	if len(addList) > 0 {
+		err = data_manage.AddEdbInfoRelationMulti(addList)
+		if err != nil {
+			err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+			return
+		}
+	}
+	fmt.Println("图表引用记录处理完成")
+	return
+}
+
+// InitChartCrossVariety 处理特殊图表,跨品种分析图表
+func InitChartCrossVariety() {
+	fmt.Println("开始跨品种分析图表中的指标引用")
+	var err error
+	defer func() {
+		if err != nil {
+			msg := fmt.Sprintf("初始化指标在跨品种分析图表中的引用失败 InitChartCrossVariety  err: %v", err)
+			utils.FileLog.Info(msg)
+			fmt.Println(msg)
+			go alarm_msg.SendAlarmMsg(msg, 3)
+		}
+	}()
+	total, err := cross_variety.GetChartInfoCrossVarietyTotal()
+	if err != nil {
+		err = fmt.Errorf("查询图表关联指标失败 err: %v", err)
+		return
+	}
+	if total == 0 {
+		return
+	}
+	//分页查询,每次处理500条记录
+	pageSize := 500
+	totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
+	addList := make([]*data_manage.EdbInfoRelation, 0)
+	//查询图表列表
+	for i := 0; i < totalPage; i += 1 {
+		startSize := i * pageSize
+		list, e := cross_variety.GetChartInfoCrossVarietyList(startSize, pageSize)
+		if e != nil {
+			err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
+			return
+		}
+		if len(list) == 0 {
+			break
+		}
+		chartIds := make([]int, 0)
+		tagIds := make([]int, 0)
+		tagIdsMap := make(map[int]struct{})
+		tagChartMap := make(map[int][]*cross_variety.ChartInfoCrossVariety)
+		for _, v := range list {
+			if _, ok := tagIdsMap[v.ChartXTagId]; !ok {
+				tagIds = append(tagIds, v.ChartXTagId)
+				tagIdsMap[v.ChartXTagId] = struct{}{}
+			}
+			if _, ok := tagIdsMap[v.ChartYTagId]; !ok {
+				tagIds = append(tagIds, v.ChartYTagId)
+				tagIdsMap[v.ChartYTagId] = struct{}{}
+			}
+			if chartCross, ok := tagChartMap[v.ChartXTagId]; ok {
+				chartCross = append(chartCross, v)
+				tagChartMap[v.ChartXTagId] = chartCross
+			} else {
+				chartCross = make([]*cross_variety.ChartInfoCrossVariety, 0)
+				chartCross = append(chartCross, v)
+				tagChartMap[v.ChartXTagId] = chartCross
+			}
+			if chartCross, ok := tagChartMap[v.ChartYTagId]; ok {
+				chartCross = append(chartCross, v)
+				tagChartMap[v.ChartYTagId] = chartCross
+			} else {
+				chartCross = make([]*cross_variety.ChartInfoCrossVariety, 0)
+				chartCross = append(chartCross, v)
+				tagChartMap[v.ChartYTagId] = chartCross
+			}
+		}
+		chartTagVarietyList, e := cross_variety.GetChartTagVarietyEdbInfoIdsByTagIds(tagIds)
+		if e != nil {
+			err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
+			return
+		}
+		edbInfoIds := make([]int, 0)
+		chartTagVarietyMap := make(map[int][]*cross_variety.ChartTagVariety)
+		for _, v := range chartTagVarietyList {
+			if tagList, ok := chartTagVarietyMap[v.EdbInfoId]; ok {
+				tagList = append(tagList, v)
+				chartTagVarietyMap[v.EdbInfoId] = tagList
+			} else {
+				tagList = make([]*cross_variety.ChartTagVariety, 0)
+				tagList = append(tagList, v)
+				chartTagVarietyMap[v.EdbInfoId] = tagList
+			}
+
+			edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+		}
+
+		// 查询指标信息表
+		edbInfoList, e := data_manage.GetEdbInfoByIdListAndSource(edbInfoIds, []int{utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_MYSTEEL_CHEMICAL})
+		if e != nil {
+			err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
+			return
+		}
+		if len(edbInfoList) == 0 {
+			continue
+		}
+		edbInfoMap := make(map[int]*data_manage.EdbInfo)
+		chartInfoCrossMap := make(map[int]struct{})
+		chartInfoCrossList := make([]*cross_variety.ChartInfoCrossVariety, 0)
+		edbCrossMap := make(map[int][]*cross_variety.ChartInfoCrossVariety)
+		for _, v := range edbInfoList {
+			edbInfoMap[v.EdbInfoId] = v
+			if tagList, ok := chartTagVarietyMap[v.EdbInfoId]; ok {
+				for _, tag := range tagList {
+					if chartCross, ok2 := tagChartMap[tag.ChartTagId]; ok2 {
+						for _, crossItem := range chartCross {
+							if _, ok3 := chartInfoCrossMap[crossItem.ChartInfoId]; !ok3 {
+								chartInfoCrossMap[crossItem.ChartInfoId] = struct{}{}
+								chartInfoCrossList = append(chartInfoCrossList, crossItem)
+								chartIds = append(chartIds, crossItem.ChartInfoId)
+							}
+						}
+					}
+				}
+			}
+			edbCrossMap[v.EdbInfoId] = chartInfoCrossList
+			chartInfoCrossMap = make(map[int]struct{})
+			chartInfoCrossList = make([]*cross_variety.ChartInfoCrossVariety, 0)
+		}
+
+		/*// 查询图表信息
+		chartInfoList, e := data_manage.GetChartInfoByChartInfoIds(chartIds)
+		if e != nil {
+			err = fmt.Errorf("查询图表信息列表失败 Err:%s", e)
+			return
+		}
+		chartInfoMap := make(map[int]*data_manage.ChartInfo)
+		for _, v := range chartInfoList {
+			chartInfoMap[v.ChartInfoId] = v
+		}
+		*/
+		//查询引用关系列表,
+		chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(chartIds, utils.EDB_RELATION_CHART)
+		if e != nil {
+			err = fmt.Errorf("查询图表引用关系列表失败 Err:%s", e)
+			return
+		}
+		existRelationMap := make(map[string]struct{})
+		for _, v := range chartEdbRelationList {
+			name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
+			existRelationMap[name] = struct{}{}
+		}
+		for edbInfoId, chartCrossList := range edbCrossMap {
+			nowTime := time.Now()
+			for _, item := range chartCrossList {
+				name := fmt.Sprintf("%d-%d", item.ChartInfoId, edbInfoId)
+				if _, ok1 := existRelationMap[name]; !ok1 {
+					edbInfo, ok2 := edbInfoMap[edbInfoId]
+					if !ok2 {
+						continue
+					}
+					//todo 引用时间
+					tmp := &data_manage.EdbInfoRelation{
+						ReferObjectId:      item.ChartInfoId,
+						ReferObjectType:    utils.EDB_RELATION_CHART,
+						ReferObjectSubType: utils.CHART_SOURCE_CROSS_HEDGING,
+						EdbInfoId:          edbInfoId,
+						EdbName:            edbInfo.EdbName,
+						Source:             edbInfo.Source,
+						EdbCode:            edbInfo.EdbCode,
+						CreateTime:         nowTime,
+						ModifyTime:         nowTime,
+						RelationTime:       item.CreateTime,
+					}
+					addList = append(addList, tmp)
+					existRelationMap[name] = struct{}{}
+					if len(addList) > pageSize {
+						err = data_manage.AddEdbInfoRelationMulti(addList)
+						if err != nil {
+							err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+							return
+						}
+						addList = make([]*data_manage.EdbInfoRelation, 0)
+					}
+				}
+			}
+		}
+	}
+	//拿到500个数据ID,判断相关的引用记录,如果已存在则直接过滤,不存在则新增
+	if len(addList) > 0 {
+		err = data_manage.AddEdbInfoRelationMulti(addList)
+		if err != nil {
+			err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+			return
+		}
+	}
+	fmt.Println("跨品种分析图表引用记录处理完成")
+	return
+}
+
+// 初始化事件日历中的指标引用
+func initCalendarIndicatorRelation() {
+	fmt.Println("开始处理事件日历中的指标引用")
+	var err error
+	defer func() {
+		if err != nil {
+			msg := fmt.Sprintf("初始化指标在事件日历中的引用失败 initCalendarIndicatorRelation  err: %v", err)
+			utils.FileLog.Info(msg)
+			fmt.Println(msg)
+			go alarm_msg.SendAlarmMsg(msg, 3)
+		}
+	}()
+	//查询chart_edb_mapping 表
+	obj := new(fe_calendar.FeCalendarMatter)
+	condition := " AND edb_info_id > 0"
+	total, err := obj.GetCountByCondition(condition, []interface{}{})
+	if err != nil {
+		err = fmt.Errorf("查询事件日历关联指标失败 err: %v", err)
+		return
+	}
+	if total == 0 {
+		return
+	}
+	//分页查询,每次处理500条记录
+	pageSize := 500
+	totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
+	addList := make([]*data_manage.EdbInfoRelation, 0)
+	//查询图表列表
+	for i := 0; i < totalPage; i += 1 {
+		startSize := i * pageSize
+		list, e := obj.GetPageItemsByCondition(condition, []interface{}{}, []string{}, "", startSize, pageSize)
+		if e != nil {
+			err = fmt.Errorf("查询事件日历关联指标列表失败 Err:%s", e)
+			return
+		}
+		if len(list) == 0 {
+			break
+		}
+
+		edbInfoIds := make([]int, 0)
+		edbInfoMatterMap := make(map[int][]*fe_calendar.FeCalendarMatter)
+		for _, v := range list {
+			edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+			items, ok := edbInfoMatterMap[v.EdbInfoId]
+			if ok {
+				items = append(items, v)
+				edbInfoMatterMap[v.EdbInfoId] = items
+			} else {
+				items = make([]*fe_calendar.FeCalendarMatter, 0)
+				items = append(items, v)
+				edbInfoMatterMap[v.EdbInfoId] = items
+			}
+		}
+		// 查询指标信息表
+		edbInfoList, e := data_manage.GetEdbInfoByIdListAndSource(edbInfoIds, []int{utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_MYSTEEL_CHEMICAL})
+		if e != nil {
+			err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
+			return
+		}
+		if len(edbInfoList) == 0 {
+			continue
+		}
+		edbInfoMap := make(map[int]*data_manage.EdbInfo)
+		matterIds := make([]int, 0)
+		for _, v := range edbInfoList {
+			edbInfoMap[v.EdbInfoId] = v
+			items, ok := edbInfoMatterMap[v.EdbInfoId]
+			if ok {
+				for _, item := range items {
+					matterIds = append(matterIds, item.FeCalendarMatterId)
+				}
+			}
+		}
+
+		//查询引用关系列表,
+		chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(matterIds, utils.EDB_RELATION_CALENDAR)
+		if e != nil {
+			err = fmt.Errorf("查询图表引用关系列表失败 Err:%s", e)
+			return
+		}
+		existRelationMap := make(map[string]struct{})
+		for _, v := range chartEdbRelationList {
+			name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
+			existRelationMap[name] = struct{}{}
+		}
+		for edbInfoId, edbInfo := range edbInfoMap {
+			nowTime := time.Now()
+			items, ok := edbInfoMatterMap[edbInfoId]
+			if ok {
+				for _, v := range items {
+					name := fmt.Sprintf("%d-%d", v.FeCalendarMatterId, v.EdbInfoId)
+					if _, ok1 := existRelationMap[name]; !ok1 {
+						//todo 引用时间
+						tmp := &data_manage.EdbInfoRelation{
+							ReferObjectId:   v.FeCalendarMatterId,
+							ReferObjectType: utils.EDB_RELATION_CALENDAR,
+							EdbInfoId:       v.EdbInfoId,
+							EdbName:         edbInfo.EdbName,
+							Source:          edbInfo.Source,
+							EdbCode:         edbInfo.EdbCode,
+							CreateTime:      nowTime,
+							ModifyTime:      nowTime,
+							RelationTime:    v.CreateTime,
+						}
+						addList = append(addList, tmp)
+						existRelationMap[name] = struct{}{}
+						if len(addList) > pageSize {
+							err = data_manage.AddEdbInfoRelationMulti(addList)
+							if err != nil {
+								err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+								return
+							}
+							addList = make([]*data_manage.EdbInfoRelation, 0)
+						}
+					}
+				}
+			}
+
+		}
+	}
+	//拿到500个数据ID,判断相关的引用记录,如果已存在则直接过滤,不存在则新增
+	if len(addList) > 0 {
+		err = data_manage.AddEdbInfoRelationMulti(addList)
+		if err != nil {
+			err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+			return
+		}
+	}
+	fmt.Println("事件日历指标引用记录处理完成")
+	return
+}
+
+// 处理逻辑图中的指标引用
+func initSandBoxEdbRelation() {
+	fmt.Println("开始处理逻辑图中的指标引用")
+	var err error
+	defer func() {
+		if err != nil {
+			msg := fmt.Sprintf("初始化指标在逻辑图中的引用失败 initSandBoxEdbRelation  err: %v", err)
+			utils.FileLog.Info(msg)
+			fmt.Println(msg)
+			go alarm_msg.SendAlarmMsg(msg, 3)
+		}
+	}()
+	condition := " AND is_delete = 0"
+	total, err := sandbox.GetSandboxListCountByCondition(condition, []interface{}{})
+	if err != nil {
+		err = fmt.Errorf("查询逻辑图总数失败 err: %v", err)
+		return
+	}
+	if total == 0 {
+		return
+	}
+	//分页查询,每次处理500条记录
+	pageSize := 100
+	totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
+	addList := make([]*data_manage.EdbInfoRelation, 0)
+	//查询图表列表
+	for i := 0; i < totalPage; i += 1 {
+		startSize := i * pageSize
+		list, e := sandbox.GetSandboxListByCondition(condition, []interface{}{}, startSize, pageSize)
+		if e != nil {
+			err = fmt.Errorf("查询逻辑图列表失败 Err:%s", e)
+			return
+		}
+		if len(list) == 0 {
+			break
+		}
+
+		edbInfoIds := make([]int, 0)
+		edbSandboxMap := make(map[int][]*sandbox.Sandbox)
+		for _, v := range list {
+			edbInfoIdsTmp, e := getSandBoxEdbIdsByContent(v.Content)
+			if e != nil {
+				err = fmt.Errorf("查询逻辑图关联的指标Id失败 Err:%s", e)
+				return
+			}
+			for _, edbId := range edbInfoIdsTmp {
+				edbInfoIds = append(edbInfoIds, edbId)
+				edbSandboxMap[edbId] = append(edbSandboxMap[edbId], v)
+			}
+		}
+		// 查询指标信息表
+		edbInfoList, e := data_manage.GetEdbInfoByIdListAndSource(edbInfoIds, []int{utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_MYSTEEL_CHEMICAL})
+		if e != nil {
+			err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
+			return
+		}
+		if len(edbInfoList) == 0 {
+			continue
+		}
+		edbInfoMap := make(map[int]*data_manage.EdbInfo)
+		sandboxIds := make([]int, 0)
+		for _, v := range edbInfoList {
+			edbInfoMap[v.EdbInfoId] = v
+			if items, ok := edbSandboxMap[v.EdbInfoId]; ok {
+				for _, item := range items {
+					sandboxIds = append(sandboxIds, item.SandboxId)
+				}
+			}
+		}
+
+		//查询引用关系列表,
+		chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(sandboxIds, utils.EDB_RELATION_SANDBOX)
+		if e != nil {
+			err = fmt.Errorf("查询逻辑图引用关系列表失败 Err:%s", e)
+			return
+		}
+		existRelationMap := make(map[string]struct{})
+		for _, v := range chartEdbRelationList {
+			name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
+			existRelationMap[name] = struct{}{}
+		}
+		for edbInfoId, sandboxList := range edbSandboxMap {
+			nowTime := time.Now()
+			for _, v := range sandboxList {
+				name := fmt.Sprintf("%d-%d", v.SandboxId, edbInfoId)
+				if _, ok := existRelationMap[name]; !ok {
+					edbInfo, ok2 := edbInfoMap[edbInfoId]
+					if !ok2 {
+						continue
+					}
+					//todo 引用时间
+					tmp := &data_manage.EdbInfoRelation{
+						ReferObjectId:   v.SandboxId,
+						ReferObjectType: utils.EDB_RELATION_SANDBOX,
+						EdbInfoId:       edbInfoId,
+						EdbName:         edbInfo.EdbName,
+						Source:          edbInfo.Source,
+						EdbCode:         edbInfo.EdbCode,
+						CreateTime:      nowTime,
+						ModifyTime:      nowTime,
+						RelationTime:    v.CreateTime,
+					}
+					addList = append(addList, tmp)
+					existRelationMap[name] = struct{}{}
+					if len(addList) > pageSize {
+						err = data_manage.AddEdbInfoRelationMulti(addList)
+						if err != nil {
+							err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+							return
+						}
+						addList = make([]*data_manage.EdbInfoRelation, 0)
+					}
+				}
+			}
+		}
+	}
+	//拿到500个数据ID,判断相关的引用记录,如果已存在则直接过滤,不存在则新增
+	if len(addList) > 0 {
+		err = data_manage.AddEdbInfoRelationMulti(addList)
+		if err != nil {
+			err = fmt.Errorf("新增引用记录失败 Err:%s", err)
+			return
+		}
+	}
+	fmt.Println("逻辑图指标引用记录处理完成")
+	return
+}
+
+func getSandBoxEdbIdsByContent(content string) (edbInfoIds []int, err error) {
+	var contentInfo sandbox.ContentDataStruct
+	err = json.Unmarshal([]byte(content), &contentInfo)
+	if err != nil {
+		err = fmt.Errorf("json.Unmarshal err:%s", err.Error())
+		return
+	}
+	// 遍历所有节点
+	for _, node := range contentInfo.Cells {
+		if node.Data == nil {
+			continue
+		}
+		for _, v := range node.Data.LinkData {
+			if v.Type == 1 {
+				edbInfoIds = append(edbInfoIds, v.Id)
+			}
+		}
+	}
+	return
+}

+ 23 - 0
utils/constants.go

@@ -156,3 +156,26 @@ const (
 
 // 已经处理了的变更id
 const CACHE_EDB_UPDATE_LOG_ID = "eta:edb_update_log:id"
+
+// 指标引用对象
+const (
+	EDB_RELATION_CHART    = 1 // 图表
+	EDB_RELATION_SANDBOX  = 2 // ETA逻辑
+	EDB_RELATION_CALENDAR = 3 // 事件日历
+	EDB_RELATION_TABLE    = 4 // 表格
+)
+
+// 图表类型
+const (
+	CHART_SOURCE_DEFAULT                         = 1
+	CHART_SOURCE_FUTURE_GOOD                     = 2
+	CHART_SOURCE_CORRELATION                     = 3  // 相关性图表
+	CHART_SOURCE_ROLLING_CORRELATION             = 4  // 滚动相关性图表
+	CHART_SOURCE_FUTURE_GOOD_PROFIT              = 5  // 商品利润曲线
+	CHART_SOURCE_LINE_EQUATION                   = 6  // 拟合方程图表
+	CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION = 7  // 统计特征-标准差图表
+	CHART_SOURCE_LINE_FEATURE_PERCENTILE         = 8  // 统计特征-百分位图表
+	CHART_SOURCE_LINE_FEATURE_FREQUENCY          = 9  // 统计特征-频率分布图表
+	CHART_SOURCE_CROSS_HEDGING                   = 10 // 跨品种分析图表
+	CHART_SOURCE_BALANCE_EXCEL                   = 11 // 平衡表图表
+)