From 67b13bb40517145cfadc05d7b22411b16f1528d7 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期三, 17 四月 2024 10:33:07 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- models/operation_details.go | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 39 insertions(+), 8 deletions(-) diff --git a/models/operation_details.go b/models/operation_details.go index d332011..f793077 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -12,8 +12,8 @@ OperationDetails struct { WmsModel Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - OperationID int `json:"operationId" gorm:"type:int;not null;comment:鎿嶄綔璁板綍id"` //鎿嶄綔id - ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id + OperationID int `json:"operationId" gorm:"index;type:int;not null;comment:鎿嶄綔璁板綍id"` //鎿嶄綔id + ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id //ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺 //Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` //鍗曚綅 @@ -31,12 +31,14 @@ OperationDetailsSearch struct { OperationDetails - 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 + OperationIDs []int + Fields string } ) @@ -83,6 +85,16 @@ return slf } +func (slf *OperationDetailsSearch) SetOperationIds(operationIds []int) *OperationDetailsSearch { + slf.OperationIDs = operationIds + return slf +} + +func (slf *OperationDetailsSearch) SetFields(fields string) *OperationDetailsSearch { + slf.Fields = fields + return slf +} + func (slf *OperationDetailsSearch) SetProductId(productId string) *OperationDetailsSearch { slf.ProductId = productId return slf @@ -111,6 +123,14 @@ } if slf.Preload { db = db.Preload("Product") + } + + if len(slf.OperationIDs) > 0 { + db = db.Where("operation_id in ?", slf.OperationIDs) + } + + if slf.Fields != "" { + db = db.Select(slf.Fields) } return db @@ -276,3 +296,14 @@ return records, nil } + +func (slf *OperationDetailsSearch) GroupSum(groupField string, sumField string) ([]*GroupSum, error) { + var ( + db = slf.build() + result = make([]*GroupSum, 0) + ) + if err := db.Select("sum(" + sumField + ") as sum, " + groupField + " as class").Group(groupField).Scan(&result).Error; err != nil { + return nil, fmt.Errorf("select group err: %v", err) + } + return result, nil +} -- Gitblit v1.8.0