From b6b889b3fcd1ecba07aa90f7ec82c6b7d5d5da3f Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 29 十二月 2023 11:49:02 +0800 Subject: [PATCH] 同步加工数过滤掉加工数为0的记录 --- model/model.go | 36 +++--------------------------------- 1 files changed, 3 insertions(+), 33 deletions(-) diff --git a/model/model.go b/model/model.go index aa1f864..efa8a39 100644 --- a/model/model.go +++ b/model/model.go @@ -2,48 +2,18 @@ import ( "apsClient/pkg/snowflake" - "encoding/json" - "github.com/jinzhu/gorm" - "strconv" "time" ) -type BigID uint - type CommonModel struct { - ID BigID `gorm:"primary_key"` + 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 = BigID(id) + c.ID = uint(snowflake.GenerateID()) } -} - -func (id *BigID) UnmarshalJSON(b []byte) error { - var idString string - if err := json.Unmarshal(b, &idString); err != nil { - return err - } - - idValue, err := strconv.ParseUint(idString, 10, 64) - if err != nil { - return err - } - - *id = BigID(idValue) - return nil -} - -func (id *BigID) MarshalJSON() ([]byte, error) { - idString := strconv.FormatUint(uint64(*id), 10) - return []byte(idString), nil } -- Gitblit v1.8.0