From ea02a2a9a8219d44b103f0a31cf9fc81ff8495e1 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 23 九月 2023 16:57:48 +0800 Subject: [PATCH] 产品列表添加类型名称 --- models/operation.go | 83 +++++++++++++++++++++++++++-------------- 1 files changed, 54 insertions(+), 29 deletions(-) diff --git a/models/operation.go b/models/operation.go index 450bd27..d1c7545 100644 --- a/models/operation.go +++ b/models/operation.go @@ -4,7 +4,6 @@ "fmt" "gorm.io/gorm" "wms/constvar" - "wms/extend/util" "wms/pkg/mysqlx" ) @@ -12,26 +11,30 @@ // Operation 鎿嶄綔琛� Operation struct { WmsModel - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿 - SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� - OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id - Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� - FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d - FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationId"` //婧愪綅缃� - ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id - ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationId"` //鐩爣浣嶇疆 - OperationDate util.JSONTime `json:"operationDate" gorm:"comment:瀹夋帓鏃ユ湡"` - CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` - CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` - Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` - Weight float64 `json:"weight" gorm:"type:decimal;comment:閲嶉噺(kg)"` - TransferWeight float64 `json:"transferWeight" gorm:"type:decimal;comment:鐗╂祦閲嶉噺(kg)"` - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О(kg)"` - Details []*OperationDetails `json:"details"` + 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)"` //婧愬崟鍙� + 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:鐘舵��"` //鐘舵�� + FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d + 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:澶囨敞"` + + Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"` + + //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"` + //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"` + //CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` + //CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` + //Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` } OperationSearch struct { @@ -46,7 +49,7 @@ ) func (slf *Operation) TableName() string { - return "operation" + return "wms_operation" } func NewOperationSearch() *OperationSearch { @@ -68,13 +71,18 @@ return slf } -func (slf *OperationSearch) SetID(id uint) *OperationSearch { - slf.ID = id +func (slf *OperationSearch) SetID(ID int) *OperationSearch { + slf.Id = ID return slf } func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { slf.Keyword = keyword + return slf +} + +func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch { + slf.OperationTypeId = operationTypeId return slf } @@ -86,16 +94,23 @@ func (slf *OperationSearch) build() *gorm.DB { var db = slf.Orm.Model(&Operation{}) - if slf.ID != 0 { - db = db.Where("id = ?", slf.ID) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) } - if slf.Order != "" { db = db.Order(slf.Order) } - if slf.Keyword != "" { - db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) + //if slf.Keyword != "" { + // db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) + //} + + if slf.OperationTypeId != 0 { + db.Where("operation_type_id = ?", slf.OperationTypeId) + } + + if slf.Preload { + db = db.Model(&Operation{}).Preload("Details").Preload("FromLocation").Preload("ToLocation") } return db @@ -123,6 +138,16 @@ return nil } +func (slf *OperationSearch) Save(record *Operation) error { + var db = slf.build() + + if err := db.Omit("CreatedAt").Save(record).Error; err != nil { + return fmt.Errorf("save err: %v, record: %+v", err, record) + } + + return nil +} + func (slf *OperationSearch) Update(record *Operation) error { var db = slf.build() -- Gitblit v1.8.0