From a8914a16b23e93f6bfd12bcfd5cbe8b24cf7eb84 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期日, 07 四月 2024 21:49:01 +0800 Subject: [PATCH] 发货支持仓库传参 --- models/operation.go | 107 +++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 78 insertions(+), 29 deletions(-) diff --git a/models/operation.go b/models/operation.go index f7c37be..bd56ea2 100644 --- a/models/operation.go +++ b/models/operation.go @@ -14,7 +14,7 @@ WmsModel Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Number string `json:"number" gorm:"type:varchar(255)"` //鍗曞彿 - SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� + SourceNumber string `json:"sourceNumber" gorm:"index;type:varchar(255)"` //婧愬崟鍙� OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id OperationTypeName string `json:"operationTypeName" gorm:"type:varchar(127);comment:浣滀笟绫诲瀷鍚嶇О"` //浣滀笟绫诲瀷鍚嶇О Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� @@ -22,18 +22,19 @@ //FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃� //ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id //ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆 - OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"` - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"` - Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` - LogisticCompanyId string `json:"logisticCompanyId" gorm:"type:varchar(191);comment:鐗╂祦鍏徃id"` - LogisticCompany LogisticCompany `json:"logisticCompany" gorm:"foreignKey:LogisticCompanyId"` - WaybillNumber string `json:"waybillNumber" gorm:"type:varchar(255);comment:杩愬崟鍙�"` //杩愬崟鍙� - Weight decimal.Decimal `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"` //閲嶉噺 - LogisticWeight decimal.Decimal `gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺" json:"logisticWeight"` //鐗╂祦閲嶉噺 - Source string `json:"source" gorm:"type:varchar(255);comment:鏉ユ簮绯荤粺,鐢ㄤ簬杩斿洖淇敼鐘舵��"` + OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` + ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` + ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` + CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"` + CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"` + Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` + LogisticCompanyId string `json:"logisticCompanyId" gorm:"type:varchar(191);comment:鐗╂祦鍏徃id"` + LogisticCompany LogisticCompany `json:"logisticCompany" gorm:"foreignKey:LogisticCompanyId"` + WaybillNumber string `json:"waybillNumber" gorm:"type:varchar(255);comment:杩愬崟鍙�"` //杩愬崟鍙� + Weight decimal.Decimal `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"` //閲嶉噺 + LogisticWeight decimal.Decimal `gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺" json:"logisticWeight"` //鐗╂祦閲嶉噺 + Source string `json:"source" gorm:"type:varchar(255);comment:鏉ユ簮绯荤粺,鐢ㄤ簬杩斿洖淇敼鐘舵��"` + OperationSource constvar.OperationSource `json:"operationSource" gorm:"type:tinyint(3);not null;default:0;comment:鎿嶄綔鏉ユ簮"` //鎿嶄綔鏉ユ簮 Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"` BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷 @@ -43,23 +44,25 @@ ReceiverPhone string `json:"receiverPhone" gorm:"type:varchar(31);comment:鑱旂郴鐢佃瘽"` ReceiverAddr string `json:"receiverAddr" gorm:"type:varchar(255);comment:鏀惰揣鍦板潃"` - LocationID int `json:"locationID" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d - Location Location `json:"location" gorm:"foreignkey:LocationID;references:Id"` //婧愪綅缃� - ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:浠撳簱浣嶇疆id"` //鐩爣浣嶇疆id - ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆 + LocationID int `json:"locationID" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d + Location Location `json:"location" gorm:"foreignkey:LocationID;references:Id"` //婧愪綅缃� + ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:浠撳簱浣嶇疆id"` //鐩爣浣嶇疆id + ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆 + SalesDetailsNumber string `gorm:"type:varchar(191);comment:閿�鍞槑缁嗙紪鐮�" json:"salesDetailsNumber"` } OperationSearch struct { Operation - Order string - PageNum int - PageSize int - Keyword string - Orm *gorm.DB - Preload bool - Disuse bool - Ids []int - Numbers []string + Order string + PageNum int + PageSize int + Keyword string + Orm *gorm.DB + Preload bool + Disuse bool + Ids []int + SourceNumbers []string + SalesDetailsNumbers []string } ) @@ -116,6 +119,11 @@ return slf } +func (slf *OperationSearch) SetSourceNumbers(numbers []string) *OperationSearch { + slf.SourceNumbers = numbers + return slf +} + func (slf *OperationSearch) SetDisuse(disuse bool) *OperationSearch { slf.Disuse = disuse return slf @@ -136,6 +144,21 @@ return slf } +func (slf *OperationSearch) SetSalesDetailsNumber(salesDetailsNumber string) *OperationSearch { + slf.SalesDetailsNumber = salesDetailsNumber + return slf +} + +func (slf *OperationSearch) SetSalesDetailsNumbers(salesDetailsNumbers []string) *OperationSearch { + slf.SalesDetailsNumbers = salesDetailsNumbers + return slf +} + +func (slf *OperationSearch) SetOperationSource(operationSource constvar.OperationSource) *OperationSearch { + slf.OperationSource = operationSource + return slf +} + func (slf *OperationSearch) build() *gorm.DB { var db = slf.Orm.Model(&Operation{}) @@ -151,7 +174,11 @@ } if slf.SourceNumber != "" { - db = db.Where("source_number like ?", fmt.Sprintf("%%%v%%", slf.SourceNumber)) + db = db.Where("source_number = ?", slf.SourceNumber) + } + + if len(slf.SourceNumbers) > 0 { + db = db.Where("source_number in (?)", slf.SourceNumbers) } if slf.Number != "" { @@ -163,7 +190,7 @@ } if slf.Preload { - db = db.Model(&Operation{}).Preload("Details").Preload("Details.Product").Preload("LogisticCompany").Preload("Location").Preload("Details.FromLocation").Preload("Details.ToLocation") + db = db.Model(&Operation{}).Preload("Details").Preload("Details.Product").Preload("LogisticCompany").Preload("Location").Preload("ToLocation").Preload("Details.FromLocation").Preload("Details.ToLocation") } if slf.Disuse { @@ -180,6 +207,18 @@ if slf.BaseOperationType != 0 { db = db.Where("base_operation_type = ?", slf.BaseOperationType) + } + + if slf.SalesDetailsNumber != "" { + db = db.Where("sales_details_number = ?", slf.SalesDetailsNumber) + } + + if len(slf.SalesDetailsNumbers) > 0 { + db = db.Where("sales_details_number in (?)", slf.SalesDetailsNumbers) + } + + if slf.OperationSource != 0 { + db = db.Where("operation_source = ?", slf.OperationSource) } return db @@ -298,7 +337,7 @@ if slf.PageNum*slf.PageSize > 0 { db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) } - if err := db.Preload("FromLocation").Preload("ToLocation").Find(&records).Error; err != nil { + if err := db.Find(&records).Error; err != nil { return records, fmt.Errorf("find records err: %v", err) } @@ -354,3 +393,13 @@ } return int(total), nil } + +func (slf *OperationSearch) Count() (int64, error) { + var ( + total int64 + db = slf.build() + ) + + err := db.Count(&total).Error + return total, err +} -- Gitblit v1.8.0