From 8fb1d1a1389c5f981248b459257ceb1ac4e2b28d Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 31 十月 2023 14:37:02 +0800 Subject: [PATCH] 出入库明细分页修改 --- models/location_product_amount.go | 88 ++++++++++++++++++++++++++++++++++++------- 1 files changed, 73 insertions(+), 15 deletions(-) diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 7ed5dea..00c7b92 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -4,15 +4,22 @@ "fmt" "github.com/shopspring/decimal" "gorm.io/gorm" + "wms/constvar" "wms/pkg/mysqlx" ) type ( LocationProductAmount struct { WmsModel - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - LocationProductId int `json:"locationProductId" gorm:"type:int;not null;comment:涓婃灦瑙勫垯id"` //涓婃灦瑙勫垯id - LocationProduct LocationProduct `json:"locationProduct" gorm:"foreignKey:LocationProductId;references:Id"` + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + //LocationProductId int `json:"locationProductId" gorm:"type:int;not null;comment:涓婃灦瑙勫垯id"` //涓婃灦瑙勫垯id + //LocationProduct LocationProduct `json:"locationProduct" gorm:"foreignKey:LocationProductId;references:Id"` + LocationId int `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id + Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"` + ProductCategoryID int `json:"productCategoryId" gorm:"type:int;not null;comment:浜у搧绉嶇被id"` //浜у搧绉嶇被id + ProductCategory ProductCategory `json:"productCategory"` + ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id + Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:搴撳瓨鏁伴噺"` //搴撳瓨鏁伴噺 CreateDate string `json:"createDate" gorm:"type:varchar(63);comment:鏃ユ湡"` //鏃ユ湡 } @@ -25,21 +32,25 @@ Keyword string Orm *gorm.DB Preload bool + //LocationProductIds []int + LocationIds []int } LocationProductAmountWithOperation struct { //LocationProductAmount LocationProductAmount `json:"locationProductAmount"` - LocationProductAmountId int `json:"locationProductAmount" gorm:"location_product_amount_id"` - LocationId int `json:"locationId" gorm:"column:location_id"` - LocationName string `json:"locationName" gorm:"column:location_name"` - ProductId string `json:"productId" gorm:"column:product_id"` - ProductName string `json:"productName" gorm:"column:product_name"` - Amount decimal.Decimal `json:"amount" gorm:"column:amount"` - Unit string `json:"unit" gorm:"column:unit"` - CreateDate string `json:"createDate" gorm:"column:create_date"` - AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` - DifferenceAmount decimal.Decimal `json:"differenceAmount" gorm:"-"` - OperationId int `json:"operationId" gorm:"column:operation_id"` + LocationProductAmountId int `json:"locationProductAmountId" gorm:"location_product_amount_id"` + LocationId int `json:"locationId" gorm:"column:location_id"` + LocationName string `json:"locationName" gorm:"column:location_name"` + ProductId string `json:"productId" gorm:"column:product_id"` + ProductName string `json:"productName" gorm:"column:product_name"` + Amount decimal.Decimal `json:"amount" gorm:"column:amount"` + Unit string `json:"unit" gorm:"column:unit"` + CreateDate string `json:"createDate" gorm:"column:create_date"` + AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` + DifferenceAmount decimal.Decimal `json:"differenceAmount" gorm:"-"` + OperationId int `json:"operationId" gorm:"column:operation_id"` + Status constvar.OperationStatus `json:"status" gorm:"status"` + BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"base_operation_type"` } ) @@ -81,6 +92,26 @@ return slf } +func (slf *LocationProductAmountSearch) SetProductId(productId string) *LocationProductAmountSearch { + slf.ProductId = productId + return slf +} + +func (slf *LocationProductAmountSearch) SetLocationId(locationId int) *LocationProductAmountSearch { + slf.LocationId = locationId + return slf +} + +//func (slf *LocationProductAmountSearch) SetLocationProductIds(ids []int) *LocationProductAmountSearch { +// slf.LocationProductIds = ids +// return slf +//} + +func (slf *LocationProductAmountSearch) SetLocationIds(ids []int) *LocationProductAmountSearch { + slf.LocationIds = ids + return slf +} + func (slf *LocationProductAmountSearch) build() *gorm.DB { var db = slf.Orm.Model(&LocationProductAmount{}) @@ -96,7 +127,25 @@ } if slf.Preload { - db = db.Model(&LocationProductAmount{}).Preload("LocationProduct").Preload("LocationProduct.Location").Preload("LocationProduct.Product") + db = db.Model(&LocationProductAmount{}).Preload("Location").Preload("Product").Preload("ProductCategory") + } + //if slf.LocationProductId != 0 { + // db = db.Where("location_product_id=?", slf.LocationProductId) + //} + //if len(slf.LocationProductIds) > 0 { + // db = db.Where("location_product_id in (?)", slf.LocationProductIds) + //} + + if len(slf.LocationIds) > 0 { + db = db.Where("location_id in (?)", slf.LocationIds) + } + + if slf.LocationId != 0 { + db = db.Where("location_id = ?", slf.LocationId) + } + + if slf.ProductId != "" { + db = db.Where("product_id=?", slf.ProductId) } return db @@ -184,3 +233,12 @@ return records, nil } + +func (slf *LocationProductAmountSearch) FirstRes() (*LocationProductAmount, *gorm.DB) { + var ( + record = new(LocationProductAmount) + db = slf.build() + ) + + return record, db.First(&record) +} -- Gitblit v1.8.0