From c68a2d376f67d60277001e3f748fbd71c5201af3 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 08 十二月 2023 17:02:12 +0800
Subject: [PATCH] debug

---
 model/model.go |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/model/model.go b/model/model.go
index f7b56b7..aa1f864 100644
--- a/model/model.go
+++ b/model/model.go
@@ -2,12 +2,16 @@
 
 import (
 	"apsClient/pkg/snowflake"
+	"encoding/json"
 	"github.com/jinzhu/gorm"
+	"strconv"
 	"time"
 )
 
+type BigID uint
+
 type CommonModel struct {
-	ID        uint `gorm:"primary_key"`
+	ID        BigID `gorm:"primary_key"`
 	CreatedAt time.Time
 	UpdatedAt time.Time
 	DeletedAt *time.Time `sql:"index"`
@@ -17,8 +21,29 @@
 	if c.ID == 0 {
 		id := snowflake.GenerateID()
 		if id < 0 {
+			// 澶勭悊 ID 涓鸿礋鏁扮殑鎯呭喌锛堝彲閫夛級
 			id = snowflake.GenerateID()
 		}
-		c.ID = uint(id)
+		c.ID = BigID(id)
 	}
 }
+
+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