case-admin-api/api/model/Project.go
2025-03-07 17:23:50 +08:00

37 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"case-admin-api/global"
"gorm.io/gorm"
"time"
)
// Project 项目表
type Project struct {
ProjectId int64 `gorm:"column:project_id;type:bigint(19);primary_key;comment:主键id" json:"project_id"`
ProjectName string `gorm:"column:project_name;type:varchar(255);comment:项目名称" json:"project_name"`
ProjectStatus int `gorm:"column:project_status;type:tinyint(1);comment:项目状态0:无效 1:正常)" json:"project_status"`
ProjectImage string `gorm:"column:project_image;type:varchar(255);comment:项目背景图" json:"project_image"`
Model
Case []*Case `gorm:"foreignKey:ProjectId;references:project_id" json:"case"`
ProjectPlatform []*ProjectPlatform `gorm:"foreignKey:ProjectId;references:project_id" json:"project_platform"`
}
func (m *Project) TableName() string {
return "project"
}
func (m *Project) BeforeCreate(tx *gorm.DB) error {
if m.ProjectId == 0 {
m.ProjectId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}