From 71288e85afbfc7ac12d5060feb1d29aa139513d6 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 16 四月 2024 20:47:10 +0800
Subject: [PATCH] 增加月度统计库存定时任务,统计期初数量,出入库数量,期末数量

---
 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