From c6e4c58288053493fe62c9a390dfdf8cf1bedf98 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期三, 17 四月 2024 13:57:50 +0800
Subject: [PATCH] 产品添加字段2

---
 models/location_product_amount.go |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/models/location_product_amount.go b/models/location_product_amount.go
index 0d27a70..447b469 100644
--- a/models/location_product_amount.go
+++ b/models/location_product_amount.go
@@ -54,6 +54,7 @@
 		OperationId             int                        `json:"operationId" gorm:"column:operation_id"`
 		Status                  constvar.OperationStatus   `json:"status" gorm:"status"`
 		BaseOperationType       constvar.BaseOperationType `json:"baseOperationType" gorm:"base_operation_type"`
+		Weight                  decimal.Decimal            `gorm:"type:decimal(20,3);comment:閲嶉噺" json:"weight"` //閲嶉噺
 	}
 )
 
@@ -288,3 +289,25 @@
 
 	return nil
 }
+
+func (slf *LocationProductAmountSearch) GroupCount(field string) ([]*GroupCount, error) {
+	var (
+		db     = slf.build()
+		result = make([]*GroupCount, 0)
+	)
+	if err := db.Select("count(*) as total, " + field + " as class").Group(field).Scan(&result).Error; err != nil {
+		return nil, fmt.Errorf("select group err: %v", err)
+	}
+	return result, nil
+}
+
+func (slf *LocationProductAmountSearch) 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