From 2d6875c93b25d0b7336c7fa11e066d213259fe2e Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 25 四月 2024 10:02:01 +0800 Subject: [PATCH] 更改定时任务时区设置 --- model/model.go | 41 +++-------------------------------------- 1 files changed, 3 insertions(+), 38 deletions(-) diff --git a/model/model.go b/model/model.go index 533c35d..efa8a39 100644 --- a/model/model.go +++ b/model/model.go @@ -2,53 +2,18 @@ import ( "apsClient/pkg/snowflake" - "encoding/json" - "github.com/jinzhu/gorm" - "strconv" "time" ) type CommonModel struct { - ID uint `gorm:"primary_key" json:"-"` - IDStr string `json:"ID" gorm:"-"` + ID uint `gorm:"primary_key" json:"ID,string"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` } -func (c *CommonModel) BeforeCreate(db *gorm.DB) { +func (c *CommonModel) BeforeCreate() { if c.ID == 0 { - id := snowflake.GenerateID() - if id < 0 { - // 澶勭悊 ID 涓鸿礋鏁扮殑鎯呭喌锛堝彲閫夛級 - id = snowflake.GenerateID() - } - c.ID = uint(id) + c.ID = uint(snowflake.GenerateID()) } -} - -func (c *CommonModel) UnmarshalJSON(b []byte) error { - var data map[string]interface{} - if err := json.Unmarshal(b, &data); err != nil { - return err - } - - if idStr, ok := data["ID"].(string); ok { - id, err := strconv.ParseUint(idStr, 10, 64) - if err != nil { - return err - } - c.ID = uint(id) - c.IDStr = idStr - } - - return nil -} - -func (c *CommonModel) MarshalJSON() ([]byte, error) { - if c.ID != 0 && c.IDStr == "" { - c.IDStr = strconv.FormatUint(uint64(c.ID), 10) - } - - return json.Marshal(c) } -- Gitblit v1.8.0