package data_manage import ( "eta/eta_task/global" "eta/eta_task/utils" "gorm.io/gorm" "time" ) type ChartInfo struct { ChartInfoId int `gorm:"column:chart_info_id;primaryKey;autoIncrement"` ChartName string `description:"来源名称"` ChartClassifyId int `description:"图表分类id"` 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:"排序字段,数字越小越排前面"` EdbEndDate string `description:"指标最后更新日期"` Source int `description:"1:ETA图库;2:商品价格曲线"` ExtraConfig string `description:"图表额外配置,json数据"` } func (m *ChartInfo) AfterFind(db *gorm.DB) (err error) { m.StartDate = utils.GormDateStrToDateStr(m.StartDate) m.EndDate = utils.GormDateStrToDateStr(m.EndDate) m.SeasonStartDate = utils.GormDateStrToDateStr(m.SeasonStartDate) m.SeasonEndDate = utils.GormDateStrToDateStr(m.SeasonEndDate) return } func GetAllChartInfo() (list []*ChartInfo, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM chart_info ` err = o.Raw(sql).Find(&list).Error return } func GetChartInfoEdbEndDate() (list []*ChartInfo, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT a.*,max(c.end_date) AS edb_end_date FROM chart_info AS a INNER JOIN chart_edb_mapping AS b ON a.chart_info_id=b.chart_info_id INNER JOIN edb_info AS c ON b.edb_info_id=c.edb_info_id GROUP BY a.chart_info_id ` err = o.Raw(sql).Find(&list).Error return } func ModifyChartInfoEdbEndDate(chartInfoId int, edbEndDate string) (err error) { o := global.DbMap[utils.DbNameIndex] sql := ` UPDATE chart_info SET edb_end_date=? WHERE chart_info_id=? ` err = o.Exec(sql, edbEndDate, chartInfoId).Error return } // 根据chart_info_id数组获取图表信息 func GetChartInfoByChartInfoIds(chartInfoIds []int) (list []*ChartInfo, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM chart_info WHERE chart_info_id IN (` + utils.GetOrmInReplace(len(chartInfoIds)) + `) ` err = o.Raw(sql, chartInfoIds).Find(&list).Error return }