From 250cbfa1ddcb3cf38e0d0505c1c7e282b940d25b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 13 十月 2023 10:30:05 +0800
Subject: [PATCH] admin user id 转crm user id
---
model/menu.go | 58 ++++++++++++++++++++--------------------------------------
1 files changed, 20 insertions(+), 38 deletions(-)
diff --git a/model/menu.go b/model/menu.go
index b74a46f..a81cf75 100644
--- a/model/menu.go
+++ b/model/menu.go
@@ -4,25 +4,16 @@
"aps_crm/pkg/mysqlx"
"fmt"
"gorm.io/gorm"
- "time"
)
type (
Menu struct {
- ID uint `json:"id" gorm:"type:bigint(20);primaryKey"` // 涓婚敭ID
- ParentId uint `json:"parentId" gorm:"index;type:bigint(20);comment:鐖惰彍鍗旾D"`
- Path string `json:"path" gorm:"type:varchar(255);comment:璺敱path"`
- Name string `json:"name" gorm:"type:varchar(255);comment:name"`
- Title string `json:"title" gorm:"type:varchar(255);comment:鏍囬"`
- Sort int `json:"sort" gorm:"type:int(11);comment:鎺掑簭鏍囪"`
- Icon string `json:"icon" gorm:"type:varchar(512);comment:鑿滃崟鍥炬爣"`
- Hidden bool `json:"hidden" gorm:"type:tinyint(1);comment:鏄惁闅愯棌"`
- Type int `json:"type" gorm:"type:int(11);comment:绫诲瀷 0-鐩綍 1-鑿滃崟 2-鎸夐挳"`
- CreateTime int64 `json:"-" gorm:"type:bigint(20);comment:鍒涘缓鏃堕棿"`
- UpdateTime int64 `json:"-" gorm:"type:bigint(20);comment:鏇存柊鏃堕棿"`
- Children []*Menu `json:"children" gorm:"-"`
- CreateAt string `json:"createAt" gorm:"-"` // 鍒涘缓鏃堕棿
- UpdateAt string `json:"updateAt" gorm:"-"` // 鏇存柊鏃堕棿
+ ID uint `json:"id" gorm:"type:bigint(20);primaryKey"` // 涓婚敭ID
+ ParentId uint `json:"parentId" gorm:"index;type:bigint(20);comment:鐖惰彍鍗旾D"`
+ Path string `json:"path" gorm:"type:varchar(255);comment:璺敱path"`
+ Name string `json:"name" gorm:"type:varchar(255);comment:name"`
+ Title string `json:"title" gorm:"type:varchar(255);comment:鏍囬"`
+ Children []*Menu `json:"children" gorm:"-"`
}
MenuSearch struct {
@@ -37,28 +28,6 @@
func (slf Menu) TableName() string {
return "menu"
-}
-
-func (slf *Menu) BeforeCreate(tx *gorm.DB) error {
- slf.CreateTime = time.Now().Unix()
- slf.UpdateTime = slf.CreateTime
- return nil
-}
-
-func (slf *Menu) BeforeSave(tx *gorm.DB) error {
- slf.UpdateTime = time.Now().Unix()
- return nil
-}
-
-func (slf *Menu) BeforeUpdate(tx *gorm.DB) error {
- slf.UpdateTime = time.Now().Unix()
- return nil
-}
-
-func (slf *Menu) AfterFind(tx *gorm.DB) error {
- slf.CreateAt = time.Unix(slf.CreateTime, 0).Format("2006-01-02 15:04:05")
- slf.UpdateAt = time.Unix(slf.UpdateTime, 0).Format("2006-01-02 15:04:05")
- return nil
}
func NewMenuSearch(db *gorm.DB) *MenuSearch {
@@ -140,7 +109,7 @@
func (slf *MenuSearch) CreateBatch(records []*Menu) error {
var db = slf.build()
- if err := db.Create(&records).Error; err != nil {
+ if err := db.Save(&records).Error; err != nil {
return fmt.Errorf("create batch err: %v, records: %+v", err, records)
}
@@ -277,3 +246,16 @@
return records, nil
}
+
+func (slf *MenuSearch) FindAll() ([]Menu, error) {
+ var (
+ records = make([]Menu, 0)
+ db = slf.build()
+ )
+
+ if err := db.Find(&records).Error; err != nil {
+ return records, fmt.Errorf("find all err: %v", err)
+ }
+
+ return records, nil
+}
--
Gitblit v1.8.0