package chart_edb_mapping

import "hongze/hongze_yb/global"

type ChartEdbInfoMapping struct {
	EdbInfoId         int     `description:"指标id"`
	SourceName        string  `description:"来源名称"`
	Source            int     `description:"来源id"`
	EdbCode           string  `description:"指标编码"`
	EdbName           string  `description:"指标名称"`
	EdbType           int     `description:"指标类型:1:基础指标,2:计算指标"`
	Frequency         string  `description:"频率"`
	Unit              string  `description:"单位"`
	StartDate         string  `description:"起始日期"`
	EndDate           string  `description:"终止日期"`
	ModifyTime        string  `description:"指标最后更新时间"`
	ChartEdbMappingId int     `description:"图表指标id"`
	ChartInfoId       int     `description:"图表id"`
	MaxData           float64 `description:"上限"`
	MinData           float64 `description:"下限"`
	IsOrder           bool    `description:"true:正序,false:逆序"`
	IsAxis            int     `description:"1:左轴,0:右轴"`
	EdbInfoType       int     `description:"1:标准指标,0:领先指标"`
	LeadValue         int     `description:"领先值"`
	LeadUnit          string  `description:"领先单位"`
	ChartStyle        string  `description:"图表类型"`
	ChartColor        string  `description:"颜色"`
	ChartWidth        float64 `description:"线条大小"`
	LatestDate        string  `description:"数据最新日期"`
	LatestValue       float64 `description:"数据最新值"`
	UniqueCode        string  `description:"指标唯一编码"`
	MinValue          float64 `json:"-" description:"最小值"`
	MaxValue          float64 `json:"-" description:"最大值"`
	DataList          interface{}
}

// GetMappingListByChartInfoId 根据图表ID获取指标映射列表
func GetMappingListByChartInfoId(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
	sql := ` SELECT a.*,b.source_name,b.source,b.edb_code,b.edb_name,b.frequency,b.unit,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code
             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=? 
             ORDER BY chart_edb_mapping_id ASC `
	err = global.MYSQL["data"].Raw(sql, chartInfoId).Scan(&list).Error

	return
}

// GetMappingListByEdbInfoId 根据指标ID获取指标映射列表
func GetMappingListByEdbInfoId(edbInfoStr string) (list []*ChartEdbInfoMapping, err error) {
	sql := ` SELECT * FROM edb_info WHERE edb_info_id IN(` + edbInfoStr + `) ORDER BY FIELD(edb_info_id,` + edbInfoStr + `) `
	err = global.MYSQL["data"].Raw(sql).Scan(&list).Error
	return
}