liujiandao
2024-04-25 c0f8f8d3a74dbdab4f6ab4926fc664d818fb50f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package global
 
import (
    "time"
 
    "gorm.io/gorm"
)
 
type GVA_MODEL struct {
    ID        uint           `json:"id" gorm:"primarykey"` // 主键ID
    CreatedAt *time.Time     `json:"-"`                    // 创建时间
    UpdatedAt *time.Time     `json:"-"`                    // 更新时间
    DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`       // 删除时间
 
    FormattedCreatedAt string `gorm:"-" json:"created_at"`
    FormattedUpdatedAt string `gorm:"-" json:"updated_at"`
}
 
func (m *GVA_MODEL) AfterFind(tx *gorm.DB) (err error) {
    if m.CreatedAt != nil {
        m.FormattedCreatedAt = m.CreatedAt.Format("2006-01-02 15:04:05")
    } else {
        m.FormattedCreatedAt = "--"
    }
    if m.UpdatedAt != nil {
        m.FormattedUpdatedAt = m.UpdatedAt.Format("2006-01-02 15:04:05")
        m.FormattedUpdatedAt = "--"
    }
 
    return
}
 
type GVA_MODEL_INT struct {
    ID        uint           `json:"id,string" gorm:"primarykey"` // 主键ID
    CreatedAt *time.Time     `json:"-"`                           // 创建时间
    UpdatedAt *time.Time     `json:"-"`                           // 更新时间
    DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`              // 删除时间
 
    FormattedCreatedAt string `gorm:"-" json:"created_at"`
    FormattedUpdatedAt string `gorm:"-" json:"updated_at"`
}