chart_setting.go 2.1 KB
package models

import (
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
	"gorm.io/gorm"
	"gorm.io/plugin/soft_delete"
	"time"
)

type ChartSetting struct {
	Id            int64               // ID
	ChartId       int64               `gorm:"uniqueIndex:idx_chart_setting_chart_id"` // 图表ID
	DataSourceId  int64               // (冗余)数据源ID,多个数据源取第一个源
	DataSourceIds []int64             `gorm:"serializer:json"`
	ChartType     string              // (冗余)图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
	Title         domain.Title        `gorm:"serializer:json"`
	TableAbility  domain.TableAbility `gorm:"serializer:json"` // 表格能力
	Series        []domain.Series     `gorm:"serializer:json"` // 系列值-数据绑定
	Other         domain.Other        `gorm:"serializer:json"`

	TenantId  int64                 `gorm:"index:idx_chart_setting_t_id"` // 租户ID
	CreatedAt int64                 `json:",omitempty"`
	UpdatedAt int64                 `json:",omitempty"`
	DeletedAt int64                 `json:",omitempty"`
	Version   int                   `json:",omitempty"`
	IsDel     soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}

func (m *ChartSetting) TableName() string {
	return "chart_setting"
}

func (m *ChartSetting) BeforeCreate(tx *gorm.DB) (err error) {
	m.CreatedAt = time.Now().Unix()
	m.UpdatedAt = time.Now().Unix()
	return
}

func (m *ChartSetting) BeforeUpdate(tx *gorm.DB) (err error) {
	m.UpdatedAt = time.Now().Unix()
	return
}

func (m *ChartSetting) CacheKeyFunc() string {
	if m.ChartId == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.ChartId)
}

func (m *ChartSetting) CacheKeyFuncByObject(obj interface{}) string {
	if v, ok := obj.(*ChartSetting); ok {
		return v.CacheKeyFunc()
	}
	return ""
}

func (m *ChartSetting) CachePrimaryKeyFunc() string {
	if len("") == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}