From 2f856eaa7e46c884f1cb7ad721919a086d7f34a3 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 13 六月 2024 15:57:45 +0800
Subject: [PATCH] 出入库明细列表和报表增加多单位
---
models/location_product.go | 68 ++++++++++++++++++++++++++-------
1 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/models/location_product.go b/models/location_product.go
index c3f26c6..6a66ba5 100644
--- a/models/location_product.go
+++ b/models/location_product.go
@@ -3,31 +3,34 @@
import (
"fmt"
"gorm.io/gorm"
+ "wms/constvar"
"wms/pkg/mysqlx"
)
type (
LocationProduct struct {
WmsModel
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- LocationId int `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id
- Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"`
- AreaId int `json:"areaId" grom:"type:int;not null;comment:鍖哄煙id"` //鍖哄煙id
- Area Location `json:"area" gorm:"foreignKey:AreaId;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"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ LocationId int `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id
+ Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"`
+ AreaId int `json:"areaId" grom:"type:int;not null;comment:鍖哄煙id"` //鍖哄煙id
+ Area Location `json:"area" gorm:"foreignKey:AreaId;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"`
+ RuleType constvar.RuleType `json:"ruleType" gorm:"type:int(11);not null;comment:涓婃灦瑙勫垯绫诲瀷 1锛氫骇鍝佺被鍨嬶紱2锛氫骇鍝佺被鍒被鍨�"`
}
LocationProductSearch struct {
LocationProduct
- Order string
- PageNum int
- PageSize int
- Keyword string
- Orm *gorm.DB
- Preload bool
+ Order string
+ PageNum int
+ PageSize int
+ Keyword string
+ Orm *gorm.DB
+ Preload bool
+ LocationIds []int
}
)
@@ -79,6 +82,21 @@
return slf
}
+func (slf *LocationProductSearch) SetLocationIds(locationIds []int) *LocationProductSearch {
+ slf.LocationIds = locationIds
+ return slf
+}
+
+func (slf *LocationProductSearch) SetAreaId(areaId int) *LocationProductSearch {
+ slf.AreaId = areaId
+ return slf
+}
+
+func (slf *LocationProductSearch) SetProductCategoryId(productCategoryID int) *LocationProductSearch {
+ slf.ProductCategoryID = productCategoryID
+ return slf
+}
+
func (slf *LocationProductSearch) build() *gorm.DB {
var db = slf.Orm.Model(&LocationProduct{})
@@ -109,6 +127,18 @@
if slf.ProductId != "" {
db = db.Where("product_id=?", slf.ProductId)
+ }
+
+ if len(slf.LocationIds) > 0 {
+ db = db.Where("location_id in (?)", slf.LocationIds)
+ }
+
+ if slf.AreaId != 0 {
+ db = db.Where("area_id = ?", slf.AreaId)
+ }
+
+ if slf.ProductCategoryID != 0 {
+ db = db.Where("product_category_id = ?", slf.ProductCategoryID)
}
return db
@@ -196,3 +226,11 @@
return records, nil
}
+
+func (slf *LocationProductSearch) FirstRes() (*LocationProduct, *gorm.DB) {
+ var (
+ record = new(LocationProduct)
+ db = slf.build()
+ )
+ return record, db.First(record)
+}
--
Gitblit v1.8.0