From a6f82a1a1cbb4a3dfde004cf29b91c9b4c7da7c3 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 19 九月 2023 19:57:03 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- models/warehouse.go | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/models/warehouse.go b/models/warehouse.go index 42f6408..c6cd670 100644 --- a/models/warehouse.go +++ b/models/warehouse.go @@ -8,9 +8,10 @@ ) type ( - // Warehouse 閮ㄩ棬淇℃伅 + // Warehouse 浠撳簱 Warehouse struct { WmsModel + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:浠撳簱鍚嶇О"` //浠撳簱鍚嶇О Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:鏄惁婵�娲�"` //鏄惁鍚敤锛屼紶true灏辫 Code string `json:"code" binding:"required,min=1,max=5" gorm:"index;type:varchar(255);not null;comment:浠撳簱缂栫爜"` //浠撳簱缂栫爜 @@ -19,6 +20,8 @@ ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:琛ョ粰鏉ユ簮浠撳簱ID"` //琛ョ粰鏉ユ簮浠撳簱ID ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱ID ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱 + CompanyId int `json:"companyId" gorm:"type:int;not null;comment:鍏徃id"` + Company Company `json:"company" gorm:"foreignKey:CompanyId"` } WarehouseSearch struct { @@ -28,11 +31,12 @@ PageSize int Keyword string Orm *gorm.DB + Preload bool } ) func (slf *Warehouse) TableName() string { - return "warehouse" + return "wms_warehouse" } func (slf *Warehouse) BeforeCreate(tx *gorm.DB) (err error) { @@ -79,8 +83,13 @@ return slf } +func (slf *WarehouseSearch) SetPreload(preload bool) *WarehouseSearch { + slf.Preload = preload + return slf +} + func (slf *WarehouseSearch) build() *gorm.DB { - var db = slf.Orm.Table(slf.TableName()) + var db = slf.Orm.Model(&Warehouse{}) if slf.ID != 0 { db = db.Where("id = ?", slf.ID) @@ -93,10 +102,15 @@ if slf.Keyword != "" { db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) } + if slf.Name != "" { db = db.Where("name = ?", slf.Name) } + if slf.Preload { + db = db.Preload("Company") + } + return db } -- Gitblit v1.8.0