| | |
| | | package models |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "wms/constvar" |
| | | "wms/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | // Product 产品 |
| | | Product struct { |
| | | WmsModel |
| | | Id int `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"` |
| | | Name string `gorm:"index;type:varchar(255);not null;comment:产品名称" json:"name"` //产品名称 |
| | | Type constvar.ProductType `gorm:"type:int(11);comment:产品类型" json:"type"` //产品类型 |
| | | InvoicingStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:开票策略" json:"invoicingStrategy"` |
| | | OrderCreation constvar.OrderCreation `gorm:"type:int(11);comment:订单创建" json:"orderCreation"` |
| | | ObjectTemplateId string `gorm:"type:varchar(191);comment:项目模版id" json:"objectTemplateId"` |
| | | SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"` //销售价格 |
| | | CustomerTaxes decimal.Decimal `gorm:"type:decimal(20,2);comment:客户税" json:"customerTaxes"` //客户税百分比 |
| | | Cost decimal.Decimal `gorm:"type:decimal(20,2);comment:成本" json:"cost"` //成本 |
| | | CategoryId int `gorm:"type:int(11);comment:产品类型id" json:"categoryId"` //产品分类id |
| | | InternalReference string `gorm:"type:varchar(255);comment:内部参考" json:"internalReference"` //内部参考 |
| | | Barcode string `gorm:"type:varchar(255);comment:条码" json:"barcode"` //条码 |
| | | ProductTagId int `gorm:"type:int(11);comment:产品标签id" json:"productTagId"` //产品标签 |
| | | ProductTagName string `gorm:"type:varchar(255);comment:产品标签名称" json:"productTagName"` |
| | | CompanyId int `gorm:"type:int(11);comment:公司id" json:"companyId"` |
| | | CompanyName string `gorm:"type:varchar(255);comment:公司名称" json:"companyName"` |
| | | InternalNotes string `gorm:"type:varchar(512);comment:内部说明" json:"internalNotes"` //内部说明 |
| | | CanBeSell bool `gorm:"type:tinyint(1);comment:是否可销售" json:"canBeSell"` //是否销售 |
| | | SelectProduct int `gorm:"type:int(11);comment:可选产品id" json:"selectProduct"` |
| | | SellExplain string `gorm:"type:varchar(512);comment:销售说明" json:"sellExplain"` |
| | | CanBePurchased bool `gorm:"type:int(11);comment:是否可采购" json:"canBePurchased"` //是否可采购 |
| | | SupplierId int `gorm:"type:int(11);comment:供应商id" json:"supplierId"` |
| | | SupplierName string `gorm:"type:varchar(255);comment:供应商名称" json:"supplierName"` |
| | | Price decimal.Decimal `gorm:"type:decimal(20,2);comment:价格" json:"price"` |
| | | CurrencyId int `gorm:"type:int(11);comment:币种id" json:"currencyId"` |
| | | CurrencyName string `gorm:"type:varchar(255);comment:币种名称" json:"currencyName"` |
| | | DeliveryAdvanceTime decimal.Decimal `gorm:"type:decimal(20,5);comment:提前交货时间" json:"deliveryAdvanceTime"` |
| | | ControlStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:控制策略" json:"controlStrategy"` |
| | | BuyExplain string `gorm:"type:varchar(512);comment:采购说明" json:"buyExplain"` |
| | | Principal string `gorm:"type:varchar(255);comment:负责人" json:"principal"` //负责人 |
| | | Weight decimal.Decimal `gorm:"type:decimal(20,2);comment:重量" json:"weight"` //重量 |
| | | Volume decimal.Decimal `gorm:"type:decimal(20,2);comment:体积" json:"volume"` //体积 |
| | | CustomerAdvanceTime decimal.Decimal `gorm:"type:decimal(20,5);comment:客户前置时间" json:"customerAdvanceTime"` |
| | | HSCode string `gorm:"type:varchar(255);comment:HS编码" json:"HSCode"` |
| | | OriginCountryId int `gorm:"type:int(11);comment:原产地id" json:"originCountryId"` |
| | | OriginCountryName string `gorm:"type:varchar(255);comment:原产地名称" json:"originCountryName"` |
| | | InStorageExplain string `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"` |
| | | OutStorageExplain string `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"` |
| | | InternalTransferExplain string `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"` |
| | | } |
| | | |
| | | 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 "wms_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 |
| | | } |
| | | // |
| | | //import ( |
| | | // "fmt" |
| | | // "github.com/shopspring/decimal" |
| | | // "gorm.io/gorm" |
| | | // "wms/constvar" |
| | | // "wms/pkg/mysqlx" |
| | | //) |
| | | // |
| | | //type ( |
| | | // // Product 产品 |
| | | // Product struct { |
| | | // WmsModel |
| | | // Id int `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"` |
| | | // Name string `gorm:"index;type:varchar(255);not null;comment:产品名称" json:"name"` //产品名称 |
| | | // Type constvar.ProductType `gorm:"type:int(11);comment:产品类型" json:"type"` //产品类型 |
| | | // InvoicingStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:开票策略" json:"invoicingStrategy"` |
| | | // OrderCreation constvar.OrderCreation `gorm:"type:int(11);comment:订单创建" json:"orderCreation"` |
| | | // ObjectTemplateId string `gorm:"type:varchar(191);comment:项目模版id" json:"objectTemplateId"` |
| | | // SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"` //销售价格 |
| | | // CustomerTaxes decimal.Decimal `gorm:"type:decimal(20,2);comment:客户税" json:"customerTaxes"` //客户税百分比 |
| | | // Cost decimal.Decimal `gorm:"type:decimal(20,2);comment:成本" json:"cost"` //成本 |
| | | // CategoryId int `gorm:"type:int(11);comment:产品类型id" json:"categoryId"` //产品分类id |
| | | // InternalReference string `gorm:"type:varchar(255);comment:内部参考" json:"internalReference"` //内部参考 |
| | | // Barcode string `gorm:"type:varchar(255);comment:条码" json:"barcode"` //条码 |
| | | // ProductTagId int `gorm:"type:int(11);comment:产品标签id" json:"productTagId"` //产品标签 |
| | | // ProductTagName string `gorm:"type:varchar(255);comment:产品标签名称" json:"productTagName"` |
| | | // CompanyId int `gorm:"type:int(11);comment:公司id" json:"companyId"` |
| | | // CompanyName string `gorm:"type:varchar(255);comment:公司名称" json:"companyName"` |
| | | // InternalNotes string `gorm:"type:varchar(512);comment:内部说明" json:"internalNotes"` //内部说明 |
| | | // CanBeSell bool `gorm:"type:tinyint(1);comment:是否可销售" json:"canBeSell"` //是否销售 |
| | | // SelectProduct int `gorm:"type:int(11);comment:可选产品id" json:"selectProduct"` |
| | | // SellExplain string `gorm:"type:varchar(512);comment:销售说明" json:"sellExplain"` |
| | | // CanBePurchased bool `gorm:"type:int(11);comment:是否可采购" json:"canBePurchased"` //是否可采购 |
| | | // SupplierId int `gorm:"type:int(11);comment:供应商id" json:"supplierId"` |
| | | // SupplierName string `gorm:"type:varchar(255);comment:供应商名称" json:"supplierName"` |
| | | // Price decimal.Decimal `gorm:"type:decimal(20,2);comment:价格" json:"price"` |
| | | // CurrencyId int `gorm:"type:int(11);comment:币种id" json:"currencyId"` |
| | | // CurrencyName string `gorm:"type:varchar(255);comment:币种名称" json:"currencyName"` |
| | | // DeliveryAdvanceTime decimal.Decimal `gorm:"type:decimal(20,5);comment:提前交货时间" json:"deliveryAdvanceTime"` |
| | | // ControlStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:控制策略" json:"controlStrategy"` |
| | | // BuyExplain string `gorm:"type:varchar(512);comment:采购说明" json:"buyExplain"` |
| | | // Principal string `gorm:"type:varchar(255);comment:负责人" json:"principal"` //负责人 |
| | | // Weight decimal.Decimal `gorm:"type:decimal(20,2);comment:重量" json:"weight"` //重量 |
| | | // Volume decimal.Decimal `gorm:"type:decimal(20,2);comment:体积" json:"volume"` //体积 |
| | | // CustomerAdvanceTime decimal.Decimal `gorm:"type:decimal(20,5);comment:客户前置时间" json:"customerAdvanceTime"` |
| | | // HSCode string `gorm:"type:varchar(255);comment:HS编码" json:"HSCode"` |
| | | // OriginCountryId int `gorm:"type:int(11);comment:原产地id" json:"originCountryId"` |
| | | // OriginCountryName string `gorm:"type:varchar(255);comment:原产地名称" json:"originCountryName"` |
| | | // InStorageExplain string `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"` |
| | | // OutStorageExplain string `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"` |
| | | // InternalTransferExplain string `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"` |
| | | // } |
| | | // |
| | | // 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 "wms_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 |
| | | //} |