From 5bc036d71ff6094e550c99168eae2e2b4d495f51 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 13 九月 2023 21:10:26 +0800
Subject: [PATCH] 增加位置表,产品分类表,产品表

---
 constvar/const.go          |   86 +++++++
 models/product_category.go |  246 ++++++++++++++++++++++
 models/db.go               |    7 
 models/location.go         |   13 +
 models/product.go          |  287 ++++++++++++++++++++++++++
 5 files changed, 637 insertions(+), 2 deletions(-)

diff --git a/constvar/const.go b/constvar/const.go
index 9a4e5c9..dff496d 100644
--- a/constvar/const.go
+++ b/constvar/const.go
@@ -41,3 +41,89 @@
 		slf == WhetherTypeAlways ||
 		slf == ReservationNever
 }
+
+// ProductType 浜у搧绫诲瀷
+type ProductType int
+
+const (
+	ProductTypeRaw      = iota + 1 // 鍘熸潗鏂�
+	ProductTypeSemi                // 鍗婃垚鍝�
+	ProductTypeFinished            // 鎴愬搧
+)
+
+type ProductStatus int
+
+const (
+	ProductStatusCreate   ProductStatus = iota // 鏂板缓
+	ProductStatusActive                        // 鍚敤
+	ProductStatusInactive = -1                 // 鍋滅敤
+)
+
+// PurchaseType 閲囪喘绫诲瀷
+type PurchaseType int
+
+const (
+	PurchaseTypeOutSource PurchaseType = iota + 1 // 閲囪喘
+	PurchaseTypeSelf                              // 鑷埗
+	PurchaseTypeEntrust                           // 濮斿
+)
+
+func (t PurchaseType) Valid() bool {
+	if t < PurchaseTypeOutSource ||
+		t > PurchaseTypeEntrust {
+		return false
+	}
+	return true
+}
+
+// LocationType 浣嶇疆绫诲瀷
+type LocationType int
+
+const (
+	LocationTypeVendor        LocationType = iota + 1 // 渚涘簲鍟嗕綅缃�
+	LocationTypeView                                  // 瑙嗗浘
+	LocationTypeInternal                              // 鍐呴儴浣嶇疆
+	LocationTypeCustomer                              // 瀹㈡埛浣嶇疆
+	LocationTypeInventoryLoss                         // 搴撳瓨鎹熷け
+	LocationTypeProduction                            // 鐢熶骇
+	LocationTypeTransit                               // 涓浆浣嶇疆
+)
+
+func (t LocationType) Valid() bool {
+	return t >= LocationTypeVendor && t <= LocationTypeTransit
+}
+
+type ForceRemovalStrategy int
+
+const (
+	ForceRemovalStrategyFIFO ForceRemovalStrategy = iota + 1
+	ForceRemovalStrategyLIFO
+	ForceRemovalStrategyClosestLocation
+)
+
+func (t ForceRemovalStrategy) Valid() bool {
+	return t >= ForceRemovalStrategyFIFO && t <= ForceRemovalStrategyClosestLocation
+}
+
+type CostingMethod int
+
+const (
+	CostingMethodStandardPrice CostingMethod = iota + 1 //鏍囧噯浠锋牸
+	CostingMethodFIFO                                   //鍏堣繘鍏堝嚭
+	CostingMethodAverageCost                            //
+)
+
+func (t CostingMethod) Valid() bool {
+	return t >= CostingMethodStandardPrice && t <= CostingMethodAverageCost
+}
+
+type InventoryValuation int
+
+const (
+	InventoryValuationManual InventoryValuation = iota + 1 //鎵嬪姩
+	InventoryValuationAuto                                 //鑷姩
+)
+
+func (t InventoryValuation) Valid() bool {
+	return t >= InventoryValuationManual && t <= InventoryValuationAuto
+}
diff --git a/models/db.go b/models/db.go
index fe88df7..e32a28e 100644
--- a/models/db.go
+++ b/models/db.go
@@ -77,6 +77,13 @@
 		Warehouse{},
 		OperationType{},
 		Location{},
+		OperationType{},
+		Operation{},
+		OperationDetails{},
+		Scrap{},
+		MoveHistory{},
+		Product{},
+		ProductCategory{},
 	)
 	return err
 }
diff --git a/models/location.go b/models/location.go
index 54ec4af..0146ca0 100644
--- a/models/location.go
+++ b/models/location.go
@@ -3,6 +3,7 @@
 import (
 	"fmt"
 	"gorm.io/gorm"
+	"wms/constvar"
 	"wms/pkg/mysqlx"
 )
 
@@ -10,8 +11,16 @@
 	// Location 浣嶇疆
 	Location 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:浣嶇疆鍚嶇О"` //浣嶇疆鍚嶇О
+		Id                int                   `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		Name              string                `json:"name" gorm:"index;type:varchar(255);not null;comment:浣嶇疆鍚嶇О"`     //浣嶇疆鍚嶇О
+		ParentId          int                   `json:"parentId" gorm:"type:int;not null"`                             //涓婄骇id
+		CompanyId         int                   `json:"companyId" gorm:"type:int;not null"`                            //鍏徃id
+		Company           Company               `json:"company" gorm:"foreignKey:CompanyId"`                           //鍏徃
+		Type              constvar.LocationType `json:"type" gorm:"type:tinyint;not null;comment:浣嶇疆绫诲瀷"`                //浣嶇疆绫诲瀷
+		CountFrequency    int                   `json:"countFrequency" gorm:"type:tinyint;not null;comment:鐩樼偣棰戠巼锛堝ぉ锛�"`   //鐩樼偣棰戠巼锛堝ぉ锛�
+		IsScrapLocation   bool                  `json:"isScrapLocation" gorm:"type:tinyint;not null;comment:鏄惁鎶ュ簾浣嶇疆"`   //鏄惁鎶ュ簾浣嶇疆
+		IsReturnLocation  bool                  `json:"isReturnLocation" gorm:"type:tinyint;not null;comment:鏄惁閫�璐т綅缃�"`  //鏄惁閫�璐т綅缃�
+		ReplenishLocation bool                  `json:"replenishLocation" gorm:"type:tinyint;not null;comment:鏄惁琛ュ厖浣嶇疆"` //鏄惁琛ュ厖浣嶇疆
 	}
 
 	LocationSearch struct {
diff --git a/models/product.go b/models/product.go
new file mode 100644
index 0000000..c97e2f1
--- /dev/null
+++ b/models/product.go
@@ -0,0 +1,287 @@
+package models
+
+import (
+	"fmt"
+	"google.golang.org/genproto/googleapis/type/decimal"
+	"gorm.io/gorm"
+	"wms/constvar"
+	"wms/pkg/mysqlx"
+)
+
+type (
+	// Product 浜у搧
+	Product 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:浜у搧鍚嶇О"` //浜у搧鍚嶇О
+		Type       constvar.ProductType `gorm:"type:tinyint;comment:浜у搧绫诲瀷" json:"type"`                     //浜у搧绫诲瀷
+		CategoryId int                  `gorm:"type:int(11);comment:浜у搧鍒嗙被" json:"categoryId"`               //浜у搧鍒嗙被id
+		Category   string               `gorm:"type:int(11);comment:浜у搧鍒嗙被" json:"category"`                 //浜у搧鍒嗙被
+		Specs      string               `gorm:"type:varchar(191);comment:浜у搧瑙勬牸" json:"specs"`               //浜у搧瑙勬牸
+		Model      string               `gorm:"type:varchar(191);comment:浜у搧鍨嬪彿" json:"model"`               //浜у搧鍨嬪彿
+		//MinInventory      decimal.Decimal         `gorm:"type:decimal(20,2);comment:鏈�灏忓簱瀛�" json:"minInventory"` //鏈�澶у簱瀛�
+		//MaxInventory      decimal.Decimal         `gorm:"type:decimal(20,2);comment:鏈�澶у簱瀛�" json:"maxInventory"` //鏈�灏忓簱瀛�
+		//Amount            decimal.Decimal         `gorm:"type:decimal(20,2);comment:鏁伴噺" json:"amount"`
+		//LockAmount        decimal.Decimal         `gorm:"type:decimal(20,2);default:0;comment:閿佸畾鏁伴噺" json:"lockAmount"`
+		Unit         string                 `gorm:"type:varchar(100);comment:鍗曚綅" json:"unit"`           //鍗曚綅
+		PurchaseUnit string                 `gorm:"type:varchar(100);comment:閲囪喘鍗曚綅" json:"purchaseUnit"` //閲囪喘鍗曚綅
+		Note         string                 `gorm:"type:varchar(1024);comment:澶囨敞" json:"note"`
+		Status       constvar.ProductStatus `gorm:"type:int(11);comment:鐘舵��" json:"status"`
+		Purchases    []*PurchaseInfo        `gorm:"-" json:"purchases"` //閲囪喘淇℃伅
+		PurchasesStr string                 `gorm:"column:purchase;type:varchar(4096);comment:璐拱淇℃伅" json:"-"`
+
+		//PurchaseType     constvar.PurchaseType `gorm:"type:int(11);comment:閲囪喘绫诲瀷" json:"purchaseType"`            ///閲囪喘绫诲瀷
+		CanBePurchased   bool            `gorm:"type:int(11);not null;comment:鏄惁鍙噰璐�" json:"purchaseType"`           //鏄惁鍙噰璐�
+		IsSale           bool            `gorm:"type:tinyint(1);comment:鏄惁閿�鍞�" json:"isSale"`                        //鏄惁閿�鍞�
+		SalePrice        decimal.Decimal `gorm:"type:decimal(35,18);comment:閿�鍞崟浠�" json:"salePrice"`                 //閿�鍞环鏍�
+		CustomerTaxes    decimal.Decimal `gorm:"type:decimal(20,2);not null;comment:瀹㈡埛绋�" json:"customerTaxes"`      //瀹㈡埛绋庣櫨鍒嗘瘮
+		Cost             decimal.Decimal `gorm:"type:decimal(20,2);not null;comment:鎴愭湰" json:"cost"`                //鎴愭湰
+		OptionalProducts []int           `gorm:"type:varchar(255);not null;comment:鐩镐技浜у搧id" json:"optionalProducts"` //鐩歌瘑浜у搧
+		Principal        string          `gorm:"type:varchar(255);not null;comment:璐熻矗浜�" json:"principal"`           //璐熻矗浜�
+		Weight           string          `gorm:"type:decimal(20,2);not null;comment:閲嶉噺" json:"weight"`              //閲嶉噺
+		Volume           string          `gorm:"type:decimal(20,2);not null;comment:浣撶Н" json:"volume"`              //浣撶Н
+
+		InternalReference string `gorm:"type:varchar(255);not null;comment:鍐呴儴鍙傝��" json:"internalReference"` //鍐呴儴鍙傝��
+		Barcode           string `gorm:"type:varchar(255);not null;comment:鏉$爜" json:"barcode"`             //鏉$爜
+		Tags              string `gorm:"type:varchar(255);not null;comment:浜у搧鏍囩" json:"tags"`              //浜у搧鏍囩
+		InternalNotes     string `gorm:"type:varchar(512);not null;comment:鍐呴儴璇存槑" json:"internalNotes"`     //鍐呴儴璇存槑
+	}
+
+	ProductSearch struct {
+		Product
+		Order    string
+		PageNum  int
+		PageSize int
+		Keyword  string
+		Orm      *gorm.DB
+		Preload  bool
+	}
+
+	PurchaseInfo struct {
+		PurchasePrice     decimal.Decimal `gorm:"type:decimal(35,18);comment:閲囪喘浠锋牸" json:"purchasePrice"`
+		PurchaseAheadDay  int             `gorm:"type:int(11);comment:閲囪喘鎻愬墠鏈�(澶�)" json:"purchaseAheadDay"`
+		ProduceAheadDay   int             `gorm:"type:int(11);comment:鍒堕�犳彁鍓嶆湡(澶�)" json:"produceAheadDay"`
+		MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忛噰璐噺" json:"minPurchaseAmount"`
+	}
+)
+
+func (slf *Product) TableName() string {
+	return "product"
+}
+
+func (slf *Product) BeforeCreate(db *gorm.DB) error {
+	return nil
+}
+
+func (slf *Product) AfterFind(db *gorm.DB) error {
+	return nil
+}
+
+func NewProductSearch() *ProductSearch {
+	return &ProductSearch{Orm: mysqlx.GetDB()}
+}
+
+func (slf *ProductSearch) SetOrm(tx *gorm.DB) *ProductSearch {
+	slf.Orm = tx
+	return slf
+}
+
+func (slf *ProductSearch) SetPage(page, size int) *ProductSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *ProductSearch) SetOrder(order string) *ProductSearch {
+	slf.Order = order
+	return slf
+}
+
+func (slf *ProductSearch) SetID(id uint) *ProductSearch {
+	slf.ID = id
+	return slf
+}
+
+func (slf *ProductSearch) SetName(name string) *ProductSearch {
+	slf.Name = name
+	return slf
+}
+
+func (slf *ProductSearch) SetKeyword(keyword string) *ProductSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
+func (slf *ProductSearch) SetPreload(preload bool) *ProductSearch {
+	slf.Preload = preload
+	return slf
+}
+
+func (slf *ProductSearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&Product{})
+
+	if slf.ID != 0 {
+		db = db.Where("id = ?", slf.ID)
+	}
+
+	if slf.Order != "" {
+		db = db.Order(slf.Order)
+	}
+
+	if slf.Keyword != "" {
+		db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+	}
+
+	if slf.Name != "" {
+		db = db.Where("name = ?", slf.Name)
+	}
+
+	return db
+}
+
+// Create 鍗曟潯鎻掑叆
+func (slf *ProductSearch) Create(record *Product) error {
+	var db = slf.build()
+
+	if err := db.Create(record).Error; err != nil {
+		return err
+	}
+
+	return nil
+}
+
+// CreateBatch 鎵归噺鎻掑叆
+func (slf *ProductSearch) CreateBatch(records []*Product) error {
+	var db = slf.build()
+
+	if err := db.Create(&records).Error; err != nil {
+		return fmt.Errorf("create batch err: %v, records: %+v", err, records)
+	}
+
+	return nil
+}
+
+func (slf *ProductSearch) Update(record *Product) error {
+	var db = slf.build()
+
+	if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+func (slf *ProductSearch) UpdateByMap(upMap map[string]interface{}) error {
+	var (
+		db = slf.build()
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
+	}
+
+	return nil
+}
+
+func (slf *ProductSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
+	var (
+		db = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
+	}
+
+	return nil
+}
+
+func (slf *ProductSearch) Delete() error {
+	var db = slf.build()
+	return db.Delete(&Product{}).Error
+}
+
+func (slf *ProductSearch) First() (*Product, error) {
+	var (
+		record = new(Product)
+		db     = slf.build()
+	)
+
+	if err := db.First(record).Error; err != nil {
+		return record, err
+	}
+
+	return record, nil
+}
+
+func (slf *ProductSearch) Find() ([]*Product, int64, error) {
+	var (
+		records = make([]*Product, 0)
+		total   int64
+		db      = slf.build()
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, total, nil
+}
+
+func (slf *ProductSearch) FindNotTotal() ([]*Product, error) {
+	var (
+		records = make([]*Product, 0)
+		db      = slf.build()
+	)
+
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, nil
+}
+
+// FindByQuery 鎸囧畾鏉′欢鏌ヨ.
+func (slf *ProductSearch) FindByQuery(query string, args []interface{}) ([]*Product, int64, error) {
+	var (
+		records = make([]*Product, 0)
+		total   int64
+		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find by query count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
+	}
+
+	return records, total, nil
+}
+
+// FindByQueryNotTotal 鎸囧畾鏉′欢鏌ヨ&涓嶆煡璇㈡�绘潯鏁�.
+func (slf *ProductSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Product, error) {
+	var (
+		records = make([]*Product, 0)
+		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
+	}
+
+	return records, nil
+}
diff --git a/models/product_category.go b/models/product_category.go
new file mode 100644
index 0000000..f71115a
--- /dev/null
+++ b/models/product_category.go
@@ -0,0 +1,246 @@
+package models
+
+import (
+	"fmt"
+	"gorm.io/gorm"
+	"wms/constvar"
+	"wms/pkg/mysqlx"
+)
+
+type (
+	// ProductCategory 浜у搧鍒嗙被
+	ProductCategory 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:浣嶇疆鍚嶇О"`        //浣嶇疆鍚嶇О
+		ParentId             int                           `json:"parentId" gorm:"type:int;not null"`                                //涓婄骇id
+		CompanyId            int                           `json:"companyId" gorm:"type:int;not null"`                               //鍏徃id
+		Company              Company                       `json:"company" gorm:"foreignKey:CompanyId"`                              //鍏徃
+		ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;not null;comment:寮哄埗涓嬫灦绛栫暐"` //寮哄埗涓嬫灦绛栫暐
+		CostingMethod        constvar.CostingMethod        `json:"costingMethod" gorm:"type:tinyint;not null;comment:鎴愭湰鏂规硶"`          //鎴愭湰鏂规硶
+		InventoryValuation   constvar.InventoryValuation   `json:"inventoryValuation" gorm:"type:tinyint;not null;comment:鎴愭湰鏂规硶"`     //搴撳瓨璁′环
+	}
+
+	ProductCategorySearch struct {
+		ProductCategory
+		Order    string
+		PageNum  int
+		PageSize int
+		Keyword  string
+		Orm      *gorm.DB
+		Preload  bool
+	}
+)
+
+func (slf *ProductCategory) TableName() string {
+	return "ProductCategory"
+}
+
+func NewProductCategorySearch() *ProductCategorySearch {
+	return &ProductCategorySearch{Orm: mysqlx.GetDB()}
+}
+
+func (slf *ProductCategorySearch) SetOrm(tx *gorm.DB) *ProductCategorySearch {
+	slf.Orm = tx
+	return slf
+}
+
+func (slf *ProductCategorySearch) SetPage(page, size int) *ProductCategorySearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *ProductCategorySearch) SetOrder(order string) *ProductCategorySearch {
+	slf.Order = order
+	return slf
+}
+
+func (slf *ProductCategorySearch) SetID(id uint) *ProductCategorySearch {
+	slf.ID = id
+	return slf
+}
+
+func (slf *ProductCategorySearch) SetName(name string) *ProductCategorySearch {
+	slf.Name = name
+	return slf
+}
+
+func (slf *ProductCategorySearch) SetKeyword(keyword string) *ProductCategorySearch {
+	slf.Keyword = keyword
+	return slf
+}
+
+func (slf *ProductCategorySearch) SetPreload(preload bool) *ProductCategorySearch {
+	slf.Preload = preload
+	return slf
+}
+
+func (slf *ProductCategorySearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&ProductCategory{})
+
+	if slf.ID != 0 {
+		db = db.Where("id = ?", slf.ID)
+	}
+
+	if slf.Order != "" {
+		db = db.Order(slf.Order)
+	}
+
+	if slf.Keyword != "" {
+		db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+	}
+
+	if slf.Name != "" {
+		db = db.Where("name = ?", slf.Name)
+	}
+
+	return db
+}
+
+// Create 鍗曟潯鎻掑叆
+func (slf *ProductCategorySearch) Create(record *ProductCategory) error {
+	var db = slf.build()
+
+	if err := db.Create(record).Error; err != nil {
+		return err
+	}
+
+	return nil
+}
+
+// CreateBatch 鎵归噺鎻掑叆
+func (slf *ProductCategorySearch) CreateBatch(records []*ProductCategory) error {
+	var db = slf.build()
+
+	if err := db.Create(&records).Error; err != nil {
+		return fmt.Errorf("create batch err: %v, records: %+v", err, records)
+	}
+
+	return nil
+}
+
+func (slf *ProductCategorySearch) Update(record *ProductCategory) error {
+	var db = slf.build()
+
+	if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+func (slf *ProductCategorySearch) UpdateByMap(upMap map[string]interface{}) error {
+	var (
+		db = slf.build()
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
+	}
+
+	return nil
+}
+
+func (slf *ProductCategorySearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
+	var (
+		db = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
+	}
+
+	return nil
+}
+
+func (slf *ProductCategorySearch) Delete() error {
+	var db = slf.build()
+	return db.Delete(&ProductCategory{}).Error
+}
+
+func (slf *ProductCategorySearch) First() (*ProductCategory, error) {
+	var (
+		record = new(ProductCategory)
+		db     = slf.build()
+	)
+
+	if err := db.First(record).Error; err != nil {
+		return record, err
+	}
+
+	return record, nil
+}
+
+func (slf *ProductCategorySearch) Find() ([]*ProductCategory, int64, error) {
+	var (
+		records = make([]*ProductCategory, 0)
+		total   int64
+		db      = slf.build()
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, total, nil
+}
+
+func (slf *ProductCategorySearch) FindNotTotal() ([]*ProductCategory, error) {
+	var (
+		records = make([]*ProductCategory, 0)
+		db      = slf.build()
+	)
+
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, nil
+}
+
+// FindByQuery 鎸囧畾鏉′欢鏌ヨ.
+func (slf *ProductCategorySearch) FindByQuery(query string, args []interface{}) ([]*ProductCategory, int64, error) {
+	var (
+		records = make([]*ProductCategory, 0)
+		total   int64
+		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find by query count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
+	}
+
+	return records, total, nil
+}
+
+// FindByQueryNotTotal 鎸囧畾鏉′欢鏌ヨ&涓嶆煡璇㈡�绘潯鏁�.
+func (slf *ProductCategorySearch) FindByQueryNotTotal(query string, args []interface{}) ([]*ProductCategory, error) {
+	var (
+		records = make([]*ProductCategory, 0)
+		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
+	}
+
+	return records, nil
+}

--
Gitblit v1.8.0