123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package models
- import (
- "encoding/json"
- "eta/eta_index_lib/global"
- "eta/eta_index_lib/utils"
- "fmt"
- "gorm.io/gorm"
- "time"
- )
- type EdbInfoReq struct {
- EdbInfoId int `description:"图表id,新增时传0"`
- }
- // DeleteChartInfoDataRedis 清除图表缓存
- func DeleteChartInfoDataRedis(bodyByte []byte) (err error) {
- var req EdbInfoReq
- err = json.Unmarshal(bodyByte, &req)
- if err != nil {
- return
- }
- if req.EdbInfoId > 0 {
- list, tmpErr := GetChartEdbMappingListByEdbInfoId(req.EdbInfoId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 删除图表的id
- for _, v := range list {
- _ = utils.Rc.Delete(GetChartInfoDataKey(v.ChartInfoId))
- }
- }
- return
- }
- // GetChartInfoDataKey 获取图表缓存的key
- func GetChartInfoDataKey(chartInfoId int) string {
- key := fmt.Sprint(utils.CACHE_CHART_INFO_DATA, chartInfoId)
- return key
- }
- type ChartInfo struct {
- ChartInfoId int `gorm:"column:chart_info_id;type:int(11);primaryKey;not null;" json:"chart_info_id"`
- ChartName string `description:"来源名称"`
- ChartNameEn 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:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
- Calendar string `description:"公历/农历"`
- SeasonStartDate string `description:"季节性图开始日期"`
- SeasonEndDate string `description:"季节性图开始日期"`
- ChartImage string `description:"图表图片"`
- Sort int `description:"排序字段,数字越小越排前面"`
- LeftMin string `description:"图表左侧最小值"`
- LeftMax string `description:"图表左侧最大值"`
- RightMin string `description:"图表右侧最小值"`
- RightMax string `description:"图表右侧最大值"`
- Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
- BarConfig string `description:"柱方图的配置,json数据"`
- Source int `description:"1:ETA图库;2:商品价格曲线"`
- ExtraConfig string `description:"图表额外配置,json数据"`
- }
- // AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
- 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
- }
- // ConvDateTimeStr
- // @Description: ConvDateTimeStr
- // @author: Roc
- // @receiver m
- // @datetime 2025-02-13 09:54:02
- // @return err error
- func (m *ChartInfo) ConvDateTimeStr() {
- 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
- }
- // GetChartInfoById 通过id获取图表信息
- func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
- sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
- err = global.DEFAULT_DB.Raw(sql, chartInfoId).First(&item).Error
- if err != nil {
- return
- }
- item.ConvDateTimeStr()
- return
- }
|