sys_company.go 1.5 KB
package models

import (
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
	"gorm.io/gorm"
	"gorm.io/plugin/soft_delete"
	"time"
)

type SysCompany struct {
	Id        int64                  // 唯一标识
	Name      string                 `gorm:"type:varchar(64)"`   // 公司名称
	Logo      string                 `gorm:"type:varchar(1024)"` // 公司图标
	AdminId   int64                  // 管理员
	BaseInfo  domain.CompanyBaseInfo `gorm:"type:jsonb;serializer:json"` // 基本信息
	Status    int
	CreatedAt int64
	UpdatedAt int64
	DeletedAt int64
	Version   int
	IsDel     soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}

func (m *SysCompany) TableName() string {
	return "sys.company"
}

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

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

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

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

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